mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +08:00
sock5 gui part
This commit is contained in:
parent
12ab22e048
commit
c0b6367137
@ -3,7 +3,7 @@ use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::bail,
|
||||
compress::{compress as compress_func, decompress},
|
||||
config::{Config, NetworkType, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT},
|
||||
config::{Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT},
|
||||
log,
|
||||
message_proto::*,
|
||||
protobuf::Message as _,
|
||||
@ -238,8 +238,9 @@ pub fn test_nat_type() {
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn test_nat_type_() -> ResultType<bool> {
|
||||
log::info!("Testing nat ...");
|
||||
let is_direct = crate::ipc::get_socks_async(1_000).await.is_none(); // sync socks BTW
|
||||
let start = std::time::Instant::now();
|
||||
let rendezvous_server = get_rendezvous_server(100).await;
|
||||
let rendezvous_server = get_rendezvous_server(1_000).await;
|
||||
let server1 = rendezvous_server;
|
||||
let tmp: Vec<&str> = server1.split(":").collect();
|
||||
if tmp.len() != 2 {
|
||||
@ -272,7 +273,7 @@ async fn test_nat_type_() -> ResultType<bool> {
|
||||
RENDEZVOUS_TIMEOUT,
|
||||
)
|
||||
.await?;
|
||||
if Config::get_network_type() == NetworkType::Direct {
|
||||
if is_direct {
|
||||
// to-do: should set NatType::UNKNOWN for proxy
|
||||
addr = socket.local_addr();
|
||||
}
|
||||
|
50
src/ipc.rs
50
src/ipc.rs
@ -89,6 +89,7 @@ pub enum Data {
|
||||
NatType(Option<i32>),
|
||||
ConfirmedKey(Option<(Vec<u8>, Vec<u8>)>),
|
||||
RawMessage(Vec<u8>),
|
||||
Socks(Option<config::Socks5Server>),
|
||||
FS(FS),
|
||||
Test,
|
||||
}
|
||||
@ -192,6 +193,20 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
};
|
||||
allow_err!(stream.send(&Data::ConfirmedKey(out)).await);
|
||||
}
|
||||
Data::Socks(s) => match s {
|
||||
None => {
|
||||
allow_err!(stream.send(&Data::Socks(Config::get_socks())).await);
|
||||
}
|
||||
Some(data) => {
|
||||
if data.proxy.is_empty() {
|
||||
Config::set_socks(None);
|
||||
} else {
|
||||
Config::set_socks(Some(data));
|
||||
}
|
||||
crate::rendezvous_mediator::RendezvousMediator::restart();
|
||||
log::info!("socks updated");
|
||||
}
|
||||
},
|
||||
Data::Config((name, value)) => match value {
|
||||
None => {
|
||||
let value;
|
||||
@ -467,6 +482,41 @@ pub async fn get_nat_type(ms_timeout: u64) -> i32 {
|
||||
.unwrap_or(Config::get_nat_type())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn get_socks_(ms_timeout: u64) -> ResultType<Option<config::Socks5Server>> {
|
||||
let mut c = connect(ms_timeout, "").await?;
|
||||
c.send(&Data::Socks(None)).await?;
|
||||
if let Some(Data::Socks(value)) = c.next_timeout(ms_timeout).await? {
|
||||
Config::set_socks(value.clone());
|
||||
Ok(value)
|
||||
} else {
|
||||
Ok(Config::get_socks())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_socks_async(ms_timeout: u64) -> Option<config::Socks5Server> {
|
||||
get_socks_(ms_timeout).await.unwrap_or(Config::get_socks())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn get_socks() -> Option<config::Socks5Server> {
|
||||
get_socks_async(1_000).await
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn set_socks(value: config::Socks5Server) -> ResultType<()> {
|
||||
Config::set_socks(if value.proxy.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(value.clone())
|
||||
});
|
||||
connect(1_000, "")
|
||||
.await?
|
||||
.send(&Data::Socks(Some(value)))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/*
|
||||
static mut SHARED_MEMORY: *mut i64 = std::ptr::null_mut();
|
||||
|
||||
|
@ -192,5 +192,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Remove from Favorites", "从收藏中删除"),
|
||||
("Empty", "空空如也"),
|
||||
("Invalid folder name", "无效文件夹名称"),
|
||||
("Socks5 Proxy", "Socks5 代理")
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ use uuid::Uuid;
|
||||
type Message = RendezvousMessage;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref SOLVING_PK_MISMATCH: Arc<Mutex<String>> = Default::default();
|
||||
static ref SOLVING_PK_MISMATCH: Arc<Mutex<String>> = Default::default();
|
||||
}
|
||||
static SHOULD_EXIT: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
@ -42,6 +42,10 @@ pub struct RendezvousMediator {
|
||||
}
|
||||
|
||||
impl RendezvousMediator {
|
||||
pub fn restart() {
|
||||
SHOULD_EXIT.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
pub async fn start_all() {
|
||||
let mut nat_tested = false;
|
||||
check_zombie();
|
||||
|
27
src/ui.rs
27
src/ui.rs
@ -8,7 +8,7 @@ use crate::common::SOFTWARE_UPDATE_URL;
|
||||
use crate::ipc;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::{Config, Fav, PeerConfig, APP_NAME, ICON},
|
||||
config::{self, Config, Fav, PeerConfig, APP_NAME, ICON},
|
||||
log, sleep,
|
||||
tokio::{self, time},
|
||||
};
|
||||
@ -372,6 +372,29 @@ impl UI {
|
||||
return "".to_owned();
|
||||
}
|
||||
|
||||
fn get_socks(&self) -> Value {
|
||||
let s = ipc::get_socks();
|
||||
match s {
|
||||
None => Value::null(),
|
||||
Some(s) => {
|
||||
let mut v = Value::array(0);
|
||||
v.push(s.proxy);
|
||||
v.push(s.username);
|
||||
v.push(s.password);
|
||||
v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_socks(&self, proxy: String, username: String, password: String) {
|
||||
ipc::set_socks(config::Socks5Server {
|
||||
proxy,
|
||||
username,
|
||||
password,
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn is_installed(&mut self) -> bool {
|
||||
crate::platform::is_installed()
|
||||
}
|
||||
@ -628,6 +651,8 @@ impl sciter::EventHandler for UI {
|
||||
fn get_msgbox();
|
||||
fn install_me(String);
|
||||
fn is_installed();
|
||||
fn set_socks(String, String, String);
|
||||
fn get_socks();
|
||||
fn is_installed_lower_version();
|
||||
fn install_path();
|
||||
fn goto_install();
|
||||
|
@ -360,8 +360,9 @@ class PasswordComponent: Reactor.Component {
|
||||
var start = el.xcall(#selectionStart) || 0;
|
||||
var end = el.xcall(#selectionEnd);
|
||||
this.update({ visible: !this.visible });
|
||||
var me = this;
|
||||
self.timer(30ms, function() {
|
||||
var el = this.$(input);
|
||||
var el = me.$(input);
|
||||
view.focus = el;
|
||||
el.value = value;
|
||||
el.xcall(#setSelection, start, end);
|
||||
|
@ -135,6 +135,7 @@ class MyIdMenu: Reactor.Component {
|
||||
<div .separator />
|
||||
<li #whitelist title={translate('whitelist_tip')}>{translate('IP Whitelisting')}</li>
|
||||
<li #custom-server>{translate('ID/Relay Server')}</li>
|
||||
<li #socks5-server>{translate('Socks5 Proxy')}</li>
|
||||
<div .separator />
|
||||
<li #stop-service class={service_stopped ? "line-through" : "selected"}><span>{svg_checkmark}</span>{translate("Enable Service")}</li>
|
||||
<div .separator />
|
||||
@ -211,6 +212,28 @@ class MyIdMenu: Reactor.Component {
|
||||
configOptions["relay-server"] = relay;
|
||||
handler.set_options(configOptions);
|
||||
}, 240);
|
||||
} else if (me.id == "socks5-server") {
|
||||
var socks5 = handler.get_socks() || {};
|
||||
var old_proxy = socks5[0] || "";
|
||||
var old_username = socks5[1] || "";
|
||||
var old_password = socks5[2] || "";
|
||||
msgbox("custom-server", "Socks5 Proxy", <div .form .set-password>
|
||||
<div><span>{translate("Hostname")}</span><input .outline-focus style='width: *' name='proxy' value={old_proxy} /></div>
|
||||
<div><span>{translate("Username")}</span><input style='width: *' name='username' value={old_username} /></div>
|
||||
<div><span>{translate("Password")}</span><PasswordComponent value={old_password} /></div>
|
||||
</div>
|
||||
, function(res=null) {
|
||||
if (!res) return;
|
||||
var proxy = (res.proxy || "").trim();
|
||||
var username = (res.username || "").trim();
|
||||
var password = (res.password || "").trim();
|
||||
if (proxy == old_proxy && username == old_username && password == old_password) return;
|
||||
if (proxy) {
|
||||
var err = handler.test_if_valid_server(proxy);
|
||||
if (err) return translate("Server") + ": " + err;
|
||||
}
|
||||
handler.set_socks(proxy, username, password);
|
||||
}, 240);
|
||||
} else if (me.id == "stop-service") {
|
||||
handler.set_option("stop-service", service_stopped ? "" : "Y");
|
||||
} else if (me.id == "about") {
|
||||
|
Loading…
Reference in New Issue
Block a user