-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
executable file
·66 lines (55 loc) · 2 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
58
59
60
61
62
63
64
65
66
import flask, os, sqlite3, json
app = flask.Flask("Xeonpanel", template_folder="themes/{}".format(json.loads(open("config.json", "r").read())["theme"]))
app.config["MAINTENANCE_MODE"] = False
app.config["DEVELOPMENT_MODE"] = True
app.config["SECRET_KEY"] = json.loads(open("config.json", "r").read())["secret"]
def query(sql, *parameter):
conn = sqlite3.connect("database.db", check_same_thread=False)
cursor = conn.cursor()
data = cursor.execute(sql, (parameter)).fetchall()
conn.commit()
return data
if not os.path.isfile("database.db"):
import routers.setup
else:
@app.get("/setup/finish")
def setup_reboot_server():
return flask.redirect("/")
import routers.dashboard, routers.auth, routers.api, routers.server
import admin.settings, admin.nodes, admin.servers, admin.images, admin.users
@app.before_request
def maintenance():
if app.config["MAINTENANCE_MODE"]:
flask.abort(503)
else:
if not "/setup" in flask.request.path:
if not "/static" in flask.request.path:
if not os.path.isfile("database.db"):
return flask.redirect("/setup/getting-started")
elif "/setup/reboot" in flask.request.path:
return flask.redirect("/")
@app.errorhandler(503)
def error_503(error):
return flask.render_template("/errors/503.html")
@app.errorhandler(404)
def error_404(error):
return flask.render_template("/errors/404.html")
@app.errorhandler(401)
def error_401(error):
return flask.render_template("/errors/401.html")
@app.get("/logout")
def logout():
if flask.session:
if flask.request.args["csrf"] == flask.session["csrf_token"]:
flask.session.clear()
return flask.redirect("/")
@app.get("/")
def main():
if flask.session:
return flask.redirect("/dashboard")
else:
return flask.redirect("/login")
if app.config["DEVELOPMENT_MODE"]:
app.run(debug=True, host="0.0.0.0", port=5000)
else:
app.run(debug=False, host="0.0.0.0", port=5000)