diff --git a/src/hbbr.rs b/src/hbbr.rs index f0633a2..7b795f5 100644 --- a/src/hbbr.rs +++ b/src/hbbr.rs @@ -21,7 +21,7 @@ fn main() -> ResultType<()> { .about("RustDesk Relay Server") .args_from_usage(&args) .get_matches(); - if !lic::check_lic(matches.value_of("email").unwrap_or("")) { + if !lic::check_lic(matches.value_of("email").unwrap_or(""), hbbs::VERSION) { return Ok(()); } let stop: Arc> = Default::default(); diff --git a/src/lic.rs b/src/lic.rs index 2970c0d..49854c0 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -21,11 +21,20 @@ pub struct Post { email: String, #[serde(default)] status: String, + #[serde(default)] + version: String, + #[serde(default)] + next_check_time: u32, } const LICENSE_FILE: &'static str = ".license.txt"; -pub fn check_lic(email: &str) -> bool { +pub fn check_lic(email: &str, version: &str) -> bool { + if email.is_empty() { + log::error!("Registered email required (-m option). Please visit https://rustdesk.com/server for more infomration."); + return false; + } + let machine = get_lic(); let path = Path::new(LICENSE_FILE); if Path::is_file(&path) { @@ -35,14 +44,9 @@ pub fn check_lic(email: &str) -> bool { } } - if email.is_empty() { - log::error!("Registered email required (-m option). Please visit https://rustdesk.com/server for more infomration."); - return false; - } - - match check_email(machine, email.to_owned()) { + match check_email(machine, email.to_owned(), version.to_owned()) { Ok(v) => { - return v; + return true; } Err(err) => { log::error!("{}", err); @@ -58,12 +62,13 @@ fn write_lic(lic: &str) { } } -fn check_email(machine: String, email: String) -> ResultType { +fn check_email(machine: String, email: String, version: String) -> ResultType { log::info!("Checking email with the server ..."); let resp = minreq::post("http://rustdesk.com/api/check-email") .with_body( serde_json::to_string(&Post { machine: machine.clone(), + version, email, ..Default::default() }) @@ -79,10 +84,10 @@ fn check_email(machine: String, email: String) -> ResultType { bail!("Verification failure"); } write_lic(&p.machine); + Ok(p.next_check_time) } else { bail!("Server error: {}", resp.reason_phrase); } - Ok(true) } fn get_lic() -> String { diff --git a/src/main.rs b/src/main.rs index 808c8fd..8e488f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ fn main() -> ResultType<()> { } return default.to_owned(); }; - if !lic::check_lic(&get_arg("email", "")) { + if !lic::check_lic(&get_arg("email", ""), crate::VERSION) { return Ok(()); } let port = get_arg("port", DEFAULT_PORT);