From 03f5ca0b054ebcb440ea79df167bfc6d8bc7e66d Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 2 Oct 2019 22:31:13 -0400 Subject: [PATCH] security: Move security report to new page Signed-off-by: James Valleroy [sunil@medhas.org Remove status header similar to other toolbars] [sunil@medhas.org Add icon to 'show security report' button] [sunil@medhas.org Handle error retrieving past CVE counts] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- .../modules/security/templates/security.html | 43 ++------------ .../security/templates/security_report.html | 56 +++++++++++++++++++ plinth/modules/security/urls.py | 1 + plinth/modules/security/views.py | 21 +++++-- 4 files changed, 76 insertions(+), 45 deletions(-) create mode 100644 plinth/modules/security/templates/security_report.html diff --git a/plinth/modules/security/templates/security.html b/plinth/modules/security/templates/security.html index 845c32127..aedea86b3 100644 --- a/plinth/modules/security/templates/security.html +++ b/plinth/modules/security/templates/security.html @@ -22,44 +22,9 @@ {% load i18n %} {% block status %} -

{% trans "Status" %}

-

- {% blocktrans trimmed with count=freedombox_vulns.count %} - The installed version of FreedomBox has {{ count }} reported security - vulnerabilities. - {% endblocktrans %} -

-

- {% blocktrans trimmed %} - The following table lists the reported number of security vulnerabilities - for each installed app. - {% endblocktrans %} -

- + + {% trans "Show security report" %} - -
- - - - - - - - - - {% for app in apps_vulns %} - - - - - - {% endfor %} - -
{% trans "App Name" %}{% trans "Current Vulnerabilities" %}{% trans "Past Vulnerabilities" %}
{{ app.name }}{{ app.count }}{{ app.past_count }}
-
{% endblock %} diff --git a/plinth/modules/security/templates/security_report.html b/plinth/modules/security/templates/security_report.html new file mode 100644 index 000000000..19bbd001c --- /dev/null +++ b/plinth/modules/security/templates/security_report.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} +{% comment %} +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% load bootstrap %} +{% load i18n %} + +{% block content %} +

{% trans "Security Report" %}

+

+ {% blocktrans trimmed with count=freedombox_vulns.count %} + The installed version of FreedomBox has {{ count }} reported security + vulnerabilities. + {% endblocktrans %} +

+

+ {% blocktrans trimmed %} + The following table lists the current reported number, and historical + count, of security vulnerabilities for each installed app. + {% endblocktrans %} +

+ + + + + + + + + + {% for app in apps_vulns %} + + + + + + {% endfor %} + +
{% trans "App Name" %}{% trans "Current Vulnerabilities" %}{% trans "Past Vulnerabilities" %}
{{ app.name }}{{ app.count }}{{ app.past_count|default_if_none:"❗"}}
+{% endblock %} diff --git a/plinth/modules/security/urls.py b/plinth/modules/security/urls.py index bc76c779b..ffdd10c22 100644 --- a/plinth/modules/security/urls.py +++ b/plinth/modules/security/urls.py @@ -26,4 +26,5 @@ from . import views urlpatterns = [ url(r'^sys/security/$', views.index, name='index'), + url(r'^sys/security/report$', views.report, name='report'), ] diff --git a/plinth/modules/security/views.py b/plinth/modules/security/views.py index 77e9490aa..3fbf5521b 100644 --- a/plinth/modules/security/views.py +++ b/plinth/modules/security/views.py @@ -43,7 +43,6 @@ def index(request): else: form = SecurityForm(initial=status, prefix='security') - vulnerability_counts = security.get_vulnerability_counts() return TemplateResponse( request, 'security.html', { 'name': @@ -52,11 +51,6 @@ def index(request): security.manual_page, 'form': form, - 'freedombox_vulns': - vulnerability_counts.pop('freedombox'), - 'apps_vulns': - sorted(vulnerability_counts.values(), - key=lambda app: app['name']), }) @@ -86,3 +80,18 @@ def _apply_changes(request, old_status, new_status): actions.superuser_run('service', ['enable', 'fail2ban']) else: actions.superuser_run('service', ['disable', 'fail2ban']) + + +def report(request): + """Serve the security report page""" + vulnerability_counts = security.get_vulnerability_counts() + return TemplateResponse( + request, 'security_report.html', { + 'title': + _('Security Report'), + 'freedombox_vulns': + vulnerability_counts.pop('freedombox'), + 'apps_vulns': + sorted(vulnerability_counts.values(), + key=lambda app: app['name']), + })