Skip to content

Commit c735fbd

Browse files
committed
improve self-host server switch case rustdesk#11749
1 parent 9d0d729 commit c735fbd

2 files changed

Lines changed: 44 additions & 29 deletions

File tree

src/common.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,19 @@ fn get_api_server_(api: String, custom: String) -> String {
993993
"https://admin.rustdesk.com".to_owned()
994994
}
995995

996+
#[inline]
997+
pub fn is_public(url: &str) -> bool {
998+
url.contains("rustdesk.com")
999+
}
1000+
1001+
#[inline]
1002+
pub fn is_selfhost(url: &str) -> bool {
1003+
!is_public(url)
1004+
}
1005+
9961006
pub fn get_audit_server(api: String, custom: String, typ: String) -> String {
9971007
let url = get_api_server(api, custom);
998-
if url.is_empty() || url.contains("rustdesk.com") {
1008+
if url.is_empty() || is_public(&url) {
9991009
return "".to_owned();
10001010
}
10011011
format!("{}/api/audit/{}", url, typ)

src/hbbs_http/sync.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,40 +106,45 @@ async fn start_hbbs_sync_async() {
106106
v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name);
107107
}
108108
let v = v.to_string();
109-
use sha2::{Digest, Sha256};
110-
let mut hasher = Sha256::new();
111-
hasher.update(url.as_bytes());
112-
hasher.update(&v.as_bytes());
113-
let res = hasher.finalize();
114-
let hash = hbb_common::base64::encode(&res[..]);
115-
let old_hash = config::Status::get("sysinfo_hash");
116-
let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side
117-
if hash == old_hash {
118-
// When the api doesn't exist, Ok("") will be returned in test.
119-
let samever = match crate::post_request(url.replace("heartbeat", "sysinfo_ver"), "".to_owned(), "").await {
120-
Ok(x) => {
121-
sysinfo_ver = x.clone();
122-
*PRO.lock().unwrap() = true;
123-
x == ver
124-
}
125-
_ => {
126-
false // to make sure Pro can be assigned in below post for old
127-
// hbbs pro not supporting sysinfo_ver, use false for ensuring
128-
}
129-
};
130-
if samever {
131-
info_uploaded = (true, url.clone(), None, id.clone());
132-
log::info!("sysinfo not changed, skip upload");
133-
continue;
134-
}
109+
let mut hash = "".to_owned();
110+
if crate::is_selfhost(&url) {
111+
use sha2::{Digest, Sha256};
112+
let mut hasher = Sha256::new();
113+
hasher.update(url.as_bytes());
114+
hasher.update(&v.as_bytes());
115+
let res = hasher.finalize();
116+
hash = hbb_common::base64::encode(&res[..]);
117+
let old_hash = config::Status::get("sysinfo_hash");
118+
let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side
119+
if hash == old_hash {
120+
// When the api doesn't exist, Ok("") will be returned in test.
121+
let samever = match crate::post_request(url.replace("heartbeat", "sysinfo_ver"), "".to_owned(), "").await {
122+
Ok(x) => {
123+
sysinfo_ver = x.clone();
124+
*PRO.lock().unwrap() = true;
125+
x == ver
126+
}
127+
_ => {
128+
false // to make sure Pro can be assigned in below post for old
129+
// hbbs pro not supporting sysinfo_ver, use false for ensuring
130+
}
131+
};
132+
if samever {
133+
info_uploaded = (true, url.clone(), None, id.clone());
134+
log::info!("sysinfo not changed, skip upload");
135+
continue;
136+
}
137+
}
135138
}
136139
match crate::post_request(url.replace("heartbeat", "sysinfo"), v, "").await {
137140
Ok(x) => {
138141
if x == "SYSINFO_UPDATED" {
139142
info_uploaded = (true, url.clone(), None, id.clone());
140143
log::info!("sysinfo updated");
141-
config::Status::set("sysinfo_hash", hash);
142-
config::Status::set("sysinfo_ver", sysinfo_ver.clone());
144+
if !hash.is_empty() {
145+
config::Status::set("sysinfo_hash", hash);
146+
config::Status::set("sysinfo_ver", sysinfo_ver.clone());
147+
}
143148
*PRO.lock().unwrap() = true;
144149
} else if x == "ID_NOT_FOUND" {
145150
info_uploaded.2 = None; // next heartbeat will upload sysinfo again

0 commit comments

Comments
 (0)