From f76f0f66e3cdc4fd320c8196ee2204683490e1bd Mon Sep 17 00:00:00 2001 From: Mike Mueller Date: Sat, 2 May 2026 18:44:59 +0200 Subject: [PATCH] Prefill deploy parameters by defaults. --- .gitignore | 1 + db_v2.sqlite3 | Bin 24576 -> 0 bytes src/api/admin/pages/deploy.rs | 57 +++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 5 deletions(-) delete mode 100644 db_v2.sqlite3 diff --git a/.gitignore b/.gitignore index 85358f1..a530f53 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ src/version.rs db_v2.sqlite3 test.* .idea +db_v2.sqlite3 diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 deleted file mode 100644 index 93d9801b0ce72813f71240b9adf5642926bfc6c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeI(PiWIn90%~U-Ktc&DAEeIw#7%bj2GYJZzkKuZNqTs% z?XJGGW~wBw8$+^51ZpAWc2gS(p(v`=TD{gfwKQ9erl}X!v+I|3qh>1=-N*Z_t<8Qf z)v~?C?Z55cYc;Vz00Izz00bZa0SG_<0uY!ZfgR1>;F^GIP%A3xk%@;)NmY%^uqm76 zVY}%~?(FXB?O$pJ9#4aQ4le>iXH+h4JfNRv5m@`z_RF#Zu+U3oSQmbXv zwt!{5{Rlub=voys{@>G&`_ipanUFY;Q zr5dLx;geCUI=#V^vjx>ouvd2_rN3)ay1N49BaY=@*$T@R^eibE+K_CFkU@2X z6m^pn%Y{OurrxSPBpbN_*=XljHvEUm@^o_Jw9??@u^U%Z{fS~-LsJ`4r;kY#H7}P7 zW_zw|7;4eX*juezVWl5d08KYXpXnl@8d^juwAOHafKmY;|fB*y_009U< zU`7Hb7WpD8`qP3HB8{*8w%qqH8NQ-iU)Fc+<9AMw*tjTgk|fGJmsb)AMu@Q@6N@Dz zCYz6Qj4XC!B`zn5Vm9V~x8XE-dS~VFPcO%=_TIfb|LnP2?;fwdbMMjGtx^5cYo6tK zhD|UWPdKqth~EF*UHh>Rp8IYx}9V)2wHb+B>v%jY-ekFHxXe*XqF z8rt;gT>8g{7woAU$qR-2#Y+p$tao%s?2OgvP)rCNn;8Go4=DNp{dPv!*ck#4fB*y_ z009U<00Izz00bZaf&VPf=2;P`&S*I2I+l9cB2$wK&Pj*K@&7Z5enx-%&z(d(1Rwwb z2tWV=5P$##AOHafKmY=>EU?%^MV#{h_Ivfm|2HZ6Iel}MyMQ diff --git a/src/api/admin/pages/deploy.rs b/src/api/admin/pages/deploy.rs index 13cfeb9..0195b61 100644 --- a/src/api/admin/pages/deploy.rs +++ b/src/api/admin/pages/deploy.rs @@ -9,14 +9,52 @@ use super::shared::{html_escape, require_admin}; use crate::api::error::ApiError; use crate::api::middleware::AuthedUser; use axum::extract::Form; +use axum::http::HeaderMap; use axum::response::Html; use serde::Deserialize; use serde_json::json; -pub async fn index(admin: AuthedUser) -> Result, ApiError> { +pub async fn index(admin: AuthedUser, headers: HeaderMap) -> Result, ApiError> { require_admin(&admin)?; let pubkey = read_pubkey(); - Ok(Html(render_form(&pubkey, "", "", "", "", None))) + // Best-effort prefill: the Host the admin's browser is currently + // talking to is almost always the same machine running hbbs, so it's + // the right default for the rendezvous-host field. Reverse proxies + // forward the original Host through unless explicitly stripped, so + // this works behind nginx/Caddy/Traefik too. Operator can edit if + // hbbr lives on a different host. + let host_default = headers + .get(axum::http::header::HOST) + .and_then(|v| v.to_str().ok()) + .map(host_only) + .unwrap_or("") + .to_string(); + let (api_default, relay_default) = if host_default.is_empty() { + (String::new(), String::new()) + } else { + (format!("https://{}", host_default), host_default.clone()) + }; + Ok(Html(render_form( + &pubkey, + &host_default, + &api_default, + &relay_default, + "", + None, + ))) +} + +/// Strip an optional `:port` (and IPv6 brackets) from a Host-header value. +/// "rustdesk.example.com:21114" -> "rustdesk.example.com" +/// "[::1]:21114" -> "::1" +/// "10.196.83.110" -> "10.196.83.110" +fn host_only(s: &str) -> &str { + if let Some(rest) = s.strip_prefix('[') { + if let Some(end) = rest.find(']') { + return &rest[..end]; + } + } + s.rsplit_once(':').map(|(h, _)| h).unwrap_or(s) } #[derive(Debug, Deserialize)] @@ -117,7 +155,14 @@ fn render_form(

The hostname or IP clients reach hbbs at (TCP/UDP 21116).

@@ -125,15 +170,17 @@ fn render_form(
-

Full URL of this admin/login API. Leave blank to disable login on the client.

+

Full URL of this admin/login API. Defaults to https://<host>; edit if your API runs on a different scheme/port. Leave blank to disable login on the client.

Only set if hbbr runs on a separate host; otherwise leave blank.