diff --git a/Cargo.lock b/Cargo.lock index 81da77a..3d6192e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,7 +98,7 @@ dependencies = [ "log", "object", "once_cell", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -112,7 +112,7 @@ dependencies = [ "hashbrown", "log", "object", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -334,23 +334,23 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "dirs" -version = "5.0.1" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -671,6 +671,7 @@ dependencies = [ "network-types", "oryx-common", "ratatui", + "regex", "serde", "serde_json", "tui-big-text", @@ -698,7 +699,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -767,13 +768,13 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.6" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 2.0.11", ] [[package]] @@ -961,7 +962,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl 2.0.11", ] [[package]] @@ -975,6 +985,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tui-big-text" version = "0.7.0" @@ -1082,22 +1103,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -1106,22 +1118,7 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1130,46 +1127,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1182,48 +1161,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/oryx-tui/Cargo.toml b/oryx-tui/Cargo.toml index af73fe3..2385697 100644 --- a/oryx-tui/Cargo.toml +++ b/oryx-tui/Cargo.toml @@ -18,7 +18,7 @@ aya = "0.13" oryx-common = { path = "../oryx-common" } mio = { version = "1", features = ["os-poll", "os-ext"] } itertools = "0.14" -dirs = "5" +dirs = "6" kanal = "0.1.0-pre8" mimalloc = "0.1" clap = { version = "4", features = ["derive", "cargo"] } @@ -28,6 +28,7 @@ log = "0.4" env_logger = "0.11" serde_json = "1" serde = { version = "1", features = ["derive"] } +regex = "1" [[bin]] name = "oryx" diff --git a/oryx-tui/src/section/metrics.rs b/oryx-tui/src/section/metrics.rs index ae49ef9..f4f44f3 100644 --- a/oryx-tui/src/section/metrics.rs +++ b/oryx-tui/src/section/metrics.rs @@ -1,11 +1,13 @@ use std::{ cmp, + ops::Range, sync::{atomic::AtomicBool, Arc, Mutex}, thread, time::Duration, }; use crossterm::event::{Event, KeyCode, KeyEvent}; +use regex::Regex; use tui_input::{backend::crossterm::EventHandler, Input}; use ratatui::{ @@ -51,28 +53,37 @@ struct UserInput { } impl UserInput { - fn validate(&mut self) -> AppResult<()> { + fn validate(&mut self) -> AppResult> { self.error = None; - if self.input.value().parse::().is_err() { - self.error = Some("Invalid Port".to_string()); - return Err("Validation Error".into()); + let re = Regex::new(r"^(?\d{1,5})\-(?\d{1,5})$").unwrap(); + + match self.input.value().parse::() { + Ok(v) => Ok(Range { + start: v, + end: v + 1, + }), + Err(_) => { + let Some(caps) = re.captures(self.input.value()) else { + self.error = Some("Invalid Port --".to_string()); + return Err("Validation Error".into()); + }; + Ok(Range { + start: caps["start"].parse()?, + end: caps["end"].parse()?, + }) + } } - Ok(()) } fn clear(&mut self) { self.input.reset(); self.error = None; } - - fn value(&self) -> u16 { - self.input.value().parse().unwrap() - } } #[derive(Debug, Default, Clone)] pub struct PortCountMetric { - port: u16, + port_range: Range, tcp_count: usize, udp_count: usize, } @@ -168,7 +179,16 @@ impl Metrics { } }) .padding(Padding::uniform(1)) - .title_top(format!("Port: {}", metric.port)), + .title_top({ + if metric.port_range.len() == 1 { + format!("Port: {}", metric.port_range.start) + } else { + format!( + "Ports: {}-{}", + metric.port_range.start, metric.port_range.end + ) + } + }), ); frame.render_widget( chart, @@ -267,12 +287,10 @@ impl Metrics { } KeyCode::Enter => { - self.user_input.validate()?; - - let port: u16 = self.user_input.value(); + let port_range: Range = self.user_input.validate()?; let port_count_metric = Arc::new(Mutex::new(PortCountMetric { - port, + port_range: port_range.clone(), tcp_count: 0, udp_count: 0, })); @@ -301,12 +319,12 @@ impl Metrics { match packet { IpPacket::V4(ipv4_packet) => match ipv4_packet.proto { IpProto::Tcp(tcp_packet) => { - if tcp_packet.dst_port == port { + if port_range.contains(&tcp_packet.dst_port) { metric.tcp_count += 1; } } IpProto::Udp(udp_packet) => { - if udp_packet.dst_port == port { + if port_range.contains(&udp_packet.dst_port) { metric.udp_count += 1; } } @@ -314,12 +332,12 @@ impl Metrics { }, IpPacket::V6(ipv6_packet) => match ipv6_packet.proto { IpProto::Tcp(tcp_packet) => { - if tcp_packet.dst_port == port { + if port_range.contains(&tcp_packet.dst_port) { metric.tcp_count += 1; } } IpProto::Udp(udp_packet) => { - if udp_packet.dst_port == port { + if port_range.contains(&udp_packet.dst_port) { metric.udp_count += 1; } }