diff --git a/plinth/modules/firewall/__init__.py b/plinth/modules/firewall/__init__.py
index 9f64467d7..7eabc6c79 100644
--- a/plinth/modules/firewall/__init__.py
+++ b/plinth/modules/firewall/__init__.py
@@ -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()
+ try:
+ return _port_details[service_port]
+ except KeyError:
+ output = _run(['get-service-ports', '--service', service_port],
+ superuser=True)
+ _port_details[service_port] = output.strip()
+ return _port_details[service_port]
def get_interfaces(zone):
diff --git a/plinth/modules/firewall/templates/firewall.html b/plinth/modules/firewall/templates/firewall.html
index 24bf2ad28..7d0d9abe8 100644
--- a/plinth/modules/firewall/templates/firewall.html
+++ b/plinth/modules/firewall/templates/firewall.html
@@ -67,19 +67,19 @@
{% endif %}
- {% for port in service.ports %}
+ {% for port in service.ports_details %}
|
- {{ port }} |
+ {{ port.name }} ({{ port.details }}) |
- {% if port in internal_enabled_services and port in external_enabled_services %}
+ {% if port.name in internal_enabled_services and port.name in external_enabled_services %}
{% trans "Permitted" %}
- {% elif port in internal_enabled_services %}
+ {% elif port.name in internal_enabled_services %}
{% trans "Permitted (internal only)" %}
- {% elif port in external_enabled_services %}
+ {% elif port.name in external_enabled_services %}
{% trans "Permitted (external only)" %}
{% else %}
diff --git a/plinth/service.py b/plinth/service.py
index 3d4f0e25e..3bd3cf82f 100644
--- a/plinth/service.py
+++ b/plinth/service.py
@@ -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
+ @property
+ def ports_details(self):
+ """Retrieve details of ports associated with service."""
+ from plinth.modules import firewall
+ ports_details = []
+ for port in self.ports:
+ ports_details.append({
+ '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():
is_enabled=True)
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)'),
- box_name=_(cfg.box_name)),
- ports=['https'], is_external=True, is_enabled=True)
+ Service(
+ 'plinth',
+ format_lazy(
+ _('{box_name} Web Interface (Plinth)'), box_name=_(cfg.box_name)),
+ ports=['https'], is_external=True, is_enabled=True)
|