-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
101 lines (85 loc) · 3.26 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os,re
from http import server
from bottle import Bottle, ServerAdapter, static_file,template, request
import process,utils
def start():
global server
class MyServer(ServerAdapter):
server = None
def run(self, handler):
from wsgiref.simple_server import make_server, WSGIRequestHandler
if self.quiet:
class QuietHandler(WSGIRequestHandler):
def log_request(*args, **kw): pass
self.options['handler_class'] = QuietHandler
self.server = make_server(self.host, self.port, handler, **self.options)
self.server.serve_forever()
def stop(self):
self.server.shutdown()
app = Bottle()
@app.route('/')
def index():
return template(utils.base_path +"templates/index.tpl")
@app.route('/css/<filename>')
def server_static(filename):
return static_file(filename, root=utils.base_path + "css")
@app.route('/data/<filename>')
def server_static(filename):
return static_file(filename, root='./data')
@app.route('/logs/<filename>')
def server_static(filename):
return static_file(filename, root='./logs')
@app.route('/pob/builds/<filename>')
def server_static(filename):
return static_file(filename, root='./pob/builds')
@app.route("/log")
def log():
return template(utils.base_path +"templates/log.tpl")
@app.route('/logdata', method="POST")
def logupdate():
logdata = []
lastlog = 0
if "lastlog" in request.forms.dict:
lastlog = parsedate(request.forms.get("lastlog"))
try:
f = open("poeclog.log", encoding='utf-8', errors='ignore')
for li in f.readlines():
if parsedate(li) > lastlog:
logdata.append(li)
except:
pass
finally:
f.close()
return {"loglines": logdata}
@app.route("/settings")
def settings():
return template(utils.base_path +"templates/settings.tpl")
@app.route("/savesettings", method='POST')
def savesettings():
message = "Settings Saved OK"
if "clientlog" in request.POST:
utils.setopt("clientlog",request.POST["clientlog"])
if not os.path.exists(request.POST["clientlog"]):
message = "Client Log not found"
if "account" in request.POST:
utils.setopt("account",request.POST["account"])
api = process.getprofile()
if api.status_code != 200:
message = "Account not found or private?"
return template(utils.base_path +"templates/settings.tpl",{"message": message,"options": utils.options})
server = MyServer(port=utils.getopt("port"))
try:
app.run(server=server)
except:
print('server error')
finally:
print("server closed")
def stop():
global server
server.stop()
def parsedate(datestr):
vals = re.search(r"^([0-9]+)/([0-9]+)/([0-9]+), ([0-9]+):([0-9]+):([0-9]+)",datestr)
if vals:
return int(vals.groups()[2].zfill(4) + vals.groups()[1].zfill(2) + vals.groups()[0].zfill(2) + vals.groups()[3].zfill(2) + vals.groups()[4].zfill(2) + vals.groups()[5].zfill(2))
else:
return 0