tor: Show port forwarding information in consistent way

Closes: #2187

Tests:

- Visit the Tor app page after installing. Port forwarding information is
shown like in all other apps. Protocol column lists 'TCP'.

- Information about SOCKS port is shown in the description.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-05-11 12:34:38 -07:00 committed by James Valleroy
parent ca13b7bd93
commit 52d55efe35
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 17 additions and 60 deletions

View File

@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _
from plinth import action_utils, actions from plinth import action_utils, actions
from plinth import app as app_module 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, from plinth.daemon import (Daemon, app_is_running, diagnose_netcat,
diagnose_port_listening) diagnose_port_listening)
from plinth.modules.apache.components import diagnose_url 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.modules.users.components import UsersAndGroups
from plinth.package import Packages from plinth.package import Packages
from plinth.signals import domain_added, domain_removed from plinth.signals import domain_added, domain_removed
from plinth.utils import format_lazy
from . import manifest, utils from . import manifest, utils
@ -28,7 +29,10 @@ _description = [
'Project</a> website. For best protection when web surfing, the ' 'Project</a> website. For best protection when web surfing, the '
'Tor Project recommends that you use the ' 'Tor Project recommends that you use the '
'<a href="https://www.torproject.org/download/download-easy.html.en">' '<a href="https://www.torproject.org/download/download-easy.html.en">'
'Tor Browser</a>.') 'Tor Browser</a>.'),
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 app = None

View File

@ -49,55 +49,6 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block configuration %}
{% if not config_running %}
{{ block.super }}
{% if status.relay_enabled %}
<h3>{% trans "Relay" %}</h3>
<p>
{% 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 %}
</p>
<div class="table-responsive">
<table class="table tor-relay-ports">
<thead>
<tr>
<th>{% trans "Service" %}</th>
<th>{% trans "Port" %}</th>
</tr>
</thead>
<tbody>
{% for name, port in status.ports.items %}
<tr>
<td class="tor-relay-port-name">{{ name }}</td>
<td class="tor-relay-port-number">{{ port }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
<h3>{% trans "SOCKS" %}</h3>
<p>
{% blocktrans trimmed %}
A Tor SOCKS port is available on your {{ box_name }} on TCP port
9050.
{% endblocktrans %}
</p>
{% endif %}
{% endblock %}
{% block page_js %} {% block page_js %}
<script type="text/javascript" src="{% static 'tor/tor.js' %}"></script> <script type="text/javascript" src="{% static 'tor/tor.js' %}"></script>

View File

@ -31,7 +31,7 @@ class TestTorApp(functional.BaseAppTests):
_feature_enable(session_browser, 'relay', should_enable=False) _feature_enable(session_browser, 'relay', should_enable=False)
_feature_enable(session_browser, 'relay', should_enable=True) _feature_enable(session_browser, 'relay', should_enable=True)
_assert_feature_enabled(session_browser, 'relay', enabled=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): def test_set_tor_bridge_relay_configuration(self, session_browser):
"""Test setting Tor bridge relay configuration.""" """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=False)
_feature_enable(session_browser, 'bridge-relay', should_enable=True) _feature_enable(session_browser, 'bridge-relay', should_enable=True)
_assert_feature_enabled(session_browser, 'bridge-relay', enabled=True) _assert_feature_enabled(session_browser, 'bridge-relay', enabled=True)
assert 'obfs3' in _get_relay_ports(session_browser) _assert_relay_port(session_browser, 'obfs3')
assert 'obfs4' in _get_relay_ports(session_browser) _assert_relay_port(session_browser, 'obfs4')
def test_set_tor_hidden_services_configuration(self, session_browser): def test_set_tor_hidden_services_configuration(self, session_browser):
"""Test setting Tor hidden services configuration.""" """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 assert browser.find_by_name(element_name).first.checked == enabled
def _get_relay_ports(browser): def _assert_relay_port(browser, port_name):
"""Return the list of ports shown in the relay table.""" """Assert that port is available in port forwarding info table."""
functional.nav_to_module(browser, 'tor') functional.nav_to_module(browser, 'tor')
return [ assert f'tor-{port_name}' in [
port_name.text name.text for name in browser.find_by_css(
for port_name in browser.find_by_css('.tor-relay-port-name') '.table-port-forwarding-info td:first-child')
] ]

View File

@ -9,7 +9,8 @@ from django.utils.translation import gettext as _
from plinth import actions from plinth import actions
from plinth.errors import ActionError from plinth.errors import ActionError
from plinth.modules import tor 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 . import utils as tor_utils
from .forms import TorForm from .forms import TorForm
@ -46,6 +47,7 @@ def index(request):
'has_diagnostics': True, 'has_diagnostics': True,
'is_enabled': status['enabled'], 'is_enabled': status['enabled'],
'is_running': status['is_running'], 'is_running': status['is_running'],
'port_forwarding_info': get_port_forwarding_info(tor.app),
'refresh_page_sec': 3 if bool(config_process) else None, 'refresh_page_sec': 3 if bool(config_process) else None,
}) })