Verified Commit 0018e14c authored by James Valleroy's avatar James Valleroy Committed by Sunil Mohan Adapa

firewall: Show ports details

Show port types and numbers.
Signed-off-by: James Valleroy's avatarJames Valleroy <>
Reviewed-by: Sunil Mohan Adapa's avatarSunil Mohan Adapa <>
parent e5081018
Pipeline #44941 failed with stages
in 7 minutes and 3 seconds
......@@ -50,6 +50,8 @@ manual_page = 'Firewall'
LOGGER = logging.getLogger(__name__)
_port_details = {}
def init():
"""Initailze firewall module"""
......@@ -97,9 +99,13 @@ def get_enabled_services(zone):
def get_port_details(service_port):
"""Return the port types and numbers for a service port"""
output = _run(
['get-service-ports', '--service', service_port], superuser=True)
return output.split()
return _port_details[service_port]
except KeyError:
output = _run(['get-service-ports', '--service', service_port],
_port_details[service_port] = output.strip()
return _port_details[service_port]
def get_interfaces(zone):
......@@ -67,19 +67,19 @@
{% endif %}
{% for port in service.ports %}
{% for port in service.ports_details %}
<tr class="collapse out {{service.service_id}}"
style="background-color: #f9f9f9" >
<td class='cell-indented'><em>{{ port }}</em></td>
<td class='cell-indented'><em>{{ }}</em> ({{ port.details }})</td>
{% if port in internal_enabled_services and port in external_enabled_services %}
{% if in internal_enabled_services and in external_enabled_services %}
<span class='label label-success'>
{% trans "Permitted" %}</span>
{% elif port in internal_enabled_services %}
{% elif in internal_enabled_services %}
<span class='label label-warning'>
{% trans "Permitted (internal only)" %}</span>
{% elif port in external_enabled_services %}
{% elif in external_enabled_services %}
<span class='label label-warning'>
{% trans "Permitted (external only)" %}</span>
{% else %}
......@@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <>.
Framework for working with servers and their services.
......@@ -44,6 +43,7 @@ class Service():
- disable (optional): method
- is_running (optional): Boolean or a method returning Boolean
def __init__(self, service_id, name, ports=None, is_external=False,
is_enabled=None, enable=None, disable=None, is_running=None):
if ports is None:
......@@ -65,6 +65,19 @@ class Service():
assert service_id not in services
services[service_id] = self
def ports_details(self):
"""Retrieve details of ports associated with service."""
from plinth.modules import firewall
ports_details = []
for port in self.ports:
'name': port,
'details': firewall.get_port_details(port),
return ports_details
def enable(self):
if self._enable is None:
actions.superuser_run('service', ['enable', self.service_id])
......@@ -126,6 +139,8 @@ def init():
Service('https', _('Web Server over Secure Socket Layer'), ports=['https'],
is_external=True, is_enabled=True)
Service('plinth', format_lazy(_('{box_name} Web Interface (Plinth)'),
ports=['https'], is_external=True, is_enabled=True)
_('{box_name} Web Interface (Plinth)'), box_name=_(cfg.box_name)),
ports=['https'], is_external=True, is_enabled=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment