mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
firewall: Show port forwarding info contextually
- When port forwarding configuration is not required in the router, don't show the ports information. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
f58b5f8962
commit
50fb524972
@ -153,7 +153,12 @@ class Firewall(app.FollowerComponent):
|
||||
|
||||
def get_port_forwarding_info(app_):
|
||||
"""Return a list of ports to be forwarded for this app to work."""
|
||||
info = []
|
||||
from plinth.modules import networks
|
||||
info = {
|
||||
'network_topology_type': networks.get_network_topology_type(),
|
||||
'router_configuration_type': networks.get_router_configuration_type(),
|
||||
'ports': []
|
||||
}
|
||||
for component in app_.components.values():
|
||||
if not isinstance(component, Firewall):
|
||||
continue
|
||||
@ -166,6 +171,9 @@ def get_port_forwarding_info(app_):
|
||||
continue
|
||||
|
||||
for detail in port['details']:
|
||||
info.append((detail[1].upper(), detail[0]))
|
||||
info['ports'].append({
|
||||
'protocol': detail[1].upper(),
|
||||
'ports': detail[0]
|
||||
})
|
||||
|
||||
return info
|
||||
|
||||
@ -4,33 +4,51 @@
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% if port_forwarding_info %}
|
||||
{% if port_forwarding_info.ports %}
|
||||
<h3>{% trans "Port Forwarding" %}</h3>
|
||||
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
If your FreedomBox is behind a router, you will need to set up port
|
||||
forwarding on your router. You should forward the following ports for
|
||||
{{ service_name }}:
|
||||
{% endblocktrans %}
|
||||
{% url 'networks:index' as networks_url %}
|
||||
{% if port_forwarding_info.network_topology_type != "to_router" %}
|
||||
{% blocktrans trimmed %}
|
||||
Your FreedomBox is <a href="{{ networks_url }}">not behind a router</a>.
|
||||
No action is necessary.
|
||||
{% endblocktrans %}
|
||||
<span class="fa fa-check" aria-hidden="true"></span>
|
||||
{% elif port_forwarding_info.router_configuration_type == 'dmz' %}
|
||||
{% blocktrans trimmed %}
|
||||
Your FreedomBox is <a href="{{ networks_url }}"> behind a router</a> and
|
||||
you are using the DMZ feature to forward all ports. No further router
|
||||
configuration is necessary.
|
||||
{% endblocktrans %}
|
||||
<span class="fa fa-check" aria-hidden="true"></span>
|
||||
{% else %}
|
||||
{% blocktrans trimmed %}
|
||||
Your FreedomBox is <a href="{{ networks_url }}">behind a router</a> and
|
||||
you are not using the DMZ feature. You will need to set up port
|
||||
forwarding on your router. You should forward the following ports for
|
||||
{{ service_name }}:
|
||||
{% endblocktrans %}
|
||||
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Protocol" %}</th>
|
||||
<th>{% trans "From Router/WAN Ports" %}</th>
|
||||
<th>{% blocktrans %}To {{box_name}} Ports{% endblocktrans %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for port in port_forwarding_info.ports %}
|
||||
<tr>
|
||||
<td>{{ port.protocol }}</td>
|
||||
<td>{{ port.ports }}</td>
|
||||
<td>{{ port.ports }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Protocol" %}</th>
|
||||
<th>{% trans "From Router/WAN Ports" %}</th>
|
||||
<th>{% blocktrans %}To {{box_name}} Ports{% endblocktrans %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for port in port_forwarding_info %}
|
||||
<tr>
|
||||
<td>{{ port.0 }}</td>
|
||||
<td>{{ port.1 }}</td>
|
||||
<td>{{ port.1 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user