forked from inpanel/inpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·83 lines (70 loc) · 2.73 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
81
82
83
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 - 2019, doudoudzj
# Copyright (c) 2012 - 2016, VPSMate development team
# All rights reserved.
#
# InPanel is distributed under the terms of The New BSD License.
# The full license can be found in 'LICENSE'.
import os
import shlex
import subprocess
import sys
root_path = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(root_path, 'lib'))
import tornado.httpserver
import tornado.ioloop
from modules import web
from modules.config import Config
from modules.utils import make_cookie_secret
def write_pid():
pidfile = '/var/run/inpanel.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'),
'conf_path': os.path.join(root_path, 'data', 'config.ini'),
'index_path': os.path.join(root_path, 'static', 'index.html'),
'static_path': os.path.join(root_path, 'static'),
'xsrf_cookies': True,
'cookie_secret': make_cookie_secret(),
}
application = web.Application([
(r'/xsrf', web.XsrfHandler),
(r'/authstatus', web.AuthStatusHandler),
(r'/login', web.LoginHandler),
(r'/logout', web.LogoutHandler),
(r'/query/(.+)', web.QueryHandler),
(r'/utils/network/(.+?)(?:/(.+))?', web.UtilsNetworkHandler),
(r'/utils/process/(.+?)(?:/(.+))?', web.UtilsProcessHandler),
(r'/utils/time/(.+?)(?:/(.+))?', web.UtilsTimeHandler),
(r'/utils/ssl/(.+?)(?:/(.+))?', web.UtilsSSLHandler),
(r'/setting/(.+)', web.SettingHandler),
(r'/operation/(.+)', web.OperationHandler),
(r'/page/(.+)/(.+)', web.PageHandler),
(r'/backend/(.+)', web.BackendHandler),
(r'/sitepackage/(.+)', web.SitePackageHandler),
(r'/client/(.+)', web.ClientHandler),
(r'/((?:css|js|js.min|lib|partials|images|favicon\.ico|robots\.txt)(?:\/.*)?)',
web.StaticFileHandler, {'path': settings['static_path']}),
(r'/($)', web.StaticFileHandler, {'path': settings['index_path']}),
(r'/file/(.+)', web.FileDownloadHandler, {'path': '/'}),
(r'/fileupload', web.FileUploadHandler),
(r'/version', web.VersionHandler),
(r'/.*', web.ErrorHandler, {'status_code': 404}),
], **settings)
# read configuration from config.ini
cfg = Config(settings['conf_path'])
server_ip = cfg.get('server', 'ip')
server_port = cfg.get('server', 'port')
server = tornado.httpserver.HTTPServer(application)
server.listen(server_port, address=server_ip)
write_pid()
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()