--set-id and --config, not tested yet
This commit is contained in:
parent
aacffd979b
commit
9ac3128309
@ -257,6 +257,45 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
my_println!("Installation and administrative privileges required!");
|
||||
}
|
||||
return None;
|
||||
} else if args[0] == "--set-id" {
|
||||
if args.len() == 2 {
|
||||
if crate::platform::is_installed()
|
||||
&& crate::platform::check_super_user_permission().unwrap_or_default()
|
||||
{
|
||||
let old_id = crate::ipc::get_id();
|
||||
let mut res = crate::ui_interface::change_id_shared(args[1].to_owned(), old_id);
|
||||
if res.is_empty() {
|
||||
res = "Done!".to_owned();
|
||||
}
|
||||
my_println!("{}", res);
|
||||
} else {
|
||||
my_println!("Installation and administrative privileges required!");
|
||||
}
|
||||
}
|
||||
return None;
|
||||
} else if args[0] == "--config" {
|
||||
if args.len() == 2 {
|
||||
if crate::platform::is_installed()
|
||||
&& crate::platform::check_super_user_permission().unwrap_or_default()
|
||||
{
|
||||
// arg: starting with `host=`, e.g. `host=127.0.0.1,api=https://test.com,key=asfs`,
|
||||
// or the filename (without ext) used in renaming exe.
|
||||
let name = format!("{}.exe", args[1]);
|
||||
if let Ok(lic) = crate::license::get_license_from_string(&name) {
|
||||
if !lic.host.is_empty() {
|
||||
crate::ui_interface::set_option("key".into(), lic.key);
|
||||
crate::ui_interface::set_option(
|
||||
"custom-rendezvous-server".into(),
|
||||
lic.host,
|
||||
);
|
||||
crate::ui_interface::set_option("api-server".into(), lic.api);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
my_println!("Installation and administrative privileges required!");
|
||||
}
|
||||
}
|
||||
return None;
|
||||
} else if args[0] == "--check-hwcodec-config" {
|
||||
#[cfg(feature = "hwcodec")]
|
||||
scrap::hwcodec::check_config();
|
||||
|
@ -53,20 +53,23 @@ pub fn get_license_from_string(s: &str) -> ResultType<License> {
|
||||
let strs: Vec<&str> = stripped.split(",").collect();
|
||||
let mut host = "";
|
||||
let mut key = "";
|
||||
let mut api = "";
|
||||
let strs_iter = strs.iter();
|
||||
for el in strs_iter {
|
||||
if el.starts_with("host=") {
|
||||
host = &el[5..el.len()];
|
||||
}
|
||||
|
||||
if el.starts_with("key=") {
|
||||
key = &el[4..el.len()];
|
||||
}
|
||||
if el.starts_with("api=") {
|
||||
api = &el[4..el.len()];
|
||||
}
|
||||
}
|
||||
return Ok(License {
|
||||
host: host.to_owned(),
|
||||
key: key.to_owned(),
|
||||
api: "".to_owned(),
|
||||
api: api.to_owned(),
|
||||
});
|
||||
} else {
|
||||
let strs = if s.contains("-licensed-") {
|
||||
@ -110,12 +113,14 @@ mod test {
|
||||
);
|
||||
// key in these tests is "foobar.,2" base64 encoded
|
||||
assert_eq!(
|
||||
get_license_from_string("rustdesk-host=server.example.net,key=Zm9vYmFyLiwyCg==.exe")
|
||||
.unwrap(),
|
||||
get_license_from_string(
|
||||
"rustdesk-host=server.example.net,api=abc,key=Zm9vYmFyLiwyCg==.exe"
|
||||
)
|
||||
.unwrap(),
|
||||
License {
|
||||
host: "server.example.net".to_owned(),
|
||||
key: "Zm9vYmFyLiwyCg==".to_owned(),
|
||||
api: "".to_owned(),
|
||||
api: "abc".to_owned(),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -1027,8 +1027,10 @@ const UNKNOWN_ERROR: &'static str = "Unknown error";
|
||||
|
||||
#[inline]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn change_id_shared(id: String, old_id: String) {
|
||||
*ASYNC_JOB_STATUS.lock().unwrap() = change_id_shared_(id, old_id).await.to_owned();
|
||||
pub async fn change_id_shared(id: String, old_id: String) -> String {
|
||||
let res = change_id_shared_(id, old_id).await.to_owned();
|
||||
*ASYNC_JOB_STATUS.lock().unwrap() = res.clone();
|
||||
res
|
||||
}
|
||||
|
||||
pub async fn change_id_shared_(id: String, old_id: String) -> &'static str {
|
||||
|
Loading…
Reference in New Issue
Block a user