mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 07:43:01 +08:00
refactor audit field
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
56f154f69a
commit
54ce0a9775
@ -45,8 +45,9 @@ class GroupModel {
|
||||
var uri0 = Uri.parse(api);
|
||||
final pageSize = 20;
|
||||
var total = 0;
|
||||
int current = 1;
|
||||
int current = 0;
|
||||
do {
|
||||
current += 1;
|
||||
var uri = Uri(
|
||||
scheme: uri0.scheme,
|
||||
host: uri0.host,
|
||||
@ -58,7 +59,6 @@ class GroupModel {
|
||||
if (gFFI.userModel.isAdmin.isFalse)
|
||||
'grp': gFFI.userModel.groupName.value,
|
||||
});
|
||||
current += pageSize;
|
||||
final resp = await http.get(uri, headers: await getHttpHeaders());
|
||||
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||
@ -76,7 +76,7 @@ class GroupModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (current < total + 1);
|
||||
} while (current * pageSize < total);
|
||||
} catch (err) {
|
||||
debugPrint('$err');
|
||||
userLoadError.value = err.toString();
|
||||
@ -96,8 +96,9 @@ class GroupModel {
|
||||
var uri0 = Uri.parse(api);
|
||||
final pageSize = 20;
|
||||
var total = 0;
|
||||
int current = 1;
|
||||
int current = 0;
|
||||
do {
|
||||
current += 1;
|
||||
var uri = Uri(
|
||||
scheme: uri0.scheme,
|
||||
host: uri0.host,
|
||||
@ -109,7 +110,6 @@ class GroupModel {
|
||||
'grp': gFFI.userModel.groupName.value,
|
||||
'target_user': username
|
||||
});
|
||||
current += pageSize;
|
||||
final resp = await http.get(uri, headers: await getHttpHeaders());
|
||||
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||
@ -129,7 +129,7 @@ class GroupModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (current < total + 1);
|
||||
} while (current * pageSize < total);
|
||||
} catch (err) {
|
||||
debugPrint('$err');
|
||||
peerLoadError.value = err.toString();
|
||||
|
@ -697,7 +697,7 @@ impl Connection {
|
||||
let mut v = v;
|
||||
v["id"] = json!(Config::get_id());
|
||||
v["uuid"] = json!(base64::encode(hbb_common::get_uuid()));
|
||||
v["Id"] = json!(self.inner.id);
|
||||
v["conn_id"] = json!(self.inner.id);
|
||||
tokio::spawn(async move {
|
||||
allow_err!(Self::post_audit_async(url, v).await);
|
||||
});
|
||||
@ -711,7 +711,7 @@ impl Connection {
|
||||
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);
|
||||
v["conn_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" {
|
||||
@ -722,7 +722,13 @@ impl Connection {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn post_file_audit(&self, action: &str, path: &str, files: Vec<(String, i64)>, info: Value) {
|
||||
fn post_file_audit(
|
||||
&self,
|
||||
r#type: FileAuditType,
|
||||
path: &str,
|
||||
files: Vec<(String, i64)>,
|
||||
info: Value,
|
||||
) {
|
||||
if self.server_audit_file.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -731,12 +737,7 @@ impl Connection {
|
||||
let mut files = files;
|
||||
files.sort_by(|a, b| b.1.cmp(&a.1));
|
||||
files.truncate(10);
|
||||
let is_file = match action {
|
||||
"send" | "receive" => files.len() == 1 && files[0].0.is_empty(),
|
||||
"remove_dir" | "create_dir" => false,
|
||||
"remove_file" => true,
|
||||
_ => true,
|
||||
};
|
||||
let is_file = files.len() == 1 && files[0].0.is_empty();
|
||||
let mut info = info;
|
||||
info["ip"] = json!(self.ip.clone());
|
||||
info["name"] = json!(self.lr.my_name.clone());
|
||||
@ -745,9 +746,8 @@ impl Connection {
|
||||
let v = json!({
|
||||
"id":json!(Config::get_id()),
|
||||
"uuid":json!(base64::encode(hbb_common::get_uuid())),
|
||||
"Id":json!(self.inner.id),
|
||||
"peer_id":json!(self.lr.my_id),
|
||||
"action": action,
|
||||
"type": r#type as i8,
|
||||
"path":path,
|
||||
"is_file":is_file,
|
||||
"info":json!(info).to_string(),
|
||||
@ -793,7 +793,7 @@ impl Connection {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
self.post_conn_audit(json!({"peer": self.peer_info, "Type": conn_type}));
|
||||
self.post_conn_audit(json!({"peer": self.peer_info, "type": conn_type}));
|
||||
#[allow(unused_mut)]
|
||||
let mut username = crate::platform::get_active_username();
|
||||
let mut res = LoginResponse::new();
|
||||
@ -1341,7 +1341,7 @@ impl Connection {
|
||||
self.read_jobs.push(job);
|
||||
self.file_timer = time::interval(MILLI1);
|
||||
self.post_file_audit(
|
||||
"send",
|
||||
FileAuditType::RemoteSend,
|
||||
&s.path,
|
||||
files
|
||||
.drain(..)
|
||||
@ -1371,7 +1371,7 @@ impl Connection {
|
||||
overwrite_detection: od,
|
||||
});
|
||||
self.post_file_audit(
|
||||
"receive",
|
||||
FileAuditType::RemoteReceive,
|
||||
&r.path,
|
||||
r.files
|
||||
.to_vec()
|
||||
@ -1866,3 +1866,8 @@ pub enum AlarmAuditType {
|
||||
ManyWrongPassword = 1,
|
||||
FrequentAttempt = 2,
|
||||
}
|
||||
|
||||
pub enum FileAuditType {
|
||||
RemoteSend = 0,
|
||||
RemoteReceive = 1,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user