2023-04-17 19:26:39 +08:00
|
|
|
#![cfg_attr(
|
2023-07-27 10:51:27 +08:00
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
2023-04-17 19:26:39 +08:00
|
|
|
windows_subsystem = "windows"
|
|
|
|
)]
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-05-12 17:35:25 +08:00
|
|
|
use librustdesk::*;
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2023-02-10 17:48:53 +08:00
|
|
|
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
2021-03-29 15:59:14 +08:00
|
|
|
fn main() {
|
2022-10-12 11:36:19 +08:00
|
|
|
if !common::global_init() {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
common::test_rendezvous_server();
|
|
|
|
common::test_nat_type();
|
2022-10-12 11:36:19 +08:00
|
|
|
common::global_clean();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2023-02-10 17:09:31 +08:00
|
|
|
#[cfg(not(any(
|
|
|
|
target_os = "android",
|
|
|
|
target_os = "ios",
|
|
|
|
feature = "cli",
|
|
|
|
feature = "flutter"
|
|
|
|
)))]
|
2021-03-29 15:59:14 +08:00
|
|
|
fn main() {
|
2022-10-12 11:36:19 +08:00
|
|
|
if !common::global_init() {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-20 14:49:06 +08:00
|
|
|
#[cfg(all(windows, not(feature = "inline")))]
|
|
|
|
unsafe {
|
|
|
|
winapi::um::shellscalingapi::SetProcessDpiAwareness(2);
|
|
|
|
}
|
2022-09-15 17:41:10 +08:00
|
|
|
if let Some(args) = crate::core_main::core_main().as_mut() {
|
|
|
|
ui::start(args);
|
2022-05-04 20:39:07 +08:00
|
|
|
}
|
2022-10-12 11:36:19 +08:00
|
|
|
common::global_clean();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "cli")]
|
|
|
|
fn main() {
|
2022-10-12 11:36:19 +08:00
|
|
|
if !common::global_init() {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
use clap::App;
|
2022-10-22 22:19:14 +08:00
|
|
|
use hbb_common::log;
|
2021-03-29 15:59:14 +08:00
|
|
|
let args = format!(
|
|
|
|
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
2022-12-29 14:17:47 +08:00
|
|
|
-c, --connect=[REMOTE_ID] 'test only'
|
2022-05-12 17:35:25 +08:00
|
|
|
-k, --key=[KEY] ''
|
2022-12-29 22:31:01 +08:00
|
|
|
-s, --server=[] 'Start server'",
|
2021-03-29 15:59:14 +08:00
|
|
|
);
|
|
|
|
let matches = App::new("rustdesk")
|
|
|
|
.version(crate::VERSION)
|
2024-03-13 21:12:04 +08:00
|
|
|
.author("Purslane Ltd<info@rustdesk.com>")
|
2021-03-29 15:59:14 +08:00
|
|
|
.about("RustDesk command line tool")
|
|
|
|
.args_from_usage(&args)
|
|
|
|
.get_matches();
|
2022-10-22 22:19:14 +08:00
|
|
|
use hbb_common::{config::LocalConfig, env_logger::*};
|
2021-03-29 15:59:14 +08:00
|
|
|
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
|
|
|
if let Some(p) = matches.value_of("port-forward") {
|
|
|
|
let options: Vec<String> = p.split(":").map(|x| x.to_owned()).collect();
|
|
|
|
if options.len() < 3 {
|
|
|
|
log::error!("Wrong port-forward options");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut port = 0;
|
|
|
|
if let Ok(v) = options[1].parse::<i32>() {
|
|
|
|
port = v;
|
|
|
|
} else {
|
|
|
|
log::error!("Wrong local-port");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut remote_port = 0;
|
|
|
|
if let Ok(v) = options[2].parse::<i32>() {
|
|
|
|
remote_port = v;
|
|
|
|
} else {
|
|
|
|
log::error!("Wrong remote-port");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut remote_host = "localhost".to_owned();
|
|
|
|
if options.len() > 3 {
|
|
|
|
remote_host = options[3].clone();
|
|
|
|
}
|
2022-12-29 14:17:47 +08:00
|
|
|
common::test_rendezvous_server();
|
|
|
|
common::test_nat_type();
|
2022-05-12 17:35:25 +08:00
|
|
|
let key = matches.value_of("key").unwrap_or("").to_owned();
|
2022-06-27 11:50:15 +08:00
|
|
|
let token = LocalConfig::get_option("access_token");
|
2022-10-22 22:19:14 +08:00
|
|
|
cli::start_one_port_forward(
|
|
|
|
options[0].clone(),
|
|
|
|
port,
|
|
|
|
remote_host,
|
|
|
|
remote_port,
|
|
|
|
key,
|
|
|
|
token,
|
|
|
|
);
|
2022-12-29 14:17:47 +08:00
|
|
|
} else if let Some(p) = matches.value_of("connect") {
|
|
|
|
common::test_rendezvous_server();
|
|
|
|
common::test_nat_type();
|
|
|
|
let key = matches.value_of("key").unwrap_or("").to_owned();
|
|
|
|
let token = LocalConfig::get_option("access_token");
|
|
|
|
cli::connect_test(p, key, token);
|
|
|
|
} else if let Some(p) = matches.value_of("server") {
|
2023-01-10 15:01:46 +08:00
|
|
|
log::info!("id={}", hbb_common::config::Config::get_id());
|
2024-09-06 14:43:38 +08:00
|
|
|
crate::start_server(true, false);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-10-12 11:36:19 +08:00
|
|
|
common::global_clean();
|
2022-10-22 22:19:14 +08:00
|
|
|
}
|