diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-22 11:19:14 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-22 13:22:40 +0200 |
commit | 1fc2dbe5a3e867eb5e6c2f759409f1c94146a794 (patch) | |
tree | 73e9b90b26fb30e115ae111bb7592fdb92615cd3 /src/hydrilla/proxy/web_ui/root.py | |
parent | fe43bd552aaacd649b0e00afada01d07ad8dae9a (diff) | |
download | haketilo-hydrilla-1fc2dbe5a3e867eb5e6c2f759409f1c94146a794.tar.gz haketilo-hydrilla-1fc2dbe5a3e867eb5e6c2f759409f1c94146a794.zip |
[proxy] make popup script injection configurable throught the web UI
Diffstat (limited to 'src/hydrilla/proxy/web_ui/root.py')
-rw-r--r-- | src/hydrilla/proxy/web_ui/root.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index 3120d0e..d775730 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -26,9 +26,15 @@ # court. """ -..... +This module instantiated Flask apps responsible for the web UI and facilitates +conversion of Flask response objects to the ResponseInfo type used by other +Haketilo code. + +In addition, the Haketilo root/settings page and landing page also have their +handlers defined here. """ +import re import dataclasses as dc import typing as t @@ -128,6 +134,10 @@ def home(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: ) return flask.make_response(html, 200) +popup_toggle_action_re = re.compile( + r'^popup_(yes|no)_when_(jsallowed|jsblocked|payloadon)$' +) + @home_bp.route('/', methods=['POST']) def home_post() -> werkzeug.Response: action = flask.request.form['action'] @@ -151,7 +161,19 @@ def home_post() -> werkzeug.Response: elif action == 'prune_orphans': state.prune_orphan_items() else: - raise ValueError() + match = popup_toggle_action_re.match(action) + if match is None: + raise ValueError() + + popup_enable = match.group(1) == 'yes' + page_type = match.group(2) + + settings_prop = f'default_popup_{page_type}' + old_settings = getattr(state.get_settings(), settings_prop) + + new_settings = dc.replace(old_settings, keyboard_trigger=popup_enable) + + state.update_settings(default_popup_settings={page_type: new_settings}) return flask.redirect(flask.url_for('.home'), 303) |