From cf2cc9f8edb5f78540685765a27783e74171f4ce Mon Sep 17 00:00:00 2001 From: mysticmomba Date: Fri, 9 Oct 2026 09:46:32 -0400 Subject: [PATCH] Added build script --- build.sh | 6 ++++++ src-tauri/src/commands/actions.rs | 2 +- src-tauri/src/commands/changelog.rs | 9 ++++----- src-tauri/src/commands/export.rs | 5 ++--- src-tauri/src/commands/scan.rs | 11 ++++++++++- src-tauri/src/models/host.rs | 8 ++++---- src-tauri/src/models/mod.rs | 2 +- src-tauri/src/net/dns.rs | 6 ++---- src-tauri/src/net/mod.rs | 2 +- src-tauri/src/net/range.rs | 2 +- src-tauri/src/scanner/mod.rs | 2 +- src-tauri/src/scanner/ping.rs | 3 +-- src-tauri/src/scanner/ports.rs | 27 ++++++++++++++++----------- 13 files changed, 50 insertions(+), 35 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..561b590 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash +cd src-tauri && cargo clean +cargo clippy --fix --all-targets --allow-dirty +cargo fmt +cargo tauri build +cargo tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc \ No newline at end of file diff --git a/src-tauri/src/commands/actions.rs b/src-tauri/src/commands/actions.rs index d5d3d7a..47a3852 100644 --- a/src-tauri/src/commands/actions.rs +++ b/src-tauri/src/commands/actions.rs @@ -16,4 +16,4 @@ pub async fn check_privileges() -> Result { // On Windows, check if running as administrator Ok(is_elevated::is_elevated()) } -} \ No newline at end of file +} diff --git a/src-tauri/src/commands/changelog.rs b/src-tauri/src/commands/changelog.rs index cc7df29..bcc1cf8 100644 --- a/src-tauri/src/commands/changelog.rs +++ b/src-tauri/src/commands/changelog.rs @@ -1,16 +1,15 @@ -use pulldown_cmark::{Options, Parser, html}; +use pulldown_cmark::{html, Options, Parser}; const CHANGELOG_MD: &str = include_str!("../../../CHANGELOG.md"); #[tauri::command] pub async fn get_changelog() -> Result { - let options = Options::ENABLE_HEADING_ATTRIBUTES - | Options::ENABLE_STRIKETHROUGH - | Options::ENABLE_TABLES; + let options = + Options::ENABLE_HEADING_ATTRIBUTES | Options::ENABLE_STRIKETHROUGH | Options::ENABLE_TABLES; let parser = Parser::new_ext(CHANGELOG_MD, options); let mut html_output = String::new(); html::push_html(&mut html_output, parser); Ok(html_output) -} \ No newline at end of file +} diff --git a/src-tauri/src/commands/export.rs b/src-tauri/src/commands/export.rs index 2889710..b3a0a24 100644 --- a/src-tauri/src/commands/export.rs +++ b/src-tauri/src/commands/export.rs @@ -11,8 +11,7 @@ pub struct ExportRequest { #[tauri::command] pub async fn export_csv(request: ExportRequest) -> Result<(), String> { - let file = File::create(&request.path) - .map_err(|e| format!("Failed to create file: {}", e))?; + let file = File::create(&request.path).map_err(|e| format!("Failed to create file: {}", e))?; let mut writer = csv::Writer::from_writer(file); @@ -43,4 +42,4 @@ pub async fn export_csv(request: ExportRequest) -> Result<(), String> { tracing::info!("Exported {} hosts to {}", request.hosts.len(), request.path); Ok(()) -} \ No newline at end of file +} diff --git a/src-tauri/src/commands/scan.rs b/src-tauri/src/commands/scan.rs index 5a68808..12a24ba 100644 --- a/src-tauri/src/commands/scan.rs +++ b/src-tauri/src/commands/scan.rs @@ -40,7 +40,16 @@ pub async fn start_scan(app: AppHandle, config: ScanConfig) -> Result<(), String let port_timeout_ms = config.port_timeout_ms.unwrap_or(1000); tokio::spawn(async move { - ping_sweep(&app, &ips, timeout_ms, cancel, port_scan, ports, port_timeout_ms).await; + ping_sweep( + &app, + &ips, + timeout_ms, + cancel, + port_scan, + ports, + port_timeout_ms, + ) + .await; }); Ok(()) } diff --git a/src-tauri/src/models/host.rs b/src-tauri/src/models/host.rs index 9f95250..9a860d2 100644 --- a/src-tauri/src/models/host.rs +++ b/src-tauri/src/models/host.rs @@ -6,7 +6,7 @@ pub enum HostStatus { Up, Down, Filtered, - Unknown + Unknown, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -42,7 +42,7 @@ pub struct PortResult { pub struct NetbiosInfo { pub computer_name: Option, pub workgroup: Option, - pub mac_from_netbios: Option + pub mac_from_netbios: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -79,7 +79,7 @@ impl HostResult { updated_at: now_ms(), } } - + pub fn down(ip: IpAddr) -> Self { Self { ip, @@ -93,4 +93,4 @@ impl HostResult { updated_at: now_ms(), } } -} \ No newline at end of file +} diff --git a/src-tauri/src/models/mod.rs b/src-tauri/src/models/mod.rs index c2de673..45d0516 100644 --- a/src-tauri/src/models/mod.rs +++ b/src-tauri/src/models/mod.rs @@ -1,2 +1,2 @@ pub mod host; -pub mod monitor; \ No newline at end of file +pub mod monitor; diff --git a/src-tauri/src/net/dns.rs b/src-tauri/src/net/dns.rs index 29e0169..985c5ec 100644 --- a/src-tauri/src/net/dns.rs +++ b/src-tauri/src/net/dns.rs @@ -3,9 +3,7 @@ use std::net::IpAddr; /// Perform reverse DNS lookup on a single IP. /// Returns the hostname if found, None otherwise. pub async fn reverse_lookup(ip: IpAddr) -> Option { - let result = tokio::task::spawn_blocking(move || { - dns_lookup::lookup_addr(&ip) - }).await; + let result = tokio::task::spawn_blocking(move || dns_lookup::lookup_addr(&ip)).await; match result { Ok(Ok(hostname)) => { @@ -17,4 +15,4 @@ pub async fn reverse_lookup(ip: IpAddr) -> Option { } _ => None, } -} \ No newline at end of file +} diff --git a/src-tauri/src/net/mod.rs b/src-tauri/src/net/mod.rs index 130c0c1..9d9093e 100644 --- a/src-tauri/src/net/mod.rs +++ b/src-tauri/src/net/mod.rs @@ -1,2 +1,2 @@ +pub mod dns; pub mod range; -pub mod dns; \ No newline at end of file diff --git a/src-tauri/src/net/range.rs b/src-tauri/src/net/range.rs index 6838684..d014e8e 100644 --- a/src-tauri/src/net/range.rs +++ b/src-tauri/src/net/range.rs @@ -140,4 +140,4 @@ mod tests { fn test_reversed_range() { assert!(parse_ip_range("192.168.1.10-192.168.1.1").is_err()); } -} \ No newline at end of file +} diff --git a/src-tauri/src/scanner/mod.rs b/src-tauri/src/scanner/mod.rs index 9387623..54b5b02 100644 --- a/src-tauri/src/scanner/mod.rs +++ b/src-tauri/src/scanner/mod.rs @@ -1,3 +1,3 @@ +pub mod netbios; pub mod ping; pub mod ports; -pub mod netbios; \ No newline at end of file diff --git a/src-tauri/src/scanner/ping.rs b/src-tauri/src/scanner/ping.rs index ab3d3e2..0401d2f 100644 --- a/src-tauri/src/scanner/ping.rs +++ b/src-tauri/src/scanner/ping.rs @@ -91,8 +91,7 @@ pub async fn ping_sweep( let nb_fut = query_netbios(enriched.ip, 500); if port_scan { - let scan_ports = ports2 - .unwrap_or_else(|| DEFAULT_PORTS.to_vec()); + let scan_ports = ports2.unwrap_or_else(|| DEFAULT_PORTS.to_vec()); let (nb_result, port_results) = tokio::join!( nb_fut, scan_host_ports(enriched.ip, &scan_ports, port_timeout_ms) diff --git a/src-tauri/src/scanner/ports.rs b/src-tauri/src/scanner/ports.rs index 35dc177..98318df 100644 --- a/src-tauri/src/scanner/ports.rs +++ b/src-tauri/src/scanner/ports.rs @@ -42,8 +42,7 @@ fn service_name(port: u16) -> Option { } pub const DEFAULT_PORTS: &[u16] = &[ - 21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, - 443, 445, 993, 995, 1433, 1521, 3306, 3389, + 21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, 443, 445, 993, 995, 1433, 1521, 3306, 3389, 5432, 5900, 5985, 5986, 8080, 8088, 8443, ]; @@ -96,7 +95,10 @@ async fn grab_banner(mut stream: TcpStream, port: u16) -> Option { }; if let Some(data) = probe { - if timeout(banner_timeout, stream.write_all(data)).await.is_err() { + if timeout(banner_timeout, stream.write_all(data)) + .await + .is_err() + { return None; } } @@ -107,8 +109,15 @@ async fn grab_banner(mut stream: TcpStream, port: u16) -> Option { Ok(Ok(n)) if n > 0 => { buf.truncate(n); // Strip to printable ASCII, replace control chars - let banner: String = buf.iter() - .map(|&b| if b >= 0x20 && b < 0x7f { b as char } else { ' ' }) + let banner: String = buf + .iter() + .map(|&b| { + if (0x20..0x7f).contains(&b) { + b as char + } else { + ' ' + } + }) .collect(); let banner = banner.trim().to_string(); if banner.is_empty() { @@ -124,11 +133,7 @@ async fn grab_banner(mut stream: TcpStream, port: u16) -> Option { const MAX_PORT_CONCURRENT: usize = 64; -pub async fn scan_host_ports( - ip: IpAddr, - ports: &[u16], - timeout_ms: u64, -) -> Vec { +pub async fn scan_host_ports(ip: IpAddr, ports: &[u16], timeout_ms: u64) -> Vec { let mut results = Vec::with_capacity(ports.len()); for chunk in ports.chunks(MAX_PORT_CONCURRENT) { @@ -148,4 +153,4 @@ pub async fn scan_host_ports( results.sort_by_key(|p| p.port); results -} \ No newline at end of file +}