diff options
Diffstat (limited to 'server.py')
-rw-r--r-- | server.py | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/server.py b/server.py deleted file mode 100644 index 4159736..0000000 --- a/server.py +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | import os | ||
2 | import subprocess | ||
3 | import tornado.web | ||
4 | import tornado.ioloop | ||
5 | import tornado.options | ||
6 | import tornado.process | ||
7 | import tornado.template | ||
8 | import tornado.httpserver | ||
9 | from mfiapi import MFiAPI | ||
10 | from tornado.options import define, options | ||
11 | |||
12 | define("port", default=8888, help="run on the given port", type=int) | ||
13 | |||
14 | |||
15 | class PowerStatusHandler(tornado.web.RequestHandler): | ||
16 | |||
17 | def __init__(self, *args, **kwargs): | ||
18 | self.api = MFiAPI('172.16.0.38:6443') | ||
19 | super(PowerStatusHandler, self).__init__(*args, **kwargs) | ||
20 | |||
21 | def get(self): | ||
22 | self.api.login('admin', 'password') | ||
23 | self.finish(self.api.port_status()) | ||
24 | |||
25 | def post(self): | ||
26 | self.api.login('admin', 'password') | ||
27 | |||
28 | for key, value in self.request.arguments.items(): | ||
29 | self.api.toggle_port(key) | ||
30 | |||
31 | |||
32 | class IndexHandler(tornado.web.RequestHandler): | ||
33 | |||
34 | def __init__(self, *args, **kwargs): | ||
35 | self.api = MFiAPI('172.16.0.38:6443') | ||
36 | super(IndexHandler, self).__init__(*args, **kwargs) | ||
37 | |||
38 | def get(self): | ||
39 | self.api.login('admin', 'password') | ||
40 | |||
41 | ports = [(port, port.replace(" ", "_").replace("'", "-")) for port in self.api.port_status().keys()] | ||
42 | |||
43 | self.render("index.html", ports=ports) | ||
44 | |||
45 | |||
46 | class Application(tornado.web.Application): | ||
47 | |||
48 | def __init__(self): | ||
49 | handlers = [ | ||
50 | (r"/power-status/?", PowerStatusHandler), | ||
51 | (r"/?", IndexHandler), | ||
52 | ] | ||
53 | settings = dict( | ||
54 | template_path=os.path.join(os.path.dirname(__file__), "templates"), | ||
55 | static_path=os.path.join(os.path.dirname(__file__), "static"), | ||
56 | debug=True, | ||
57 | autoescape=None, | ||
58 | ) | ||
59 | tornado.web.Application.__init__(self, handlers, **settings) | ||
60 | |||
61 | |||
62 | if __name__ == "__main__": | ||
63 | tornado.options.parse_command_line() | ||
64 | http_server = tornado.httpserver.HTTPServer(Application()) | ||
65 | http_server.listen(options.port) | ||
66 | tornado.ioloop.IOLoop.instance().start() | ||