Skip to content

Commit

Permalink
Refactor Multi Report to comply to the new report flow (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rieven authored Oct 30, 2024
1 parent 1c08cde commit 5b33461
Show file tree
Hide file tree
Showing 28 changed files with 1,939 additions and 191 deletions.
8 changes: 4 additions & 4 deletions boefjes/tests/examples/report-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@
}
},
"summary": {
"Critical vulnerabilities": 0,
"IPs scanned": 1,
"Hostnames scanned": 1,
"Terms in report": ""
"critical_vulnerabilities": 0,
"ips_scanned": 1,
"hostnames_scanned": 1,
"terms_in_report": ""
},
"total_findings": 0,
"total_systems": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any

import structlog
from django.utils.translation import gettext_lazy as _

from octopoes.connector.octopoes import OctopoesAPIConnector
from octopoes.models import OOI
Expand Down Expand Up @@ -372,16 +371,16 @@ def is_mail_compliant(result):

summary = {
# _("General recommendations"): "",
str(_("Critical vulnerabilities")): total_criticals,
str(_("IPs scanned")): total_ips,
str(_("Hostnames scanned")): total_hostnames,
"critical_vulnerabilities": total_criticals,
"ips_scanned": total_ips,
"hostnames_scanned": total_hostnames,
# _("Systems found"): total_systems,
# _("Sector of organisation"): "",
# _("Basic security score compared to sector"): "",
# _("Sector defined"): "",
# _("Lowest security score in organisation"): "",
# _("Newly discovered items since last week, october 8th 2023"): "",
str(_("Terms in report")): ", ".join(sorted(terms)),
"terms_in_report": ", ".join(sorted(terms)),
}

all_findings = set()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@
<div>
<h2>{% translate "Summary" %}</h2>
<dl>
{% for key, value in data.items %}
<div>
<dt>{{ key }}</dt>
<dd>
{{ value }}
</dd>
</div>
{% endfor %}
<div>
<dt>{% translate "Critical Vulnerabilities" %}</dt>
<dd>
{{ data.critical_vulnerabilities }}
</dd>
</div>
<div>
<dt>{% translate "IPs scanned" %}</dt>
<dd>
{{ data.ips_scanned }}
</dd>
</div>
<div>
<dt>{% translate "Hostnames scanned" %}</dt>
<dd>
{{ data.hostnames_scanned }}
</dd>
</div>
<div>
<dt>{% translate "Terms in report" %}</dt>
<dd>
{{ data.terms_in_report }}
</dd>
</div>
</dl>
</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load i18n %}

