This commit is contained in:
rustdesk
2025-05-13 19:56:48 +08:00
parent 9d0d729522
commit c735fbd54c
2 changed files with 44 additions and 29 deletions

View File

@@ -993,9 +993,19 @@ fn get_api_server_(api: String, custom: String) -> String {
"https://admin.rustdesk.com".to_owned() "https://admin.rustdesk.com".to_owned()
} }
#[inline]
pub fn is_public(url: &str) -> bool {
url.contains("rustdesk.com")
}
#[inline]
pub fn is_selfhost(url: &str) -> bool {
!is_public(url)
}
pub fn get_audit_server(api: String, custom: String, typ: String) -> String { pub fn get_audit_server(api: String, custom: String, typ: String) -> String {
let url = get_api_server(api, custom); let url = get_api_server(api, custom);
if url.is_empty() || url.contains("rustdesk.com") { if url.is_empty() || is_public(&url) {
return "".to_owned(); return "".to_owned();
} }
format!("{}/api/audit/{}", url, typ) format!("{}/api/audit/{}", url, typ)

View File

@@ -106,12 +106,14 @@ async fn start_hbbs_sync_async() {
v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name); v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name);
} }
let v = v.to_string(); let v = v.to_string();
let mut hash = "".to_owned();
if crate::is_selfhost(&url) {
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(url.as_bytes()); hasher.update(url.as_bytes());
hasher.update(&v.as_bytes()); hasher.update(&v.as_bytes());
let res = hasher.finalize(); let res = hasher.finalize();
let hash = hbb_common::base64::encode(&res[..]); hash = hbb_common::base64::encode(&res[..]);
let old_hash = config::Status::get("sysinfo_hash"); let old_hash = config::Status::get("sysinfo_hash");
let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side
if hash == old_hash { if hash == old_hash {
@@ -133,13 +135,16 @@ async fn start_hbbs_sync_async() {
continue; continue;
} }
} }
}
match crate::post_request(url.replace("heartbeat", "sysinfo"), v, "").await { match crate::post_request(url.replace("heartbeat", "sysinfo"), v, "").await {
Ok(x) => { Ok(x) => {
if x == "SYSINFO_UPDATED" { if x == "SYSINFO_UPDATED" {
info_uploaded = (true, url.clone(), None, id.clone()); info_uploaded = (true, url.clone(), None, id.clone());
log::info!("sysinfo updated"); log::info!("sysinfo updated");
if !hash.is_empty() {
config::Status::set("sysinfo_hash", hash); config::Status::set("sysinfo_hash", hash);
config::Status::set("sysinfo_ver", sysinfo_ver.clone()); config::Status::set("sysinfo_ver", sysinfo_ver.clone());
}
*PRO.lock().unwrap() = true; *PRO.lock().unwrap() = true;
} else if x == "ID_NOT_FOUND" { } else if x == "ID_NOT_FOUND" {
info_uploaded.2 = None; // next heartbeat will upload sysinfo again info_uploaded.2 = None; // next heartbeat will upload sysinfo again