f8ead215d8
build-windows / build-hello-agent-x64 (push) Successful in 5m41s
A single-binary, Flutter-free remote-support agent that speaks the stock
RustDesk wire protocol. Designed for one-line MDM deployment against a
self-hosted rustdesk-server: a supporter using the unmodified rustdesk.exe
client connects, the controlled-side user gets a native Win32 approval
prompt, click Yes / No.
CLI surface
hello-agent.exe --install # register + start service
hello-agent.exe --uninstall # stop, delete, clean up
hello-agent.exe --config <BLOB> # admin-UI deploy string
hello-agent.exe --install --config <BLOB> # MDM one-liner
--config accepts both forms emitted by the rustdesk-server admin UI: the
reversed-base64 deploy string and the host=,key=,api=,relay= filename
form. Decoded via the upstream custom_server module, persisted via
hbb_common::config::Config::set_option.
Architecture
--service runs as a Session 0 LocalSystem service. It polls
WTSGetActiveConsoleSessionId and (re)spawns hello-agent.exe --server
into the active console session via librustdesk::platform::run_as_user,
handling the Session 0 → user-session token impersonation.
--server is the worker. It boots three concurrent components:
1. cm_popup: an IPC listener on the rustdesk `_cm` named pipe
2. librustdesk::start_server(true, false): the upstream protocol
stack — rendezvous mediator, NAT punch, IPC server, screen
capture, login validation, hbbs_http heartbeat / sysinfo sync
3. (implicit) ApproveMode::Click is pinned in config, so every
incoming connection routes through cm_popup
The popup mechanism reuses an existing upstream contract without any
patches to the protocol code: when a peer connects with no password,
Connection::start in the upstream code calls try_start_cm_ipc, which
ipc::connect-s the `_cm` pipe before falling back to spawning a Flutter
CM child. Since cm_popup is up first, step 1 succeeds; we read the
Data::Login{authorized:false} frame, show MessageBoxTimeoutW (Yes/No,
60s, top-most, system-modal), and reply Data::Authorize or Data::Close.
Source tree
src/main.rs CLI dispatcher + run_server() composition
src/cli.rs hand-rolled argv parser + unit tests
src/service.rs windows-service install/uninstall/dispatcher
src/config_import.rs --config blob decoding + persistence
src/cm_popup.rs _cm IPC listener + Win32 approval dialog
Vendoring
The upstream RustDesk crate is vendored under vendor/rustdesk/ — full
workspace including libs/{hbb_common, scrap, enigo, clipboard,
virtual_display, remote_printer}. This makes the build self-contained
(no submodules, no sibling-repo checkout in CI) and gives us freedom to
fork in a different direction later. Excluded from the vendor: .git,
target/, flutter/, appimage/, flatpak/, fastlane/, docs/, examples/,
ci/, build.py, Dockerfile, upstream README/CLAUDE/AGENTS/GEMINI.
One local divergence vs. upstream: vendor/rustdesk/src/lib.rs flips
`mod custom_server` → `pub mod custom_server` so config_import.rs can
call get_custom_server_from_string without going through the
ui_interface shim. Documented in README.md → "Re-syncing the vendored
copy".
CI
.gitea/workflows/build-windows.yml builds on a self-hosted Windows
runner with Rust 1.75, LLVM 15.0.6 (libclang for bindgen via libvpx-sys),
and a vcpkg cache. The vendored vcpkg.json drives x64-windows-static
deps. The workflow stages the resulting hello-agent.exe into
SignOutput\, reports authenticode signing status (warns on unsigned),
and uploads as artifact. ~15 min full build, faster on incremental.
Out of scope for this commit: Linux/macOS builds, code signing, MSI
packaging, coexistence with stock rustdesk on the same box (currently
shares the RustDesk APP_NAME and config dir).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
279 lines
7.5 KiB
Rust
279 lines
7.5 KiB
Rust
use hbb_common::regex::Regex;
|
|
use std::ops::Deref;
|
|
|
|
mod ar;
|
|
mod be;
|
|
mod bg;
|
|
mod ca;
|
|
mod cn;
|
|
mod cs;
|
|
mod da;
|
|
mod de;
|
|
mod el;
|
|
mod en;
|
|
mod eo;
|
|
mod es;
|
|
mod et;
|
|
mod eu;
|
|
mod fa;
|
|
mod gu;
|
|
mod fr;
|
|
mod he;
|
|
mod hi;
|
|
mod hr;
|
|
mod hu;
|
|
mod id;
|
|
mod it;
|
|
mod ja;
|
|
mod ko;
|
|
mod kz;
|
|
mod lt;
|
|
mod lv;
|
|
mod nb;
|
|
mod nl;
|
|
mod pl;
|
|
mod ptbr;
|
|
mod ro;
|
|
mod ru;
|
|
mod sc;
|
|
mod sk;
|
|
mod sl;
|
|
mod sq;
|
|
mod sr;
|
|
mod sv;
|
|
mod th;
|
|
mod tr;
|
|
mod tw;
|
|
mod uk;
|
|
mod vi;
|
|
mod ta;
|
|
mod ge;
|
|
mod fi;
|
|
mod ml;
|
|
|
|
pub const LANGS: &[(&str, &str)] = &[
|
|
("en", "English"),
|
|
("it", "Italiano"),
|
|
("fr", "Français"),
|
|
("de", "Deutsch"),
|
|
("nl", "Nederlands"),
|
|
("nb", "Norsk bokmål"),
|
|
("zh-cn", "简体中文"),
|
|
("zh-tw", "繁體中文"),
|
|
("pt", "Português"),
|
|
("es", "Español"),
|
|
("et", "Eesti keel"),
|
|
("eu", "Euskara"),
|
|
("hu", "Magyar"),
|
|
("bg", "Български"),
|
|
("be", "Беларуская"),
|
|
("ru", "Русский"),
|
|
("sk", "Slovenčina"),
|
|
("id", "Indonesia"),
|
|
("cs", "Čeština"),
|
|
("da", "Dansk"),
|
|
("eo", "Esperanto"),
|
|
("tr", "Türkçe"),
|
|
("vi", "Tiếng Việt"),
|
|
("pl", "Polski"),
|
|
("ja", "日本語"),
|
|
("ko", "한국어"),
|
|
("kz", "Қазақ"),
|
|
("uk", "Українська"),
|
|
("fa", "فارسی"),
|
|
("ca", "Català"),
|
|
("el", "Ελληνικά"),
|
|
("sv", "Svenska"),
|
|
("sq", "Shqip"),
|
|
("sr", "Srpski"),
|
|
("th", "ภาษาไทย"),
|
|
("sl", "Slovenščina"),
|
|
("ro", "Română"),
|
|
("lt", "Lietuvių"),
|
|
("lv", "Latviešu"),
|
|
("ar", "العربية"),
|
|
("he", "עברית"),
|
|
("hr", "Hrvatski"),
|
|
("sc", "Sardu"),
|
|
("ta", "தமிழ்"),
|
|
("ge", "ქართული"),
|
|
("fi", "Suomi"),
|
|
("ml", "മലയാളം"),
|
|
("hi", "हिंदी"),
|
|
("gu", "ગુજરાતી"),
|
|
];
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
pub fn translate(name: String) -> String {
|
|
let locale = sys_locale::get_locale().unwrap_or_default();
|
|
translate_locale(name, &locale)
|
|
}
|
|
|
|
pub fn translate_locale(name: String, locale: &str) -> String {
|
|
let locale = locale.to_lowercase();
|
|
let mut lang = hbb_common::config::LocalConfig::get_option("lang").to_lowercase();
|
|
if lang.is_empty() {
|
|
// zh_CN on Linux, zh-Hans-CN on mac, zh_CN_#Hans on Android
|
|
if locale.starts_with("zh") {
|
|
lang = (if locale.contains("tw") {
|
|
"zh-tw"
|
|
} else {
|
|
"zh-cn"
|
|
})
|
|
.to_owned();
|
|
}
|
|
}
|
|
if lang.is_empty() {
|
|
lang = locale
|
|
.split("-")
|
|
.next()
|
|
.map(|x| x.split("_").next().unwrap_or_default())
|
|
.unwrap_or_default()
|
|
.to_owned();
|
|
}
|
|
let lang = lang.to_lowercase();
|
|
let m = match lang.as_str() {
|
|
"fr" => fr::T.deref(),
|
|
"zh-cn" => cn::T.deref(),
|
|
"it" => it::T.deref(),
|
|
"zh-tw" => tw::T.deref(),
|
|
"de" => de::T.deref(),
|
|
"nb" => nb::T.deref(),
|
|
"nl" => nl::T.deref(),
|
|
"es" => es::T.deref(),
|
|
"et" => et::T.deref(),
|
|
"eu" => eu::T.deref(),
|
|
"hu" => hu::T.deref(),
|
|
"ru" => ru::T.deref(),
|
|
"eo" => eo::T.deref(),
|
|
"id" => id::T.deref(),
|
|
"br" => ptbr::T.deref(),
|
|
"pt" => ptbr::T.deref(),
|
|
"tr" => tr::T.deref(),
|
|
"cs" => cs::T.deref(),
|
|
"da" => da::T.deref(),
|
|
"sk" => sk::T.deref(),
|
|
"vi" => vi::T.deref(),
|
|
"pl" => pl::T.deref(),
|
|
"ja" => ja::T.deref(),
|
|
"ko" => ko::T.deref(),
|
|
"kz" => kz::T.deref(),
|
|
"uk" => uk::T.deref(),
|
|
"fa" => fa::T.deref(),
|
|
"fi" => fi::T.deref(),
|
|
"ca" => ca::T.deref(),
|
|
"el" => el::T.deref(),
|
|
"sv" => sv::T.deref(),
|
|
"sq" => sq::T.deref(),
|
|
"sr" => sr::T.deref(),
|
|
"th" => th::T.deref(),
|
|
"sl" => sl::T.deref(),
|
|
"ro" => ro::T.deref(),
|
|
"lt" => lt::T.deref(),
|
|
"lv" => lv::T.deref(),
|
|
"ar" => ar::T.deref(),
|
|
"bg" => bg::T.deref(),
|
|
"be" => be::T.deref(),
|
|
"he" => he::T.deref(),
|
|
"hr" => hr::T.deref(),
|
|
"sc" => sc::T.deref(),
|
|
"ta" => ta::T.deref(),
|
|
"ge" => ge::T.deref(),
|
|
"ml" => ml::T.deref(),
|
|
"hi" => hi::T.deref(),
|
|
"gu" => gu::T.deref(),
|
|
_ => en::T.deref(),
|
|
};
|
|
let (name, placeholder_value) = extract_placeholder(&name);
|
|
let replace = |s: &&str| {
|
|
let mut s = s.to_string();
|
|
if let Some(value) = placeholder_value.as_ref() {
|
|
s = s.replace("{}", &value);
|
|
}
|
|
if !crate::is_rustdesk() {
|
|
if s.contains("RustDesk")
|
|
&& !name.starts_with("upgrade_rustdesk_server_pro")
|
|
&& name != "powered_by_me"
|
|
{
|
|
let app_name = crate::get_app_name();
|
|
if !app_name.contains("RustDesk") {
|
|
s = s.replace("RustDesk", &app_name);
|
|
} else {
|
|
// https://github.com/rustdesk/rustdesk-server-pro/issues/845
|
|
// If app_name contains "RustDesk" (e.g., "RustDesk-Admin"), we need to avoid
|
|
// replacing "RustDesk" within the already-substituted app_name, which would
|
|
// cause duplication like "RustDesk-Admin" -> "RustDesk-Admin-Admin".
|
|
//
|
|
// app_name only contains alphanumeric and hyphen.
|
|
const PLACEHOLDER: &str = "#A-P-P-N-A-M-E#";
|
|
if !s.contains(PLACEHOLDER) {
|
|
s = s.replace(&app_name, PLACEHOLDER);
|
|
s = s.replace("RustDesk", &app_name);
|
|
s = s.replace(PLACEHOLDER, &app_name);
|
|
} else {
|
|
// It's very unlikely to reach here.
|
|
// Skip replacement to avoid incorrect result.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
s
|
|
};
|
|
if let Some(v) = m.get(&name as &str) {
|
|
if !v.is_empty() {
|
|
return replace(v);
|
|
}
|
|
}
|
|
if lang != "en" {
|
|
if let Some(v) = en::T.get(&name as &str) {
|
|
if !v.is_empty() {
|
|
return replace(v);
|
|
}
|
|
}
|
|
}
|
|
replace(&name.as_str())
|
|
}
|
|
|
|
// Matching pattern is {}
|
|
// Write {value} in the UI and {} in the translation file
|
|
//
|
|
// Example:
|
|
// Write in the UI: translate("There are {24} hours in a day")
|
|
// Write in the translation file: ("There are {} hours in a day", "{} hours make up a day")
|
|
fn extract_placeholder(input: &str) -> (String, Option<String>) {
|
|
if let Ok(re) = Regex::new(r#"\{(.*?)\}"#) {
|
|
if let Some(captures) = re.captures(input) {
|
|
if let Some(inner_match) = captures.get(1) {
|
|
let name = re.replace(input, "{}").to_string();
|
|
let value = inner_match.as_str().to_string();
|
|
return (name, Some(value));
|
|
}
|
|
}
|
|
}
|
|
(input.to_string(), None)
|
|
}
|
|
|
|
mod test {
|
|
#[test]
|
|
fn test_extract_placeholders() {
|
|
use super::extract_placeholder as f;
|
|
|
|
assert_eq!(f(""), ("".to_string(), None));
|
|
assert_eq!(
|
|
f("{3} sessions"),
|
|
("{} sessions".to_string(), Some("3".to_string()))
|
|
);
|
|
assert_eq!(f(" } { "), (" } { ".to_string(), None));
|
|
// Allow empty value
|
|
assert_eq!(
|
|
f("{} sessions"),
|
|
("{} sessions".to_string(), Some("".to_string()))
|
|
);
|
|
// Match only the first one
|
|
assert_eq!(
|
|
f("{2} times {4} makes {8}"),
|
|
("{} times {4} makes {8}".to_string(), Some("2".to_string()))
|
|
);
|
|
}
|
|
}
|