template restructure

This commit is contained in:
2025-10-21 21:00:48 -05:00
parent 583cbffeca
commit f394e268da
11 changed files with 512 additions and 126 deletions

View File

@@ -3,8 +3,6 @@ import logging
logging.basicConfig(level=logging.INFO)
# TODO:
# LOGGING
# REPORT - use the scan config names for the names of the report and file
# REPORT - make darkmode
# TLS SCANNING
# TLS Version PROBE
@@ -12,13 +10,14 @@ logging.basicConfig(level=logging.INFO)
import time
from pathlib import Path
from typing import Dict, List, Set
from dataclasses import asdict
from ipaddress import ip_address
from typing import Any, Dict, List, Set
from utils.scan_config_loader import ScanConfigRepository, ScanConfigFile
from utils.schedule_manager import ScanScheduler
from utils.scanner import nmap_scanner
from utils.models import HostResult
from utils.models import HostResult, HostReport, GroupedReports
from reporting_jinja import write_html_report_jinja
from utils.settings import get_settings
@@ -29,8 +28,6 @@ logger = logging.getLogger(__file__)
utils = get_common_utils()
settings = get_settings()
HTML_REPORT_FILE = Path() / "data" / "report.html"
def results_to_open_sets(
results: List[HostResult],
count_as_open: Set[str] = frozenset({"open", "open|filtered"})) -> Dict[str, Dict[str, Set[int]]]:
@@ -125,16 +122,35 @@ def build_reports(
def run_repo_scan(scan_config:ScanConfigFile):
logger.info(f"Starting scan for {scan_config.name}")
logger.info("Options: udp=%s tls_sec=%s tls_exp=%s",
scan_config.scan_options.udp_scan,
scan_config.scan_options.tls_security_scan,
scan_config.scan_options.tls_exp_check)
logger.info(f"Options: udp={scan_config.scan_options.udp_scan} tls_sec={scan_config.scan_options.tls_security_scan} tls_exp={scan_config.scan_options.tls_exp_check}",)
logger.info(f"Reporting Options: Dark Mode: {scan_config.reporting.dark_mode}")
logger.info("Targets: %d hosts", len(scan_config.scan_targets))
# tack the filename on the end of our data path
file_out_path = Path() / "data" / "output" / scan_config.reporting.report_filename
LIGHT_TEMPLATE = "report_light.html.j2"
DARK_TEMPLATE = "report_dark.html.j2"
template = LIGHT_TEMPLATE
if scan_config.reporting.dark_mode:
template = DARK_TEMPLATE
logger.info(f"Reporting Template Set to: {template}")
scanner = nmap_scanner(scan_config)
scan_results = scanner.scan_targets()
discovered_sets = results_to_open_sets(scan_results, count_as_open={"open", "open|filtered"})
reports = build_reports(scan_config, discovered_sets)
write_html_report_jinja(reports=reports,host_results=scan_results,out_path=HTML_REPORT_FILE,title="Compliance Report",only_issues=True)
# build the HTML report
write_html_report_jinja(reports=reports,
host_results=scan_results,
out_path=file_out_path,
title=scan_config.reporting.report_name,
template_name=template,
only_issues=True)
scanner.cleanup()
def main():