From 728985e3bf10ab0049fde048e26f501ac5630283 Mon Sep 17 00:00:00 2001 From: 21pages Date: Tue, 27 Sep 2022 13:30:49 +0800 Subject: [PATCH] elevation prompt && uac warning Signed-off-by: 21pages --- .../lib/desktop/pages/desktop_home_page.dart | 9 +++++++ libs/hbb_common/protos/message.proto | 1 + src/client/io_loop.rs | 6 +++++ src/flutter_ffi.rs | 8 ++++++ src/lang/cn.rs | 3 +++ src/lang/cs.rs | 3 +++ src/lang/da.rs | 3 +++ src/lang/de.rs | 3 +++ src/lang/en.rs | 2 ++ src/lang/eo.rs | 3 +++ src/lang/es.rs | 3 +++ src/lang/fr.rs | 3 +++ src/lang/hu.rs | 3 +++ src/lang/id.rs | 3 +++ src/lang/it.rs | 3 +++ src/lang/ja.rs | 3 +++ src/lang/ko.rs | 3 +++ src/lang/kz.rs | 3 +++ src/lang/pl.rs | 3 +++ src/lang/pt_PT.rs | 3 +++ src/lang/ptbr.rs | 3 +++ src/lang/ru.rs | 3 +++ src/lang/sk.rs | 3 +++ src/lang/template.rs | 3 +++ src/lang/tr.rs | 3 +++ src/lang/tw.rs | 3 +++ src/lang/vn.rs | 3 +++ src/server/connection.rs | 15 +++++++++++ src/server/video_service.rs | 19 +++++++++++++ src/ui.rs | 27 ++++++++----------- src/ui/index.tis | 6 +++++ src/ui_interface.rs | 13 +++++++++ 32 files changed, 156 insertions(+), 16 deletions(-) diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dart index f25e3263a..fcc8c4991 100644 --- a/flutter/lib/desktop/pages/desktop_home_page.dart +++ b/flutter/lib/desktop/pages/desktop_home_page.dart @@ -407,6 +407,15 @@ class _DesktopHomePageState extends State @override void initState() { super.initState(); + Timer(const Duration(seconds: 1), () async { + final installed = bind.mainIsInstalled(); + final root = await bind.mainIsRoot(); + final release = await bind.mainIsRelease(); + if (Platform.isWindows && release && !installed && !root) { + msgBox('custom-elevation-nocancel', 'Prompt', 'elevation_prompt', + gFFI.dialogManager); + } + }); Timer(const Duration(seconds: 5), () async { updateUrl = await bind.mainGetSoftwareUpdateUrl(); if (updateUrl.isNotEmpty) setState(() {}); diff --git a/libs/hbb_common/protos/message.proto b/libs/hbb_common/protos/message.proto index 8fb67e5c1..1ed538759 100644 --- a/libs/hbb_common/protos/message.proto +++ b/libs/hbb_common/protos/message.proto @@ -556,6 +556,7 @@ message Misc { bool video_received = 12; BackNotification back_notification = 13; bool restart_remote_device = 14; + bool uac = 15; } } diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index cf6168834..619c67b79 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -979,6 +979,12 @@ impl Remote { return false; } } + Some(misc::Union::Uac(uac)) => { + if uac { + self.handler + .msgbox("custom-uac-nocancel", "Warning", "uac_warning"); + } + } _ => {} }, Some(message::Union::TestDelay(t)) => { diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 1adee6988..d4c198eea 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -800,6 +800,14 @@ pub fn main_has_hwcodec() -> SyncReturn { SyncReturn(has_hwcodec()) } +pub fn main_is_root() -> bool { + is_root() +} + +pub fn main_is_release() -> bool { + is_release() +} + pub fn session_send_mouse(id: String, msg: String) { if let Ok(m) = serde_json::from_str::>(&msg) { let alt = m.get("alt").is_some(); diff --git a/src/lang/cn.rs b/src/lang/cn.rs index c974bf7fe..ab92b047b 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", "允许局域网发现"), ("Deny LAN Discovery", "拒绝局域网发现"), ("Write a message", "输入聊天消息"), + ("Prompt", "提示"), + ("elevation_prompt", "以当前用户权限运行软件,可能导致远端在访问本机时,没有足够的权限来操作部分窗口。"), + ("uac_warning", "暂时无法访问远端设备,因为远端设备正在请求用户账户权限,请等待对方关闭UAC窗口。为避免这个问题,建议在远端设备上安装或者以管理员权限运行本软件。"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index def7206a7..8c89e5552 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index 8151ea4e0..18f5af14e 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index 57596f709..0f8fe34b3 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/en.rs b/src/lang/en.rs index 14232c4e2..e4c862203 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -30,5 +30,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("android_open_battery_optimizations_tip", "If you want to disable this feature, please go to the next RustDesk application settings page, find and enter [Battery], Uncheck [Unrestricted]"), ("remote_restarting_tip", "Remote device is restarting, please close this message box and reconnect with permanent password after a while"), ("Are you sure to close the connection?", "Are you sure you want to close the connection?"), + ("elevation_prompt", "Running software without privilege elevation may cause problems when remote users operate certain windows."), + ("uac_warning", "Temporarily denied access due to elevation request, please wait for the remote user to accept the UAC dialog. To avoid this problem, it is recommended to install the software on the remote device or run it with administrator privileges."), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index cc21e7509..226255eb3 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index 1e57c6913..5a31d730b 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index 479c701bf..cf9109378 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index 1847c8cc5..17467077a 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index ebb83c862..57e5669ae 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index 2db9f3026..1c59a319d 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index 0021f0db9..a20b5436a 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 89bc69fa2..1c11c54e3 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/kz.rs b/src/lang/kz.rs index 6eea0d8be..6c576b497 100644 --- a/src/lang/kz.rs +++ b/src/lang/kz.rs @@ -359,5 +359,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pl.rs b/src/lang/pl.rs index 1f101a069..983fe5b48 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index ab49d9f93..13f645d95 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index 640a35d10..66636bc20 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index f1d9c6f31..205874a5b 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index a7b527302..a0ec2682a 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index e879b2a21..20112dd81 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index 50ce2ec2a..1df6473d7 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index c02c95df1..271bfc829 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", "允許局域網發現"), ("Deny LAN Discovery", "拒絕局域網發現"), ("Write a message", "輸入聊天消息"), + ("Prompt", "提示"), + ("elevation_prompt", "以當前用戶權限運行軟件,可能導致遠端在訪問本機時,沒有足夠的權限來操作部分窗口。"), + ("uac_warning", "暂时无法访问远端设备,因为远端设备正在请求用户账户权限,请等待对方关闭UAC窗口。为避免这个问题,建议在远端设备上安装或者以管理员权限运行本软件。"), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index dce16bb7b..9f6841d10 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -360,5 +360,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Enable LAN Discovery", ""), ("Deny LAN Discovery", ""), ("Write a message", ""), + ("Prompt", ""), + ("elevation_prompt", ""), + ("uac_warning", ""), ].iter().cloned().collect(); } diff --git a/src/server/connection.rs b/src/server/connection.rs index 15d313fbe..056c906fa 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -229,6 +229,8 @@ impl Connection { #[cfg(not(any(target_os = "android", target_os = "ios")))] std::thread::spawn(move || Self::handle_input(rx_input, tx_cloned)); + let mut second_timer = time::interval(Duration::from_secs(1)); + let mut uac = false; loop { tokio::select! { @@ -400,6 +402,19 @@ impl Connection { break; } }, + _ = second_timer.tick() => { + let is_uac = crate::video_service::IS_UAC_RUNNING.lock().unwrap().clone(); + if uac != is_uac { + if !crate::platform::is_installed() && !crate::platform::is_root() { + uac = is_uac; + let mut misc = Misc::new(); + misc.set_uac(uac); + let mut msg = Message::new(); + msg.set_misc(misc); + conn.inner.send(msg.into()); + } + } + } _ = test_delay_timer.tick() => { if last_recv_time.elapsed() >= SEC30 { conn.on_close("Timeout", true).await; diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 272bcf8d5..25806f0aa 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -33,6 +33,7 @@ use std::{ collections::HashSet, io::ErrorKind::WouldBlock, ops::{Deref, DerefMut}, + sync::Once, time::{self, Duration, Instant}, }; #[cfg(windows)] @@ -51,6 +52,7 @@ lazy_static::lazy_static! { static ref PRIVACY_MODE_CONN_ID: Mutex = Mutex::new(0); static ref IS_CAPTURER_MAGNIFIER_SUPPORTED: bool = is_capturer_mag_supported(); pub static ref VIDEO_QOS: Arc> = Default::default(); + pub static ref IS_UAC_RUNNING: Arc> = Default::default(); } fn is_capturer_mag_supported() -> bool { @@ -451,6 +453,8 @@ fn run(sp: GenericService) -> ResultType<()> { }; #[cfg(any(target_os = "android", target_os = "ios"))] let recorder: Arc>> = Default::default(); + #[cfg(windows)] + start_uac_check(); while sp.ok() { #[cfg(windows)] @@ -832,3 +836,18 @@ pub(super) fn get_current_display_2(mut all: Vec) -> ResultType<(usize, fn get_current_display() -> ResultType<(usize, usize, Display)> { get_current_display_2(try_get_displays()?) } + +#[cfg(windows)] +fn start_uac_check() { + static START: Once = Once::new(); + START.call_once(|| { + if !crate::platform::is_installed() && !crate::platform::is_root() { + std::thread::spawn(|| loop { + std::thread::sleep(std::time::Duration::from_secs(1)); + if let Ok(uac) = crate::ui::win_privacy::is_process_consent_running() { + *IS_UAC_RUNNING.lock().unwrap() = uac; + } + }); + } + }); +} diff --git a/src/ui.rs b/src/ui.rs index 095559811..63dc4704a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -20,22 +20,7 @@ use hbb_common::{ use crate::common::get_app_name; use crate::ipc; -use crate::ui_interface::{ - check_mouse_time, closing, create_shortcut, current_is_wayland, default_video_save_directory, - fix_login_wayland, forget_password, get_api_server, get_async_job_status, get_connect_status, - get_error, get_fav, get_icon, get_lan_peers, get_langs, get_license, get_local_option, - get_mouse_time, get_new_version, get_option, get_options, get_peer, get_peer_option, - get_recent_sessions, get_remote_id, get_size, get_socks, get_software_ext, - get_software_store_path, get_software_update_url, get_uuid, get_version, goto_install, - has_hwcodec, has_rendezvous_service, install_me, install_path, is_can_screen_recording, - is_installed, is_installed_daemon, is_installed_lower_version, 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_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, -}; +use crate::ui_interface::*; mod cm; #[cfg(feature = "inline")] @@ -349,6 +334,14 @@ impl UI { is_installed() } + fn is_root(&self) -> bool { + is_root() + } + + fn is_release(&self) -> bool { + is_release() + } + fn is_rdp_service_open(&self) -> bool { is_rdp_service_open() } @@ -615,6 +608,8 @@ impl sciter::EventHandler for UI { fn get_icon(); fn install_me(String, String); fn is_installed(); + fn is_root(); + fn is_release(); fn set_socks(String, String, String); fn get_socks(); fn is_rdp_service_open(); diff --git a/src/ui/index.tis b/src/ui/index.tis index b889ff010..a2d895733 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -1242,3 +1242,9 @@ function refreshCurrentUser() { function getHttpHeaders() { return "Authorization: Bearer " + handler.get_local_option("access_token"); } + +$(body).timer(1000, function check_elevation(){ + if (is_win && handler.is_release() && !handler.is_installed() && !handler.is_root()) { + msgbox("custom-elevation-nocancel", "Prompt", "elevation_prompt"); + } +}); \ No newline at end of file diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 31c203fb4..3e357faa7 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -755,6 +755,19 @@ pub fn has_hwcodec() -> bool { return true; } +#[inline] +pub fn is_release() -> bool { + #[cfg(not(debug_assertions))] + return true; + #[cfg(debug_assertions)] + return false; +} + +#[inline] +pub fn is_root() -> bool { + crate::platform::is_root() +} + #[inline] pub fn check_super_user_permission() -> bool { #[cfg(any(windows, target_os = "linux"))]