-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor reports module to reports_xss, add JSON output support…
… and enhance error handling
- Loading branch information
Showing
6 changed files
with
83 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,6 @@ dumpsync1.yml | |
# Reports files | ||
*.csv | ||
*.json | ||
*.html | ||
*.xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod reports; | ||
pub mod reports_xss; | ||
pub mod scan_xss; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use csv::Writer; | ||
use std::fs::File; | ||
use serde::Serialize; | ||
use std::error::Error; | ||
use serde_json::to_writer_pretty; | ||
|
||
use crate::ui::scan_alerts::ScanAlerts; | ||
|
||
#[derive(Serialize)] | ||
struct Detection { | ||
table: String, | ||
row_index: usize, | ||
column: String, | ||
value: String, | ||
} | ||
|
||
pub struct ReportsXSS; | ||
|
||
impl ReportsXSS { | ||
|
||
pub fn csv(&self, detections: Vec<(String, usize, String, String)>, output_path: &str) -> Result<(), Box<dyn Error>> { | ||
let mut writer = Writer::from_path(output_path)?; | ||
writer.write_record(&["Table", "Row Index", "Column", "Value"])?; | ||
|
||
for (table, row_index, column, value) in detections { | ||
writer.write_record(&[ | ||
table, | ||
row_index.to_string(), | ||
column, | ||
value, | ||
])?; | ||
} | ||
|
||
writer.flush()?; | ||
|
||
ScanAlerts::reports_generated(output_path); | ||
Ok(()) | ||
} | ||
|
||
pub fn json(&self, detections: Vec<(String, usize, String, String)>, output_path: &str) -> Result<(), Box<dyn Error>> { | ||
let detections: Vec<Detection> = detections | ||
.into_iter() | ||
.map(|(table, row_index, column, value)| Detection { | ||
table, | ||
row_index, | ||
column, | ||
value, | ||
}) | ||
.collect(); | ||
|
||
let file = File::create(output_path)?; | ||
to_writer_pretty(file, &detections)?; | ||
|
||
ScanAlerts::reports_generated(output_path); | ||
Ok(()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters