mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
firewall: Show ports details
Show port types and numbers. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
e5081018a3
commit
0018e14cab
@ -50,6 +50,8 @@ manual_page = 'Firewall'
|
|||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_port_details = {}
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initailze firewall module"""
|
"""Initailze firewall module"""
|
||||||
@ -97,9 +99,13 @@ def get_enabled_services(zone):
|
|||||||
|
|
||||||
def get_port_details(service_port):
|
def get_port_details(service_port):
|
||||||
"""Return the port types and numbers for a service port"""
|
"""Return the port types and numbers for a service port"""
|
||||||
output = _run(
|
try:
|
||||||
['get-service-ports', '--service', service_port], superuser=True)
|
return _port_details[service_port]
|
||||||
return output.split()
|
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):
|
def get_interfaces(zone):
|
||||||
|
|||||||
@ -67,19 +67,19 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for port in service.ports %}
|
{% for port in service.ports_details %}
|
||||||
<tr class="collapse out {{service.service_id}}"
|
<tr class="collapse out {{service.service_id}}"
|
||||||
style="background-color: #f9f9f9" >
|
style="background-color: #f9f9f9" >
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class='cell-indented'><em>{{ port }}</em></td>
|
<td class='cell-indented'><em>{{ port.name }}</em> ({{ port.details }})</td>
|
||||||
<td>
|
<td>
|
||||||
{% 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 %}
|
||||||
<span class='label label-success'>
|
<span class='label label-success'>
|
||||||
{% trans "Permitted" %}</span>
|
{% trans "Permitted" %}</span>
|
||||||
{% elif port in internal_enabled_services %}
|
{% elif port.name in internal_enabled_services %}
|
||||||
<span class='label label-warning'>
|
<span class='label label-warning'>
|
||||||
{% trans "Permitted (internal only)" %}</span>
|
{% trans "Permitted (internal only)" %}</span>
|
||||||
{% elif port in external_enabled_services %}
|
{% elif port.name in external_enabled_services %}
|
||||||
<span class='label label-warning'>
|
<span class='label label-warning'>
|
||||||
{% trans "Permitted (external only)" %}</span>
|
{% trans "Permitted (external only)" %}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Framework for working with servers and their services.
|
Framework for working with servers and their services.
|
||||||
"""
|
"""
|
||||||
@ -44,6 +43,7 @@ class Service():
|
|||||||
- disable (optional): method
|
- disable (optional): method
|
||||||
- is_running (optional): Boolean or a method returning Boolean
|
- is_running (optional): Boolean or a method returning Boolean
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, service_id, name, ports=None, is_external=False,
|
def __init__(self, service_id, name, ports=None, is_external=False,
|
||||||
is_enabled=None, enable=None, disable=None, is_running=None):
|
is_enabled=None, enable=None, disable=None, is_running=None):
|
||||||
if ports is None:
|
if ports is None:
|
||||||
@ -65,6 +65,19 @@ class Service():
|
|||||||
assert service_id not in services
|
assert service_id not in services
|
||||||
services[service_id] = self
|
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):
|
def enable(self):
|
||||||
if self._enable is None:
|
if self._enable is None:
|
||||||
actions.superuser_run('service', ['enable', self.service_id])
|
actions.superuser_run('service', ['enable', self.service_id])
|
||||||
@ -126,6 +139,8 @@ def init():
|
|||||||
is_enabled=True)
|
is_enabled=True)
|
||||||
Service('https', _('Web Server over Secure Socket Layer'), ports=['https'],
|
Service('https', _('Web Server over Secure Socket Layer'), ports=['https'],
|
||||||
is_external=True, is_enabled=True)
|
is_external=True, is_enabled=True)
|
||||||
Service('plinth', format_lazy(_('{box_name} Web Interface (Plinth)'),
|
Service(
|
||||||
box_name=_(cfg.box_name)),
|
'plinth',
|
||||||
ports=['https'], is_external=True, is_enabled=True)
|
format_lazy(
|
||||||
|
_('{box_name} Web Interface (Plinth)'), box_name=_(cfg.box_name)),
|
||||||
|
ports=['https'], is_external=True, is_enabled=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user