forked from fanshengshuai/VPSMate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·80 lines (67 loc) · 2.67 KB
/
server.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012, VPSMate development team
# All rights reserved.
#
# VPSMate is distributed under the terms of the (new) BSD License.
# The full license can be found in 'LICENSE.txt'.
import os
import sys
import subprocess
import shlex
root_path = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(root_path, 'lib'))
import tornado.ioloop
import tornado.httpserver
import vpsmate.web
import vpsmate.config
from vpsmate.utils import make_cookie_secret
def write_pid():
pidfile = '/var/run/vpsmate.pid'
pidfp = open(pidfile, 'w')
pidfp.write(str(os.getpid()))
pidfp.close()
def main():
# settings of tornado application
settings = {
'root_path': root_path,
'data_path': os.path.join(root_path, 'data'),
'static_path': os.path.join(root_path, 'static'),
'xsrf_cookies': True,
'cookie_secret': make_cookie_secret(),
}
application = vpsmate.web.Application([
(r'/xsrf', vpsmate.web.XsrfHandler),
(r'/authstatus', vpsmate.web.AuthStatusHandler),
(r'/login', vpsmate.web.LoginHandler),
(r'/logout', vpsmate.web.LogoutHandler),
(r'/query/(.+)', vpsmate.web.QueryHandler),
(r'/utils/network/(.+?)(?:/(.+))?', vpsmate.web.UtilsNetworkHandler),
(r'/utils/time/(.+?)(?:/(.+))?', vpsmate.web.UtilsTimeHandler),
(r'/setting/(.+)', vpsmate.web.SettingHandler),
(r'/operation/(.+)', vpsmate.web.OperationHandler),
(r'/page/(.+)/(.+)', vpsmate.web.PageHandler),
(r'/backend/(.+)', vpsmate.web.BackendHandler),
(r'/sitepackage/(.+)', vpsmate.web.SitePackageHandler),
(r'/client/(.+)', vpsmate.web.ClientHandler),
(r'/((?:css|js|js.min|lib|partials|images|favicon\.ico|robots\.txt)(?:\/.*)?)',
vpsmate.web.StaticFileHandler, {'path': settings['static_path']}),
(r'/($)', vpsmate.web.StaticFileHandler,
{'path': settings['static_path'] + '/index.html'}),
(r'/file/(.+)', vpsmate.web.FileDownloadHandler, {'path': '/'}),
(r'/fileupload', vpsmate.web.FileUploadHandler),
(r'/version', vpsmate.web.VersionHandler),
(r'/.*', vpsmate.web.ErrorHandler, {'status_code': 404}),
], **settings)
# read configuration from config.ini
cfg = vpsmate.config.Config(settings['data_path'] + '/config.ini')
server_ip = cfg.get('server', 'ip')
server_port = cfg.get('server', 'port')
# subprocess.call(shlex.split("set LANG=en"))
server = tornado.httpserver.HTTPServer(application)
server.listen(server_port, address=server_ip)
write_pid()
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()