feat(report): implement exportable executive security report with A4 Paged.js pagination

This commit is contained in:
Lucas Rayan committed 2026-11-02 09:36:41 -03:00
1 parent e8e529b09c
commit f388d95839
7 files changed
+1432 -1

No files matched your search

+34
View File
@@ -18,6 +18,7 @@ use tokio::sync::{Mutex, RwLock};
use xexeu_core::batch::{EngineMode, ServiceObservation, SweepBatch, SweepManifest, SweepStatus};
use xexeu_core::config::{GroupConfig, ValidationReport, XexeuConfig};
use xexeu_core::diff::{diff_batch, DiffOptions, EventKind};
use xexeu_core::report::ExecutiveReport;
use xexeu_core::scan::{
discover_hosts_tcp, fingerprint_service, scan_hosts_tcp_connect, DiscoveryConfig, HostState,
PortScanConfig, PortState, PortTarget, DEFAULT_DISCOVERY_PORTS,
@@ -1255,11 +1256,31 @@ async fn changes_handler(
Ok(Json(events))
}
async fn report_handler(
State(state): State<ServerState>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
let config = state.config.read().await.clone();
let storage = state.storage.lock().await;
let current_state = storage.load_state(&[]).map_err(|error| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("erro ao consultar estado para relatório: {error}"),
)
})?;
let vuln_db = state.vuln_db.read().await.clone();
let last_sync = *state.feeds_last_sync.read().await;
let report = ExecutiveReport::build(&config, &current_state, &vuln_db, last_sync, Utc::now());
let html = report.render_html();
Ok(([(header::CONTENT_TYPE, "text/html; charset=utf-8")], html))
}
const INDEX_HTML: &str = include_str!("../../../apps/gui/ui/index.html");
const APP_CSS: &str = include_str!("../../../apps/gui/ui/app.css");
const APP_JS: &str = include_str!("../../../apps/gui/ui/app.js");
const I18N_JS: &str = include_str!("../../../apps/gui/ui/i18n.js");
const I18N_EN_JS: &str = include_str!("../../../apps/gui/ui/i18n-en.js");
const PAGED_JS: &str = include_str!("../../../apps/gui/ui/paged.polyfill.min.js");
const LOGO_PNG: &[u8] = include_bytes!("../../../logo.png");
async fn index_handler() -> impl IntoResponse {
@@ -1303,6 +1324,16 @@ async fn i18n_en_js_handler() -> impl IntoResponse {
)
}
async fn paged_js_handler() -> impl IntoResponse {
(
[(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)],
PAGED_JS,
)
}
async fn logo_handler() -> impl IntoResponse {
([(header::CONTENT_TYPE, "image/png")], LOGO_PNG)
}
@@ -1454,12 +1485,15 @@ async fn run_serve(
"/api/export/changes.csv",
axum::routing::get(export_changes_csv_handler),
)
.route("/relatorio", axum::routing::get(report_handler))
.route("/report", axum::routing::get(report_handler))
.route("/", axum::routing::get(index_handler))
.route("/dashboard", axum::routing::get(index_handler))
.route("/app.css", axum::routing::get(css_handler))
.route("/app.js", axum::routing::get(js_handler))
.route("/i18n.js", axum::routing::get(i18n_js_handler))
.route("/i18n-en.js", axum::routing::get(i18n_en_js_handler))
.route("/paged.polyfill.js", axum::routing::get(paged_js_handler))
.route("/logo.png", axum::routing::get(logo_handler))
.with_state(state);
@@ -202,6 +202,18 @@ alvos = ["127.0.0.1/32"]
assert!(headers.contains("content-type: text/csv; charset=utf-8"));
assert!(headers.contains("content-disposition: attachment; filename=\"xexeu-changes-"));
assert!(body.starts_with("Data/Hora (UTC),Tipo de Evento,Alvo / Host,Grupo,Detalhe"));
// Executive Report HTML
let (code, headers, body) = http_request(&addr, "GET", "/relatorio", None);
assert_eq!(code, 200);
assert!(headers.contains("content-type: text/html; charset=utf-8"));
assert!(body.contains("Relatório Executivo de Segurança — Xexéu"));
assert!(body.contains("Indicadores-Chave de Exposição (KPIs)"));
assert!(body.contains("Glossário e Metodologia de Avaliação"));
let (code, headers, _) = http_request(&addr, "GET", "/report", None);
assert_eq!(code, 200);
assert!(headers.contains("content-type: text/html; charset=utf-8"));
}
#[test]
+1
View File
@@ -5,6 +5,7 @@ pub mod batch;
pub mod config;
pub mod diff;
pub mod doctor;
pub mod report;
pub mod scan;
pub mod schedule;
pub mod storage;
File diff suppressed because it is too large. Load diff