-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.py
59 lines (49 loc) · 1.86 KB
/
webserver.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
import cherrypy, config
def _get_verify_html(key, user):
key = str(key)
user = str(user)
f = open("web/verify.html", "r")
cts = f.read().replace("{{key}}", key).replace("{{user}}", user).replace("{{domain}}", config.domain).replace("{{port}}", config.port).replace("{{protocol}}", config.websocket_protocol)
f.close()
return cts
def _get_html(key, user):
key = str(key)
user = str(user)
f = open("web/forget.html", "r")
cts = f.read().replace("{{key}}", key).replace("{{user}}", user).replace("{{domain}}", config.domain).replace("{{port}}", config.port).replace("{{protocol}}", config.websocket_protocol)
f.close()
return cts
def change_to_user():
try:
if os.name == 'posix':
pw = pwd.getpwnam("chat")
uid = pw.pw_uid
os.setuid(uid)
##--- create file as test of permissions
except Exception as e:
print(e) # Error
class RootServer:
@cherrypy.expose
def index(self, **keywords):
change_to_user()
return _get_html(cherrypy.request.params.get("key"), cherrypy.request.params.get("user"))
@cherrypy.expose("/verify")
def verify(self, **keywords):
change_to_user()
return _get_verify_html(cherrypy.request.params.get("key"), cherrypy.request.params.get("user"))
if __name__ == '__main__':
if config.use_ssl:
server_config={
'server.socket_host': '0.0.0.0',
'server.socket_port': config.webserver_port,
'server.ssl_module': 'builtin',
'server.ssl_private_key': config.ssl_key,
'server.ssl_certificate': config.ssl_cert
}
else:
server_config={
'server.socket_host': '0.0.0.0',
'server.socket_port': config.webserver_port
}
cherrypy.config.update(server_config)
cherrypy.quickstart(RootServer())