use std::io::Write;
fn load_config(path: &str) -> String {
std::fs::read_to_string(path).unwrap_or_else(|_| "default_config".into())
}
fn save_result(path: &str, data: &str) {
std::fs::write(path, data).expect("failed to write result");
}
fn send_report(addr: &str, data: &str) {
if let Ok(mut stream) = std::net::TcpStream::connect(addr) {
let _ = stream.write_all(data.as_bytes());
}
}
fn run_cleanup(dir: &str) {
let output = std::process::Command::new("rm")
.args(["-rf", dir])
.output()
.expect("failed to run cleanup");
if !output.status.success() {
eprintln!("cleanup failed");
}
}
fn main() {
let config = load_config("/etc/app/config.toml");
save_result("/tmp/result.txt", &config);
send_report("telemetry.example.com:8080", &config);
run_cleanup("/tmp/scratch");
println!("Done. Now run `cargo capsec audit` to see what this code does.");
}