-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (48 loc) · 1.38 KB
/
app.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
from bottle import Bottle, route, run, template, static_file, request, error, hook, get, post, server_names
import os.path
import uuid
import bottle
import datetime
import logging
logging.basicConfig(level=logging.INFO, filename="log/log.txt", filemode="a+",
format='%(asctime)s - %(message)s')
@route('/static/<type>/<filename>')
def serve_css(type, filename):
return static_file(filename, root=type+'/')
lab_open = False
def get_secret():
file = "log/secret.txt"
if not os.path.isfile(file):
with open(file, "w") as f:
f.write((str)(uuid.uuid4()))
f.flush()
with open(file, "r") as f:
return f.readline()
@get('/set_status/<status>/<secret>')
def set_status(status, secret):
if secret != get_secret():
print("wrong secret")
return "wrong secret"
global lab_open
if status == "open":
print("lab opened")
lab_open = True
if status == "closed":
print("lab closed")
lab_open = False
return "ok"
@get('/')
def main():
lab_status = "geschlossen"
if lab_open:
lab_status = "offen"
return template("main.tpl", lab_status=lab_status)
@get('/get_status')
def get_status():
if lab_open:
return "open"
else:
return "closed"
logging.info("Starting Service")
run(host='0.0.0.0', port=10127)
logging.info("Finishing Service")