diff --git a/AGENTS.md b/AGENTS.md index 946a65d..49e6f4f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -116,6 +116,7 @@ viewer does not reconnect them automatically. | `UU_FFMPEG_ROOT` | FFmpeg prefix (`bin/ffmpeg`, libs in `lib/x86_64-linux-gnu`) | | `UU_AUDIO=0`, `UU_AUDIO_SOURCE` | disable sound / choose the Pulse source (default `@DEFAULT_MONITOR@`) | | `UU_LOGIN_WINDOW=0` | don't auto-open the login window | +| `UU_USE_PROXY=1` | honor HTTP/SOCKS proxy env vars; cloud API clients bypass env proxies by default | | `UU_REMOTE_ASSIST=0`, `UU_ASSIST_ALLOW=1`, `UU_ASSIST_UI=tty`, `UU_ASSIST_DEBUG=1` | disable assistance / allow at start / terminal UI for `assist` / include the server's short error message in assist errors | Token has no expiry field; API code 1120 (HTTP 422) means invalid/expired → re-login. The config is re-read diff --git a/README.en.md b/README.en.md index b007ae5..b1ab7d0 100644 --- a/README.en.md +++ b/README.en.md @@ -288,6 +288,7 @@ Common environment variables: | `UU_ASSIST_ALLOW=1` | Allow remote assistance at start (overrides the saved switch) | | `UU_LOGIN_WINDOW=0` | Do not open the login window automatically when credentials are missing | | `UU_PORT_MAPPING=0` | Disable port mapping (the official host's controlled-side switch) | +| `UU_USE_PROXY=1` | Honor HTTP/SOCKS proxy environment variables; by default proxies are ignored and NetEase servers are reached directly | Host settings such as "lock after remote session" and "mute host" are stored in `~/.config/uuremote/host_settings.json`. diff --git a/README.md b/README.md index c3c8f91..11642ad 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,7 @@ systemctl --user restart uuremote-native.service | `UU_REMOTE_ASSIST=0` | 关闭远程协助(未登录时也不再以访客身份提供协助) | | `UU_ASSIST_ALLOW=1` | 启动时就允许他人远程协助(覆盖窗口里保存的开关状态) | | `UU_PORT_MAPPING=0` | 关闭端口映射(对应官方被控端的开关) | +| `UU_USE_PROXY=1` | 使用环境变量里的 HTTP/SOCKS 代理;默认忽略代理、直连网易服务器 | 「远程结束后自动锁屏」「静音运行」等设置保存在 `~/.config/uuremote/host_settings.json`。 diff --git a/src/auth.rs b/src/auth.rs index 947aa9a..7bd8a90 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -121,9 +121,24 @@ fn redact_urls(text: &str) -> String { out } +/// Cloud API clients ignore ambient HTTP/SOCKS proxy settings by default: a local +/// proxy that intercepts TLS breaks login and signaling. `UU_USE_PROXY=1` opts back +/// into reqwest's standard proxy environment handling. +pub fn http_client_builder() -> reqwest::ClientBuilder { + let builder = reqwest::Client::builder(); + if std::env::var("UU_USE_PROXY").ok().as_deref().is_some_and(proxy_requested) { + builder + } else { + builder.no_proxy() + } +} +fn proxy_requested(value: &str) -> bool { + matches!(value.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on") +} + impl UUAuthClient { pub fn new(creds: Credentials) -> Self { - let http = reqwest::Client::builder() + let http = http_client_builder() .timeout(std::time::Duration::from_secs(12)) .build() .unwrap(); @@ -346,4 +361,10 @@ mod guest_tests { let text = super::redact_urls("proxy http://user:secret@proxy.example:3128 failed for (https://api.example/p?token=abc)"); assert_eq!(text, "proxy http://proxy.example:3128 failed for (https://api.example/p)"); } + + #[test] + fn proxy_opt_in_accepts_only_explicit_truthy_values() { + for value in ["1", "true", "TRUE", " yes ", "On"] { assert!(super::proxy_requested(value)); } + for value in ["", "0", "false", "no", "off", "2"] { assert!(!super::proxy_requested(value)); } + } } diff --git a/src/viewer/api.rs b/src/viewer/api.rs index 2b64f28..49e1bf4 100644 --- a/src/viewer/api.rs +++ b/src/viewer/api.rs @@ -93,7 +93,7 @@ pub struct Api { } impl Api { pub fn new(signer: UUAuthClient, base: &str) -> Self { - Self { signer, base: base.trim_end_matches('/').into(), http: reqwest::Client::builder().timeout(Duration::from_secs(12)).build().unwrap() } + Self { signer, base: base.trim_end_matches('/').into(), http: crate::auth::http_client_builder().timeout(Duration::from_secs(12)).build().unwrap() } } pub async fn join_share(&self, connect_id: &str, connect_code: &str) -> Result { if connect_id.trim().is_empty() || connect_code.trim().is_empty() || connect_id.chars().chain(connect_code.chars()).any(char::is_control) { return Err(Error::InvalidAssist); }