Skip to content

Commit

Permalink
Update scan summary for infected file & styling for google chat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandesh Grangdan committed Sep 8, 2024
1 parent 896d1b1 commit 7de9eff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "antivirus"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

# Github Repo
Expand Down
24 changes: 18 additions & 6 deletions src/antivirus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ impl Antivirus {
.expect("Failed to execute clamscan");

let regex_patterns = vec![
Regex::new(r": FOUND$").unwrap(),
Regex::new(r"^----------- SCAN SUMMARY -----------").unwrap(),
Regex::new(r"^Known viruses:").unwrap(),
Regex::new(r"^Engine version:").unwrap(),
Expand All @@ -240,10 +239,13 @@ impl Antivirus {
];

let infected_regex_patterns = vec![
Regex::new(r": FOUND$").unwrap(),
Regex::new(r" FOUND$").unwrap(),
];

self.summary.push_str(&format!("{}\n\n", self.home_dir));
self.summary.push_str(&format!("_Scanned directory_: `{}`\n", dir));
self.summary.push_str(&format!("_Result Output_: `{}`\n\n", self.tmp_file));

let mut found_infected = false;

if let Some(stdout) = child.stdout.take() {
let reader = io::BufReader::new(stdout);
Expand All @@ -255,7 +257,13 @@ impl Antivirus {
self.summary.push_str(&format!("{}\n", line));
}
if infected_regex_patterns.iter().any(|regex| regex.is_match(&line)) {
self.infected_files.push_str(&format!("{}\n", line));
if found_infected == false {
found_infected = true;
self.infected_files.push_str("===================================================\n");
self.infected_files.push_str(" *Infected File Summary*\n");
self.infected_files.push_str("===================================================\n\n");
}
self.infected_files.push_str(&format!("- {}\n", line));
}
},
Err(err) => eprintln!("Error reading line: {}", err),
Expand All @@ -264,6 +272,11 @@ impl Antivirus {
}

let status = child.wait().expect("Failed to wait on child");
if self.infected_files != "" {
self.infected_files.push_str("\n_Action Required:_\n");
self.infected_files.push_str("- Review the file and determine if it needs further action.\n");
self.infected_files.push_str("- Consider running additional scans or consulting with security team.\n");
}

println!("Scan Process exited with: {}", status);

Expand All @@ -273,8 +286,7 @@ impl Antivirus {
if self.google_chat_url != "" {
self.google_chat(&self.summary);
if self.infected_files != "" {
self.infected_files.push_str(&format!("\nResult Output: {}\n", self.tmp_file));
self.google_chat(&self.infected_files);
self.google_chat(&format!("{}",&self.infected_files));
}
}
}
Expand Down

0 comments on commit 7de9eff

Please sign in to comment.