added stopping the template box to ensure
that cloning operations works
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use core::error;
|
||||
use std::os::unix::thread::JoinHandleExt;
|
||||
use std::process::Command;
|
||||
use std::{path::PathBuf, process};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::stdin;
|
||||
use std::io::Write;
|
||||
use std::thread;
|
||||
use std::thread::{self, JoinHandle, Thread};
|
||||
use std::time::Duration;
|
||||
use std::str::FromStr;
|
||||
use crate::Project;
|
||||
@@ -72,6 +75,11 @@ pub fn project_inline_terminal(project: Project){
|
||||
}
|
||||
|
||||
pub fn make_box(project: &Project, tools_dir: &PathBuf, boxtemplate: &String, new: bool){
|
||||
println!("stopping template box to ensure we can clone it!");
|
||||
let stop_result = Command::new("distrobox").arg("stop").arg("--root").arg(boxtemplate).status();
|
||||
if stop_result.is_err(){
|
||||
println!("error stopping template!");
|
||||
}
|
||||
if !new{
|
||||
let _distrobox_stop_status = process::Command::new("distrobox").arg("stop").arg("--root").arg(&project.boxname).status().expect("error stopping distrobox");
|
||||
let distrobox_rm_status = process::Command::new("distrobox-rm")
|
||||
@@ -138,3 +146,40 @@ pub fn make_box(project: &Project, tools_dir: &PathBuf, boxtemplate: &String, ne
|
||||
println!("distrobox enter --rrot {} -- sudo -s ln -sf /pentest/boxname /etc/boxname", &box_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn clean_unused_boxes(projects: &Vec<Project>, boxtemplate: &String) -> Option<JoinHandle<()>>{
|
||||
println!("starting template box: {}", boxtemplate);
|
||||
let template_status = process::Command::new("distrobox").arg("enter").arg("--root").arg(boxtemplate).arg("--").arg("exit").status();
|
||||
if template_status.is_err(){
|
||||
let start_error = template_status.err().unwrap();
|
||||
println!("OOOF issue starting template box, cancelling...");
|
||||
println!("ERROR: {}", start_error);
|
||||
return None;
|
||||
}
|
||||
println!("starting project boxes...");
|
||||
for project in projects{
|
||||
if project.stage.contains("current"){
|
||||
let start_status = process::Command::new("distrobox").arg("enter").arg("--root").arg(&project.boxname).arg("--").arg("exit").status();
|
||||
if start_status.is_err(){
|
||||
let start_error = start_status.err().unwrap();
|
||||
println!("OOOF issue starting {}, cancelling...", project.boxname);
|
||||
println!("ERROR: {}", start_error);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("pruning unused containers...");
|
||||
let handle = thread::spawn(move ||{
|
||||
let spawn_result = process::Command::new("sudo").arg("podman").arg("system").arg("prune").arg("-a").arg("-f").output();
|
||||
if spawn_result.is_err(){
|
||||
let spawn_error = spawn_result.err().unwrap();
|
||||
println!("oof trouble spawing prune command!, try manually");
|
||||
println!("ERROR: {}", spawn_error);
|
||||
}
|
||||
println!("PRUNING COMPLETE!");
|
||||
});
|
||||
thread::sleep(Duration::from_secs(3));
|
||||
println!("this will take some time, but its running on a different thread so you can continue working!");
|
||||
return Some(handle);
|
||||
}
|
||||
@@ -37,6 +37,7 @@ fn get_active_project(projects: &Vec<Project>) -> &Project{
|
||||
pub fn main_menu(mut projects: Vec<Project>, config_path: PathBuf, base_files: &PathBuf, base_notes: &PathBuf, tools_dir: &PathBuf, boxtemplate: String, terminal: String, cracking_rig: String, rockyou: String, rule: String, upcoming_files: &PathBuf, upcoming_notes: &PathBuf, password_spray_file: &PathBuf){
|
||||
let mut loopize = true;
|
||||
let mut new_id = next_project_id(&config_path);
|
||||
let mut threads = Vec::new();
|
||||
loop {
|
||||
let active_project = get_active_project(&projects);
|
||||
let mut response = String::new();
|
||||
@@ -135,7 +136,8 @@ Year: {}
|
||||
20.) Stop All Distroboxes
|
||||
21.) Password Spray (will print password to spray, and wait the obervation window time)
|
||||
22.) crack password hashes on your cracking rig
|
||||
23.) Quit Application
|
||||
23.) prune unused distroboxes (free up system storage)
|
||||
24.) Quit Application
|
||||
\n",&base_files.display(), &upcoming_files.display(), active_project.customer, active_project.project_name, active_project.files_folder.display(), active_project.notes_folder.display(), active_project.boxname, terminal, season, year);
|
||||
std::io::stdin().read_line(&mut response).expect("error getting menu input");
|
||||
clear().expect("error clearing screen");
|
||||
@@ -165,7 +167,8 @@ Year: {}
|
||||
"20" => box_controls::stop_all_boxes(&projects),
|
||||
"21" => info_controls::password_spray_help(&active_project, season, lseason, year, &tools_dir, &config_path),
|
||||
"22" => info_controls::crack_hashes(&cracking_rig, &active_project, &terminal, &rockyou, &rule),
|
||||
"23" => {project_controls::save_projects(&projects, &config_path);
|
||||
"23" => {let prune_thread = box_controls::clean_unused_boxes(&projects, &boxtemplate); if prune_thread.is_some(){threads.push(prune_thread.unwrap());}},
|
||||
"24" => {project_controls::save_projects(&projects, &config_path);
|
||||
let mut stop = String::new();
|
||||
println!("stop all boxes?\ny/n");
|
||||
std::io::stdin().read_line(&mut stop).unwrap();
|
||||
@@ -182,4 +185,7 @@ Year: {}
|
||||
let mut enter = String::new();
|
||||
std::io::stdin().read_line(&mut enter).unwrap();
|
||||
}
|
||||
for thread in threads{
|
||||
thread.join().unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user