working on new version

This commit is contained in:
rustdesk
2021-04-17 16:12:34 +08:00
parent 6482934949
commit d87d761ab6
3 changed files with 17 additions and 12 deletions

View File

@@ -21,7 +21,7 @@ fn main() -> ResultType<()> {
.about("RustDesk Relay Server") .about("RustDesk Relay Server")
.args_from_usage(&args) .args_from_usage(&args)
.get_matches(); .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(()); return Ok(());
} }
let stop: Arc<Mutex<bool>> = Default::default(); let stop: Arc<Mutex<bool>> = Default::default();

View File

@@ -21,11 +21,20 @@ pub struct Post {
email: String, email: String,
#[serde(default)] #[serde(default)]
status: String, status: String,
#[serde(default)]
version: String,
#[serde(default)]
next_check_time: u32,
} }
const LICENSE_FILE: &'static str = ".license.txt"; 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 machine = get_lic();
let path = Path::new(LICENSE_FILE); let path = Path::new(LICENSE_FILE);
if Path::is_file(&path) { if Path::is_file(&path) {
@@ -35,14 +44,9 @@ pub fn check_lic(email: &str) -> bool {
} }
} }
if email.is_empty() { match check_email(machine, email.to_owned(), version.to_owned()) {
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()) {
Ok(v) => { Ok(v) => {
return v; return true;
} }
Err(err) => { Err(err) => {
log::error!("{}", err); log::error!("{}", err);
@@ -58,12 +62,13 @@ fn write_lic(lic: &str) {
} }
} }
fn check_email(machine: String, email: String) -> ResultType<bool> { fn check_email(machine: String, email: String, version: String) -> ResultType<u32> {
log::info!("Checking email with the server ..."); log::info!("Checking email with the server ...");
let resp = minreq::post("http://rustdesk.com/api/check-email") let resp = minreq::post("http://rustdesk.com/api/check-email")
.with_body( .with_body(
serde_json::to_string(&Post { serde_json::to_string(&Post {
machine: machine.clone(), machine: machine.clone(),
version,
email, email,
..Default::default() ..Default::default()
}) })
@@ -79,10 +84,10 @@ fn check_email(machine: String, email: String) -> ResultType<bool> {
bail!("Verification failure"); bail!("Verification failure");
} }
write_lic(&p.machine); write_lic(&p.machine);
Ok(p.next_check_time)
} else { } else {
bail!("Server error: {}", resp.reason_phrase); bail!("Server error: {}", resp.reason_phrase);
} }
Ok(true)
} }
fn get_lic() -> String { fn get_lic() -> String {

View File

@@ -47,7 +47,7 @@ fn main() -> ResultType<()> {
} }
return default.to_owned(); return default.to_owned();
}; };
if !lic::check_lic(&get_arg("email", "")) { if !lic::check_lic(&get_arg("email", ""), crate::VERSION) {
return Ok(()); return Ok(());
} }
let port = get_arg("port", DEFAULT_PORT); let port = get_arg("port", DEFAULT_PORT);