From cc8f181f24b551e1a1d283462bf91f602d62fb62 Mon Sep 17 00:00:00 2001 From: lare Date: Sat, 19 Nov 2022 18:12:01 +0100 Subject: [PATCH] add waitress as production WSGI server --- web/backend/config.sample.json | 9 ++++++--- web/backend/main.py | 14 +++++++++++--- web/frontend/base.html | 2 +- web/requirements.txt | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/web/backend/config.sample.json b/web/backend/config.sample.json index cb7625b..8805f79 100644 --- a/web/backend/config.sample.json +++ b/web/backend/config.sample.json @@ -1,16 +1,18 @@ { "nodes": { "": { - "pub-endpoint": "", //optional, recommended + "pub-endpoint": "", //optional, recommended, default: None/null "api-con": "http://:/", // required - "comment": "/* from here: data to be displayed on the webinterface */", + "#comment": "/* from here: data to be displayed on the webinterface */", "country": "...", // Countrycode: 2 capital letters "city": "...", "wg-key": "...=", // pubkey of node; required "internal-v4": "172.2x.xxx.xxx", //at least one ipv{4,6} addr required "internal-v6": "fdxx:...", "internal-v4ll": "169.254.xxx.xxx", - "internal-v6ll": "fe80::..." + "internal-v6ll": "fe80::...", + "note": "...", //optional, special precausions, like only supporting a specific amount of peers/ipv{4,6} in clearnet, etc + "capacity": 100 //optional, default: -1 (infinite); estimated capacity of that node (i.e. OPENVZ(7) only has userspace WG (which consumes memory for every interface created)) } }, "MNT": "YOUR-MNT", // your MNT tag @@ -18,6 +20,7 @@ "port": 8042, "domain": "example.org", // domain to use for kioubit verification service "base-dir": "/", //optional:directury for which it is reachable (if behind some sort of reverse proxy) default "/" + "production": true, //optional, default true; "debug-mode": false, // optional; whethet to enable debugging; default false "flask-secret-key": "", // secret key for session cookies "flask-template-dir": "../frontend/" // optional; default "../frontend" diff --git a/web/backend/main.py b/web/backend/main.py index 4025915..bdd987a 100644 --- a/web/backend/main.py +++ b/web/backend/main.py @@ -21,6 +21,9 @@ class Config (dict): #self.__getitem__ = self._config.__getitem__ super().__init__(self) + def __contains__(self, o): + return self._config.__contains__(o) + def __delitem__(self, v): raise NotImplementedError() super().__delitem__(self,v) @@ -96,12 +99,12 @@ def login(): asn = asn[2:] if asn[:1].lower() == "as" else asn if "allowed4" in request.form: allowed4 = request.form["allowed4"] - allowed4 = allowed_v4.split(",") if "," in allowed_v4 else allowed_v4 + allowed4 = allowed4.split(",") if "," in allowed4 else allowed4 else: allowed4 = None if "allowed6" in request.form: allowed6 = request.form["allowed6"] - allowed6 = allowed_v6.split(",") if "," in allowed_v6 else allowed_v6 + allowed6 = allowed6.split(",") if "," in allowed6 else allowed6 else: allowed6 = None session["user-data"] = {'asn':asn,'allowed4': allowed4, 'allowed6': allowed6,'mnt':mnt, 'authtype': "debug"} @@ -152,7 +155,12 @@ def main(): app.static_folder= config["flask-template-dir"]+"/static/" app.template_folder=config["flask-template-dir"] app.secret_key = config["flask-secret-key"] - app.run(host=config["listen"], port=config["port"], debug=config["debug-mode"], threaded=True) + if "production" in config and config["production"] == False: + app.run(host=config["listen"], port=config["port"], debug=config["debug-mode"], threaded=True) + else: + from waitress import serve + serve(app, host=config["listen"], port=config["port"]) + if __name__ == "__main__": diff --git a/web/frontend/base.html b/web/frontend/base.html index b1b1d8a..e8b1e98 100644 --- a/web/frontend/base.html +++ b/web/frontend/base.html @@ -8,7 +8,7 @@ -
{{config["MNT"]}} Autopeering{% if "login" in session %}logout{% else %} login{%endif%}
+
{{config["MNT"]}} Autopeering{% if "login" in session %}logout{% else %} login{%endif%}
{% block content %} {% endblock %} diff --git a/web/requirements.txt b/web/requirements.txt index 7cf74ff..1309823 100644 --- a/web/requirements.txt +++ b/web/requirements.txt @@ -1,2 +1,3 @@ Flask +waitress pyopenssl \ No newline at end of file