diff --git a/ostp-client/src/runner.rs b/ostp-client/src/runner.rs index b464527..db40484 100644 --- a/ostp-client/src/runner.rs +++ b/ostp-client/src/runner.rs @@ -32,7 +32,7 @@ fn hide_console() { } #[cfg(target_os = "windows")] -fn is_admin() -> bool { +pub fn is_admin() -> bool { std::process::Command::new("net") .arg("session") .stdout(std::process::Stdio::null()) @@ -100,6 +100,12 @@ fn relaunch_as_admin() -> Result<()> { } pub async fn run_client(config: crate::config::ClientConfig) -> Result<()> { + #[cfg(target_os = "windows")] + if config.mode == "tun" && !is_admin() { + println!("[ostp-client] TUN mode requires Administrator privileges. Relaunching executable as Admin..."); + relaunch_as_admin()?; + } + let bg = std::env::args().any(|a| a == "--bg"); if bg { @@ -130,8 +136,7 @@ pub async fn run_client_core( ) -> Result<()> { #[cfg(target_os = "windows")] if config.mode == "tun" && !is_admin() { - println!("[ostp-client] TUN mode requires Administrator privileges. Relaunching executable as Admin..."); - relaunch_as_admin()?; + return Err(anyhow::anyhow!("Administrator privileges are required to initialize TUN mode. Please run the application as Administrator.")); } if config.mode == "tun" && !config.exclusions.processes.is_empty() { diff --git a/ostp-gui/src-tauri/src/lib.rs b/ostp-gui/src-tauri/src/lib.rs index d7b7b5b..e3db7a6 100644 --- a/ostp-gui/src-tauri/src/lib.rs +++ b/ostp-gui/src-tauri/src/lib.rs @@ -234,6 +234,11 @@ async fn start_tunnel(state: tauri::State<'_, AppState>) -> Result dns_server: client_cfg.tun.as_ref().and_then(|t| t.dns.clone()), }; + #[cfg(target_os = "windows")] + if mapped_config.mode == "tun" && !ostp_client::runner::is_admin() { + return Err("Administrator privileges are required to initialize TUN mode. Please run the application as Administrator.".to_string()); + } + let metrics = Arc::new(BridgeMetrics { bytes_sent: portable_atomic::AtomicU64::new(0), bytes_recv: portable_atomic::AtomicU64::new(0), diff --git a/ostp-gui/src/main.js b/ostp-gui/src/main.js index 6e253bc..9de8dd2 100644 --- a/ostp-gui/src/main.js +++ b/ostp-gui/src/main.js @@ -118,7 +118,7 @@ async function handleToggleConnect() { setUIState('disconnected'); } } catch (err) { - console.error(err); + alert('Error starting tunnel: ' + err); setUIState('disconnected'); } } else {