From 7247e85762a1e4ae320309f6154b2e7059c0ccf4 Mon Sep 17 00:00:00 2001 From: pyro Date: Wed, 23 Sep 2026 11:14:28 -0500 Subject: [PATCH] added a step to make sure state infomration is saved before exit, and updated the parse_scope command to work better. --- src/appstate.rs | 57 +++++++++++++++++++++++++++++++++++++------------ src/funcs.rs | 3 +++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/appstate.rs b/src/appstate.rs index 99f002d..2e3d635 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -865,23 +865,52 @@ impl AppState { } "parse_scope" => { let mut general_path = self.projects[self.selected_project].notes.clone(); + let mut scope_path = self.projects[self.selected_project].notes.clone(); + scope_path.push("scope.md"); general_path.push("general.md"); let general_string = read_to_string(general_path)?; - if let Some((_, scope_section)) = general_string.split_once("# Scope") { - if let Some((scope_section, _)) = scope_section.split_once("#") { - scope_section.lines().into_iter().for_each(|line| { - if line.contains("|") { - if !line.contains("Subnet") { - if !line.contains("--") { - let host = - line.split("|").collect::>()[1].to_string(); - self.projects[self.selected_project].add_scope(host); - } - } + let mut scope_file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open(scope_path)?; + general_string + .split_whitespace() + .into_iter() + .for_each(|word| { + if let Ok(_) = word.trim().parse::() { + if let Err(e) = write!(scope_file, "{}\n", word) { + let _ = self.main_tx.send(ToolMessage::Output(( + rid, + format!("Error writing scope file! {e}"), + ))); } - }); - } - } + } else if let Ok(_) = word.trim().parse::() { + if let Err(e) = write!(scope_file, "{}\n", word) { + let _ = self.main_tx.send(ToolMessage::Output(( + rid, + format!("Error writing scope file! {e}"), + ))); + } + } else if word.contains(".com") + || word.contains(".org") + || word.contains(".gov") + || word.contains(".site") + || word.contains(".local") + || word.contains(".ad") + { + if let Err(e) = write!(scope_file, "{}\n", word) { + let _ = self.main_tx.send(ToolMessage::Output(( + rid, + format!("Error writing scope file! {e}"), + ))); + } + } + }); + let _ = self.main_tx.send(ToolMessage::Output(( + rid, + "[success] scope parsed and scope.md written!".to_string(), + ))); } "show_config" | "sc" => { let _ = self diff --git a/src/funcs.rs b/src/funcs.rs index bd70a27..0d6d23e 100644 --- a/src/funcs.rs +++ b/src/funcs.rs @@ -1086,6 +1086,9 @@ pub fn run_tui( server_lock.action_que.push("disconnect".to_string()); } }); + println!("saving state information"); + let _ = state.save_all(); + println!("SAVED!"); for handle in handles { handle.join().unwrap(); }