change sled to sqlite and remove lic

This commit is contained in:
rustdesk
2022-05-12 20:00:33 +08:00
parent d36d6da445
commit b3f39598a7
33 changed files with 4125 additions and 2646 deletions

View File

@@ -1,15 +1,18 @@
// https://tools.ietf.org/rfc/rfc5128.txt
// https://blog.csdn.net/bytxl/article/details/44344855
use clap::App;
use hbb_common::{env_logger::*, log, ResultType};
use hbbs::*;
mod lic;
use ini::Ini;
use std::sync::{Arc, Mutex};
use flexi_logger::*;
use hbb_common::{bail, config::RENDEZVOUS_PORT, ResultType};
use hbbs::{common::*, *};
const RMEM: usize = 0;
fn main() -> ResultType<()> {
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
let _logger = Logger::try_with_env_or_str("info")?
.log_to_stdout()
.format(opt_format)
.write_mode(WriteMode::Async)
.start()?;
let args = format!(
"-c --config=[FILE] +takes_value 'Sets a custom config file'
-p, --port=[NUMBER(default={})] 'Sets the listening port'
@@ -18,66 +21,19 @@ fn main() -> ResultType<()> {
-u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
-r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon'
-C, --change-id=[BOOL(default=Y)] 'Sets if support to change id'
{}
-M, --rmem=[NUMBER(default={})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl p'
-k, --key=[KEY] 'Only allow the client with the same key'",
DEFAULT_PORT,
lic::EMAIL_ARG
RENDEZVOUS_PORT,
RMEM,
);
let matches = App::new("hbbs")
.version(crate::VERSION)
.author("CarrieZ Studio<info@rustdesk.com>")
.about("RustDesk ID/Rendezvous Server")
.args_from_usage(&args)
.get_matches();
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>);
}
init_args(&args, "hbbs", "RustDesk ID/Rendezvous Server");
let port = get_arg_or("port", RENDEZVOUS_PORT.to_string()).parse::<i32>()?;
if port < 3 {
bail!("Invalid port");
}
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();
};
if !lic::check_lic(&get_arg("email", ""), crate::VERSION) {
return Ok(());
}
let port = get_arg("port", DEFAULT_PORT);
let relay_servers: Vec<String> = get_arg("relay-servers", "")
.split(",")
.filter(|x| !x.is_empty() && test_if_valid_server(x, "relay-server").is_ok())
.map(|x| x.to_owned())
.collect();
let serial: i32 = get_arg("serial", "").parse().unwrap_or(0);
let id_change_support: bool = get_arg("change-id", "Y").to_uppercase() == "Y";
let rendezvous_servers: Vec<String> = get_arg("rendezvous-servers", "")
.split(",")
.filter(|x| !x.is_empty() && test_if_valid_server(x, "rendezvous-server").is_ok())
.map(|x| x.to_owned())
.collect();
let addr = format!("0.0.0.0:{}", port);
let addr2 = format!("0.0.0.0:{}", port.parse::<i32>().unwrap_or(0) - 1);
log::info!("serial={}", serial);
log::info!("rendezvous-servers={:?}", rendezvous_servers);
let stop: Arc<Mutex<bool>> = Default::default();
RendezvousServer::start(
&addr,
&addr2,
relay_servers,
serial,
rendezvous_servers,
get_arg("software-url", ""),
&get_arg("key", ""),
stop,
id_change_support,
)?;
let rmem = get_arg("rmem").parse::<usize>().unwrap_or(RMEM);
let serial: i32 = get_arg("serial").parse().unwrap_or(0);
let id_change_support: bool = get_arg_or("change-id", "Y".to_owned()).to_uppercase() == "Y";
RendezvousServer::start(port, serial, &get_arg("key"), id_change_support, rmem)?;
Ok(())
}