diff options
Diffstat (limited to 'src/hydrilla')
-rw-r--r-- | src/hydrilla/locales/en_US/LC_MESSAGES/messages.po | 158 | ||||
-rw-r--r-- | src/hydrilla/proxy/web_ui/options.py | 70 | ||||
-rw-r--r-- | src/hydrilla/proxy/web_ui/root.py | 36 | ||||
-rw-r--r-- | src/hydrilla/proxy/web_ui/templates/base.html.jinja | 1 | ||||
-rw-r--r-- | src/hydrilla/proxy/web_ui/templates/index.html.jinja | 89 | ||||
-rw-r--r-- | src/hydrilla/proxy/web_ui/templates/options.html.jinja | 112 |
6 files changed, 194 insertions, 272 deletions
diff --git a/src/hydrilla/locales/en_US/LC_MESSAGES/messages.po b/src/hydrilla/locales/en_US/LC_MESSAGES/messages.po index 277678e..addfe8e 100644 --- a/src/hydrilla/locales/en_US/LC_MESSAGES/messages.po +++ b/src/hydrilla/locales/en_US/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: hydrilla 2.0\n" "Report-Msgid-Bugs-To: koszko@koszko.org\n" -"POT-Creation-Date: 2022-09-27 10:53+0200\n" +"POT-Creation-Date: 2022-09-27 11:23+0200\n" "PO-Revision-Date: 2022-02-12 00:00+0000\n" "Last-Translator: Wojtek Kosior <koszko@koszko.org>\n" "Language: en_US\n" @@ -226,26 +226,22 @@ msgid "web_ui.base.nav.home" msgstr "Home" #: src/hydrilla/proxy/web_ui/templates/base.html.jinja:242 -msgid "web_ui.base.nav.options" -msgstr "Options" - -#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:243 msgid "web_ui.base.nav.rules" msgstr "Script blocking" -#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:244 +#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:243 msgid "web_ui.base.nav.packages" msgstr "Packages" -#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:245 +#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:244 msgid "web_ui.base.nav.libraries" msgstr "Libraries" -#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:246 +#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:245 msgid "web_ui.base.nav.repos" msgstr "Repositories" -#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:247 +#: src/hydrilla/proxy/web_ui/templates/base.html.jinja:246 msgid "web_ui.base.nav.load" msgstr "Import from file" @@ -275,6 +271,76 @@ msgstr "" "custom logic to them. Haketilo was orignally developed as a browser " "extension but has since been made into an HTTP proxy." +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:45 +msgid "web_ui.home.heading.options" +msgstr "Global options" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:55 +msgid "web_ui.home.packages_are_used_when_enabled" +msgstr "" +"Hektilo is currently configured to only use packages that were explicitly" +" enabled." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:58 +msgid "web_ui.home.user_gets_asked_whether_to_enable_package" +msgstr "" +"Hektilo is currently configured to ask whenever a package is found that " +"could be used for the current site." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:62 +msgid "web_ui.home.packages_are_used_automatically" +msgstr "" +"Hektilo is currently configured to automatically use packages that are " +"available for the current site." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:69 +msgid "web_ui.home.use_enabled_button" +msgstr "Use when enabled" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:72 +msgid "web_ui.home.use_question_button" +msgstr "Ask whether to use" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:75 +msgid "web_ui.home.use_auto_button" +msgstr "Use automatically" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:88 +msgid "web_ui.home.scripts_are_allowed_by_default" +msgstr "" +"By default Haketilo currently allows JavaScript sent by websites to the " +"browser to execute." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:91 +msgid "web_ui.home.scripts_are_blocked_by_default" +msgstr "" +"By default Haketilo currently blocks JavaScript sent by websites to the " +"browser from executing." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:95 +msgid "web_ui.home.allow_scripts_button" +msgstr "Allow scripts" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:96 +msgid "web_ui.home.block_scripts_button" +msgstr "Block scripts" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:113 +msgid "web_ui.home.user_is_advanced_user" +msgstr "Interface features for advanced users are currently enabled." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:116 +msgid "web_ui.home.user_is_simple_user" +msgstr "Interface features for advanced users are currently disabled." + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:123 +msgid "web_ui.home.user_make_advanced_button" +msgstr "Enable" + +#: src/hydrilla/proxy/web_ui/templates/index.html.jinja:126 +msgid "web_ui.home.user_make_simple_button" +msgstr "Disable" + #: src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja:25 #: src/hydrilla/proxy/web_ui/templates/prompts/package_suggestion.html.jinja:30 #: src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja:33 @@ -528,80 +594,6 @@ msgstr "Available packages" msgid "web_ui.packages.enabled_version_{}" msgstr "enabled version {}" -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:23 -msgid "web_ui.options.title" -msgstr "Global options" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:27 -msgid "web_ui.options.heading" -msgstr "Haketilo global options" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:37 -msgid "web_ui.options.packages_are_used_when_enabled" -msgstr "" -"Hektilo is currently configured to only use packages that were explicitly" -" enabled." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:40 -msgid "web_ui.options.user_gets_asked_whether_to_enable_package" -msgstr "" -"Hektilo is currently configured to ask whenever a package is found that " -"could be used for the current site." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:44 -msgid "web_ui.options.packages_are_used_automatically" -msgstr "" -"Hektilo is currently configured to automatically use packages that are " -"available for the current site." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:51 -msgid "web_ui.options.use_enabled_button" -msgstr "Use when enabled" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:54 -msgid "web_ui.options.use_question_button" -msgstr "Ask whether to use" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:57 -msgid "web_ui.options.use_auto_button" -msgstr "Use automatically" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:70 -msgid "web_ui.options.scripts_are_allowed_by_default" -msgstr "" -"By default Haketilo currently allows JavaScript sent by websites to the " -"browser to execute." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:73 -msgid "web_ui.options.scripts_are_blocked_by_default" -msgstr "" -"By default Haketilo currently blocks JavaScript sent by websites to the " -"browser from executing." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:77 -msgid "web_ui.options.allow_scripts_button" -msgstr "Allow scripts" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:78 -msgid "web_ui.options.block_scripts_button" -msgstr "Block scripts" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:95 -msgid "web_ui.options.user_is_advanced_user" -msgstr "Interface features for advanced users are currently enabled." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:98 -msgid "web_ui.options.user_is_simple_user" -msgstr "Interface features for advanced users are currently disabled." - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:105 -msgid "web_ui.options.user_make_advanced_button" -msgstr "Enable" - -#: src/hydrilla/proxy/web_ui/templates/options.html.jinja:108 -msgid "web_ui.options.user_make_simple_button" -msgstr "Disable" - #: src/hydrilla/proxy/web_ui/templates/prompts/auto_install_error.html.jinja:24 msgid "web_ui.prompts.auto_install_error.title" msgstr "Installation failure" diff --git a/src/hydrilla/proxy/web_ui/options.py b/src/hydrilla/proxy/web_ui/options.py deleted file mode 100644 index 7d59375..0000000 --- a/src/hydrilla/proxy/web_ui/options.py +++ /dev/null @@ -1,70 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -# Proxy web UI options page. -# -# This file is part of Hydrilla&Haketilo. -# -# Copyright (C) 2022 Wojtek Kosior -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. -# -# -# I, Wojtek Kosior, thereby promise not to sue for violation of this -# file's license. Although I request that you do not make use of this -# code in a proprietary program, I am not going to enforce this in -# court. - -# Enable using with Python 3.7. -from __future__ import annotations - -import typing as t - -import flask -import werkzeug - -from .. import state as st -from . import _app - - -bp = flask.Blueprint('options', __package__) - -@bp.route('/options', methods=['GET']) -def options(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: - html = flask.render_template('options.html.jinja', **errors) - return flask.make_response(html, 200) - -@bp.route('/options', methods=['POST']) -def options_post() -> werkzeug.Response: - action = flask.request.form['action'] - - state = _app.get_haketilo_state() - - if action == 'use_enabled': - state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED) - elif action == 'use_auto': - state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO) - elif action == 'use_question': - state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION) - elif action == 'allow_scripts': - state.update_settings(default_allow_scripts=True) - elif action == 'block_scripts': - state.update_settings(default_allow_scripts=False) - elif action == 'user_make_advanced': - state.update_settings(advanced_user=True) - elif action == 'user_make_simple': - state.update_settings(advanced_user=False) - else: - raise ValueError() - - return flask.redirect(flask.url_for('.options'), 303) diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index 21c491b..a28fde8 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -45,7 +45,6 @@ from ...translations import translation as make_translation from ... import item_infos from .. import state as st from .. import http_messages -from . import options from . import rules from . import repos from . import items @@ -100,7 +99,7 @@ class WebUIAppImpl(_app.WebUIApp): self.before_request(authenticate_by_referrer) - for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp, options.bp]: + for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp]: self.register_blueprint(blueprint) # Flask app is not thread-safe and has to be accompanied by an ugly lock. This @@ -110,10 +109,35 @@ app = WebUIAppImpl() app_lock = Lock() -@app.route('/') -def home() -> str: - return flask.render_template('index.html.jinja') - +@app.route('/', methods=['GET']) +def home(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: + html = flask.render_template('index.html.jinja', **errors) + return flask.make_response(html, 200) + +@app.route('/', methods=['POST']) +def home_post() -> werkzeug.Response: + action = flask.request.form['action'] + + state = _app.get_haketilo_state() + + if action == 'use_enabled': + state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED) + elif action == 'use_auto': + state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO) + elif action == 'use_question': + state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION) + elif action == 'allow_scripts': + state.update_settings(default_allow_scripts=True) + elif action == 'block_scripts': + state.update_settings(default_allow_scripts=False) + elif action == 'user_make_advanced': + state.update_settings(advanced_user=True) + elif action == 'user_make_simple': + state.update_settings(advanced_user=False) + else: + raise ValueError() + + return flask.redirect(flask.url_for('.home'), 303) def process_request( request_info: http_messages.RequestInfo, diff --git a/src/hydrilla/proxy/web_ui/templates/base.html.jinja b/src/hydrilla/proxy/web_ui/templates/base.html.jinja index 37930e2..c0eecce 100644 --- a/src/hydrilla/proxy/web_ui/templates/base.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/base.html.jinja @@ -239,7 +239,6 @@ code in a proprietary work, I am not going to enforce this in court. {% set navigation_bar = [ ('home', _('web_ui.base.nav.home'), false), - ('options.options', _('web_ui.base.nav.options'), false), ('rules.rules', _('web_ui.base.nav.rules'), false), ('items.packages', _('web_ui.base.nav.packages'), false), ('items.libraries', _('web_ui.base.nav.libraries'), true), diff --git a/src/hydrilla/proxy/web_ui/templates/index.html.jinja b/src/hydrilla/proxy/web_ui/templates/index.html.jinja index b0c0b36..d95937a 100644 --- a/src/hydrilla/proxy/web_ui/templates/index.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/index.html.jinja @@ -40,4 +40,93 @@ code in a proprietary work, I am not going to enforce this in court. <p> {{ _('web_ui.home.haketilo_is_blah_blah') }} </p> + + <div class="horizontal-separator"></div> + + <h4> + {{ _('web_ui.home.heading.options') }} + </h4> + + {% set use_enabled_but_classes = ['green-button'] %} + {% set use_auto_but_classes = ['green-button'] %} + {% set use_question_but_classes = ['green-button'] %} + + <p> + {% if settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED %} + {% do use_enabled_but_classes.append('disabled-button') %} + {{ _('web_ui.home.packages_are_used_when_enabled') }} + {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %} + {% do use_question_but_classes.append('disabled-button') %} + {{ _('web_ui.home.user_gets_asked_whether_to_enable_package') }} + {% else %} + {# settings.mapping_use_mode == MappingUseMode.AUTO #} + {% do use_auto_but_classes.append('disabled-button') %} + {{ _('web_ui.home.packages_are_used_automatically') }} + {% endif %} + </p> + + {{ + button_row([ + (use_enabled_but_classes, + _('web_ui.home.use_enabled_button'), + {'action': 'use_enabled'}), + (use_question_but_classes, + _('web_ui.home.use_question_button'), + {'action': 'use_question'}), + (use_auto_but_classes, + _('web_ui.home.use_auto_button'), + {'action': 'use_auto'}) + ]) + }} + + <div class="horizontal-separator"></div> + + {% set allow_but_classes = ['red-button'] %} + {% set block_but_classes = ['blue-button'] %} + + <p> + {% if settings.default_allow_scripts %} + {% do allow_but_classes.append('disabled-button') %} + {{ _('web_ui.home.scripts_are_allowed_by_default') }} + {% else %} + {% do block_but_classes.append('disabled-button') %} + {{ _('web_ui.home.scripts_are_blocked_by_default') }} + {% endif %} + </p> + + {% set allow_but_text = _('web_ui.home.allow_scripts_button') %} + {% set block_but_text = _('web_ui.home.block_scripts_button') %} + + {{ + button_row([ + (allow_but_classes, allow_but_text, {'action': 'allow_scripts'}), + (block_but_classes, block_but_text, {'action': 'block_scripts'}) + ]) + }} + + <div class="horizontal-separator"></div> + + {% set advanced_user_but_classes = ['red-button'] %} + {% set simple_user_but_classes = ['blue-button'] %} + + <p> + {% if settings.advanced_user %} + {% do advanced_user_but_classes.append('disabled-button') %} + {{ _('web_ui.home.user_is_advanced_user') }} + {% else %} + {% do simple_user_but_classes.append('disabled-button') %} + {{ _('web_ui.home.user_is_simple_user') }} + {% endif %} + </p> + + {{ + button_row([ + (advanced_user_but_classes, + _('web_ui.home.user_make_advanced_button'), + {'action': 'user_make_advanced'}), + (simple_user_but_classes, + _('web_ui.home.user_make_simple_button'), + {'action': 'user_make_simple'}) + ]) + }} {% endblock %} diff --git a/src/hydrilla/proxy/web_ui/templates/options.html.jinja b/src/hydrilla/proxy/web_ui/templates/options.html.jinja deleted file mode 100644 index 26519c4..0000000 --- a/src/hydrilla/proxy/web_ui/templates/options.html.jinja +++ /dev/null @@ -1,112 +0,0 @@ -{# -SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0 - -Proxy web UI settings page. - -This file is part of Hydrilla&Haketilo. - -Copyright (C) 2022 Wojtek Kosior - -Dual licensed under -* GNU General Public License v3.0 or later and -* Creative Commons Attribution Share Alike 4.0 International. - -You can choose to use either of these licenses or both. - - -I, Wojtek Kosior, thereby promise not to sue for violation of this -file's licenses. Although I request that you do not make use of this -code in a proprietary work, I am not going to enforce this in court. -#} -{% extends "base.html.jinja" %} - -{% block title %} {{ _('web_ui.options.title') }} {% endblock %} - -{% block main %} - <h3> - {{ _('web_ui.options.heading') }} - </h3> - - {% set use_enabled_but_classes = ['green-button'] %} - {% set use_auto_but_classes = ['green-button'] %} - {% set use_question_but_classes = ['green-button'] %} - - <p> - {% if settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED %} - {% do use_enabled_but_classes.append('disabled-button') %} - {{ _('web_ui.options.packages_are_used_when_enabled') }} - {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %} - {% do use_question_but_classes.append('disabled-button') %} - {{ _('web_ui.options.user_gets_asked_whether_to_enable_package') }} - {% else %} - {# settings.mapping_use_mode == MappingUseMode.AUTO #} - {% do use_auto_but_classes.append('disabled-button') %} - {{ _('web_ui.options.packages_are_used_automatically') }} - {% endif %} - </p> - - {{ - button_row([ - (use_enabled_but_classes, - _('web_ui.options.use_enabled_button'), - {'action': 'use_enabled'}), - (use_question_but_classes, - _('web_ui.options.use_question_button'), - {'action': 'use_question'}), - (use_auto_but_classes, - _('web_ui.options.use_auto_button'), - {'action': 'use_auto'}) - ]) - }} - - <div class="horizontal-separator"></div> - - {% set allow_but_classes = ['red-button'] %} - {% set block_but_classes = ['green-button'] %} - - <p> - {% if settings.default_allow_scripts %} - {% do allow_but_classes.append('disabled-button') %} - {{ _('web_ui.options.scripts_are_allowed_by_default') }} - {% else %} - {% do block_but_classes.append('disabled-button') %} - {{ _('web_ui.options.scripts_are_blocked_by_default') }} - {% endif %} - </p> - - {% set allow_but_text = _('web_ui.options.allow_scripts_button') %} - {% set block_but_text = _('web_ui.options.block_scripts_button') %} - - {{ - button_row([ - (allow_but_classes, allow_but_text, {'action': 'allow_scripts'}), - (block_but_classes, block_but_text, {'action': 'block_scripts'}) - ]) - }} - - <div class="horizontal-separator"></div> - - {% set advanced_user_but_classes = ['red-button'] %} - {% set simple_user_but_classes = ['green-button'] %} - - <p> - {% if settings.advanced_user %} - {% do advanced_user_but_classes.append('disabled-button') %} - {{ _('web_ui.options.user_is_advanced_user') }} - {% else %} - {% do simple_user_but_classes.append('disabled-button') %} - {{ _('web_ui.options.user_is_simple_user') }} - {% endif %} - </p> - - {{ - button_row([ - (advanced_user_but_classes, - _('web_ui.options.user_make_advanced_button'), - {'action': 'user_make_advanced'}), - (simple_user_but_classes, - _('web_ui.options.user_make_simple_button'), - {'action': 'user_make_simple'}) - ]) - }} -{% endblock %} |