-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.py
109 lines (95 loc) · 3.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
""" Main application for public release"""
import tornado.auth
import tornado.escape
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.log
import Settings
import jira_ticket
from tornado.options import define, options
import base64
import netaddr
import bcrypt
define("port", default=8080, help="run on the given port", type=int)
class BaseHandler(tornado.web.RequestHandler):
def get_current_user(self):
return self.get_secure_cookie("user")
class MainHandler(tornado.web.RequestHandler):
"""
Class that handle most of the request, all the rest of the handling is done
by page.js
"""
@tornado.web.asynchronous
def get(self, path = ''):
self.render('index.html', rootPath = r'{}/'.format(Settings.APP_ROOT))
#passwords = read_passwd_file()
#if verify_password(passwords, basicauth_user, basicauth_pass):
#self.render('index.html')
class EasywebBypassHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self, path = ''):
self.render('easyweb_bypass.html')
class HelpHandler(tornado.web.RequestHandler):
"""
This class is special as it also include a post request to
deal with the form submission
"""
@tornado.web.asynchronous
def post(self):
arguments = { k.lower(): self.get_argument(k) for k in self.request.arguments }
print(arguments)
name = self.get_argument("name", "")
last = self.get_argument("lastname", "")
email = self.get_argument("email", "")
subject = self.get_argument("subject", "")
question = self.get_argument("question", "")
topic = self.get_argument("topic", "")
topics = topic.replace(',', '\n')
print(name, last, email, topic, question)
jira_ticket.create_ticket(name, last, email, topics, subject, question)
self.set_status(200)
self.flush()
self.finish()
class My404Handler(tornado.web.RequestHandler):
"""
Handles 404 requests, basically bust just changin the status to 404
"""
def get(self):
self.set_status(404)
self.render('index.html', chichi=False)
def post(self):
self.set_status(404)
self.render('index.html', chichi=False)
class Application(tornado.web.Application):
"""
The tornado application class
"""
def __init__(self):
# The order of the route handlers matters!
handlers = [
(r"{}".format(Settings.APP_ROOT), MainHandler),
(r"{}/static/(.*)".format(Settings.APP_ROOT), tornado.web.StaticFileHandler, {'path':Settings.STATIC_PATH}),
(r"{}/help/".format(Settings.APP_ROOT), HelpHandler),
(r"{}/releases/sva1/content/(.*)".format(Settings.APP_ROOT), tornado.web.StaticFileHandler, {'path':Settings.SVA1_PATH}),
(r"{}/easyweb(.*)".format(Settings.APP_ROOT), EasywebBypassHandler),
(r"{}/(.*)".format(Settings.APP_ROOT), MainHandler),
]
settings = {
"template_path":Settings.TEMPLATE_PATH,
"debug":Settings.DEBUG,
"default_handler_class": My404Handler,
}
tornado.web.Application.__init__(self, handlers, **settings)
def main():
"""
The main function
"""
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
#http_server = tornado.httpserver.HTTPServer(Application(), ssl_options={"certfile": "/etc/httpd/ssl/des.crt", "keyfile": "/etc/httpd/ssl/des.key",})
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()