add waitress as production WSGI server

This commit is contained in:
lare 2022-11-19 18:12:01 +01:00
parent 85135dd449
commit 7d5937f3fb
4 changed files with 19 additions and 7 deletions

View file

@ -1,16 +1,18 @@
{
"nodes": {
"<nodename>": {
"pub-endpoint": "<clearnet-fqdn/ip-address>", //optional, recommended
"pub-endpoint": "<clearnet-fqdn/ip-address>", //optional, recommended, default: None/null
"api-con": "http://<node-(internal)-ip/hostname>:<port>/", // 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-please-replace>", // secret key for session cookies
"flask-template-dir": "../frontend/" // optional; default "../frontend"

View file

@ -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"]
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__":

View file

@ -8,7 +8,7 @@
<link rel="stylesheet" href="{{config['base-dir']}}static/style.css">
</head>
<body>
<header class="flex flex-row"><div></div><a href="{{config['base-dir']}}">{{config["MNT"]}} Autopeering</a>{% if "login" in session %}<a href="{{config['base-dir']}}logout">logout</a>{% else %} <a href="{{config['base-dir']}}login?return=/peer">login</a>{%endif%}</header>
<header class="flex flex-row"><div></div><a href="{{config['base-dir']}}">{{config["MNT"]}} Autopeering</a>{% if "login" in session %}<a href="{{config['base-dir']}}logout">logout</a>{% else %} <a href="{{config['base-dir']}}login?return=/peerings">login</a>{%endif%}</header>
<div class="content flex">
{% block content %}
{% endblock %}

View file

@ -1,2 +1,3 @@
Flask
waitress
pyopenssl