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

+1
View File
@@ -155,6 +155,7 @@ export const EN = {
// Actions, Exports & Group Management
'Exportar CSV': 'Export CSV',
'Exportar Relatório Executivo': 'Export Executive Report',
'Exportar relatório executivo (em breve)': 'Export executive report (coming soon)',
'+ Novo grupo': '+ New group',
'Novo Grupo': 'New Group',
+1 -1
View File
@@ -157,7 +157,7 @@
<div class="panel-actions">
<span id="hostCount" class="panel-tag">—</span>
<a href="/api/export/hosts.csv" class="btn secondary btn-sm" download>Exportar CSV</a>
<button type="button" class="btn secondary btn-sm" disabled title="Em breve">Exportar relatório executivo (em breve)</button>
<a href="/relatorio" target="_blank" rel="noopener noreferrer" class="btn secondary btn-sm">Exportar Relatório Executivo</a>
</div>
</div>
+4
View File
@@ -0,0 +1,4 @@
/**
* @license Paged.js v0.4.3 | MIT | https://gitlab.coko.foundation/pagedjs/pagedjs
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PagedPolyfill=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n,r={exports:{}},a={exports:{}};var i,o,s,l,d=function(){},p=d(),c=function(e){return e!==p&&null!==e};function u(){return l||(l=1,s=(n?t:(n=1,t=function(){try{return Object.keys("primitive"),!0}catch(e){return!1}}))()?Object.keys:function(){if(o)return i;o=1;var e=c,t=Object.keys;return i=function(n){return t(e(n)?Object(n):n)}}()),s}var m,h,g=c,f=function(e){if(!g(e))throw new TypeError("Cannot use null or undefined");return e};var y,b,S=function(){var e,t=Object.assign;return"function"==typeof t&&(t(e={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),e.foo+e.bar+e.trzy==="razdwatrzy")}()?Object.assign:function(){if(h)return m;h=1;var e=u(),t=f,n=Math.max;return m=function(r,a){var i,o,s,l=n(arguments.length,2);for(r=Object(t(r)),s=function(e){try{r[e]=a[e]}catch(e){i||(i=e)}},o=1;o<l;++o)e(a=arguments[o]).forEach(s);if(void 0!==i)throw i;return r},m}(),v=c,x=Array.prototype.forEach,k=Object.create,w="razdwatrzy";var C,T="function"==typeof w.contains&&!0===w.contains("dwa")&&!1===w.contains("foo")?String.prototype.contains:function(){if(b)return y;b=1;var e=String.prototype.indexOf;return y=function(t){return e.call(this,t,arguments[1])>-1},y}(),_=S,z=function(e){var t=k(null);return x.call(arguments,(function(e){v(e)&&function(e,t){var n;for(n in e)t[n]=e[n]}(Object(e),t)})),t},O=function(e){return"function"==typeof e},A=T;C=a.exports=function(e,t){var n,r,a,i,o;return arguments.length<2||"string"!=typeof e?(i=t,t=e,e=null):i=arguments[2],null==e?(n=a=!0,r=!1):(n=A.call(e,"c"),r=A.call(e,"e"),a=A.call(e,"w")),o={value:t,configurable:n,enumerable:r,writable:a},i?_(z(i),o):o},C.gs=function(e,t,n){var r,a,i,o;return"string"!=typeof e?(i=n,n=t,t=e,e=null):i=arguments[3],null==t?t=void 0:O(t)?null==n?n=void 0:O(n)||(i=n,n=void 0):(i=t,t=n=void 0),null==e?(r=!0,a=!1):(r=A.call(e,"c"),a=A.call(e,"e")),o={get:t,set:n,configurable:r,enumerable:a},i?_(z(i),o):o};var E=a.exports,j=function(e){if("function"!=typeof e)throw new TypeError(e+" is not a function");return e};!function(e,t){var n,r,a,i,o,s,l,d=E,p=j,c=Function.prototype.apply,u=Function.prototype.call,m=Object.create,h=Object.defineProperty,g=Object.defineProperties,f=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};n=function(e,t){var n;return p(t),f.call(this,"__ee__")?n=this.__ee__:(n=y.value=m(null),h(this,"__ee__",y),y.value=null),n[e]?"object"==typeof n[e]?n[e].push(t):n[e]=[n[e],t]:n[e]=t,this},r=function(e,t){var r,i;return p(t),i=this,n.call(this,e,r=function(){a.call(i,e,r),c.call(t,this,arguments)}),r.__eeOnceListener__=t,this},a=function(e,t){var n,r,a,i;if(p(t),!f.call(this,"__ee__"))return this;if(!(n=this.__ee__)[e])return this;if("object"==typeof(r=n[e]))for(i=0;a=r[i];++i)a!==t&&a.__eeOnceListener__!==t||(2===r.length?n[e]=r[i?0:1]:r.splice(i,1));else r!==t&&r.__eeOnceListener__!==t||delete n[e];return this},i=function(e){var t,n,r,a,i;if(f.call(this,"__ee__")&&(a=this.__ee__[e]))if("object"==typeof a){for(n=arguments.length,i=new Array(n-1),t=1;t<n;++t)i[t-1]=arguments[t];for(a=a.slice(),t=0;r=a[t];++t)c.call(r,this,i)}else switch(arguments.length){case 1:u.call(a,this);break;case 2:u.call(a,this,arguments[1]);break;case 3:u.call(a,this,arguments[1],arguments[2]);break;default:for(n=arguments.length,i=new Array(n-1),t=1;t<n;++t)i[t-1]=arguments[t];c.call(a,this,i)}},o={on:n,once:r,off:a,emit:i},s={on:d(n),once:d(r),off:d(a),emit:d(i)},l=g({},s),e.exports=t=function(e){return null==e?m(l):g(Object(e),s)},t.methods=o}(r,r.exports);var W=r.exports,L=e(W);class B{constructor(e){this.context=e||this,this.hooks=[]}register(){for(var e=0;e<arguments.length;++e)if("function"==typeof arguments[e])this.hooks.push(arguments[e]);else for(var t=0;t<arguments[e].length;++t)this.hooks.push(arguments[e][t])}trigger(){var e=arguments,t=this.context,n=[];return this.hooks.forEach((function(r){var a=r.apply(t,e);a&&"function"==typeof a.then?n.push(a):n.push(new Promise(((e,t)=>{e(a)})))})),Promise.all(n)}triggerSync(){var e=arguments,t=this.context,n=[];return this.hooks.forEach((function(r){var a=r.apply(t,e);n.push(a)})),n}list(){return this.hooks}clear(){return this.hooks=[]}}function P(e){if(!e)return;let t;if(void 0!==e.getBoundingClientRect)t=e.getBoundingClientRect();else{let n=document.createRange();n.selectNode(e),t=n.getBoundingClientRect()}return t}function q(e){if(!e)return;let t;if(void 0!==e.getClientRects)t=e.getClientRects();else{let n=document.createRange();n.selectNode(e),t=n.getClientRects()}return t}function M(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceLine truncated
+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