added ability to stop previously unstoppable scans

This commit is contained in:
epi
2023-03-10 20:43:12 -06:00
parent b5debed322
commit 771041d225
4 changed files with 27 additions and 47 deletions

View File

@@ -27,9 +27,6 @@ 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
@@ -40,15 +37,7 @@ pub struct TermInputHandler {
impl TermInputHandler {
/// Create new event handler
pub fn new(handles: Arc<Handles>) -> Self {
let default_message = format!(
"🚨 Caught {} 🚨 saving scan state to {} ...",
style("ctrl+c").yellow(),
filename
);
Self {
handles,
ctrl_c_message: Some(default_message),
}
Self { handles }
}
/// Initialize the sigint and enter handlers that are responsible for handling initial user

View File

@@ -144,18 +144,6 @@ 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

@@ -190,11 +190,7 @@ impl Menu {
if value.contains('-') {
// range of two values, needs further processing
let range: Vec<usize> = value
.split('-')
.map(|s| self.str_to_usize(s))
// .filter(|m| *m != 0)
.collect();
let range: Vec<usize> = value.split('-').map(|s| self.str_to_usize(s)).collect();
if range.len() != 2 {
// expecting [1, 4] or similar, if a 0 was used, we'd be left with a vec of size 1
@@ -212,9 +208,8 @@ impl Menu {
} else {
let value = self.str_to_usize(value);
// if value != 0 && !nums.contains(&value) {
if !nums.contains(&value) {
// the zeroth scan is always skipped, skip already known values
// skip already known values
nums.push(value);
}
}

View File

@@ -325,11 +325,6 @@ 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_type, ScanType::Directory) {
if printed == 0 {
self.menu
@@ -385,7 +380,6 @@ impl FeroxScans {
let pb = selected.progress_bar();
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,8 +420,6 @@ 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 {
@@ -461,14 +453,30 @@ 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();
}
let has_active_scans = if let Ok(guard) = self.scans.read() {
guard.iter().any(|s| s.is_active())
} else {
// if we can't tell for sure, we'll let it ride
//
// i'm not sure which is the better option here:
// either return true and let it potentially hang, or
// return false and exit, so just going with not
// abruptly exiting for maybe no reason
true
};
if !has_active_scans {
// the last active scan was cancelled, so we can exit
self.menu.println(&format!(
" 😱 no more active scans... {}",
style("exiting").red()
));
let (tx, rx) = tokio::sync::oneshot::channel::<bool>();
handles
.send_scan_command(Command::JoinTasks(tx))
.unwrap_or_default();
rx.await.unwrap_or_default();
}
result