2020-03-06 17:18:22 +08:00
|
|
|
// https://tools.ietf.org/rfc/rfc5128.txt
|
|
|
|
// https://blog.csdn.net/bytxl/article/details/44344855
|
|
|
|
|
2020-09-18 13:04:39 +08:00
|
|
|
use clap::App;
|
2021-03-19 16:38:10 +08:00
|
|
|
use hbb_common::{env_logger::*, log, ResultType};
|
2020-03-06 17:18:22 +08:00
|
|
|
use hbbs::*;
|
2020-09-18 17:07:17 +08:00
|
|
|
use ini::Ini;
|
2021-03-19 16:38:10 +08:00
|
|
|
use std::sync::{Arc, Mutex};
|
2020-03-06 17:18:22 +08:00
|
|
|
|
2021-03-19 18:26:53 +08:00
|
|
|
const LICENSE_KEY: &'static str = "";
|
|
|
|
|
2021-03-19 16:38:10 +08:00
|
|
|
fn main() -> ResultType<()> {
|
2020-09-17 10:02:20 +08:00
|
|
|
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
2020-09-18 13:04:39 +08:00
|
|
|
let args = format!(
|
2020-09-18 17:07:17 +08:00
|
|
|
"-c --config=[FILE] +takes_value 'Sets a custom config file'
|
|
|
|
-p, --port=[NUMBER(default={})] 'Sets the listening port'
|
2020-09-24 17:26:58 +08:00
|
|
|
-s, --serial=[NUMBER(default=0)] 'Sets configure update serial number'
|
2020-09-18 17:07:17 +08:00
|
|
|
-R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon'
|
2020-09-21 22:56:38 +08:00
|
|
|
-u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
|
2020-10-31 14:33:25 +08:00
|
|
|
-r, --relay-server{}=[HOST] 'Sets the default relay server{}'",
|
|
|
|
DEFAULT_PORT,
|
|
|
|
if LICENSE_KEY.is_empty() { "" } else { "s" },
|
|
|
|
if LICENSE_KEY.is_empty() {
|
|
|
|
""
|
|
|
|
} else {
|
|
|
|
"s, seperated by colon, only available for licensed users"
|
|
|
|
}
|
2020-09-18 13:04:39 +08:00
|
|
|
);
|
|
|
|
let matches = App::new("hbbs")
|
2020-09-24 17:26:58 +08:00
|
|
|
.version(crate::VERSION)
|
2020-09-24 17:45:38 +08:00
|
|
|
.author("CarrieZ Studio<info@rustdesk.com>")
|
|
|
|
.about("RustDesk ID/Rendezvous Server")
|
2020-09-18 13:04:39 +08:00
|
|
|
.args_from_usage(&args)
|
|
|
|
.get_matches();
|
2020-09-18 17:07:17 +08:00
|
|
|
let mut section = None;
|
|
|
|
let conf; // for holding section
|
|
|
|
if let Some(config) = matches.value_of("config") {
|
|
|
|
if let Ok(v) = Ini::load_from_file(config) {
|
|
|
|
conf = v;
|
|
|
|
section = conf.section(None::<String>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let get_arg = |name: &str, default: &str| -> String {
|
|
|
|
if let Some(v) = matches.value_of(name) {
|
|
|
|
return v.to_owned();
|
|
|
|
} else if let Some(section) = section {
|
|
|
|
if let Some(v) = section.get(name) {
|
|
|
|
return v.to_owned();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return default.to_owned();
|
|
|
|
};
|
|
|
|
let port = get_arg("port", DEFAULT_PORT);
|
2020-10-31 14:33:25 +08:00
|
|
|
let mut relay_servers: Vec<String> = get_arg(
|
|
|
|
&format!(
|
|
|
|
"relay-server{}",
|
|
|
|
if LICENSE_KEY.is_empty() { "" } else { "s" }
|
|
|
|
),
|
|
|
|
"",
|
|
|
|
)
|
|
|
|
.split(",")
|
|
|
|
.filter(|x| !x.is_empty() && test_if_valid_server(x, "relay-server").is_ok())
|
|
|
|
.map(|x| x.to_owned())
|
|
|
|
.collect();
|
|
|
|
if relay_servers.len() > 1 && LICENSE_KEY.is_empty() {
|
|
|
|
log::error!("Only support multiple relay servers for licenced users");
|
|
|
|
relay_servers = vec![relay_servers[0].clone()];
|
2020-09-18 17:07:17 +08:00
|
|
|
}
|
|
|
|
let serial: i32 = get_arg("serial", "").parse().unwrap_or(0);
|
|
|
|
let rendezvous_servers: Vec<String> = get_arg("rendezvous-servers", "")
|
|
|
|
.split(",")
|
2020-10-31 14:33:25 +08:00
|
|
|
.filter(|x| !x.is_empty() && test_if_valid_server(x, "rendezvous-server").is_ok())
|
2020-09-20 20:02:42 +08:00
|
|
|
.map(|x| x.to_owned())
|
2020-09-18 17:07:17 +08:00
|
|
|
.collect();
|
|
|
|
let addr = format!("0.0.0.0:{}", port);
|
2020-09-27 22:20:42 +08:00
|
|
|
let addr2 = format!("0.0.0.0:{}", port.parse::<i32>().unwrap_or(0) - 1);
|
2020-09-18 17:07:17 +08:00
|
|
|
log::info!("serial={}", serial);
|
2020-09-24 22:40:07 +08:00
|
|
|
log::info!("rendezvous-servers={:?}", rendezvous_servers);
|
2021-03-19 16:38:10 +08:00
|
|
|
let stop: Arc<Mutex<bool>> = Default::default();
|
2020-09-21 22:56:38 +08:00
|
|
|
RendezvousServer::start(
|
|
|
|
&addr,
|
2020-09-27 22:20:42 +08:00
|
|
|
&addr2,
|
2020-10-31 14:33:25 +08:00
|
|
|
relay_servers,
|
2020-09-21 22:56:38 +08:00
|
|
|
serial,
|
|
|
|
rendezvous_servers,
|
|
|
|
get_arg("software-url", ""),
|
2021-03-19 18:26:53 +08:00
|
|
|
LICENSE_KEY,
|
2021-03-19 16:38:10 +08:00
|
|
|
stop,
|
|
|
|
)?;
|
2020-03-06 17:18:22 +08:00
|
|
|
Ok(())
|
2020-03-09 19:35:57 +08:00
|
|
|
}
|