diff --git a/plinth/modules/tor/templates/tor.html b/plinth/modules/tor/templates/tor.html index 4b900a0e0..2ad5a5c16 100644 --- a/plinth/modules/tor/templates/tor.html +++ b/plinth/modules/tor/templates/tor.html @@ -34,30 +34,42 @@ Tor Browser.

Status

-{% if is_running %} +{% if status.is_running %}

Tor is running {% else %}
Tor is not running {% endif %}

-

Hidden Service

+{% if status.hs_enabled %} +
+
+ + + + + + + + + + + + + +
Hidden ServicePort
{{ status.hs_hostname }}{{ status.hs_ports }}
+
+
+{% endif %} -

A hidden service will allow your {{ cfg.box_name }} to provide selected -services (such as OwnCloud or Chat) without revealing its location. -Here is the current configuration:

+

Configuration

- - -
+ {% csrf_token %} {{ form|bootstrap }} - +

Bridge

@@ -77,7 +89,7 @@ port-forwarded, if necessary:

- {% for name, port in tor_ports.items %} + {% for name, port in status.ports.items %} {{ name }} {{ port }} diff --git a/plinth/modules/tor/tor.py b/plinth/modules/tor/tor.py index e35b1a584..d87099bc1 100644 --- a/plinth/modules/tor/tor.py +++ b/plinth/modules/tor/tor.py @@ -32,9 +32,15 @@ from plinth import package class TorForm(forms.Form): # pylint: disable=W0232 """Tor configuration form""" - hs_enabled = forms.BooleanField( - label=_('Enable Hidden Service'), + enabled = forms.BooleanField( + label=_('Enable Tor'), required=False) + hs_enabled = forms.BooleanField( + label=_('Enable Tor Hidden Service'), + required=False, + help_text=_('A hidden service will allow FreedomBox to provide ' + 'selected services (such as ownCloud or Chat) without ' + 'revealing its location.')) def init(): @@ -63,11 +69,7 @@ def index(request): return TemplateResponse(request, 'tor.html', {'title': _('Tor Control Panel'), - 'is_running': status['is_running'], - 'tor_ports': status['ports'], - 'tor_hs_enabled': status['hs_enabled'], - 'tor_hs_hostname': status['hs_hostname'], - 'tor_hs_ports': status['hs_ports'], + 'status': status, 'form': form}) @@ -99,7 +101,8 @@ def get_status(): hs_hostname = hs_info[0] hs_ports = hs_info[1] - return {'is_running': action_utils.service_is_running('tor'), + return {'enabled': action_utils.service_is_enabled('tor'), + 'is_running': action_utils.service_is_running('tor'), 'ports': ports, 'hs_enabled': hs_enabled, 'hs_hostname': hs_hostname, @@ -107,16 +110,24 @@ def get_status(): def _apply_changes(request, old_status, new_status): - """Apply the changes""" - if old_status['hs_enabled'] == new_status['hs_enabled']: + """Apply the changes.""" + if old_status['enabled'] == new_status['enabled'] and \ + old_status['hs_enabled'] == new_status['hs_enabled']: messages.info(request, _('Setting unchanged')) return - if new_status['hs_enabled']: - messages.success(request, _('Tor hidden service enabled')) - command = 'enable-hs' - else: - messages.success(request, _('Tor hidden service disabled')) - command = 'disable-hs' + if old_status['enabled'] != new_status['enabled']: + if new_status['enabled']: + messages.success(request, _('Tor enabled')) + actions.superuser_run('tor', ['enable']) + else: + messages.success(request, _('Tor disabled')) + actions.superuser_run('tor', ['disable']) - actions.superuser_run('tor', [command]) + if old_status['hs_enabled'] != new_status['hs_enabled']: + if new_status['hs_enabled']: + messages.success(request, _('Tor hidden service enabled')) + actions.superuser_run('tor', ['enable-hs']) + else: + messages.success(request, _('Tor hidden service disabled')) + actions.superuser_run('tor', ['disable-hs'])