From 50fb5249720895a9f2e87bffc2deb17ffd87e06f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 2 Sep 2020 16:47:03 -0700 Subject: [PATCH] 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 Reviewed-by: Veiko Aasa --- plinth/modules/firewall/components.py | 12 +++- plinth/templates/port-forwarding-info.html | 66 ++++++++++++++-------- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/plinth/modules/firewall/components.py b/plinth/modules/firewall/components.py index dd721861d..37c4dbc29 100644 --- a/plinth/modules/firewall/components.py +++ b/plinth/modules/firewall/components.py @@ -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 diff --git a/plinth/templates/port-forwarding-info.html b/plinth/templates/port-forwarding-info.html index a7b2211a8..c37737c62 100644 --- a/plinth/templates/port-forwarding-info.html +++ b/plinth/templates/port-forwarding-info.html @@ -4,33 +4,51 @@ {% load i18n %} -{% if port_forwarding_info %} +{% if port_forwarding_info.ports %}

{% trans "Port Forwarding" %}

- {% 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 not behind a router. + No action is necessary. + {% endblocktrans %} + + {% elif port_forwarding_info.router_configuration_type == 'dmz' %} + {% blocktrans trimmed %} + Your FreedomBox is behind a router and + you are using the DMZ feature to forward all ports. No further router + configuration is necessary. + {% endblocktrans %} + + {% else %} + {% blocktrans trimmed %} + Your FreedomBox is behind a router 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 %} + + + + + + + + + + + {% for port in port_forwarding_info.ports %} + + + + + + {% endfor %} + +
{% trans "Protocol" %}{% trans "From Router/WAN Ports" %}{% blocktrans %}To {{box_name}} Ports{% endblocktrans %}
{{ port.protocol }}{{ port.ports }}{{ port.ports }}
+ {% endif %}

- - - - - - - - - - {% for port in port_forwarding_info %} - - - - - - {% endfor %} - -
{% trans "Protocol" %}{% trans "From Router/WAN Ports" %}{% blocktrans %}To {{box_name}} Ports{% endblocktrans %}
{{ port.0 }}{{ port.1 }}{{ port.1 }}
{% endif %}