diff --git a/src/afterfact.rs b/src/afterfact.rs index e51c8d7a..dc6a8923 100644 --- a/src/afterfact.rs +++ b/src/afterfact.rs @@ -546,7 +546,10 @@ fn emit_csv( } } if html_output_flag { - htmlreport::add_md_data("Results Summary {#results_summary}".to_string(), html_output_stock); + htmlreport::add_md_data( + "Results Summary {#results_summary}".to_string(), + html_output_stock, + ); } Ok(()) } @@ -805,7 +808,11 @@ fn _print_detection_summary_tables( let mut col_color = vec![]; for level in LEVEL_ABBR.values() { let mut col_output: Vec = vec![]; - let header_output = &format!("Top {} alerts: {{#top_{}_alerts}}", LEVEL_FULL.get(level.as_str()).unwrap(), LEVEL_FULL.get(level.as_str()).unwrap()); + let header_output = &format!( + "Top {} alerts: {{#top_{}_alerts}}", + LEVEL_FULL.get(level.as_str()).unwrap(), + LEVEL_FULL.get(level.as_str()).unwrap() + ); col_output.push(header_output.to_owned()); col_color.push(_get_table_color( @@ -825,10 +832,11 @@ fn _print_detection_summary_tables( for x in sorted_detections.iter() { html_output_stock.push(format!( "- [{}]({}) ({})", - x.0 - ,rule_title_path_map + x.0, + rule_title_path_map .get(x.0) - .unwrap_or(&"".to_string()).replace('\\', "/"), + .unwrap_or(&"".to_string()) + .replace('\\', "/"), x.1.to_formatted_string(&Locale::en) )); } diff --git a/src/detections/detection.rs b/src/detections/detection.rs index 9fb7557b..43581a7c 100644 --- a/src/detections/detection.rs +++ b/src/detections/detection.rs @@ -696,7 +696,10 @@ impl Detection { html_report_stock.push(format!("- {}", tmp_total_detect_output)); } if !html_report_stock.is_empty() { - htmlreport::add_md_data("General Overview {#general_overview}".to_string(), html_report_stock); + htmlreport::add_md_data( + "General Overview {#general_overview}".to_string(), + html_report_stock, + ); } } } diff --git a/src/main.rs b/src/main.rs index 1adb19f8..432f1f28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,13 +93,14 @@ impl App { } let analysis_start_time: DateTime = Local::now(); if configs::CONFIG.read().unwrap().args.html_report.is_some() { - let output_data = vec![ - format!( - "- Start time: {}", - analysis_start_time.format("%Y/%m/%d %H:%M") - ), - ]; - htmlreport::add_md_data("General Overview {#general_overview}".to_string(), output_data); + let output_data = vec![format!( + "- Start time: {}", + analysis_start_time.format("%Y/%m/%d %H:%M") + )]; + htmlreport::add_md_data( + "General Overview {#general_overview}".to_string(), + output_data, + ); } // Show usage when no arguments. @@ -390,7 +391,10 @@ impl App { println!(); if configs::CONFIG.read().unwrap().args.html_report.is_some() { let output_data = vec![format!("- {}", elapsed_output_str)]; - htmlreport::add_md_data("General Overview {#general_overview}".to_string(), output_data); + htmlreport::add_md_data( + "General Overview {#general_overview}".to_string(), + output_data, + ); } // Qオプションを付けた場合もしくはパースのエラーがない場合はerrorのstackが0となるのでエラーログファイル自体が生成されない。 if ERROR_LOG_STACK.lock().unwrap().len() > 0 { @@ -612,7 +616,10 @@ impl App { format!("- Analyzed event files: {}", evtx_files.len()), format!("- {}", total_size_output), ]; - htmlreport::add_md_data("General Overview #{general_overview}".to_string(), output_data); + htmlreport::add_md_data( + "General Overview #{general_overview}".to_string(), + output_data, + ); } let rule_files = detection::Detection::parse_rule_files( diff --git a/src/options/htmlreport.rs b/src/options/htmlreport.rs index 673796f4..fa52f953 100644 --- a/src/options/htmlreport.rs +++ b/src/options/htmlreport.rs @@ -1,5 +1,7 @@ use crate::detections::message::AlertMessage; use hashbrown::HashMap; +use horrorshow::helper::doctype; +use horrorshow::prelude::*; use lazy_static::lazy_static; use pulldown_cmark::{html, Options, Parser}; use std::fs::create_dir; @@ -8,8 +10,6 @@ use std::io::BufWriter; use std::io::Write; use std::path::Path; use std::sync::RwLock; -use horrorshow::prelude::*; -use horrorshow::helper::doctype; lazy_static! { pub static ref HTML_REPORTER: RwLock = RwLock::new(HtmlReporter::new()); @@ -105,18 +105,21 @@ pub fn create_html_file(input_html: String, path_str: String) { return; } let mut html_writer = BufWriter::new(File::create(path).unwrap()); - let html_data = format!("{}", html! { - : doctype::HTML; - html { - head { - meta(charset="UTF-8"); - link(rel="stylesheet", type="text/css", href="./hayabusa_report.css"); + let html_data = format!( + "{}", + html! { + : doctype::HTML; + html { + head { + meta(charset="UTF-8"); + link(rel="stylesheet", type="text/css", href="./hayabusa_report.css"); + } + body : Raw(input_html.clone().as_str()) } - body : Raw(input_html.clone().as_str()) } - }); + ); - writeln!(html_writer,"{}", html_data).ok(); + writeln!(html_writer, "{}", html_data).ok(); println!( "HTML Report was generated. Please check {} for details.", path_str @@ -146,9 +149,10 @@ mod tests { "- Elapsed Time: 00:00:29.035".to_string(), "".to_string(), ]; - html_reporter - .md_datas - .insert("General Overview {#general_overview}".to_string(), general_data.clone()); + html_reporter.md_datas.insert( + "General Overview {#general_overview}".to_string(), + general_data.clone(), + ); let general_overview_str = format!( "
    \n
  • {}
  • \n
", general_data[..general_data.len() - 1]