mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-18 09:10:49 +00:00
Convert firewall page to template
This commit is contained in:
parent
76f49916a3
commit
1c338e538a
@ -49,91 +49,24 @@ class Firewall(PagePlugin):
|
||||
"""Serve introcution page"""
|
||||
del kwargs # Unused
|
||||
|
||||
# XXX: Use templates here instead of generating HTML
|
||||
main = _('''
|
||||
<p>Firewall is a network security system that controls the incoming
|
||||
and outgoing network traffic on your {box_name}. Keeping a firewall
|
||||
enabled and properly configured reduces risk of security threat from
|
||||
the Internet.</p>
|
||||
|
||||
<p>The following the current status:</p>
|
||||
''').format(box_name=cfg.box_name)
|
||||
|
||||
if not self.get_installed_status():
|
||||
status = _('''
|
||||
<p>Firewall is not installed. Please install it. Firewall comes
|
||||
pre-installed with {box_name}. On any Debian based system (such as
|
||||
{box_name}) you may install it using the command 'aptitude install
|
||||
firewalld'</p>''').format(box_name=cfg.box_name)
|
||||
|
||||
return util.render_template(title=_("Firewall"),
|
||||
main=main + status)
|
||||
return util.render_template(template='firewall',
|
||||
title=_("Firewall"),
|
||||
firewall_status='not_installed')
|
||||
|
||||
if not self.get_enabled_status():
|
||||
status = _('''
|
||||
<p>Firewall daemon is not running. Please run it. Firewall comes
|
||||
enabled by default on {box_name}. On any Debian based system (such as
|
||||
{box_name}) you may run it using the command 'service firewalld start'
|
||||
or in case of system with systemd 'systemctl start firewalld'</p>
|
||||
''').format(box_name=cfg.box_name)
|
||||
return util.render_template(template='firewall',
|
||||
title=_("Firewall"),
|
||||
firewall_status='not_running')
|
||||
|
||||
return util.render_template(title=_("Firewall"),
|
||||
main=main + status)
|
||||
internal_enabled_services = self.get_enabled_services(zone='internal')
|
||||
external_enabled_services = self.get_enabled_services(zone='external')
|
||||
|
||||
internal_enabled_sevices = self.get_enabled_services(zone='internal')
|
||||
external_enabled_sevices = self.get_enabled_services(zone='external')
|
||||
|
||||
services_info = '<ul>'
|
||||
for service in service_module.SERVICES.values():
|
||||
if service.is_enabled():
|
||||
service_text = _('Enabled')
|
||||
service_class = 'firewall-permitted'
|
||||
else:
|
||||
service_text = _('Disabled')
|
||||
service_class = 'firewall-blocked'
|
||||
|
||||
port_info = []
|
||||
for port in service.ports:
|
||||
if port in internal_enabled_sevices and \
|
||||
port in external_enabled_sevices:
|
||||
text = _('Permitted')
|
||||
css_class = 'firewall-permitted'
|
||||
elif port in internal_enabled_sevices:
|
||||
text = _('Permitted (internal only)')
|
||||
css_class = 'firewall-permitted'
|
||||
elif port in external_enabled_sevices:
|
||||
text = _('Permitted (external only)')
|
||||
css_class = 'firewall-permitted'
|
||||
else:
|
||||
text = _('Blocked')
|
||||
css_class = 'firewall-blocked'
|
||||
|
||||
info = _('''
|
||||
<li>{port}: <span class={css_class}>{text}</span></li>
|
||||
''').format(port=port, css_class=css_class, text=text)
|
||||
port_info.append(info)
|
||||
|
||||
port_info = '<ul>{port_info}</ul>'.format(
|
||||
port_info=''.join(port_info))
|
||||
|
||||
services_info += _('''
|
||||
<li>
|
||||
{name}: <span class={service_class}>{service_text}</span>
|
||||
{port_info}
|
||||
</li>
|
||||
''').format(
|
||||
name=service.name, service_class=service_class,
|
||||
service_text=service_text, port_info=port_info)
|
||||
|
||||
services_info += '</ul>'
|
||||
|
||||
footnote = '''
|
||||
<p><em>The operation of the firewall is automatic. When you enable a
|
||||
service it is automatically permitted in the firewall and you disable
|
||||
a service is automatically disabled in the firewall.</em></p>'''
|
||||
|
||||
return util.render_template(title=_("Firewall"), main=main +
|
||||
services_info + footnote)
|
||||
return util.render_template(
|
||||
template='firewall', title=_('Firewall'),
|
||||
services=service_module.SERVICES.values(),
|
||||
internal_enabled_services=internal_enabled_services,
|
||||
external_enabled_services=external_enabled_services)
|
||||
|
||||
def get_installed_status(self):
|
||||
"""Return whether firewall is installed"""
|
||||
|
||||
64
modules/installed/system/templates/firewall.html
Normal file
64
modules/installed/system/templates/firewall.html
Normal file
@ -0,0 +1,64 @@
|
||||
{% extends "login_nav.html" %}
|
||||
|
||||
{% block main_block %}
|
||||
|
||||
<p>Firewall is a network security system that controls the incoming
|
||||
and outgoing network traffic on your {{ cfg.box_name }}. Keeping a
|
||||
firewall enabled and properly configured reduces risk of security
|
||||
threat from the Internet.</p>
|
||||
|
||||
<p>The following the current status:</p>
|
||||
|
||||
{% if firewall_status = 'not_installed' %}
|
||||
<p>Firewall is not installed. Please install it. Firewall comes
|
||||
pre-installed with {{ cfg.box_name }}. On any Debian based system
|
||||
(such as {{ cfg.box_name }}) you may install it using the command 'aptitude
|
||||
install firewalld'</p>
|
||||
|
||||
{% elif firewall_status = 'not_running' %}
|
||||
|
||||
<p>Firewall daemon is not running. Please run it. Firewall comes
|
||||
enabled by default on {{ cfg.box_name }}. On any Debian based system
|
||||
(such as {{ cfg.box_name }}) you may run it using the command 'service
|
||||
firewalld start' or in case of a system with systemd 'systemctl start
|
||||
firewalld'</p>
|
||||
|
||||
{% else %}
|
||||
|
||||
<ul>
|
||||
|
||||
{% for service in services %}
|
||||
<li>{{ service.name }}:
|
||||
{% if service.is_enabled %}
|
||||
<span class='firewall-permitted'>Enabled</span>
|
||||
{% else %}
|
||||
<span class='firewall-blocked'>Disabled</span>
|
||||
{% endif %}
|
||||
|
||||
<ul>
|
||||
{% for port in service.ports %}
|
||||
<li> {{ port }}:
|
||||
{% if port in internal_enabled_services and port in external_enabled_services %}
|
||||
<span class='firewall-permitted'>Permitted</span>
|
||||
{% elif port in internal_enabled_services %}
|
||||
<span class='firewall-permitted'>Permitted (internal only)</span>
|
||||
{% elif port in external_enabled_services %}
|
||||
<span class='firewall-permitted'>Permitted (external only)</span>
|
||||
{% else %}
|
||||
<span class='firewall-blocked'>Blocked</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
||||
|
||||
<p><em>The operation of the firewall is automatic. When you enable a
|
||||
service it is automatically permitted in the firewall and you disable
|
||||
a service is automatically disabled in the firewall.</em></p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user