disconnect conn from web console

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-12-20 10:22:28 +08:00
parent 38b6ba6691
commit 866ab24087
30 changed files with 67 additions and 9 deletions

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -406,5 +406,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "添加到地址簿"), ("Add to Address Book", "添加到地址簿"),
("Group", "小组"), ("Group", "小组"),
("Search", "搜索"), ("Search", "搜索"),
("Closed manually by the web console", "被web控制台手动关闭"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Zum Adressbuch hinzufügen"), ("Add to Address Book", "Zum Adressbuch hinzufügen"),
("Group", "Gruppe"), ("Group", "Gruppe"),
("Search", "Suchen"), ("Search", "Suchen"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -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"), ("Add to Address Book", "Añadir a la libreta de direcciones"),
("Group", "Grupo"), ("Group", "Grupo"),
("Search", "Búsqueda"), ("Search", "Búsqueda"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "افزودن به دفترچه آدرس"), ("Add to Address Book", "افزودن به دفترچه آدرس"),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Ajouter au carnet d'adresses"), ("Add to Address Book", "Ajouter au carnet d'adresses"),
("Group", "Groupe"), ("Group", "Groupe"),
("Search", "Rechercher"), ("Search", "Rechercher"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Προσθήκη στο Βιβλίο Διευθύνσεων"), ("Add to Address Book", "Προσθήκη στο Βιβλίο Διευθύνσεων"),
("Group", "Ομάδα"), ("Group", "Ομάδα"),
("Search", "Αναζήτηση"), ("Search", "Αναζήτηση"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Aggiungi alla rubrica"), ("Add to Address Book", "Aggiungi alla rubrica"),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Dodaj do Książki Adresowej"), ("Add to Address Book", "Dodaj do Książki Adresowej"),
("Group", "Grypy"), ("Group", "Grypy"),
("Search", "Szukaj"), ("Search", "Szukaj"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Добавить в адресную книгу"), ("Add to Address Book", "Добавить в адресную книгу"),
("Group", "Группа"), ("Group", "Группа"),
("Search", "Поиск"), ("Search", "Поиск"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -410,5 +410,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Dodaj u adresar"), ("Add to Address Book", "Dodaj u adresar"),
("Group", "Grupa"), ("Group", "Grupa"),
("Search", "Pretraga"), ("Search", "Pretraga"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "添加到地址簿"), ("Add to Address Book", "添加到地址簿"),
("Group", "小組"), ("Group", "小組"),
("Search", "搜索"), ("Search", "搜索"),
("Closed manually by the web console", "被web控制台手動關閉"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", "Додати IP до Адресної книги"), ("Add to Address Book", "Додати IP до Адресної книги"),
("Group", "Група"), ("Group", "Група"),
("Search", "Пошук"), ("Search", "Пошук"),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -405,5 +405,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add to Address Book", ""), ("Add to Address Book", ""),
("Group", ""), ("Group", ""),
("Search", ""), ("Search", ""),
("Closed manually by the web console", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -26,6 +26,7 @@ use hbb_common::{
}; };
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
use scrap::android::call_main_service_mouse_input; use scrap::android::call_main_service_mouse_input;
use serde::Deserialize;
use serde_json::{json, value::Value}; use serde_json::{json, value::Value};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
@ -261,7 +262,7 @@ impl Connection {
} }
} }
ipc::Data::Close => { ipc::Data::Close => {
conn.on_close_manually("connection manager").await; conn.on_close_manually("connection manager", "peer").await;
break; break;
} }
ipc::Data::ChatMessage{text} => { ipc::Data::ChatMessage{text} => {
@ -392,7 +393,10 @@ impl Connection {
} }
} }
_ = conn.http_timer.tick() => { _ = 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() => { Some((instant, value)) = rx_video.recv() => {
if !conn.video_ack_required { if !conn.video_ack_required {
@ -420,7 +424,7 @@ impl Connection {
Some(message::Union::Misc(m)) => { Some(message::Union::Misc(m)) => {
match &m.union { match &m.union {
Some(misc::Union::StopService(_)) => { Some(misc::Union::StopService(_)) => {
conn.on_close_manually("stop service").await; conn.on_close_manually("stop service", "peer").await;
break; break;
} }
_ => {}, _ => {},
@ -609,7 +613,7 @@ impl Connection {
if last_recv_time.elapsed() >= H1 { if last_recv_time.elapsed() >= H1 {
bail!("Timeout"); 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::<ConnAuditResponse>(&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) { fn post_file_audit(&self, action: &str, path: &str, files: Vec<(String, i64)>, info: Value) {
if self.server_audit_file.is_empty() { if self.server_audit_file.is_empty() {
return; return;
@ -728,9 +751,8 @@ impl Connection {
} }
#[inline] #[inline]
async fn post_audit_async(url: String, v: Value) -> ResultType<()> { async fn post_audit_async(url: String, v: Value) -> ResultType<String> {
crate::post_request(url, v.to_string(), "").await?; crate::post_request(url, v.to_string(), "").await
Ok(())
} }
async fn send_logon_response(&mut self) { async fn send_logon_response(&mut self) {
@ -1610,10 +1632,10 @@ impl Connection {
self.port_forward_socket.take(); 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; self.close_manually = true;
let mut misc = Misc::new(); 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(); let mut msg_out = Message::new();
msg_out.set_misc(misc); msg_out.set_misc(misc);
self.send(msg_out).await; self.send(msg_out).await;
@ -1790,3 +1812,10 @@ mod privacy_mode {
} }
} }
} }
#[derive(Debug, Deserialize)]
struct ConnAuditResponse {
#[allow(dead_code)]
ret: bool,
action: String,
}