diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | src/relay_server.rs | 27 | ||||
-rw-r--r-- | src/rendezvous_server.rs | 20 | ||||
-rw-r--r-- | ui/setup.nsi | 2 |
6 files changed, 44 insertions, 13 deletions
@@ -779,7 +779,7 @@ dependencies = [ [[package]] name = "hbbs" -version = "1.1.11-1" +version = "1.1.12" dependencies = [ "async-speed-limit", "async-trait", @@ -1,6 +1,6 @@ [package] name = "hbbs" -version = "1.1.11-1" +version = "1.1.12" authors = ["rustdesk <[email protected]>"] edition = "2021" build = "build.rs" diff --git a/debian/changelog b/debian/changelog index 9058df0..7305d3a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,7 @@ +rustdesk-server (1.1.12) UNRELEASED; urgency=medium + * WS real ip + * Bump s6-overlay to v3.2.0.0 and fix env warnings + rustdesk-server (1.1.11-1) UNRELEASED; urgency=medium * set reuse port to make restart friendly * revert hbbr `-k` to not ruin back-compatibility diff --git a/src/relay_server.rs b/src/relay_server.rs index b55d544..abe6fc2 100644 --- a/src/relay_server.rs +++ b/src/relay_server.rs @@ -392,19 +392,30 @@ async fn handle_connection( async fn make_pair( stream: TcpStream, - addr: SocketAddr, + mut addr: SocketAddr, key: &str, limiter: Limiter, ws: bool, ) -> ResultType<()> { if ws { - make_pair_( - tokio_tungstenite::accept_async(stream).await?, - addr, - key, - limiter, - ) - .await; + use tokio_tungstenite::tungstenite::handshake::server::{Request, Response}; + let callback = |req: &Request, response: Response| { + let headers = req.headers(); + let real_ip = headers + .get("X-Real-IP") + .or_else(|| headers.get("X-Forwarded-For")) + .and_then(|header_value| header_value.to_str().ok()); + if let Some(ip) = real_ip { + if ip.contains('.') { + addr = format!("{ip}:0").parse().unwrap_or(addr); + } else { + addr = format!("[{ip}]:0").parse().unwrap_or(addr); + } + } + Ok(response) + }; + let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?; + make_pair_(ws_stream, addr, key, limiter).await; } else { make_pair_(FramedStream::from(stream, addr), addr, key, limiter).await; } diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 3449e75..9394731 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -1106,13 +1106,29 @@ impl RendezvousServer { async fn handle_listener_inner( &mut self, stream: TcpStream, - addr: SocketAddr, + mut addr: SocketAddr, key: &str, ws: bool, ) -> ResultType<()> { let mut sink; if ws { - let ws_stream = tokio_tungstenite::accept_async(stream).await?; + use tokio_tungstenite::tungstenite::handshake::server::{Request, Response}; + let callback = |req: &Request, response: Response| { + let headers = req.headers(); + let real_ip = headers + .get("X-Real-IP") + .or_else(|| headers.get("X-Forwarded-For")) + .and_then(|header_value| header_value.to_str().ok()); + if let Some(ip) = real_ip { + if ip.contains('.') { + addr = format!("{ip}:0").parse().unwrap_or(addr); + } else { + addr = format!("[{ip}]:0").parse().unwrap_or(addr); + } + } + Ok(response) + }; + let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?; let (a, mut b) = ws_stream.split(); sink = Some(Sink::Ws(a)); while let Ok(Some(Ok(msg))) = timeout(30_000, b.next()).await { diff --git a/ui/setup.nsi b/ui/setup.nsi index 5186666..d386879 100644 --- a/ui/setup.nsi +++ b/ui/setup.nsi @@ -15,7 +15,7 @@ !define PRODUCT_NAME "rustdesk_server" !define PRODUCT_DESCRIPTION "Installer for ${PRODUCT_NAME}" !define COPYRIGHT "Copyright © 2021" -!define VERSION "1.1.10" +!define VERSION "1.1.12" VIProductVersion "${VERSION}.0" VIAddVersionKey "ProductName" "${PRODUCT_NAME}" |