mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-17 09:41:28 +03:00
more assign from cli and devices.py (#13050)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
Submodule libs/hbb_common updated: 43556b948b...1df14d90c9
@@ -95,8 +95,17 @@ def delete(url, token, guid, id):
|
|||||||
|
|
||||||
def assign(url, token, guid, id, type, value):
|
def assign(url, token, guid, id, type, value):
|
||||||
print("assign", id, type, value)
|
print("assign", id, type, value)
|
||||||
if type != "ab" and type != "strategy_name" and type != "user_name":
|
valid_types = [
|
||||||
print("Invalid type, it must be 'ab', 'strategy_name' or 'user_name'")
|
"ab",
|
||||||
|
"strategy_name",
|
||||||
|
"user_name",
|
||||||
|
"device_group_name",
|
||||||
|
"note",
|
||||||
|
"device_username",
|
||||||
|
"device_name",
|
||||||
|
]
|
||||||
|
if type not in valid_types:
|
||||||
|
print(f"Invalid type, it must be one of: {', '.join(valid_types)}")
|
||||||
return
|
return
|
||||||
data = {"type": type, "value": value}
|
data = {"type": type, "value": value}
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
@@ -124,7 +133,7 @@ def main():
|
|||||||
parser.add_argument("--device_group_name", help="Device group name")
|
parser.add_argument("--device_group_name", help="Device group name")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--assign_to",
|
"--assign_to",
|
||||||
help="<type>=<value>, e.g. user_name=mike, strategy_name=test, ab=ab1, ab=ab1,tag1",
|
help="<type>=<value>, e.g. user_name=mike, strategy_name=test, device_group_name=group1, note=note1, device_username=username1, device_name=name1, ab=ab1, ab=ab1,tag1,alias1,password1,note1"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--offline_days", type=int, help="Offline duration in days, e.g., 7"
|
"--offline_days", type=int, help="Offline duration in days, e.g., 7"
|
||||||
@@ -148,28 +157,37 @@ def main():
|
|||||||
if args.command == "view":
|
if args.command == "view":
|
||||||
for device in devices:
|
for device in devices:
|
||||||
print(device)
|
print(device)
|
||||||
elif args.command == "disable":
|
elif args.command in ["disable", "enable", "delete", "assign"]:
|
||||||
for device in devices:
|
# Check if we need user confirmation for multiple devices
|
||||||
response = disable(args.url, args.token, device["guid"], device["id"])
|
if len(devices) > 1:
|
||||||
print(response)
|
print(f"Found {len(devices)} devices. Do you want to proceed with {args.command} operation on the devices? (Y/N)")
|
||||||
elif args.command == "enable":
|
confirmation = input("Type 'Y' to confirm: ").strip()
|
||||||
for device in devices:
|
if confirmation.upper() != 'Y':
|
||||||
response = enable(args.url, args.token, device["guid"], device["id"])
|
print("Operation cancelled.")
|
||||||
print(response)
|
return
|
||||||
elif args.command == "delete":
|
|
||||||
for device in devices:
|
if args.command == "disable":
|
||||||
response = delete(args.url, args.token, device["guid"], device["id"])
|
for device in devices:
|
||||||
print(response)
|
response = disable(args.url, args.token, device["guid"], device["id"])
|
||||||
elif args.command == "assign":
|
print(response)
|
||||||
if "=" not in args.assign_to:
|
elif args.command == "enable":
|
||||||
print("Invalid assign_to format, it must be <type>=<value>")
|
for device in devices:
|
||||||
return
|
response = enable(args.url, args.token, device["guid"], device["id"])
|
||||||
type, value = args.assign_to.split("=", 1)
|
print(response)
|
||||||
for device in devices:
|
elif args.command == "delete":
|
||||||
response = assign(
|
for device in devices:
|
||||||
args.url, args.token, device["guid"], device["id"], type, value
|
response = delete(args.url, args.token, device["guid"], device["id"])
|
||||||
)
|
print(response)
|
||||||
print(response)
|
elif args.command == "assign":
|
||||||
|
if "=" not in args.assign_to:
|
||||||
|
print("Invalid assign_to format, it must be <type>=<value>")
|
||||||
|
return
|
||||||
|
type, value = args.assign_to.split("=", 1)
|
||||||
|
for device in devices:
|
||||||
|
response = assign(
|
||||||
|
args.url, args.token, device["guid"], device["id"], type, value
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -462,51 +462,25 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
let token = args[pos + 1].to_owned();
|
let token = args[pos + 1].to_owned();
|
||||||
let id = crate::ipc::get_id();
|
let id = crate::ipc::get_id();
|
||||||
let uuid = crate::encode64(hbb_common::get_uuid());
|
let uuid = crate::encode64(hbb_common::get_uuid());
|
||||||
let mut user_name = None;
|
let get_value = |c: &str| {
|
||||||
let pos = args.iter().position(|x| x == "--user_name").unwrap_or(max);
|
let pos = args.iter().position(|x| x == c).unwrap_or(max);
|
||||||
if pos < max {
|
if pos < max {
|
||||||
user_name = Some(args[pos + 1].to_owned());
|
Some(args[pos + 1].to_owned())
|
||||||
}
|
} else {
|
||||||
let mut strategy_name = None;
|
None
|
||||||
let pos = args
|
}
|
||||||
.iter()
|
};
|
||||||
.position(|x| x == "--strategy_name")
|
let user_name = get_value("--user_name");
|
||||||
.unwrap_or(max);
|
let strategy_name = get_value("--strategy_name");
|
||||||
if pos < max {
|
let address_book_name = get_value("--address_book_name");
|
||||||
strategy_name = Some(args[pos + 1].to_owned());
|
let address_book_tag = get_value("--address_book_tag");
|
||||||
}
|
let address_book_alias = get_value("--address_book_alias");
|
||||||
let mut address_book_name = None;
|
let address_book_password = get_value("--address_book_password");
|
||||||
let pos = args
|
let address_book_note = get_value("--address_book_note");
|
||||||
.iter()
|
let device_group_name = get_value("--device_group_name");
|
||||||
.position(|x| x == "--address_book_name")
|
let note = get_value("--note");
|
||||||
.unwrap_or(max);
|
let device_username = get_value("--device_username");
|
||||||
if pos < max {
|
let device_name = get_value("--device_name");
|
||||||
address_book_name = Some(args[pos + 1].to_owned());
|
|
||||||
}
|
|
||||||
let mut address_book_tag = None;
|
|
||||||
let pos = args
|
|
||||||
.iter()
|
|
||||||
.position(|x| x == "--address_book_tag")
|
|
||||||
.unwrap_or(max);
|
|
||||||
if pos < max {
|
|
||||||
address_book_tag = Some(args[pos + 1].to_owned());
|
|
||||||
}
|
|
||||||
let mut address_book_alias = None;
|
|
||||||
let pos = args
|
|
||||||
.iter()
|
|
||||||
.position(|x| x == "--address_book_alias")
|
|
||||||
.unwrap_or(max);
|
|
||||||
if pos < max {
|
|
||||||
address_book_alias = Some(args[pos + 1].to_owned());
|
|
||||||
}
|
|
||||||
let mut device_group_name = None;
|
|
||||||
let pos = args
|
|
||||||
.iter()
|
|
||||||
.position(|x| x == "--device_group_name")
|
|
||||||
.unwrap_or(max);
|
|
||||||
if pos < max {
|
|
||||||
device_group_name = Some(args[pos + 1].to_owned());
|
|
||||||
}
|
|
||||||
let mut body = serde_json::json!({
|
let mut body = serde_json::json!({
|
||||||
"id": id,
|
"id": id,
|
||||||
"uuid": uuid,
|
"uuid": uuid,
|
||||||
@@ -516,9 +490,19 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
&& strategy_name.is_none()
|
&& strategy_name.is_none()
|
||||||
&& address_book_name.is_none()
|
&& address_book_name.is_none()
|
||||||
&& device_group_name.is_none()
|
&& device_group_name.is_none()
|
||||||
|
&& note.is_none()
|
||||||
|
&& device_username.is_none()
|
||||||
|
&& device_name.is_none()
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"--user_name or --strategy_name or --address_book_name or --device_group_name is required!"
|
r#"At least one of the following options is required:
|
||||||
|
--user_name
|
||||||
|
--strategy_name
|
||||||
|
--address_book_name
|
||||||
|
--device_group_name
|
||||||
|
--note
|
||||||
|
--device_username
|
||||||
|
--device_name"#
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if let Some(name) = user_name {
|
if let Some(name) = user_name {
|
||||||
@@ -535,10 +519,25 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
if let Some(name) = address_book_alias {
|
if let Some(name) = address_book_alias {
|
||||||
body["address_book_alias"] = serde_json::json!(name);
|
body["address_book_alias"] = serde_json::json!(name);
|
||||||
}
|
}
|
||||||
|
if let Some(name) = address_book_password {
|
||||||
|
body["address_book_password"] = serde_json::json!(name);
|
||||||
|
}
|
||||||
|
if let Some(name) = address_book_note {
|
||||||
|
body["address_book_note"] = serde_json::json!(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(name) = device_group_name {
|
if let Some(name) = device_group_name {
|
||||||
body["device_group_name"] = serde_json::json!(name);
|
body["device_group_name"] = serde_json::json!(name);
|
||||||
}
|
}
|
||||||
|
if let Some(name) = note {
|
||||||
|
body["note"] = serde_json::json!(name);
|
||||||
|
}
|
||||||
|
if let Some(name) = device_username {
|
||||||
|
body["device_username"] = serde_json::json!(name);
|
||||||
|
}
|
||||||
|
if let Some(name) = device_name {
|
||||||
|
body["device_name"] = serde_json::json!(name);
|
||||||
|
}
|
||||||
let url = crate::ui_interface::get_api_server() + "/api/devices/cli";
|
let url = crate::ui_interface::get_api_server() + "/api/devices/cli";
|
||||||
match crate::post_request_sync(url, body.to_string(), &header) {
|
match crate::post_request_sync(url, body.to_string(), &header) {
|
||||||
Err(err) => println!("{}", err),
|
Err(err) => println!("{}", err),
|
||||||
|
|||||||
@@ -140,6 +140,18 @@ async fn start_hbbs_sync_async() {
|
|||||||
if !ab_tag.is_empty() {
|
if !ab_tag.is_empty() {
|
||||||
v[keys::OPTION_PRESET_ADDRESS_BOOK_TAG] = json!(ab_tag);
|
v[keys::OPTION_PRESET_ADDRESS_BOOK_TAG] = json!(ab_tag);
|
||||||
}
|
}
|
||||||
|
let ab_alias = Config::get_option(keys::OPTION_PRESET_ADDRESS_BOOK_ALIAS);
|
||||||
|
if !ab_alias.is_empty() {
|
||||||
|
v[keys::OPTION_PRESET_ADDRESS_BOOK_ALIAS] = json!(ab_alias);
|
||||||
|
}
|
||||||
|
let ab_password = Config::get_option(keys::OPTION_PRESET_ADDRESS_BOOK_PASSWORD);
|
||||||
|
if !ab_password.is_empty() {
|
||||||
|
v[keys::OPTION_PRESET_ADDRESS_BOOK_PASSWORD] = json!(ab_password);
|
||||||
|
}
|
||||||
|
let ab_note = Config::get_option(keys::OPTION_PRESET_ADDRESS_BOOK_NOTE);
|
||||||
|
if !ab_note.is_empty() {
|
||||||
|
v[keys::OPTION_PRESET_ADDRESS_BOOK_NOTE] = json!(ab_note);
|
||||||
|
}
|
||||||
let username = get_builtin_option(keys::OPTION_PRESET_USERNAME);
|
let username = get_builtin_option(keys::OPTION_PRESET_USERNAME);
|
||||||
if !username.is_empty() {
|
if !username.is_empty() {
|
||||||
v[keys::OPTION_PRESET_USERNAME] = json!(username);
|
v[keys::OPTION_PRESET_USERNAME] = json!(username);
|
||||||
@@ -152,6 +164,18 @@ async fn start_hbbs_sync_async() {
|
|||||||
if !device_group_name.is_empty() {
|
if !device_group_name.is_empty() {
|
||||||
v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name);
|
v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name);
|
||||||
}
|
}
|
||||||
|
let device_username = Config::get_option(keys::OPTION_PRESET_DEVICE_USERNAME);
|
||||||
|
if !device_username.is_empty() {
|
||||||
|
v["username"] = json!(device_username);
|
||||||
|
}
|
||||||
|
let device_name = Config::get_option(keys::OPTION_PRESET_DEVICE_NAME);
|
||||||
|
if !device_name.is_empty() {
|
||||||
|
v["hostname"] = json!(device_name);
|
||||||
|
}
|
||||||
|
let note = Config::get_option(keys::OPTION_PRESET_NOTE);
|
||||||
|
if !note.is_empty() {
|
||||||
|
v[keys::OPTION_PRESET_NOTE] = json!(note);
|
||||||
|
}
|
||||||
let v = v.to_string();
|
let v = v.to_string();
|
||||||
let mut hash = "".to_owned();
|
let mut hash = "".to_owned();
|
||||||
if crate::is_public(&url) {
|
if crate::is_public(&url) {
|
||||||
|
|||||||
Reference in New Issue
Block a user