-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
64 lines (47 loc) · 1.3 KB
/
server.py
File metadata and controls
64 lines (47 loc) · 1.3 KB
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
from bottle import post, run, request, response
from os import environ
from DB import AnalyticsDB
db = AnalyticsDB()
install_validations = {
"uuid": str,
"ver": str,
"mmc": str,
"inst": str,
"sys": str
}
crash_validations = {
"exc": str,
"email": str,
"notes": str,
"uuid": str,
"ver": str
}
base = ""
if "OMM_BASE_PATH" in environ:
base = environ["OMM_BASE_PATH"]
def validate_request(req: request, validations: dict):
for i in validations:
if i not in req.json:
return False
if type(req.json[i]) != validations[i]:
return False
return True
@post(base+"/installed")
def installed():
if not validate_request(request, install_validations):
response.status = 401
return
ip = int(request.get_header("CF-Connecting-IP", "0.0.0.0").split(".")[-1])
loc = request.get_header("CF-IPCountry", "XX")
rj = request.json
db.insert_anal(rj["ver"], loc, ip, rj["uuid"], rj["mmc"], rj["inst"], rj["sys"])
return
@post(base+"/crash")
def crashed():
if not validate_request(request, crash_validations):
response.status = 401
return
rj = request.json
db.insert_crash(rj["ver"], rj["exc"], rj["email"], rj["notes"], rj["uuid"])
return
run(host="0.0.0.0", port=9615)