A global middleware wraps the router and its fallback: only PUBLIC_ROUTES answer without a credential, and unknown paths look like protected ones. Adds cookie sessions with per-session CSRF, scoped Bearer tokens, the /api/auth and /api/admin handlers, Transport for client IP and Secure, and pending-token enrollment re-checked inside one store update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
4.4 KiB
Rust
144 lines
4.4 KiB
Rust
mod auth_http;
|
|
mod transport;
|
|
mod web;
|
|
|
|
use acaua_core::{doctor, update, zeek};
|
|
use clap::{Parser, Subcommand};
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Parser)]
|
|
#[command(
|
|
name = "acaua",
|
|
about = "Acauã — caça determinística a ameaças em rede",
|
|
version
|
|
)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum Command {
|
|
Serve {
|
|
#[arg(long, default_value = "127.0.0.1:8787")]
|
|
bind: String,
|
|
#[arg(long, default_value = ".acaua")]
|
|
data_dir: PathBuf,
|
|
},
|
|
Analyze {
|
|
directory: PathBuf,
|
|
#[arg(long, default_value = ".acaua")]
|
|
data_dir: PathBuf,
|
|
#[arg(long)]
|
|
json: bool,
|
|
},
|
|
Doctor {
|
|
#[arg(long)]
|
|
json: bool,
|
|
},
|
|
Update,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let cli = Cli::parse();
|
|
if let Err(error) = run(cli).await {
|
|
eprintln!("erro: {error}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
|
|
async fn run(cli: Cli) -> acaua_core::Result<()> {
|
|
match cli.command {
|
|
Command::Serve { bind, data_dir } => web::serve(&bind, data_dir).await,
|
|
Command::Analyze {
|
|
directory,
|
|
data_dir,
|
|
json,
|
|
} => {
|
|
let report = zeek::analyze_dir(&directory, &data_dir)?;
|
|
if json {
|
|
println!("{}", serde_json::to_string_pretty(&report)?);
|
|
} else {
|
|
println!("diretório: {}", report.directory);
|
|
println!("logs lidos: {}", report.logs_seen);
|
|
println!("registros: {}", report.records);
|
|
println!("alertas: {}", report.alerts.len());
|
|
for alert in &report.alerts {
|
|
println!(" [{:.3}] {}", alert.score, alert.summary);
|
|
}
|
|
if !report.hosts.is_empty() {
|
|
println!("hosts:");
|
|
for host in report.hosts.iter().take(10) {
|
|
let m1 = host
|
|
.terms
|
|
.iter()
|
|
.find(|t| t.pillar == 1)
|
|
.map(|t| t.m)
|
|
.unwrap_or(0.0);
|
|
let m2 = host
|
|
.terms
|
|
.iter()
|
|
.find(|t| t.pillar == 2)
|
|
.map(|t| t.m)
|
|
.unwrap_or(0.0);
|
|
let m3 = host
|
|
.terms
|
|
.iter()
|
|
.find(|t| t.pillar == 3)
|
|
.map(|t| t.m)
|
|
.unwrap_or(0.0);
|
|
println!(
|
|
" [{:.3}] {:<18} {:.3}/{:.3}/{:.3}",
|
|
host.score, host.orig_h, m1, m2, m3
|
|
);
|
|
}
|
|
}
|
|
println!("estado: {}", report.status);
|
|
}
|
|
Ok(())
|
|
}
|
|
Command::Doctor { json } => {
|
|
let report = doctor::run();
|
|
if json {
|
|
println!("{}", serde_json::to_string_pretty(&report)?);
|
|
} else {
|
|
for check in &report.checks {
|
|
println!(
|
|
"{:<10} {:<5} {}",
|
|
check.name,
|
|
if check.ok { "ok" } else { "falha" },
|
|
check.detail
|
|
);
|
|
}
|
|
println!("estado: {}", report.status);
|
|
}
|
|
Ok(())
|
|
}
|
|
Command::Update => {
|
|
let status = update::check(env!("CARGO_PKG_VERSION"))?;
|
|
println!(
|
|
"versão atual: {} | última: {}",
|
|
status.current_version,
|
|
status.latest_version.as_deref().unwrap_or("desconhecida")
|
|
);
|
|
println!(
|
|
"atualização disponível: {}",
|
|
if status.update_available {
|
|
"sim"
|
|
} else {
|
|
"não"
|
|
}
|
|
);
|
|
if status.update_available {
|
|
if std::env::var("ACAUA_RUNTIME").as_deref() == Ok("container") {
|
|
println!("para atualizar: docker compose pull && docker compose up -d");
|
|
} else {
|
|
println!("para atualizar: baixe a nova imagem ou recompile a partir da tag");
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|