/python/webapp/app.py

https://github.com/Sidnicious/0xfe-experiments
Python | 60 lines | 44 code | 14 blank | 2 comment | 1 complexity | 065dbe8273e8337605e06f710d2021ee MD5 | raw file
  1. #!/usr/bin/env python2.7
  2. # Built for tornado 1.2
  3. import json
  4. import logging
  5. import os
  6. import tornado.options
  7. from tornado import auth, ioloop, web
  8. from tornado.options import define, options
  9. from vexweb.handlers import BaseHandler, GET
  10. from login import DBLoginHandler
  11. from models.api import APIFactory
  12. define("port", default=8888, help="HTTP listen port.")
  13. define("cookie_secret", default="boo baa", help="Encrypted cookie key.")
  14. tornado.options.parse_command_line()
  15. logging.basicConfig(level=logging.INFO)
  16. class Config:
  17. port = int(options.port)
  18. base_path = os.path.dirname(__file__)
  19. web_settings = {
  20. "static_path": os.path.join(base_path, "static"),
  21. "template_path": base_path + "/templates",
  22. "cookie_secret": options.cookie_secret,
  23. "login_url": "/login",
  24. "xsrf_cookies": True
  25. }
  26. class MainHandler(BaseHandler):
  27. def process_fail(self, message):
  28. user = self.current_user
  29. self.add_error(message)
  30. self.render_template("frontpage.html", action="Unknown", user=user)
  31. @web.authenticated
  32. @GET
  33. def list(self):
  34. self.render_template("frontpage.html", action="list", user=user)
  35. if __name__ == "__main__":
  36. application = web.Application([
  37. (r"/", MainHandler),
  38. (r"/login", DBLoginHandler)
  39. ], **Config.web_settings)
  40. application.vexconfig = Config()
  41. api = APIFactory()
  42. api.create_tables()
  43. application.model_api = api
  44. application.listen(Config.port)
  45. logging.info("Starting HTTP Server on port %d" % Config.port)
  46. ioloop.IOLoop.instance().start()