diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index 1c81edacd..dc11e2209 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ from plinth import action_utils, actions from plinth import app as app_module -from plinth import menu +from plinth import cfg, menu from plinth.daemon import (Daemon, app_is_running, diagnose_netcat, diagnose_port_listening) from plinth.modules.apache.components import diagnose_url @@ -19,6 +19,7 @@ from plinth.modules.names.components import DomainType from plinth.modules.users.components import UsersAndGroups from plinth.package import Packages from plinth.signals import domain_added, domain_removed +from plinth.utils import format_lazy from . import manifest, utils @@ -28,7 +29,10 @@ _description = [ 'Project website. For best protection when web surfing, the ' 'Tor Project recommends that you use the ' '' - 'Tor Browser.') + 'Tor Browser.'), + format_lazy( + _('A Tor SOCKS port is available on your {box_name} for internal ' + 'networks on TCP port 9050.'), box_name=_(cfg.box_name)) ] app = None diff --git a/plinth/modules/tor/templates/tor.html b/plinth/modules/tor/templates/tor.html index e48adf12a..70fa6a5fc 100644 --- a/plinth/modules/tor/templates/tor.html +++ b/plinth/modules/tor/templates/tor.html @@ -49,55 +49,6 @@ {% endif %} {% endblock %} -{% block configuration %} - - {% if not config_running %} - - {{ block.super }} - - {% if status.relay_enabled %} -

{% trans "Relay" %}

-

- {% blocktrans trimmed %} - If your {{ box_name }} is behind a router or firewall, you should - make sure the following ports are open, and port-forwarded, if - necessary: - {% endblocktrans %} -

-
- - - - - - - - - {% for name, port in status.ports.items %} - - - - - {% endfor %} - -
{% trans "Service" %}{% trans "Port" %}
{{ name }}{{ port }}
-
- {% endif %} - -

{% trans "SOCKS" %}

- -

- {% blocktrans trimmed %} - A Tor SOCKS port is available on your {{ box_name }} on TCP port - 9050. - {% endblocktrans %} -

- - {% endif %} - -{% endblock %} - - {% block page_js %} diff --git a/plinth/modules/tor/tests/test_functional.py b/plinth/modules/tor/tests/test_functional.py index 6804c24e6..a1ce6bcef 100644 --- a/plinth/modules/tor/tests/test_functional.py +++ b/plinth/modules/tor/tests/test_functional.py @@ -31,7 +31,7 @@ class TestTorApp(functional.BaseAppTests): _feature_enable(session_browser, 'relay', should_enable=False) _feature_enable(session_browser, 'relay', should_enable=True) _assert_feature_enabled(session_browser, 'relay', enabled=True) - assert 'orport' in _get_relay_ports(session_browser) + _assert_relay_port(session_browser, 'orport') def test_set_tor_bridge_relay_configuration(self, session_browser): """Test setting Tor bridge relay configuration.""" @@ -39,8 +39,8 @@ class TestTorApp(functional.BaseAppTests): _feature_enable(session_browser, 'bridge-relay', should_enable=False) _feature_enable(session_browser, 'bridge-relay', should_enable=True) _assert_feature_enabled(session_browser, 'bridge-relay', enabled=True) - assert 'obfs3' in _get_relay_ports(session_browser) - assert 'obfs4' in _get_relay_ports(session_browser) + _assert_relay_port(session_browser, 'obfs3') + _assert_relay_port(session_browser, 'obfs4') def test_set_tor_hidden_services_configuration(self, session_browser): """Test setting Tor hidden services configuration.""" @@ -109,12 +109,12 @@ def _assert_feature_enabled(browser, feature, enabled): assert browser.find_by_name(element_name).first.checked == enabled -def _get_relay_ports(browser): - """Return the list of ports shown in the relay table.""" +def _assert_relay_port(browser, port_name): + """Assert that port is available in port forwarding info table.""" functional.nav_to_module(browser, 'tor') - return [ - port_name.text - for port_name in browser.find_by_css('.tor-relay-port-name') + assert f'tor-{port_name}' in [ + name.text for name in browser.find_by_css( + '.table-port-forwarding-info td:first-child') ] diff --git a/plinth/modules/tor/views.py b/plinth/modules/tor/views.py index 9242c8932..2d9871af2 100644 --- a/plinth/modules/tor/views.py +++ b/plinth/modules/tor/views.py @@ -9,7 +9,8 @@ from django.utils.translation import gettext as _ from plinth import actions from plinth.errors import ActionError from plinth.modules import tor -from plinth.modules.firewall.components import Firewall +from plinth.modules.firewall.components import (Firewall, + get_port_forwarding_info) from . import utils as tor_utils from .forms import TorForm @@ -46,6 +47,7 @@ def index(request): 'has_diagnostics': True, 'is_enabled': status['enabled'], 'is_running': status['is_running'], + 'port_forwarding_info': get_port_forwarding_info(tor.app), 'refresh_page_sec': 3 if bool(config_process) else None, })