mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
ca13b7bd93
commit
52d55efe35
@ -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</a> website. For best protection when web surfing, the '
|
||||
'Tor Project recommends that you use the '
|
||||
'<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
|
||||
|
||||
@ -49,55 +49,6 @@
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
|
||||
<script type="text/javascript" src="{% static 'tor/tor.js' %}"></script>
|
||||
|
||||
@ -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')
|
||||
]
|
||||
|
||||
|
||||
|
||||
@ -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,
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user