diff --git a/Cargo.lock b/Cargo.lock index 0781aca..f1ecfbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1545,6 +1545,7 @@ dependencies = [ "tokio-util", "tracing", "tracing-subscriber", + "windows 0.58.0", ] [[package]] diff --git a/doc/BUILD b/doc/BUILD index e22d205..f19786c 100644 --- a/doc/BUILD +++ b/doc/BUILD @@ -22,6 +22,7 @@ mdbook( "service.md", "transparent_proxy.md", "usage.md", + "windows.md", ":proxydetox_help", ], book = "//:book.toml", diff --git a/doc/SUMMARY.md b/doc/SUMMARY.md index 8694cd3..aeb48c7 100644 --- a/doc/SUMMARY.md +++ b/doc/SUMMARY.md @@ -5,6 +5,7 @@ - [Installation](installation.md) - [Configuration](configuration.md) - [Usage](usage.md) + - [Windows users](windows.md) --- diff --git a/doc/windows.md b/doc/windows.md new file mode 100644 index 0000000..94dd168 --- /dev/null +++ b/doc/windows.md @@ -0,0 +1,11 @@ +# Windows + +On Windows Proxydetox is _not_ a console application and therefor no console window is visible. +No console window is shown, such that Proxydetox can be launched as a background process without any disturbing windows. + +The missing console windows also has the effect, that when Proxydetox is launched from the terminal no output is visible. +The help output as well as the log output is affected by this. An online version of the help output can be found in the +[command line reference](cliref.md) section. + +Additionally there is the `--attach-console` options on Windows builds of Proxydetox to attach to the parrent console. +When running Proxydetox from the Windows command prompt, add the `--attach-console` optin to be able to see the output. diff --git a/proxydetox/Cargo.toml b/proxydetox/Cargo.toml index 11c9aae..5d024e7 100644 --- a/proxydetox/Cargo.toml +++ b/proxydetox/Cargo.toml @@ -31,3 +31,9 @@ tracing-subscriber.workspace = true tokio-rustls.workspace = true rustls-pemfile.workspace = true rustls.workspace = true + +[target.'cfg(windows)'.dependencies] +windows = { version = "0.58", features = [ + "Win32_System", + "Win32_System_Console", +] } diff --git a/proxydetox/src/main.rs b/proxydetox/src/main.rs index 8a041c4..7d14f7c 100644 --- a/proxydetox/src/main.rs +++ b/proxydetox/src/main.rs @@ -35,6 +35,16 @@ pub extern "C" fn main() { fn main() { let config = Options::load(); + #[cfg(target_family = "windows")] + if config.attach_console { + unsafe { + windows::Win32::System::Console::AttachConsole( + windows::Win32::System::Console::ATTACH_PARENT_PROCESS, + ) + .unwrap(); + } + } + if let Err(error) = run(config) { tracing::error!(%error, "fatal error"); write_error(&mut std::io::stderr(), error).ok(); diff --git a/proxydetox/src/options.rs b/proxydetox/src/options.rs index 55171ad..8f2d3e3 100644 --- a/proxydetox/src/options.rs +++ b/proxydetox/src/options.rs @@ -26,6 +26,8 @@ pub enum Authorization { #[derive(Debug)] pub struct Options { + #[cfg(target_family = "windows")] + pub attach_console: bool, pub log_level: LevelFilter, pub log_filepath: Option, pub pac_file: Option, @@ -113,6 +115,14 @@ impl Options { .about("A small proxy to relieve the pain of some corporate proxies") .args_override_self(true); + #[cfg(target_family = "windows")] + let app = app.arg( + Arg::new("attach_console") + .long("attach-console") + .help("Attache to the console of the parent process") + .action(ArgAction::SetTrue), + ); + #[cfg(feature = "negotiate")] let app = app.arg( Arg::new("negotiate") @@ -354,6 +364,8 @@ impl From for Options { .with_retries(m.get_one::("server_tcp_keepalive_retries").cloned()); Self { + #[cfg(target_family = "windows")] + attach_console: m.get_flag("attach_console"), log_level, log_filepath: m.get_one("log_filepath").cloned(), pac_file: m