diff --git a/README.en.md b/README.en.md index 3ae6b33..0606d90 100644 --- a/README.en.md +++ b/README.en.md @@ -405,7 +405,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_WOL_HELPER=1` | Experimental: act as a remote-boot helper like the official Windows host — report this host's LAN info after sign-in and send a magic packet to the LAN when the cloud asks to wake a PC (not verified end to end) | +| `UU_WOL_HELPER=1` | Experimental: act as a remote-boot helper like the official Windows host — report this host's LAN info after sign-in and send a magic packet to the LAN when the cloud asks to wake a PC (verified end to end with a headless Linux host on a NAS and the official iOS controller) | | `UU_USE_PROXY=1` | Share environment HTTP/HTTPS proxy policy between REST and host/viewer WebSocket signaling; proxies are ignored by default | diff --git a/README.md b/README.md index a5005da..b262fd5 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ systemctl --user restart uuremote-native.service | `UU_REMOTE_ASSIST=0` | 关闭远程协助(未登录时也不再以访客身份提供协助) | | `UU_ASSIST_ALLOW=1` | 启动时就允许他人远程协助(覆盖窗口里保存的开关状态) | | `UU_PORT_MAPPING=0` | 关闭端口映射(对应官方被控端的开关) | -| `UU_WOL_HELPER=1` | 实验性:让这台主机像官方 Windows 被控端一样充当「远程开机」辅助设备——登录后向网易上报本机局域网信息,收到云端唤醒请求时向同一局域网发送唤醒包(未经端到端验证) | +| `UU_WOL_HELPER=1` | 实验性:让这台主机像官方 Windows 被控端一样充当「远程开机」辅助设备——登录后向网易上报本机局域网信息,收到云端唤醒请求时向同一局域网发送唤醒包(已在 NAS 上的无头 Linux 主机配合官方 iOS 控制端实测可远程开机) | | `UU_USE_PROXY=1` | REST API 与 host/viewer WebSocket 信令共用环境 HTTP/HTTPS 代理策略;默认忽略代理、直连 | diff --git a/src/wol.rs b/src/wol.rs index 78c9886..876c2fe 100644 --- a/src/wol.rs +++ b/src/wol.rs @@ -83,10 +83,18 @@ pub fn lan_info() -> Option<(String, String, String)> { #[cfg(not(target_os = "linux"))] pub fn lan_info() -> Option<(String, String, String)> { None } +/// Body of the helper registration request (same address as `inner_ip` and `ip`: this host has one LAN address). +fn report_body(mac: &str, ip: &str, subnet_mask: &str) -> serde_json::Value { + serde_json::json!({ "mac": mac, "inner_ip": ip, "ip": ip, "subnet_mask": subnet_mask }) +} + /// Report this host's LAN identity like the official host after sign-in. +/// The server rejects the report (HTTP 422, code 1001) unless `inner_ip` is present; the official macOS +/// client sends `inner_ip`, `ip`, `mac` and `subnet_mask`. Verified live: with `inner_ip` the helper is +/// accepted (HTTP 200) and the cloud forwards `wake_on_lan` pushes to this host. pub async fn report(auth: &crate::auth::UUAuthClient) { let Some((mac, ip, subnet_mask)) = lan_info() else { log::warn!("WOL helper: no IPv4 default-route interface"); return; }; - let body = serde_json::json!({ "mac": mac, "ip": ip, "subnet_mask": subnet_mask }); + let body = report_body(&mac, &ip, &subnet_mask); match auth.post_json_url("https://api-ipv4.nrd.nie.163.com", "/api/v1/device/wake_on_lan/info", &body).await { Ok((status, value)) => log::info!("WOL helper: LAN info reported: status={status} code={:?} turn_on_wol={:?}", value.get("code").and_then(serde_json::Value::as_i64), @@ -108,6 +116,15 @@ mod tests { assert_eq!(&packet[..6], &[0xff; 6]); assert_eq!(&packet[96..], &[1, 2, 3, 4, 5, 6]); } + #[test] + fn report_body_has_inner_ip() { + let body = report_body("aa:bb:cc:dd:ee:01", "192.168.2.29", "255.255.255.0"); + assert_eq!(body["inner_ip"], "192.168.2.29"); + assert_eq!(body["ip"], "192.168.2.29"); + assert_eq!(body["mac"], "aa:bb:cc:dd:ee:01"); + assert_eq!(body["subnet_mask"], "255.255.255.0"); + } + #[test] fn directed_broadcast() { assert_eq!(subnet_broadcast("192.168.2.29", "255.255.255.0"), Some(Ipv4Addr::new(192, 168, 2, 255)));