diff --git a/src/lang/ca.rs b/src/lang/ca.rs index a8f39a23f..2f9bf7b25 100644 --- a/src/lang/ca.rs +++ b/src/lang/ca.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/cn.rs b/src/lang/cn.rs index 5dce8cd38..be0d7803e 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -406,5 +406,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "添加到地址簿"), ("Group", "小组"), ("Search", "搜索"), + ("Closed manually by the web console", "被web控制台手动关闭"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index 52571ef07..eb57edc0a 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index 138777e32..c34a31aef 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index d5d75d90b..b551774bf 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Zum Adressbuch hinzufügen"), ("Group", "Gruppe"), ("Search", "Suchen"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index d22cb2311..3f22f489e 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index ce0254a98..6923029ff 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Añadir a la libreta de direcciones"), ("Group", "Grupo"), ("Search", "Búsqueda"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fa.rs b/src/lang/fa.rs index b3850e1f2..20a1663f2 100644 --- a/src/lang/fa.rs +++ b/src/lang/fa.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "افزودن به دفترچه آدرس"), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index 124bfc00c..3b81fa1e4 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Ajouter au carnet d'adresses"), ("Group", "Groupe"), ("Search", "Rechercher"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/gr.rs b/src/lang/gr.rs index 933a84143..c708ce478 100644 --- a/src/lang/gr.rs +++ b/src/lang/gr.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Προσθήκη στο Βιβλίο Διευθύνσεων"), ("Group", "Ομάδα"), ("Search", "Αναζήτηση"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index f3f1e8fd9..849bfa0af 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index 89728b3e6..da69f2c76 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index 2237c81db..3b112618d 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Aggiungi alla rubrica"), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index e40c81ae8..3d76f446b 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 426a027db..92bb85bce 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/kz.rs b/src/lang/kz.rs index 6acd892f8..90a2730f6 100644 --- a/src/lang/kz.rs +++ b/src/lang/kz.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pl.rs b/src/lang/pl.rs index eb3a45d53..e5604c442 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Dodaj do Książki Adresowej"), ("Group", "Grypy"), ("Search", "Szukaj"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index 4d3d057ee..2adb4eb9e 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index bc878b680..6256d2e7a 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index f42d3146e..6e08322f3 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Добавить в адресную книгу"), ("Group", "Группа"), ("Search", "Поиск"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index e1b82d4f4..a65e0519b 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sq.rs b/src/lang/sq.rs index cbc71d4aa..27f37260d 100644 --- a/src/lang/sq.rs +++ b/src/lang/sq.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sr.rs b/src/lang/sr.rs index 43490c0b2..5d04f0150 100644 --- a/src/lang/sr.rs +++ b/src/lang/sr.rs @@ -410,5 +410,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Dodaj u adresar"), ("Group", "Grupa"), ("Search", "Pretraga"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sv.rs b/src/lang/sv.rs index 4dcababc0..72cc83fce 100644 --- a/src/lang/sv.rs +++ b/src/lang/sv.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index 34fe5077f..a92df2b52 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index b0c0686c1..cb7203c2d 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index d8d6c5ba0..6eef3656c 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "添加到地址簿"), ("Group", "小組"), ("Search", "搜索"), + ("Closed manually by the web console", "被web控制台手動關閉"), ].iter().cloned().collect(); } diff --git a/src/lang/ua.rs b/src/lang/ua.rs index 83b5e6984..373c3267e 100644 --- a/src/lang/ua.rs +++ b/src/lang/ua.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", "Додати IP до Адресної книги"), ("Group", "Група"), ("Search", "Пошук"), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index 412f04999..7b7808bea 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Add to Address Book", ""), ("Group", ""), ("Search", ""), + ("Closed manually by the web console", ""), ].iter().cloned().collect(); } diff --git a/src/server/connection.rs b/src/server/connection.rs index 659a97136..bfc8cd78b 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -26,6 +26,7 @@ use hbb_common::{ }; #[cfg(any(target_os = "android", target_os = "ios"))] use scrap::android::call_main_service_mouse_input; +use serde::Deserialize; use serde_json::{json, value::Value}; use sha2::{Digest, Sha256}; #[cfg(not(any(target_os = "android", target_os = "ios")))] @@ -261,7 +262,7 @@ impl Connection { } } ipc::Data::Close => { - conn.on_close_manually("connection manager").await; + conn.on_close_manually("connection manager", "peer").await; break; } ipc::Data::ChatMessage{text} => { @@ -392,7 +393,10 @@ impl Connection { } } _ = conn.http_timer.tick() => { - conn.post_conn_audit(json!({})); // heartbeat + if let Err(_) = Connection::post_heartbeat(conn.server_audit_conn.clone(), conn.inner.id).await { + conn.on_close_manually("web console", "web console").await; + break; + } }, Some((instant, value)) = rx_video.recv() => { if !conn.video_ack_required { @@ -420,7 +424,7 @@ impl Connection { Some(message::Union::Misc(m)) => { match &m.union { Some(misc::Union::StopService(_)) => { - conn.on_close_manually("stop service").await; + conn.on_close_manually("stop service", "peer").await; break; } _ => {}, @@ -609,7 +613,7 @@ impl Connection { if last_recv_time.elapsed() >= H1 { bail!("Timeout"); } - self.post_conn_audit(json!({})); // heartbeat + Connection::post_heartbeat(self.server_audit_conn.clone(), self.inner.id).await?; } } } @@ -692,6 +696,25 @@ impl Connection { }); } + async fn post_heartbeat(server_audit_conn: String, conn_id: i32) -> ResultType<()> { + if server_audit_conn.is_empty() { + return Ok(()); + } + let url = server_audit_conn.clone(); + let mut v = Value::default(); + v["id"] = json!(Config::get_id()); + v["uuid"] = json!(base64::encode(hbb_common::get_uuid())); + v["Id"] = json!(conn_id); + if let Ok(rsp) = Self::post_audit_async(url, v).await { + if let Ok(rsp) = serde_json::from_str::(&rsp) { + if rsp.action == "disconnect" { + bail!("disconnect by server"); + } + } + } + return Ok(()); + } + fn post_file_audit(&self, action: &str, path: &str, files: Vec<(String, i64)>, info: Value) { if self.server_audit_file.is_empty() { return; @@ -728,9 +751,8 @@ impl Connection { } #[inline] - async fn post_audit_async(url: String, v: Value) -> ResultType<()> { - crate::post_request(url, v.to_string(), "").await?; - Ok(()) + async fn post_audit_async(url: String, v: Value) -> ResultType { + crate::post_request(url, v.to_string(), "").await } async fn send_logon_response(&mut self) { @@ -1610,10 +1632,10 @@ impl Connection { self.port_forward_socket.take(); } - async fn on_close_manually(&mut self, close_from: &str) { + async fn on_close_manually(&mut self, close_from: &str, close_by: &str) { self.close_manually = true; let mut misc = Misc::new(); - misc.set_close_reason("Closed manually by the peer".into()); + misc.set_close_reason(format!("Closed manually by the {}", close_by)); let mut msg_out = Message::new(); msg_out.set_misc(misc); self.send(msg_out).await; @@ -1790,3 +1812,10 @@ mod privacy_mode { } } } + +#[derive(Debug, Deserialize)] +struct ConnAuditResponse { + #[allow(dead_code)] + ret: bool, + action: String, +}