feat: ip whitelist, id/relay server/ socks5 proxy, about page

This commit is contained in:
Kingtous
2022-07-18 18:20:00 +08:00
parent b1382c2d57
commit 08043732a8
4 changed files with 769 additions and 132 deletions

View File

@@ -19,7 +19,10 @@ use crate::flutter::connection_manager::{self, get_clients_length, get_clients_s
use crate::flutter::{self, Session, SESSIONS};
use crate::start_server;
use crate::ui_interface;
use crate::ui_interface::{change_id, get_async_job_status, get_sound_inputs, is_ok_change_id};
use crate::ui_interface::{
change_id, get_app_name, get_async_job_status, get_license, get_options, get_socks,
get_sound_inputs, get_version, is_ok_change_id, set_options, set_socks, test_if_valid_server,
};
fn initialize(app_dir: &str) {
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
@@ -391,6 +394,41 @@ pub fn main_get_async_status() -> String {
get_async_job_status()
}
pub fn main_get_options() -> String {
get_options()
}
pub fn main_set_options(json: String) {
let map: HashMap<String, String> = serde_json::from_str(&json).unwrap_or(HashMap::new());
if !map.is_empty() {
set_options(map)
}
}
pub fn main_test_if_valid_server(server: String) -> String {
test_if_valid_server(server)
}
pub fn main_set_socks(proxy: String, username: String, password: String) {
set_socks(proxy, username, password)
}
pub fn main_get_socks() -> Vec<String> {
get_socks()
}
pub fn main_get_app_name() -> String {
get_app_name()
}
pub fn main_get_license() -> String {
get_license()
}
pub fn main_get_version() -> String {
get_version()
}
/// FFI for **get** commands which are idempotent.
/// Return result in c string.
///

View File

@@ -1,20 +1,23 @@
mod cm;
#[cfg(feature = "inline")]
mod inline;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
pub mod win_privacy;
pub mod remote;
use crate::ui_interface::*;
use hbb_common::{allow_err, config::PeerConfig, log};
use sciter::Value;
use std::{
collections::HashMap,
iter::FromIterator,
sync::{Arc, Mutex},
};
use sciter::Value;
use hbb_common::{allow_err, config::PeerConfig, log};
use crate::ui_interface::*;
mod cm;
#[cfg(feature = "inline")]
mod inline;
#[cfg(target_os = "macos")]
mod macos;
pub mod remote;
#[cfg(target_os = "windows")]
pub mod win_privacy;
lazy_static::lazy_static! {
// stupid workaround for https://sciter.com/forums/topic/crash-on-latest-tis-mac-sdk-sometimes/
static ref STUPID_VALUES: Mutex<Vec<Arc<Vec<Value>>>> = Default::default();
@@ -227,7 +230,7 @@ impl UI {
}
fn get_options(&self) -> Value {
let hashmap = get_options();
let hashmap: HashMap<String, String> = serde_json::from_str(&get_options()).unwrap();
let mut m = Value::map();
for (k, v) in hashmap {
m.set_item(k, v);

View File

@@ -1,5 +1,10 @@
use crate::common::SOFTWARE_UPDATE_URL;
use crate::ipc;
use std::{
collections::HashMap,
process::Child,
sync::{Arc, Mutex},
time::SystemTime,
};
use hbb_common::{
allow_err,
config::{self, Config, LocalConfig, PeerConfig, RENDEZVOUS_PORT, RENDEZVOUS_TIMEOUT},
@@ -11,12 +16,9 @@ use hbb_common::{
tcp::FramedStream,
tokio::{self, sync::mpsc, time},
};
use std::{
collections::HashMap,
process::Child,
sync::{Arc, Mutex},
time::SystemTime,
};
use crate::common::SOFTWARE_UPDATE_URL;
use crate::ipc;
type Message = RendezvousMessage;
@@ -72,7 +74,9 @@ pub fn goto_install() {
pub fn install_me(_options: String, _path: String, silent: bool, debug: bool) {
#[cfg(windows)]
std::thread::spawn(move || {
allow_err!(crate::platform::windows::install_me(&_options, _path, silent, debug));
allow_err!(crate::platform::windows::install_me(
&_options, _path, silent, debug
));
std::process::exit(0);
});
}
@@ -185,14 +189,13 @@ pub fn using_public_server() -> bool {
crate::get_custom_rendezvous_server(get_option_("custom-rendezvous-server")).is_empty()
}
pub fn get_options() -> HashMap<String, String> {
// TODO Vec<(String,String)>
pub fn get_options() -> String {
let options = OPTIONS.lock().unwrap();
let mut m = HashMap::new();
let mut m = serde_json::Map::new();
for (k, v) in options.iter() {
m.insert(k.into(), v.into());
m.insert(k.into(), v.to_owned().into());
}
m
serde_json::to_string(&m).unwrap()
}
pub fn test_if_valid_server(host: String) -> String {