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);
|
var uri0 = Uri.parse(api);
|
||||||
final pageSize = 20;
|
final pageSize = 20;
|
||||||
var total = 0;
|
var total = 0;
|
||||||
int current = 1;
|
int current = 0;
|
||||||
do {
|
do {
|
||||||
|
current += 1;
|
||||||
var uri = Uri(
|
var uri = Uri(
|
||||||
scheme: uri0.scheme,
|
scheme: uri0.scheme,
|
||||||
host: uri0.host,
|
host: uri0.host,
|
||||||
@ -58,7 +59,6 @@ class GroupModel {
|
|||||||
if (gFFI.userModel.isAdmin.isFalse)
|
if (gFFI.userModel.isAdmin.isFalse)
|
||||||
'grp': gFFI.userModel.groupName.value,
|
'grp': gFFI.userModel.groupName.value,
|
||||||
});
|
});
|
||||||
current += pageSize;
|
|
||||||
final resp = await http.get(uri, headers: await getHttpHeaders());
|
final resp = await http.get(uri, headers: await getHttpHeaders());
|
||||||
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
||||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||||
@ -76,7 +76,7 @@ class GroupModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (current < total + 1);
|
} while (current * pageSize < total);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugPrint('$err');
|
debugPrint('$err');
|
||||||
userLoadError.value = err.toString();
|
userLoadError.value = err.toString();
|
||||||
@ -96,8 +96,9 @@ class GroupModel {
|
|||||||
var uri0 = Uri.parse(api);
|
var uri0 = Uri.parse(api);
|
||||||
final pageSize = 20;
|
final pageSize = 20;
|
||||||
var total = 0;
|
var total = 0;
|
||||||
int current = 1;
|
int current = 0;
|
||||||
do {
|
do {
|
||||||
|
current += 1;
|
||||||
var uri = Uri(
|
var uri = Uri(
|
||||||
scheme: uri0.scheme,
|
scheme: uri0.scheme,
|
||||||
host: uri0.host,
|
host: uri0.host,
|
||||||
@ -109,7 +110,6 @@ class GroupModel {
|
|||||||
'grp': gFFI.userModel.groupName.value,
|
'grp': gFFI.userModel.groupName.value,
|
||||||
'target_user': username
|
'target_user': username
|
||||||
});
|
});
|
||||||
current += pageSize;
|
|
||||||
final resp = await http.get(uri, headers: await getHttpHeaders());
|
final resp = await http.get(uri, headers: await getHttpHeaders());
|
||||||
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
||||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||||
@ -129,7 +129,7 @@ class GroupModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (current < total + 1);
|
} while (current * pageSize < total);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugPrint('$err');
|
debugPrint('$err');
|
||||||
peerLoadError.value = err.toString();
|
peerLoadError.value = err.toString();
|
||||||
|
@ -697,7 +697,7 @@ impl Connection {
|
|||||||
let mut v = v;
|
let mut v = v;
|
||||||
v["id"] = json!(Config::get_id());
|
v["id"] = json!(Config::get_id());
|
||||||
v["uuid"] = json!(base64::encode(hbb_common::get_uuid()));
|
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 {
|
tokio::spawn(async move {
|
||||||
allow_err!(Self::post_audit_async(url, v).await);
|
allow_err!(Self::post_audit_async(url, v).await);
|
||||||
});
|
});
|
||||||
@ -711,7 +711,7 @@ impl Connection {
|
|||||||
let mut v = Value::default();
|
let mut v = Value::default();
|
||||||
v["id"] = json!(Config::get_id());
|
v["id"] = json!(Config::get_id());
|
||||||
v["uuid"] = json!(base64::encode(hbb_common::get_uuid()));
|
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) = Self::post_audit_async(url, v).await {
|
||||||
if let Ok(rsp) = serde_json::from_str::<ConnAuditResponse>(&rsp) {
|
if let Ok(rsp) = serde_json::from_str::<ConnAuditResponse>(&rsp) {
|
||||||
if rsp.action == "disconnect" {
|
if rsp.action == "disconnect" {
|
||||||
@ -722,7 +722,13 @@ impl Connection {
|
|||||||
return Ok(());
|
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() {
|
if self.server_audit_file.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -731,12 +737,7 @@ impl Connection {
|
|||||||
let mut files = files;
|
let mut files = files;
|
||||||
files.sort_by(|a, b| b.1.cmp(&a.1));
|
files.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
files.truncate(10);
|
files.truncate(10);
|
||||||
let is_file = match action {
|
let is_file = files.len() == 1 && files[0].0.is_empty();
|
||||||
"send" | "receive" => files.len() == 1 && files[0].0.is_empty(),
|
|
||||||
"remove_dir" | "create_dir" => false,
|
|
||||||
"remove_file" => true,
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
let mut info = info;
|
let mut info = info;
|
||||||
info["ip"] = json!(self.ip.clone());
|
info["ip"] = json!(self.ip.clone());
|
||||||
info["name"] = json!(self.lr.my_name.clone());
|
info["name"] = json!(self.lr.my_name.clone());
|
||||||
@ -745,9 +746,8 @@ impl Connection {
|
|||||||
let v = json!({
|
let v = json!({
|
||||||
"id":json!(Config::get_id()),
|
"id":json!(Config::get_id()),
|
||||||
"uuid":json!(base64::encode(hbb_common::get_uuid())),
|
"uuid":json!(base64::encode(hbb_common::get_uuid())),
|
||||||
"Id":json!(self.inner.id),
|
|
||||||
"peer_id":json!(self.lr.my_id),
|
"peer_id":json!(self.lr.my_id),
|
||||||
"action": action,
|
"type": r#type as i8,
|
||||||
"path":path,
|
"path":path,
|
||||||
"is_file":is_file,
|
"is_file":is_file,
|
||||||
"info":json!(info).to_string(),
|
"info":json!(info).to_string(),
|
||||||
@ -793,7 +793,7 @@ impl Connection {
|
|||||||
} else {
|
} else {
|
||||||
0
|
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)]
|
#[allow(unused_mut)]
|
||||||
let mut username = crate::platform::get_active_username();
|
let mut username = crate::platform::get_active_username();
|
||||||
let mut res = LoginResponse::new();
|
let mut res = LoginResponse::new();
|
||||||
@ -1341,7 +1341,7 @@ impl Connection {
|
|||||||
self.read_jobs.push(job);
|
self.read_jobs.push(job);
|
||||||
self.file_timer = time::interval(MILLI1);
|
self.file_timer = time::interval(MILLI1);
|
||||||
self.post_file_audit(
|
self.post_file_audit(
|
||||||
"send",
|
FileAuditType::RemoteSend,
|
||||||
&s.path,
|
&s.path,
|
||||||
files
|
files
|
||||||
.drain(..)
|
.drain(..)
|
||||||
@ -1371,7 +1371,7 @@ impl Connection {
|
|||||||
overwrite_detection: od,
|
overwrite_detection: od,
|
||||||
});
|
});
|
||||||
self.post_file_audit(
|
self.post_file_audit(
|
||||||
"receive",
|
FileAuditType::RemoteReceive,
|
||||||
&r.path,
|
&r.path,
|
||||||
r.files
|
r.files
|
||||||
.to_vec()
|
.to_vec()
|
||||||
@ -1866,3 +1866,8 @@ pub enum AlarmAuditType {
|
|||||||
ManyWrongPassword = 1,
|
ManyWrongPassword = 1,
|
||||||
FrequentAttempt = 2,
|
FrequentAttempt = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum FileAuditType {
|
||||||
|
RemoteSend = 0,
|
||||||
|
RemoteReceive = 1,
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user