merged main

This commit is contained in:
epi
2023-03-10 19:42:44 -06:00
parent 30407cd338
commit b5debed322
4 changed files with 45 additions and 9 deletions

View File

@@ -27,6 +27,9 @@ pub static SCAN_COMPLETE: AtomicBool = AtomicBool::new(false);
pub struct TermInputHandler {
/// handles to other handlers
handles: Arc<Handles>,
/// message to print when the user presses ctrl+c, or we trigger serialization of state internally
ctrl_c_message: Option<String>,
}
/// implementation of event handler for terminal input
@@ -37,7 +40,15 @@ pub struct TermInputHandler {
impl TermInputHandler {
/// Create new event handler
pub fn new(handles: Arc<Handles>) -> Self {
Self { handles }
let default_message = format!(
"🚨 Caught {} 🚨 saving scan state to {} ...",
style("ctrl+c").yellow(),
filename
);
Self {
handles,
ctrl_c_message: Some(default_message),
}
}
/// Initialize the sigint and enter handlers that are responsible for handling initial user

View File

@@ -144,6 +144,18 @@ impl ScanHandler {
while let Some(command) = self.receiver.recv().await {
match command {
Command::Exit => {
// std::fs::write(
// "hi",
// format!("{:?}", self.handles.ferox_scans().unwrap_or_default()),
// )
// .unwrap();
crate::event_handlers::inputs::TermInputHandler::sigint_handler(
self.handles.clone(),
)
.unwrap();
// break;
}
Command::ScanInitialUrls(targets) => {
self.ordered_scan_url(targets, ScanOrder::Initial).await?;
}

View File

@@ -193,7 +193,7 @@ impl Menu {
let range: Vec<usize> = value
.split('-')
.map(|s| self.str_to_usize(s))
.filter(|m| *m != 0)
// .filter(|m| *m != 0)
.collect();
if range.len() != 2 {
@@ -212,7 +212,8 @@ impl Menu {
} else {
let value = self.str_to_usize(value);
if value != 0 && !nums.contains(&value) {
// if value != 0 && !nums.contains(&value) {
if !nums.contains(&value) {
// the zeroth scan is always skipped, skip already known values
nums.push(value);
}

View File

@@ -325,10 +325,10 @@ impl FeroxScans {
let mut printed = 0;
for (i, scan) in scans.iter().enumerate() {
if matches!(scan.scan_order, ScanOrder::Initial) || scan.task.try_lock().is_err() {
// original target passed in via either -u or --stdin
continue;
}
// if matches!(scan.scan_order, ScanOrder::Initial) || scan.task.try_lock().is_err() {
// // original target passed in via either -u or --stdin
// continue;
// }
if matches!(scan.scan_type, ScanType::Directory) {
if printed == 0 {
@@ -378,14 +378,14 @@ impl FeroxScans {
if input == 'y' || input == '\n' {
self.menu.println(&format!("Stopping {}...", selected.url));
selected
.abort()
.await
.unwrap_or_else(|e| log::warn!("Could not cancel task: {}", e));
let pb = selected.progress_bar();
num_cancelled += pb.length() as usize - pb.position() as usize
num_cancelled += pb.length() as usize - pb.position() as usize;
std::fs::write("hi", format!("{} {:?}", num_cancelled, selected)).unwrap();
} else {
self.menu.println("Ok, doing nothing...");
}
@@ -426,6 +426,8 @@ impl FeroxScans {
self.display_filters(handles.clone());
self.menu.print_footer();
self.menu.println(&format!("{:?}", self.scans));
let menu_cmd = if let Ok(line) = self.menu.term.read_line() {
self.menu.get_command_input_from_user(&line)
} else {
@@ -459,6 +461,16 @@ impl FeroxScans {
self.menu.show_progress_bars();
if let Ok(guard) = self.scans.read() {
let has_active_scans = guard.iter().any(|s| s.is_active());
if !has_active_scans {
self.menu.print_border();
self.menu.println("No active scans.");
self.menu.print_border();
handles.send_scan_command(Command::Exit).unwrap_or_default();
}
}
result
}