feat(gui): implement polished vanilla dashboard with CVSS severity palette and SVG charts

This commit is contained in:
Lucas Rayan committed 2026-11-02 01:01:54 -03:00
1 parent 3e41c169d0
commit bc72dbffbd
8 files changed
+2833 -64

No files matched your search

+59 -63
View File
@@ -8,8 +8,8 @@ use std::sync::Arc;
use std::time::Duration;
use axum::extract::{Query, State};
use axum::http::StatusCode;
use axum::response::Html;
use axum::http::{header, StatusCode};
use axum::response::IntoResponse;
use axum::{Json, Router};
use chrono::{DateTime, Utc};
use clap::{Parser, Subcommand};
@@ -883,65 +883,56 @@ async fn changes_handler(
Ok(Json(events))
}
async fn dashboard_handler() -> Html<&'static str> {
const HTML: &str = r#"<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Xexéu — Painel de Auditoria Contínua</title>
<style>
body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #0f172a; color: #f8fafc; margin: 0; padding: 28px; }
h1 { font-size: 1.6rem; margin-bottom: 6px; color: #38bdf8; }
.subtitle { color: #94a3b8; font-size: 0.95rem; margin-bottom: 24px; }
.card { background: #1e293b; border: 1px solid #334155; border-radius: 8px; padding: 18px; margin-bottom: 20px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
.badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; }
.badge-active { background: #065f46; color: #34d399; }
.badge-open { background: #0284c7; color: #bae6fd; margin-right: 4px; font-family: monospace; }
table { width: 100%; border-collapse: collapse; margin-top: 14px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #334155; font-size: 0.9rem; }
th { color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
</style>
</head>
<body>
<h1>Xexéu</h1>
<div class="subtitle">Auditoria contínua de superfície de ataque e identificação de vulnerabilidades</div>
<div id="status-card" class="card"><strong>Carregando status...</strong></div>
<div class="card">
<h2 style="font-size: 1.15rem; margin-top: 0; margin-bottom: 12px;">Ativos e Superfície Descoberta</h2>
<div id="hosts-container">Carregando ativos...</div>
</div>
<script>
async function loadData() {
try {
const sRes = await fetch('/api/status');
const status = await sRes.json();
document.getElementById('status-card').innerHTML = `
<div><strong>Versão:</strong> ${status.version} &nbsp;|&nbsp; <strong>Lotes Ingeridos:</strong> ${status.sweeps_ingested} &nbsp;|&nbsp; <strong>CVEs:</strong> ${status.feeds_cve_count} (${status.feeds_kev_count} no KEV)</div>
<div style="margin-top: 6px; font-size: 0.85rem; color: #94a3b8;">Configuração: <code>${status.config_path}</code> &nbsp;|&nbsp; <strong>Último Sync:</strong> ${status.feeds_last_sync || 'não executado'}</div>
`;
const hRes = await fetch('/api/hosts');
const hosts = await hRes.json();
if (hosts.length === 0) {
document.getElementById('hosts-container').innerHTML = '<p style="color: #94a3b8; margin: 0;">Nenhum ativo ingerido ainda.</p>';
return;
}
let html = '<table><thead><tr><th>IP</th><th>Grupo</th><th>Status</th><th>Portas Abertas</th><th>Visto em</th></tr></thead><tbody>';
for (const h of hosts) {
const ports = h.ports.filter(p => p.status === 'aberta').map(p => `<span class="badge badge-open">${p.protocol}/${p.port}</span>`).join(' ') || '—';
html += `<tr><td><strong>${h.ip}</strong></td><td>${h.network}</td><td><span class="badge badge-active">${h.status}</span></td><td>${ports}</td><td>${h.last_seen}</td></tr>`;
}
html += '</tbody></table>';
document.getElementById('hosts-container').innerHTML = html;
} catch (e) {
console.error(e);
}
}
loadData();
setInterval(loadData, 5000);
</script>
</body>
</html>"#;
Html(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 LOGO_PNG: &[u8] = include_bytes!("../../../logo.png");
async fn index_handler() -> impl IntoResponse {
(
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
INDEX_HTML,
)
}
async fn css_handler() -> impl IntoResponse {
([(header::CONTENT_TYPE, "text/css; charset=utf-8")], APP_CSS)
}
async fn js_handler() -> impl IntoResponse {
(
[(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)],
APP_JS,
)
}
async fn i18n_js_handler() -> impl IntoResponse {
(
[(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)],
I18N_JS,
)
}
async fn i18n_en_js_handler() -> impl IntoResponse {
(
[(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)],
I18N_EN_JS,
)
}
async fn logo_handler() -> impl IntoResponse {
([(header::CONTENT_TYPE, "image/png")], LOGO_PNG)
}
fn parse_duration_str(raw: &str) -> Option<Duration> {
@@ -1070,8 +1061,13 @@ async fn run_serve(
.route("/api/status", axum::routing::get(status_handler))
.route("/api/hosts", axum::routing::get(hosts_handler))
.route("/api/changes", axum::routing::get(changes_handler))
.route("/", axum::routing::get(dashboard_handler))
.route("/dashboard", axum::routing::get(dashboard_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("/logo.png", axum::routing::get(logo_handler))
.with_state(state);
let listener = tokio::net::TcpListener::bind(bind)
+30 -1
View File
@@ -189,12 +189,41 @@ alvos = ["127.0.0.1/32"]
"changes events: {body}"
);
// 10. Verify / and /dashboard return HTML
// 10. Verify / and /dashboard return HTML, and static assets are served
let (status, body) = http_get(&server_addr, "/");
assert_eq!(status, 200);
assert!(body.contains("Xexéu"), "dashboard html: {body}");
assert!(body.contains("app.css"), "dashboard html links css: {body}");
let (status, body) = http_get(&server_addr, "/dashboard");
assert_eq!(status, 200);
assert!(body.contains("Xexéu"), "dashboard html: {body}");
let (status, body) = http_get(&server_addr, "/app.css");
assert_eq!(status, 200);
assert!(
body.contains("--sev-critical"),
"app.css contains severity tokens"
);
let (status, body) = http_get(&server_addr, "/app.js");
assert_eq!(status, 200);
assert!(
body.contains("renderSeverityChart"),
"app.js contains chart logic"
);
let (status, body) = http_get(&server_addr, "/i18n.js");
assert_eq!(status, 200);
assert!(
body.contains("export function tr"),
"i18n.js contains tr function"
);
let (status, body) = http_get(&server_addr, "/i18n-en.js");
assert_eq!(status, 200);
assert!(
body.contains("export const EN"),
"i18n-en.js contains dictionary"
);
}
@@ -0,0 +1,121 @@
use std::io::{BufRead, BufReader, Read, Write};
use std::net::TcpStream;
use std::path::Path;
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
struct ChildGuard(std::process::Child);
impl Drop for ChildGuard {
fn drop(&mut self) {
let _ = self.0.kill();
let _ = self.0.wait();
}
}
fn http_get(addr: &str, path: &str) -> (u16, String) {
let mut stream = TcpStream::connect(addr).expect("connect to server");
stream
.set_read_timeout(Some(Duration::from_secs(3)))
.expect("set read timeout");
let request = format!("GET {path} HTTP/1.1\r\nHost: {addr}\r\nConnection: close\r\n\r\n");
stream.write_all(request.as_bytes()).expect("write request");
let mut bytes = Vec::new();
stream.read_to_end(&mut bytes).expect("read response");
let response = String::from_utf8_lossy(&bytes).to_string();
let status_line = response.lines().next().unwrap_or("");
let code: u16 = status_line
.split_whitespace()
.nth(1)
.unwrap_or("0")
.parse()
.unwrap_or(0);
let body = response.split("\r\n\r\n").nth(1).unwrap_or("").to_string();
(code, body)
}
#[test]
fn serve_validates_against_real_dvwa_scan_data() {
let validate_dir = Path::new("/tmp/xexeu-validate");
if !validate_dir.exists() {
eprintln!("skip: /tmp/xexeu-validate does not exist");
return;
}
let config_path = validate_dir.join("xexeu.toml");
let sweeps_dir = validate_dir.join("sweeps");
let data_dir = validate_dir.join("data");
let mut child = Command::new(env!("CARGO_BIN_EXE_xexeu"))
.args([
"serve",
"--bind",
"127.0.0.1:0",
"--config",
config_path.to_str().expect("config"),
"--sweeps",
sweeps_dir.to_str().expect("sweeps"),
"--data-dir",
data_dir.to_str().expect("data"),
])
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.expect("spawn xexeu serve");
let stdout = child.stdout.take().expect("take stdout");
let mut reader = BufReader::new(stdout);
let mut server_addr = None;
let deadline = Instant::now() + Duration::from_secs(5);
while Instant::now() < deadline {
let mut line = String::new();
if reader.read_line(&mut line).unwrap_or(0) > 0 {
if let Some(pos) = line.find("http://") {
let rest = &line[pos + "http://".len()..];
let addr = rest.split_whitespace().next().unwrap_or("").trim();
server_addr = Some(addr.to_string());
break;
}
}
}
let _guard = ChildGuard(child);
let server_addr = server_addr.expect("server listening addr");
// Poll /api/hosts
let poll_deadline = Instant::now() + Duration::from_secs(6);
let mut dvwa_found = false;
while Instant::now() < poll_deadline {
let (status, body) = http_get(&server_addr, "/api/hosts");
if status == 200 && body.contains("172.30.0.10") && body.contains("CVE-2017-3167") {
dvwa_found = true;
assert!(body.contains("Apache HTTP Server"));
assert!(body.contains("2.4.25"));
assert!(body.contains(r#""cvss":9.8"#));
break;
}
std::thread::sleep(Duration::from_millis(300));
}
assert!(
dvwa_found,
"expected DVWA host 172.30.0.10 with CVE-2017-3167 in /api/hosts"
);
// Check dashboard and static assets
let (status, body) = http_get(&server_addr, "/");
assert_eq!(status, 200);
assert!(body.contains("Xexéu"));
let (status, body) = http_get(&server_addr, "/app.css");
assert_eq!(status, 200);
assert!(body.contains("--sev-critical"));
let (status, body) = http_get(&server_addr, "/app.js");
assert_eq!(status, 200);
assert!(body.contains("renderSeverityChart"));
let (status, _) = http_get(&server_addr, "/logo.png");
assert_eq!(status, 200);
}