mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-26 14:41:04 +03:00
more assign from cli and devices.py (#13050)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -462,51 +462,25 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
let token = args[pos + 1].to_owned();
|
||||
let id = crate::ipc::get_id();
|
||||
let uuid = crate::encode64(hbb_common::get_uuid());
|
||||
let mut user_name = None;
|
||||
let pos = args.iter().position(|x| x == "--user_name").unwrap_or(max);
|
||||
if pos < max {
|
||||
user_name = Some(args[pos + 1].to_owned());
|
||||
}
|
||||
let mut strategy_name = None;
|
||||
let pos = args
|
||||
.iter()
|
||||
.position(|x| x == "--strategy_name")
|
||||
.unwrap_or(max);
|
||||
if pos < max {
|
||||
strategy_name = Some(args[pos + 1].to_owned());
|
||||
}
|
||||
let mut address_book_name = None;
|
||||
let pos = args
|
||||
.iter()
|
||||
.position(|x| x == "--address_book_name")
|
||||
.unwrap_or(max);
|
||||
if pos < max {
|
||||
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 get_value = |c: &str| {
|
||||
let pos = args.iter().position(|x| x == c).unwrap_or(max);
|
||||
if pos < max {
|
||||
Some(args[pos + 1].to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
let user_name = get_value("--user_name");
|
||||
let strategy_name = get_value("--strategy_name");
|
||||
let address_book_name = get_value("--address_book_name");
|
||||
let address_book_tag = get_value("--address_book_tag");
|
||||
let address_book_alias = get_value("--address_book_alias");
|
||||
let address_book_password = get_value("--address_book_password");
|
||||
let address_book_note = get_value("--address_book_note");
|
||||
let device_group_name = get_value("--device_group_name");
|
||||
let note = get_value("--note");
|
||||
let device_username = get_value("--device_username");
|
||||
let device_name = get_value("--device_name");
|
||||
let mut body = serde_json::json!({
|
||||
"id": id,
|
||||
"uuid": uuid,
|
||||
@@ -516,9 +490,19 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
&& strategy_name.is_none()
|
||||
&& address_book_name.is_none()
|
||||
&& device_group_name.is_none()
|
||||
&& note.is_none()
|
||||
&& device_username.is_none()
|
||||
&& device_name.is_none()
|
||||
{
|
||||
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 {
|
||||
if let Some(name) = user_name {
|
||||
@@ -535,10 +519,25 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
if let Some(name) = address_book_alias {
|
||||
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 {
|
||||
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";
|
||||
match crate::post_request_sync(url, body.to_string(), &header) {
|
||||
Err(err) => println!("{}", err),
|
||||
|
||||
@@ -140,6 +140,18 @@ async fn start_hbbs_sync_async() {
|
||||
if !ab_tag.is_empty() {
|
||||
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);
|
||||
if !username.is_empty() {
|
||||
v[keys::OPTION_PRESET_USERNAME] = json!(username);
|
||||
@@ -152,6 +164,18 @@ async fn start_hbbs_sync_async() {
|
||||
if !device_group_name.is_empty() {
|
||||
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 mut hash = "".to_owned();
|
||||
if crate::is_public(&url) {
|
||||
|
||||
Reference in New Issue
Block a user