rustdesk лет назад: 4
Родитель
Сommit
d87d761ab6
3 измененных файлов с 17 добавлено и 12 удалено
  1. 1 1
      src/hbbr.rs
  2. 15 10
      src/lic.rs
  3. 1 1
      src/main.rs

+ 1 - 1
src/hbbr.rs

@@ -21,7 +21,7 @@ fn main() -> ResultType<()> {
21
         .about("RustDesk Relay Server")
21
         .about("RustDesk Relay Server")
22
         .args_from_usage(&args)
22
         .args_from_usage(&args)
23
         .get_matches();
23
         .get_matches();
24
-    if !lic::check_lic(matches.value_of("email").unwrap_or("")) {
24
+    if !lic::check_lic(matches.value_of("email").unwrap_or(""), hbbs::VERSION) {
25
         return Ok(());
25
         return Ok(());
26
     }
26
     }
27
     let stop: Arc<Mutex<bool>> = Default::default();
27
     let stop: Arc<Mutex<bool>> = Default::default();

+ 15 - 10
src/lic.rs

@@ -21,11 +21,20 @@ pub struct Post {
21
     email: String,
21
     email: String,
22
     #[serde(default)]
22
     #[serde(default)]
23
     status: String,
23
     status: String,
24
+    #[serde(default)]
25
+    version: String,
26
+    #[serde(default)]
27
+    next_check_time: u32,
24
 }
28
 }
25
 
29
 
26
 const LICENSE_FILE: &'static str = ".license.txt";
30
 const LICENSE_FILE: &'static str = ".license.txt";
27
 
31
 
28
-pub fn check_lic(email: &str) -> bool {
32
+pub fn check_lic(email: &str, version: &str) -> bool {
33
+    if email.is_empty() {
34
+        log::error!("Registered email required (-m option). Please visit https://rustdesk.com/server for more infomration.");
35
+        return false;
36
+    }
37
+
29
     let machine = get_lic();
38
     let machine = get_lic();
30
     let path = Path::new(LICENSE_FILE);
39
     let path = Path::new(LICENSE_FILE);
31
     if Path::is_file(&path) {
40
     if Path::is_file(&path) {
@@ -35,14 +44,9 @@ pub fn check_lic(email: &str) -> bool {
35
         }
44
         }
36
     }
45
     }
37
 
46
 
38
-    if email.is_empty() {
39
-        log::error!("Registered email required (-m option). Please visit https://rustdesk.com/server for more infomration.");
40
-        return false;
41
-    }
42
-
43
-    match check_email(machine, email.to_owned()) {
47
+    match check_email(machine, email.to_owned(), version.to_owned()) {
44
         Ok(v) => {
48
         Ok(v) => {
45
-            return v;
49
+            return true;
46
         }
50
         }
47
         Err(err) => {
51
         Err(err) => {
48
             log::error!("{}", err);
52
             log::error!("{}", err);
@@ -58,12 +62,13 @@ fn write_lic(lic: &str) {
58
     }
62
     }
59
 }
63
 }
60
 
64
 
61
-fn check_email(machine: String, email: String) -> ResultType<bool> {
65
+fn check_email(machine: String, email: String, version: String) -> ResultType<u32> {
62
     log::info!("Checking email with the server ...");
66
     log::info!("Checking email with the server ...");
63
     let resp = minreq::post("http://rustdesk.com/api/check-email")
67
     let resp = minreq::post("http://rustdesk.com/api/check-email")
64
         .with_body(
68
         .with_body(
65
             serde_json::to_string(&Post {
69
             serde_json::to_string(&Post {
66
                 machine: machine.clone(),
70
                 machine: machine.clone(),
71
+                version,
67
                 email,
72
                 email,
68
                 ..Default::default()
73
                 ..Default::default()
69
             })
74
             })
@@ -79,10 +84,10 @@ fn check_email(machine: String, email: String) -> ResultType<bool> {
79
             bail!("Verification failure");
84
             bail!("Verification failure");
80
         }
85
         }
81
         write_lic(&p.machine);
86
         write_lic(&p.machine);
87
+        Ok(p.next_check_time)
82
     } else {
88
     } else {
83
         bail!("Server error: {}", resp.reason_phrase);
89
         bail!("Server error: {}", resp.reason_phrase);
84
     }
90
     }
85
-    Ok(true)
86
 }
91
 }
87
 
92
 
88
 fn get_lic() -> String {
93
 fn get_lic() -> String {

+ 1 - 1
src/main.rs

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