security: Add past vulnerabilities count

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil@medhas.org isort]
[sunil@medhas.org Handle errors during HTTP request]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2019-10-02 21:44:32 -04:00 committed by Sunil Mohan Adapa
parent f0e45d39c9
commit 5fe84bf395
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 20 additions and 1 deletions

1
debian/control vendored
View File

@ -99,6 +99,7 @@ Depends:
python3-gi,
python3-paramiko,
python3-psutil,
python3-requests,
python3-ruamel.yaml,
python3-yaml,
sudo,

View File

@ -21,6 +21,7 @@ FreedomBox app for security configuration.
import subprocess
from collections import defaultdict
import requests
from django.utils.translation import ugettext_lazy as _
from plinth import actions
@ -121,13 +122,23 @@ def get_vulnerability_counts():
(label, package, *_) = line.split()
cves[label].add(package)
try:
past_cves = requests.get(
'https://security-tracker.debian.org/tracker/data/json').json()
except Exception:
past_cves = None
apps = {
'freedombox': {
'name': 'freedombox',
'packages': {'freedombox'},
'count': 0,
'past_count': 0 if past_cves else None,
}
}
if past_cves and 'freedombox' in past_cves:
apps['freedombox']['past_count'] = len(past_cves['freedombox'])
for module_name, module in module_loader.loaded_modules.items():
try:
packages = module.managed_packages
@ -142,8 +153,13 @@ def get_vulnerability_counts():
'name': module_name,
'packages': set(packages),
'count': 0,
'past_count': 0 if past_cves else None,
}
for package in packages:
if past_cves and package in past_cves:
apps[module_name]['past_count'] += len(past_cves[package])
for cve_packages in cves.values():
for app_ in apps.values():
if cve_packages & app_['packages']:

View File

@ -47,7 +47,8 @@
<thead>
<tr>
<th>{% trans "App Name" %}</th>
<th>{% trans "Vulnerabilities Reported" %}</th>
<th>{% trans "Current Vulnerabilities" %}</th>
<th>{% trans "Past Vulnerabilities" %}</th>
</tr>
</thead>
<tbody>
@ -55,6 +56,7 @@
<tr>
<td>{{ app.name }}</td>
<td>{{ app.count }}</td>
<td>{{ app.past_count }}</td>
</tr>
{% endfor %}
</tbody>