From f1b84c00dcd615ab72b4e8a45aba74b2a2877f2c Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Thu, 10 Nov 2022 22:51:17 +0100 Subject: [PATCH] solved root directory macOS bundle and added info on filters in waiting screen --- src/gui_run_page.rs | 25 ++++++++++++++++++++----- src/thread_write_report.rs | 9 +++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gui_run_page.rs b/src/gui_run_page.rs index 934c59e4..e36eaba0 100644 --- a/src/gui_run_page.rs +++ b/src/gui_run_page.rs @@ -116,8 +116,8 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column { let tot_packets_text = Text::new(format!("Total intercepted packets: {}\n\n\ Filtered packets: 0\n\n\ - Some packets have been intercepted, but still none has been selected according to the filters you specified...", - observed.separate_with_spaces())).font(font); + Some packets have been intercepted, but still none has been selected according to the filters you specified...\n\n{}", + observed.separate_with_spaces(), get_active_filters_string_nobr(sniffer.filters.clone()))).font(font); body = body .push(Row::new().height(Length::FillPortion(1))) @@ -128,7 +128,6 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column { } (observed, filtered) => { //observed > filtered > 0 || observed = filtered > 0 - let filters_string = get_active_filters_string(sniffer.filters.clone()); let percentage_string_packets = if format!("{:.1}", 100.0*(filtered) as f32/observed as f32).eq("0.0") { @@ -176,7 +175,7 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column { .width(Length::FillPortion(1)) .padding(10) //.push(iced::Text::new(std::env::current_dir().unwrap().to_str().unwrap()).font(font)) - .push(Text::new(filters_string).font(font)) + .push(Text::new(get_active_filters_string(sniffer.filters.clone())).font(font)) .push(Text::new(" ")) .push(Text::new(format!("Filtered packets:\n {} ({} of the total)", filtered.separate_with_spaces(), percentage_string_packets)).font(font)) @@ -315,7 +314,7 @@ fn get_active_filters_string(filters: Arc>) -> String { else { let mut ret_val = "Active filters:".to_string(); if filters_lock.ip != "no filter" { - ret_val.push_str(&format!("\n {}", filters_lock.ip.replace('v', "V"))); + ret_val.push_str(&format!("\n {}", filters_lock.ip.replace("ip", "IP"))); } if filters_lock.transport.ne(&TransProtocol::Other) { ret_val.push_str(&format!("\n {}", filters_lock.transport)); @@ -328,6 +327,22 @@ fn get_active_filters_string(filters: Arc>) -> String { } +fn get_active_filters_string_nobr(filters: Arc>) -> String { + let filters_lock = filters.lock().unwrap(); + let mut ret_val = "Active filters:".to_string(); + if filters_lock.ip != "no filter" { + ret_val.push_str(&format!(" {}", filters_lock.ip.replace("ip", "IP"))); + } + if filters_lock.transport.ne(&TransProtocol::Other) { + ret_val.push_str(&format!(" {}", filters_lock.transport)); + } + if filters_lock.application.ne(&AppProtocol::Other) { + ret_val.push_str(&format!(" {}", filters_lock.application)); + } + ret_val +} + + fn get_connection_color(traffic_type: TrafficType) -> Color { if traffic_type == TrafficType::Incoming || traffic_type == TrafficType::Multicast { diff --git a/src/thread_write_report.rs b/src/thread_write_report.rs index ad8a7f25..56f211a0 100644 --- a/src/thread_write_report.rs +++ b/src/thread_write_report.rs @@ -58,11 +58,8 @@ pub fn sleep_and_write_report_loop(current_capture_id: Arc>, // .arg("./sniffnet_report/report.txt") // .spawn() // .unwrap(); - // #[cfg(target_os = "macos")] - // std::process::Command::new("cd") - // .args('~`) - // .spawn() - // .unwrap(); + #[cfg(target_os = "macos")] + std::env::set_current_dir(std::env::var("HOME").unwrap()).unwrap(); // #[cfg(target_os = "linux")] // std::process::Command::new("explorer") // .arg("./sniffnet_report/report.txt") @@ -195,7 +192,7 @@ pub fn get_app_count_string(app_count: HashMap, tot_packets: let spaces_string_2 = " ".to_string() .repeat(10-percentage_string.len()); - ret_val.push_str(&format!(" {}:{}{}{}{}\n", + ret_val.push_str(&format!(" {}:{}{}{}{} \n", app_proto_string, spaces_string_1, num_string,