Skip to content

Commit

Permalink
refactor: rename and reorganize alert reporting for improved clarity …
Browse files Browse the repository at this point in the history
…and functionality
  • Loading branch information
Kremilly committed Jan 3, 2025
1 parent 09fcd2e commit 5827a79
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/core/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
handlers::dump_handlers::DumpHandlers,

ui::{
normal_alerts::NormalAlerts,
report_alerts::ReportAlerts,
success_alerts::SuccessAlerts
},

Expand Down Expand Up @@ -132,7 +132,7 @@ impl Dump {
let dump_count = DUMP_COUNT.load(Ordering::SeqCst);

if let Some(last_dump) = DumpHandlers.get_most_recent_sql_file(&dump_file_path_clone) {
NormalAlerts::report(&dump_file_path_clone, dump_count, &last_dump);
ReportAlerts::report(&dump_file_path_clone, dump_count, &last_dump);
}

SuccessAlerts::terminate();
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/reports_xss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::{

use crate::{
utils::file::FileUtils,
ui::report_alerts::ReportAlerts,
handlers::html_handlers::HTMLHandlers,
ui::report_xss_alerts::ReportXSSAlerts,

constants::{
urls::Urls,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl ReportsXSS {

file.write_all(b"</XSSDetectionReport>\n")?;

ReportAlerts::generated(output_path);
ReportXSSAlerts::generated(output_path);
Ok(())
}

Expand All @@ -68,7 +68,7 @@ impl ReportsXSS {
writeln!(file, "---------------------")?;
}

ReportAlerts::generated(output_path);
ReportXSSAlerts::generated(output_path);
Ok(())
}

Expand All @@ -87,7 +87,7 @@ impl ReportsXSS {

writer.flush()?;

ReportAlerts::generated(output_path);
ReportXSSAlerts::generated(output_path);
Ok(())
}

Expand All @@ -105,7 +105,7 @@ impl ReportsXSS {
let file = File::create(output_path)?;
to_writer_pretty(file, &detections)?;

ReportAlerts::generated(output_path);
ReportXSSAlerts::generated(output_path);
Ok(())
}

Expand Down Expand Up @@ -135,7 +135,7 @@ impl ReportsXSS {

file.write_all(b"</table></div></body></html>")?;

ReportAlerts::generated(output_path);
ReportXSSAlerts::generated(output_path);
Ok(())
}

Expand All @@ -149,7 +149,7 @@ impl ReportsXSS {
"xml" => self.xml(detections, file_path),
"json" => self.json(detections, file_path),
"html" => self.html(detections, file_path),
_ => Ok(ReportAlerts::invalid_format()),
_ => Ok(ReportXSSAlerts::invalid_format()),
};

result?;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pub mod ui_base;
pub mod scan_alerts;
pub mod share_alerts;
pub mod schema_alerts;
pub mod report_alerts;
pub mod checksum_alerts;
pub mod report_xss_alerts;

pub mod normal_alerts;
pub mod report_alerts;
pub mod errors_alerts;
pub mod success_alerts;
8 changes: 0 additions & 8 deletions src/ui/normal_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,4 @@ impl NormalAlerts {
);
}

pub fn report(dump_file_path: &str, dump_count: usize, last_dump: &str) {
println!("\nFinal Report:\n");

println!("Directory: {}", dump_file_path.bold().blue());
println!("Total number of dumps: {}", dump_count.to_string().bold().blue());
println!("Last dump: {}", last_dump.bold().cyan());
}

}
16 changes: 5 additions & 11 deletions src/ui/report_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ pub struct ReportAlerts;

impl ReportAlerts {

pub fn generated(output_path: &str) {
println!("{}", "-".repeat(50));
println!("Report generated and salved in: {}", output_path.green());
}

pub fn invalid_format() {
let message = "Invalid file format, only TXT, CSV, HTML and JSON are supported.";
pub fn report(dump_file_path: &str, dump_count: usize, last_dump: &str) {
println!("\nFinal Report:\n");

println!("{}", "-".repeat(50));
println!(
"{}", message.red().bold(),
);
println!("Directory: {}", dump_file_path.bold().blue());
println!("Total number of dumps: {}", dump_count.to_string().bold().blue());
println!("Last dump: {}", last_dump.bold().cyan());
}

}
23 changes: 23 additions & 0 deletions src/ui/report_xss_alerts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extern crate colored;

use colored::*;

pub struct ReportXSSAlerts;

impl ReportXSSAlerts {

pub fn generated(output_path: &str) {
println!("{}", "-".repeat(50));
println!("Report generated and salved in: {}", output_path.green());
}

pub fn invalid_format() {
let message = "Invalid file format, only TXT, CSV, HTML and JSON are supported.";

println!("{}", "-".repeat(50));
println!(
"{}", message.red().bold(),
);
}

}

0 comments on commit 5827a79

Please sign in to comment.