Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7247e85762 | ||
|
|
0bad1c7b66 |
No files matched your search
+78
-21
@@ -281,6 +281,7 @@ impl AppState {
|
|||||||
self.help.push(
|
self.help.push(
|
||||||
"Shortcuts:\nCTRL+P = new_project\nCTRL+s = save\nCTRL_+h = select_host\n".to_string(),
|
"Shortcuts:\nCTRL+P = new_project\nCTRL+s = save\nCTRL_+h = select_host\n".to_string(),
|
||||||
);
|
);
|
||||||
|
self.help.push("exclude\nexcludes an IP or a cidr network from the scope and all future tool calls.\nexport 192.168.1.1 192.168.2.0/24\n".to_string());
|
||||||
self.help.push("exit\nquit the tool\n".to_string());
|
self.help.push("exit\nquit the tool\n".to_string());
|
||||||
self.initialize_modules();
|
self.initialize_modules();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -864,23 +865,52 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
"parse_scope" => {
|
"parse_scope" => {
|
||||||
let mut general_path = self.projects[self.selected_project].notes.clone();
|
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");
|
general_path.push("general.md");
|
||||||
let general_string = read_to_string(general_path)?;
|
let general_string = read_to_string(general_path)?;
|
||||||
if let Some((_, scope_section)) = general_string.split_once("# Scope") {
|
let mut scope_file = OpenOptions::new()
|
||||||
if let Some((scope_section, _)) = scope_section.split_once("#") {
|
.create(true)
|
||||||
scope_section.lines().into_iter().for_each(|line| {
|
.truncate(true)
|
||||||
if line.contains("|") {
|
.write(true)
|
||||||
if !line.contains("Subnet") {
|
.open(scope_path)?;
|
||||||
if !line.contains("--") {
|
general_string
|
||||||
let host =
|
.split_whitespace()
|
||||||
line.split("|").collect::<Vec<&str>>()[1].to_string();
|
.into_iter()
|
||||||
self.projects[self.selected_project].add_scope(host);
|
.for_each(|word| {
|
||||||
}
|
if let Ok(_) = word.trim().parse::<IpNet>() {
|
||||||
}
|
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::<IpAddr>() {
|
||||||
}
|
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" => {
|
"show_config" | "sc" => {
|
||||||
let _ = self
|
let _ = self
|
||||||
@@ -1151,15 +1181,17 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
args_vec[0].split(",").into_iter().for_each(|ip| {
|
args_vec[0].split(",").into_iter().for_each(|ip| {
|
||||||
if let Ok(ip) = ip.parse::<IpAddr>() {
|
if !project.exclusions.contains(&ip.to_string()) {
|
||||||
let mut new_host = Host::new();
|
if let Ok(ip) = ip.parse::<IpAddr>() {
|
||||||
new_host.ip = ip.to_string();
|
|
||||||
hosts.push(new_host);
|
|
||||||
} else if let Ok(net) = ip.parse::<IpNet>() {
|
|
||||||
for host_addr in net.hosts() {
|
|
||||||
let mut new_host = Host::new();
|
let mut new_host = Host::new();
|
||||||
new_host.ip = host_addr.to_string();
|
new_host.ip = ip.to_string();
|
||||||
hosts.push(new_host);
|
hosts.push(new_host);
|
||||||
|
} else if let Ok(net) = ip.parse::<IpNet>() {
|
||||||
|
for host_addr in net.hosts() {
|
||||||
|
let mut new_host = Host::new();
|
||||||
|
new_host.ip = host_addr.to_string();
|
||||||
|
hosts.push(new_host);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1660,6 +1692,30 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"exclude" => {
|
||||||
|
if let Some(args) = command_args {
|
||||||
|
let project = self.projects[self.selected_project].clone();
|
||||||
|
if args.contains(" ") {
|
||||||
|
args.split(" ")
|
||||||
|
.into_iter()
|
||||||
|
.filter(|ex| !project.exclusions.contains(&ex.to_string()))
|
||||||
|
.for_each(|ex| {
|
||||||
|
if let Ok(_) = ex.parse::<IpAddr>() {
|
||||||
|
self.projects[self.selected_project]
|
||||||
|
.exclusions
|
||||||
|
.push(ex.to_string());
|
||||||
|
} else if let Ok(net) = ex.parse::<IpNet>() {
|
||||||
|
net.hosts().into_iter().for_each(|ip| {
|
||||||
|
self.projects[self.selected_project]
|
||||||
|
.exclusions
|
||||||
|
.push(ip.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"exit" => {
|
"exit" => {
|
||||||
self.save_all()?;
|
self.save_all()?;
|
||||||
let _ = self.main_tx.send(ToolMessage::AppStateExit);
|
let _ = self.main_tx.send(ToolMessage::AppStateExit);
|
||||||
@@ -1945,6 +2001,7 @@ impl AppState {
|
|||||||
current: false,
|
current: false,
|
||||||
db: db,
|
db: db,
|
||||||
scope: Vec::new(),
|
scope: Vec::new(),
|
||||||
|
exclusions: Vec::new(),
|
||||||
};
|
};
|
||||||
match new_project.save_config() {
|
match new_project.save_config() {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -1086,6 +1086,9 @@ pub fn run_tui(
|
|||||||
server_lock.action_que.push("disconnect".to_string());
|
server_lock.action_que.push("disconnect".to_string());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
println!("saving state information");
|
||||||
|
let _ = state.save_all();
|
||||||
|
println!("SAVED!");
|
||||||
for handle in handles {
|
for handle in handles {
|
||||||
handle.join().unwrap();
|
handle.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-10
@@ -10,6 +10,7 @@ use std::net::IpAddr;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
@@ -22,6 +23,7 @@ pub struct Project {
|
|||||||
pub current: bool,
|
pub current: bool,
|
||||||
pub db: Option<DistroBox>,
|
pub db: Option<DistroBox>,
|
||||||
pub scope: Vec<String>,
|
pub scope: Vec<String>,
|
||||||
|
pub exclusions: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Project {
|
impl Project {
|
||||||
@@ -36,6 +38,7 @@ impl Project {
|
|||||||
current: false,
|
current: false,
|
||||||
db: None,
|
db: None,
|
||||||
scope: Vec::new(),
|
scope: Vec::new(),
|
||||||
|
exclusions: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,16 +59,18 @@ impl Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_host(&mut self, mut host: Host) {
|
pub fn add_host(&mut self, mut host: Host) {
|
||||||
let mut new_id = 0;
|
if !self.exclusions.contains(&host.ip) {
|
||||||
self.hosts.iter().for_each(|h| {
|
let mut new_id = 0;
|
||||||
if h.id > new_id {
|
self.hosts.iter().for_each(|h| {
|
||||||
new_id = h.id.clone();
|
if h.id > new_id {
|
||||||
|
new_id = h.id.clone();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
new_id += 1;
|
||||||
|
if !self.hosts.iter().any(|h| h.ip == host.ip) {
|
||||||
|
host.id = new_id;
|
||||||
|
self.hosts.push(host);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
new_id += 1;
|
|
||||||
if !self.hosts.iter().any(|h| h.ip == host.ip) {
|
|
||||||
host.id = new_id;
|
|
||||||
self.hosts.push(host);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +111,12 @@ impl Project {
|
|||||||
self.add_scope(ip.trim().to_string());
|
self.add_scope(ip.trim().to_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
"exclusions" => {
|
||||||
|
let ips: Vec<&str> = parts[1].split(",").collect();
|
||||||
|
ips.iter().for_each(|ip| {
|
||||||
|
self.exclusions.push(ip.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,12 +236,13 @@ impl Project {
|
|||||||
}
|
}
|
||||||
let mut file = File::create(&self.config_folder)?;
|
let mut file = File::create(&self.config_folder)?;
|
||||||
let mut out_string = format!(
|
let mut out_string = format!(
|
||||||
"org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\n",
|
"org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\nexclusions: {}\n",
|
||||||
self.org_name,
|
self.org_name,
|
||||||
self.name,
|
self.name,
|
||||||
self.notes.display(),
|
self.notes.display(),
|
||||||
self.files.display(),
|
self.files.display(),
|
||||||
self.scope.join(","),
|
self.scope.join(","),
|
||||||
|
self.exclusions.join(","),
|
||||||
);
|
);
|
||||||
if self.current {
|
if self.current {
|
||||||
out_string.push_str("stage: current");
|
out_string.push_str("stage: current");
|
||||||
|
|||||||
Reference in new issue
Block a user