mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
@@ -34,7 +34,8 @@ use hbb_common::{
|
||||
anyhow::{anyhow, Context},
|
||||
bail,
|
||||
config::{
|
||||
Config, PeerConfig, PeerInfoSerde, Resolution, CONNECT_TIMEOUT, READ_TIMEOUT, RELAY_PORT,
|
||||
Config, LocalConfig, PeerConfig, PeerInfoSerde, Resolution, CONNECT_TIMEOUT, READ_TIMEOUT,
|
||||
RELAY_PORT,
|
||||
},
|
||||
get_version_number, log,
|
||||
message_proto::{option_message::BoolOption, *},
|
||||
@@ -42,6 +43,7 @@ use hbb_common::{
|
||||
rand,
|
||||
rendezvous_proto::*,
|
||||
socket_client,
|
||||
sodiumoxide::base64,
|
||||
sodiumoxide::crypto::{box_, secretbox, sign},
|
||||
tcp::FramedStream,
|
||||
timeout,
|
||||
@@ -2235,6 +2237,22 @@ pub async fn handle_hash(
|
||||
if password.is_empty() {
|
||||
password = lc.read().unwrap().config.password.clone();
|
||||
}
|
||||
if password.is_empty() {
|
||||
let access_token = LocalConfig::get_option("access_token");
|
||||
let ab = hbb_common::config::Ab::load();
|
||||
if !access_token.is_empty() && access_token == ab.access_token {
|
||||
let id = lc.read().unwrap().id.clone();
|
||||
if let Some(p) = ab
|
||||
.peers
|
||||
.iter()
|
||||
.find_map(|p| if p.id == id { Some(p) } else { None })
|
||||
{
|
||||
if let Ok(hash) = base64::decode(p.hash.clone(), base64::Variant::Original) {
|
||||
password = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let password = if password.is_empty() {
|
||||
// login without password, the remote side can click accept
|
||||
interface.msgbox("input-password", "Password Required", "", "");
|
||||
|
||||
@@ -618,7 +618,7 @@ pub fn main_show_option(_key: String) -> SyncReturn<bool> {
|
||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||
if _key.eq(config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS) {
|
||||
return SyncReturn(true)
|
||||
return SyncReturn(true);
|
||||
}
|
||||
SyncReturn(false)
|
||||
}
|
||||
@@ -777,6 +777,15 @@ pub fn main_set_peer_alias(id: String, alias: String) {
|
||||
set_peer_option(id, "alias".to_owned(), alias)
|
||||
}
|
||||
|
||||
pub fn main_get_new_stored_peers() -> String {
|
||||
let peers: Vec<String> = config::NEW_STORED_PEER_CONFIG
|
||||
.lock()
|
||||
.unwrap()
|
||||
.drain()
|
||||
.collect();
|
||||
serde_json::to_string(&peers).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn main_forget_password(id: String) {
|
||||
forget_password(id)
|
||||
}
|
||||
@@ -787,7 +796,7 @@ pub fn main_peer_has_password(id: String) -> bool {
|
||||
|
||||
pub fn main_load_recent_peers() {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers()
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(None)
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| peer_to_map(id, p))
|
||||
.collect();
|
||||
@@ -808,7 +817,7 @@ pub fn main_load_recent_peers() {
|
||||
|
||||
pub fn main_load_recent_peers_sync() -> SyncReturn<String> {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers()
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(None)
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| peer_to_map(id, p))
|
||||
.collect();
|
||||
@@ -825,10 +834,22 @@ pub fn main_load_recent_peers_sync() -> SyncReturn<String> {
|
||||
SyncReturn("".to_string())
|
||||
}
|
||||
|
||||
pub fn main_load_recent_peers_for_ab(filter: String) -> String {
|
||||
let id_filters = serde_json::from_str::<Vec<String>>(&filter).unwrap_or_default();
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(Some(id_filters))
|
||||
.drain(..)
|
||||
.map(|(id, _, p)| peer_to_map_ab(id, p))
|
||||
.collect();
|
||||
return serde_json::ser::to_string(&peers).unwrap_or("".to_owned());
|
||||
}
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
pub fn main_load_fav_peers() {
|
||||
if !config::APP_DIR.read().unwrap().is_empty() {
|
||||
let favs = get_fav();
|
||||
let mut recent = PeerConfig::peers();
|
||||
let mut recent = PeerConfig::peers(None);
|
||||
let mut lan = config::LanPeers::load()
|
||||
.peers
|
||||
.iter()
|
||||
@@ -1086,6 +1107,20 @@ pub fn main_start_dbus_server() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_save_ab(json: String) {
|
||||
if json.len() > 1024 {
|
||||
std::thread::spawn(|| {
|
||||
config::Ab::store(json);
|
||||
});
|
||||
} else {
|
||||
config::Ab::store(json);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_clear_ab() {
|
||||
config::Ab::remove();
|
||||
}
|
||||
|
||||
pub fn session_send_pointer(session_id: SessionID, msg: String) {
|
||||
if let Ok(m) = serde_json::from_str::<HashMap<String, serde_json::Value>>(&msg) {
|
||||
let alt = m.get("alt").is_some();
|
||||
|
||||
@@ -412,7 +412,7 @@ impl UI {
|
||||
|
||||
fn get_recent_sessions(&mut self) -> Value {
|
||||
// to-do: limit number of recent sessions, and remove old peer file
|
||||
let peers: Vec<Value> = PeerConfig::peers()
|
||||
let peers: Vec<Value> = PeerConfig::peers(None)
|
||||
.drain(..)
|
||||
.map(|p| Self::get_peer_value(p.0, p.2))
|
||||
.collect();
|
||||
|
||||
@@ -3,7 +3,9 @@ use hbb_common::password_security;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::{self, Config, LocalConfig, PeerConfig},
|
||||
directories_next, log, tokio,
|
||||
directories_next, log,
|
||||
sodiumoxide::base64,
|
||||
tokio,
|
||||
};
|
||||
use hbb_common::{
|
||||
bytes::Bytes,
|
||||
@@ -610,6 +612,16 @@ pub fn peer_to_map(id: String, p: PeerConfig) -> HashMap<&'static str, String> {
|
||||
])
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
pub fn peer_to_map_ab(id: String, p: PeerConfig) -> HashMap<&'static str, String> {
|
||||
let mut m = peer_to_map(id, p.clone());
|
||||
m.insert(
|
||||
"hash",
|
||||
base64::encode(p.password, base64::Variant::Original),
|
||||
);
|
||||
m
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_lan_peers() -> Vec<HashMap<&'static str, String>> {
|
||||
config::LanPeers::load()
|
||||
|
||||
Reference in New Issue
Block a user