Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-08-01 20:42:30 +08:00
parent 627a940317
commit ffbab698b7
5 changed files with 353 additions and 70 deletions

View File

@@ -24,8 +24,7 @@ use crate::ui_interface::{
get_async_job_status, get_connect_status, get_fav, get_id, get_lan_peers, get_license,
get_local_option, get_options, get_peer, get_peer_option, get_socks, get_sound_inputs,
get_uuid, get_version, has_rendezvous_service, is_ok_change_id, post_request, set_local_option,
set_options, set_peer_option, set_socks, store_fav, temporary_password, test_if_valid_server,
using_public_server,
set_options, set_peer_option, set_socks, store_fav, test_if_valid_server, using_public_server,
};
fn initialize(app_dir: &str) {
@@ -613,7 +612,7 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
}
"option" => {
if let Ok(arg) = arg.to_str() {
res = Config::get_option(arg);
res = ui_interface::get_option(arg.to_owned());
}
}
// "image_quality" => {
@@ -642,7 +641,10 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
res = ui_interface::get_id();
}
"temporary_password" => {
res = password_security::temporary_password();
res = ui_interface::temporary_password();
}
"permanent_password" => {
res = ui_interface::permanent_password();
}
"connect_statue" => {
res = ONLINE
@@ -829,7 +831,7 @@ unsafe extern "C" fn set_by_name(name: *const c_char, value: *const c_char) {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(value) {
if let Some(name) = m.get("name") {
if let Some(value) = m.get("value") {
Config::set_option(name.to_owned(), value.to_owned());
ui_interface::set_option(name.to_owned(), value.to_owned());
if name == "custom-rendezvous-server" {
#[cfg(target_os = "android")]
crate::rendezvous_mediator::RendezvousMediator::restart();
@@ -1049,6 +1051,12 @@ unsafe extern "C" fn set_by_name(name: *const c_char, value: *const c_char) {
connection_manager::close_conn(id);
};
}
"temporary_password" => {
ui_interface::update_temporary_password();
}
"permanent_password" => {
ui_interface::set_permanent_password(value.to_owned());
}
_ => {
log::error!("Unknown name of set_by_name: {}", name);
}

View File

@@ -32,9 +32,9 @@ use crate::ui_interface::{
is_login_wayland, is_ok_change_id, is_process_trusted, is_rdp_service_open, is_share_rdp,
is_xfce, modify_default_login, new_remote, open_url, peer_has_password, permanent_password,
post_request, recent_sessions_updated, remove_peer, run_without_install, set_local_option,
set_option, set_options, set_peer_option, set_remote_id, set_share_rdp, set_socks,
show_run_without_install, store_fav, t, temporary_password, test_if_valid_server, update_me,
update_temporary_password, using_public_server,
set_option, set_options, set_peer_option, set_permanent_password, set_remote_id, set_share_rdp,
set_socks, show_run_without_install, store_fav, t, temporary_password, test_if_valid_server,
update_me, update_temporary_password, using_public_server,
};
mod cm;
@@ -205,7 +205,7 @@ impl UI {
}
fn set_permanent_password(&self, password: String) {
allow_err!(ipc::set_permanent_password(password));
set_permanent_password(password);
}
fn get_remote_id(&mut self) -> String {

View File

@@ -5,11 +5,13 @@ use std::{
time::SystemTime,
};
#[cfg(any(target_os = "android", target_os = "ios"))]
use hbb_common::password_security;
use hbb_common::{
allow_err,
config::{self, Config, LocalConfig, PeerConfig, RENDEZVOUS_PORT, RENDEZVOUS_TIMEOUT},
futures::future::join_all,
log, password_security,
log,
protobuf::Message as _,
rendezvous_proto::*,
sleep,
@@ -129,7 +131,10 @@ pub fn get_license() -> String {
}
pub fn get_option(key: String) -> String {
get_option_(&key)
#[cfg(any(target_os = "android", target_os = "ios"))]
return Config::get_option(arg);
#[cfg(not(any(target_os = "android", target_os = "ios")))]
return get_option_(&key);
}
fn get_option_(key: &str) -> String {
@@ -243,20 +248,25 @@ pub fn set_options(m: HashMap<String, String>) {
}
pub fn set_option(key: String, value: String) {
let mut options = OPTIONS.lock().unwrap();
#[cfg(target_os = "macos")]
if &key == "stop-service" {
let is_stop = value == "Y";
if is_stop && crate::platform::macos::uninstall() {
return;
#[cfg(any(target_os = "android", target_os = "ios"))]
Config::set_option(name.to_owned(), value.to_owned());
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
let mut options = OPTIONS.lock().unwrap();
#[cfg(target_os = "macos")]
if &key == "stop-service" {
let is_stop = value == "Y";
if is_stop && crate::platform::macos::uninstall() {
return;
}
}
if value.is_empty() {
options.remove(&key);
} else {
options.insert(key.clone(), value.clone());
}
ipc::set_options(options.clone()).ok();
}
if value.is_empty() {
options.remove(&key);
} else {
options.insert(key.clone(), value.clone());
}
ipc::set_options(options.clone()).ok();
}
pub fn install_path() -> String {
@@ -358,16 +368,32 @@ pub fn get_connect_status() -> Status {
res
}
pub fn temporary_password() -> String {
#[cfg(any(target_os = "android", target_os = "ios"))]
return password_security::temporary_password();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
return TEMPORARY_PASSWD.lock().unwrap().clone();
}
pub fn update_temporary_password() {
#[cfg(any(target_os = "android", target_os = "ios"))]
password_security::update_temporary_password();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
allow_err!(ipc::update_temporary_password());
}
pub fn permanent_password() -> String {
ipc::get_permanent_password()
#[cfg(any(target_os = "android", target_os = "ios"))]
return Config::get_permanent_password();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
return ipc::get_permanent_password();
}
pub fn temporary_password() -> String {
password_security::temporary_password()
pub fn set_permanent_password(password: String) {
#[cfg(any(target_os = "android", target_os = "ios"))]
Config::set_permanent_password(&password);
#[cfg(not(any(target_os = "android", target_os = "ios")))]
allow_err!(ipc::set_permanent_password(password));
}
pub fn get_peer(id: String) -> PeerConfig {
@@ -680,6 +706,8 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
Ok(Some(ipc::Data::Config((name, Some(value))))) => {
if name == "id" {
id = value;
} else if name == "temporary-password" {
*TEMPORARY_PASSWD.lock().unwrap() = value;
}
}
Ok(Some(ipc::Data::OnlineStatus(Some((mut x, c))))) => {
@@ -699,6 +727,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
c.send(&ipc::Data::OnlineStatus(None)).await.ok();
c.send(&ipc::Data::Options(None)).await.ok();
c.send(&ipc::Data::Config(("id".to_owned(), None))).await.ok();
c.send(&ipc::Data::Config(("temporary-password".to_owned(), None))).await.ok();
}
}
}