diff --git a/web/__init__.py b/web/__init__.py index adc8cb1..ac9aac3 100644 --- a/web/__init__.py +++ b/web/__init__.py @@ -96,6 +96,8 @@ def create_app(test_config=None): version = db.load('settings').get('version') nodes = db.read('nodes') return flask.render_template('nodes.html', version=version, nodes=nodes) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') diff --git a/web/config.py b/web/config.py index ef0102f..96f20f2 100644 --- a/web/config.py +++ b/web/config.py @@ -21,6 +21,8 @@ def index(): system.run(system.save_config) settings = db.read('settings') return flask.render_template('config/index.html', **locals()) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') @@ -37,6 +39,8 @@ def edit(name): system.run(system.save_config) content = json.dumps(db.load(name), indent=2) return flask.render_template('config/edit.html', **locals()) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') diff --git a/web/nat.py b/web/nat.py index 9d11807..daa5b20 100644 --- a/web/nat.py +++ b/web/nat.py @@ -27,7 +27,8 @@ def index(): return flask.redirect(flask.url_for('nat.index')) return flask.render_template('nat/index.html', nat=nat) - + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') diff --git a/web/rules.py b/web/rules.py index eacc9f0..b9b843b 100644 --- a/web/rules.py +++ b/web/rules.py @@ -27,6 +27,8 @@ def index(): system.run(system.save_config) return flask.render_template('rules/index.html', rules=db.load('rules')) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') @@ -51,6 +53,8 @@ def edit(index): return flask.render_template('rules/edit.html', index=index, rule=db.load('rules')[index]) except IndexError as e: return flask.Response(f'invalid rule: {index}', status=400, mimetype='text/plain') + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') @@ -65,6 +69,8 @@ def manage(): rules = [rule|{'index': index} for index, rule in enumerate(db.load('rules')) if can_toggle(flask_login.current_user, rule)] return flask.render_template('rules/manage.html', rules=rules) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') @@ -83,6 +89,8 @@ def toggle(index, enable): return flask.redirect(flask.url_for('rules.manage')) except IndexError as e: return flask.Response(f'invalid rule: {index}', status=400, mimetype='text/plain') + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') diff --git a/web/templates/busy.html b/web/templates/busy.html new file mode 100644 index 0000000..5bd9653 --- /dev/null +++ b/web/templates/busy.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} + +{% block content %} +

+Strežnik je zaseden, poskusite znova pozneje. +{% endblock %} diff --git a/web/vpn.py b/web/vpn.py index e76a691..0f3cbd6 100644 --- a/web/vpn.py +++ b/web/vpn.py @@ -24,6 +24,8 @@ def list(): try: user = flask_login.current_user.get_id() return flask.jsonify({k: v for k, v in db.load('wireguard').items() if v.get('user') == user}) + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'failed: {e}', status=500, mimetype='text/plain') @@ -75,7 +77,8 @@ def new(): 'use_dns': flask.request.json.get('use_dns', True), } return flask.render_template('vpn/wg-fri.conf', **args) - + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain') @@ -96,7 +99,8 @@ def delete(): system.run(system.save_config) return flask.Response(f'deleted key {pubkey}', status=200, mimetype='text/plain') - + except TimeoutError: + return flask.render_template('busy.html') except Exception as e: return flask.Response(f'something went catastrophically wrong: {e}', status=400, mimetype='text/plain')