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,40 +106,45 @@ 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();
use sha2::{Digest, Sha256}; let mut hash = "".to_owned();
let mut hasher = Sha256::new(); if crate::is_selfhost(&url) {
hasher.update(url.as_bytes()); use sha2::{Digest, Sha256};
hasher.update(&v.as_bytes()); let mut hasher = Sha256::new();
let res = hasher.finalize(); hasher.update(url.as_bytes());
let hash = hbb_common::base64::encode(&res[..]); hasher.update(&v.as_bytes());
let old_hash = config::Status::get("sysinfo_hash"); let res = hasher.finalize();
let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side hash = hbb_common::base64::encode(&res[..]);
if hash == old_hash { let old_hash = config::Status::get("sysinfo_hash");
// When the api doesn't exist, Ok("") will be returned in test. let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side
let samever = match crate::post_request(url.replace("heartbeat", "sysinfo_ver"), "".to_owned(), "").await { if hash == old_hash {
Ok(x) => { // When the api doesn't exist, Ok("") will be returned in test.
sysinfo_ver = x.clone(); let samever = match crate::post_request(url.replace("heartbeat", "sysinfo_ver"), "".to_owned(), "").await {
*PRO.lock().unwrap() = true; Ok(x) => {
x == ver sysinfo_ver = x.clone();
} *PRO.lock().unwrap() = true;
_ => { x == ver
false // to make sure Pro can be assigned in below post for old }
// hbbs pro not supporting sysinfo_ver, use false for ensuring _ => {
} false // to make sure Pro can be assigned in below post for old
}; // hbbs pro not supporting sysinfo_ver, use false for ensuring
if samever { }
info_uploaded = (true, url.clone(), None, id.clone()); };
log::info!("sysinfo not changed, skip upload"); if samever {
continue; info_uploaded = (true, url.clone(), None, id.clone());
} log::info!("sysinfo not changed, skip upload");
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");
config::Status::set("sysinfo_hash", hash); if !hash.is_empty() {
config::Status::set("sysinfo_ver", sysinfo_ver.clone()); config::Status::set("sysinfo_hash", hash);
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