<section id="appendix">
<div class="chapter-numbers">
<div class="chapter-numbers type-a">
<h2 id="appendix">{% translate "Appendix" %}</h2>
{% include "aggregate_organisation_report/term_overview.html" %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ <h2>{% translate "Asset overview" %}</h2>
</thead>
<tbody>
{% for asset_vulnerability in report_data.asset_vulnerabilities %}
{% if asset_vulnerability.vulnerabilities %}
<tr>
<td>{{ asset_vulnerability.asset }}</td>
<td>{{ asset_vulnerability.vulnerabilities|join:", " }}</td>
<td>{% translate "Organisation" %} {{ asset_vulnerability.organisation }}</td>
</tr>
{% endif %}
<tr>
<td>{{ asset_vulnerability.asset }}</td>
<td>
{% if asset_vulnerability.vulnerabilities %}
{{ asset_vulnerability.vulnerabilities|join:", " }}
{% else %}
{% translate "No vulnerabilities found." %}
{% endif %}
</td>
<td>{% translate "Organisation" %} {{ asset_vulnerability.organisation }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
<section class="introduction" id="introduction">
<div>
<div class="horizontal-view toolbar">
<h1>Sector Report</h1>
<h1>{{ report_ooi.name }}</h1>
<div class="horizontal-view">
<a href="{{ report_download_url }}"
<a href="{{ report_download_pdf_url }}"
target="_blank"
rel="noopener noreferrer"
class="button ghost">{% translate "Download report" %}</a>
</div>
</div>
<div>
<p>{% translate "This is the OpenKAT Sector rapport." %}</p>
<p>{% translate "This is the OpenKAT" %} {{ report_ooi.name }}</p>
<div>
<p>
<strong>{% translate "Created with date from:" %}</strong> {{ observed_at }} {{ TIME_ZONE }}
{% translate "Created with date from: " %}<strong>{{ report_ooi.observed_at|date }}</strong>
</p>
<p>
{% translate "Created on:" %} <strong>{{ created_at }}</strong>
{% translate "Created on: " %}<strong>{{ report_ooi.date_generated|date }}</strong>
</p>
<p>
<strong>{% translate "Created by:" %}</strong> {{ organization_member.user.full_name }}
{% translate "Created by: " %}<strong>{{ organization_member.user.full_name }}</strong>
</p>
</div>
<p>
{% translate "This sector contains" %}
{{ report_data.organizations|length }}
{% translate "Scanned organizations." %}
{% translate "scanned organizations." %}
{% if report_data.tags %}
{% translate "Of these organizations" %}
{% for tag, organizations in report_data.tags.items %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
<div>
<h2>Open ports</h2>
<p>{% translate "See an overview of open ports found over all systems and the services these systems provide." %}</p>
<div class="horizontal-scroll">
<table>
<caption class="visually-hidden">{% translate "Overview of detected open ports" %}</caption>
<thead>
<tr>
<th scope="col">{% translate "Open ports" %}</th>
<th scope="col">{% translate "Occurrences (IP addresses)" %}</th>
<th scope="col">{% translate "Services" %}</th>
</tr>
</thead>
<tbody>
{% for port, port_info in report_data.open_ports.ports.items %}
{% if report_data.open_ports.ports %}
<div class="horizontal-scroll">
<table>
<caption class="visually-hidden">{% translate "Overview of detected open ports" %}</caption>
<thead>
<tr>
<td>{{ port }}</td>
<td>{{ port_info.open }}/{{ report_data.open_ports.total }}</td>
<td>{{ port_info.services|join:", "|upper }}</td>
<th scope="col">{% translate "Open ports" %}</th>
<th scope="col">{% translate "Occurrences (IP addresses)" %}</th>
<th scope="col">{% translate "Services" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</thead>
<tbody>
{% for port, port_info in report_data.open_ports.ports.items %}
<tr>
<td>{{ port }}</td>
<td>{{ port_info.open }}/{{ report_data.open_ports.total }}</td>
<td>{{ port_info.services|join:", "|upper }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
{% translate "No open ports found." %}
{% endif %}
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
<section id="recommendations">
<div>
<h2>{% translate "Recommendations" %}</h2>
{% if total_findings %}
<p>
{% blocktranslate count total_findings as count trimmed %}
There is <i>{{ total_findings }}</i> vulnerability
{% plural %}
There are <i>{{ total_findings }}</i> vulnerabilities
{% endblocktranslate %}
{% blocktranslate count total_systems as count trimmed %}
found on <i>{{ total_systems }}</i> system.
{% plural %}
found on <i>{{ total_systems }}</i> systems.
{% endblocktranslate %}
</p>
{% endif %}
{% if report_data.recommendation_counts %}
<div class="horizontal-scroll">
<table>
Expand Down
11 changes: 8 additions & 3 deletions rocky/reports/report_types/multi_organization_report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def post_process_data(self, data: dict[str, Any]) -> dict[str, Any]:
organization_metrics: dict[str, Any] = {}

for organization, report_data in data.items():
aggregate_data = report_data["data"]
basic_security = {"compliant": 0, "total": 0}

for tag in report_data["organization_tags"]:
Expand All @@ -63,13 +64,17 @@ def post_process_data(self, data: dict[str, Any]) -> dict[str, Any]:

tags[tag].append(report_data["organization_code"])

aggregate_data = report_data["data"]["post_processed_data"]
total_critical_vulnerabilities += aggregate_data["summary"]["Critical vulnerabilities"]
# Added for backward compatability issues
if "Critical vulnerabilities" in aggregate_data["summary"]:
total_critical_vulnerabilities += aggregate_data["summary"]["Critical vulnerabilities"]
else:
total_critical_vulnerabilities += aggregate_data["summary"]["critical_vulnerabilities"]

total_findings += aggregate_data["total_findings"]
total_systems += aggregate_data["total_systems"]
total_hostnames += aggregate_data["total_hostnames"]

for compliance in report_data["data"]["post_processed_data"]["basic_security"]["summary"].values():
for compliance in report_data["data"]["basic_security"]["summary"].values():
for counts in compliance.values():
basic_security["total"] += counts["total"]
basic_security["compliant"] += counts["number_of_compliant"]
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/templates/multi_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block content %}
{% include "header.html" %}
{% include template %}
{% include report_ooi.template with data=report_data %}

{% endblock content %}
{% block html_at_end_body %}
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/templates/multi_report_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% endcompress %}
</head>
<body>
{% include template %}
{% include report_ooi.template with data=report_data %}

</body>
</html>
42 changes: 22 additions & 20 deletions rocky/reports/templates/partials/report_sidemenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ <h2 class="heading-large">{% translate "Table of contents" %}</h2>
</ol>
</li>
{% endif %}
{% if data.vulnerabilities %}
<li>
<a href="#vulnerabilities">{% translate "Vulnerabilities" %}</a>
<li>
<a href="#vulnerabilities">{% translate "Vulnerabilities" %}</a>
{% if data.vulnerabilities %}
<ol>
{% for input_ooi, vulnerabilities in data.vulnerabilities.items %}
{% if vulnerabilities.vulnerabilities %}
<li class="object">
<a href="#vulnerabilities">{{ vulnerabilities.title }}</a>
</li>
{% endif %}
{% endfor %}
</ol>
</ol>
{% endfor %}
</li>
{% endif %}
</ol>
Expand All @@ -71,21 +71,23 @@ <h2 class="heading-large">{% translate "Table of contents" %}</h2>
<li>
<a href="#term-overview">{% translate "Term Overview" %}</a>
</li>
<li>
<a href="#selected-oois">{% translate "Selected Objects" %}</a>
</li>
<li>
<a href="#selected-report-types">{% translate "Selected Report Types" %}</a>
</li>
<li>
<a href="#selected-plugins">{% translate "Selected Plugins" %}</a>
</li>
<li>
<a href="#service-versions-and-health">{% translate "Service Versions and Health" %}</a>
</li>
<li>
<a href="#used-config-oois">{% translate "Used Config Objects" %}</a>
</li>
{% if 'multi-organization-report' not in data.input_data.report_types %}
<li>
<a href="#selected-oois">{% translate "Selected Objects" %}</a>
</li>
<li>
<a href="#selected-report-types">{% translate "Selected Report Types" %}</a>
</li>
<li>
<a href="#selected-plugins">{% translate "Selected Plugins" %}</a>
</li>
<li>
<a href="#service-versions-and-health">{% translate "Service Versions and Health" %}</a>
</li>
<li>
<a href="#used-config-oois">{% translate "Used Config Objects" %}</a>
</li>
{% endif %}
</ol>
</li>
</ol>
Expand Down
2 changes: 0 additions & 2 deletions rocky/reports/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from reports.views.multi_report import (
ExportSetupMultiReportView,
LandingMultiReportView,
MultiReportPDFView,
MultiReportView,
OOISelectionMultiReportView,
ReportTypesSelectionMultiReportView,
Expand Down Expand Up @@ -87,5 +86,4 @@
path("multi-report/setup-scan/", SetupScanMultiReportView.as_view(), name="multi_report_setup_scan"),
path("multi-report/export-setup/", ExportSetupMultiReportView.as_view(), name="multi_report_export_setup"),
path("multi-report/view/", MultiReportView.as_view(), name="multi_report_view"),
path("multi-report/view/pdf/", MultiReportPDFView.as_view(), name="multi_report_pdf"),
]
6 changes: 3 additions & 3 deletions rocky/reports/views/aggregate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.views.generic import TemplateView

from reports.report_types.aggregate_organisation_report.report import AggregateOrganisationReport
from reports.report_types.helpers import get_ooi_types_from_aggregate_report
from reports.views.base import (
REPORTS_PRE_SELECTION,
OOISelectionView,
Expand Down Expand Up @@ -61,7 +60,7 @@ class OOISelectionAggregateReportView(AggregateReportStepsMixin, BreadcrumbsAggr
template_name = "aggregate_report/select_oois.html"
breadcrumbs_step = 3
current_step = 1
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)
report_type = AggregateOrganisationReport

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand All @@ -81,7 +80,6 @@ class ReportTypesSelectionAggregateReportView(
breadcrumbs_step = 4
current_step = 2
report_type = AggregateOrganisationReport
ooi_types = get_ooi_types_from_aggregate_report(report_type)


class SetupScanAggregateReportView(
Expand All @@ -94,6 +92,7 @@ class SetupScanAggregateReportView(
template_name = "aggregate_report/setup_scan.html"
breadcrumbs_step = 5
current_step = 3
report_type = AggregateOrganisationReport


class ExportSetupAggregateReportView(
Expand All @@ -117,3 +116,4 @@ class SaveAggregateReportView(SaveAggregateReportMixin, BreadcrumbsAggregateRepo
template_name = "aggregate_report.html"
breadcrumbs_step = 6
current_step = 5
report_type = AggregateOrganisationReport
Loading

0 comments on commit 5b33461

Please sign in to comment.