|
|
@@ -24,7 +24,7 @@ pub struct Post {
|
|
24
|
24
|
#[serde(default)]
|
|
25
|
25
|
version: String,
|
|
26
|
26
|
#[serde(default)]
|
|
27
|
|
- next_check_time: u32,
|
|
|
27
|
+ next_check_time: u64,
|
|
28
|
28
|
}
|
|
29
|
29
|
|
|
30
|
30
|
const LICENSE_FILE: &'static str = ".license.txt";
|
|
|
@@ -40,12 +40,14 @@ pub fn check_lic(email: &str, version: &str) -> bool {
|
|
40
|
40
|
if Path::is_file(&path) {
|
|
41
|
41
|
let contents = std::fs::read_to_string(&path).unwrap_or("".to_owned());
|
|
42
|
42
|
if verify(&contents, &machine) {
|
|
|
43
|
+ async_check_email(&machine, email, version, 0);
|
|
43
|
44
|
return true;
|
|
44
|
45
|
}
|
|
45
|
46
|
}
|
|
46
|
47
|
|
|
47
|
|
- match check_email(machine, email.to_owned(), version.to_owned()) {
|
|
|
48
|
+ match check_email(machine.clone(), email.to_owned(), version.to_owned()) {
|
|
48
|
49
|
Ok(v) => {
|
|
|
50
|
+ async_check_email(&machine, email, version, v);
|
|
49
|
51
|
return true;
|
|
50
|
52
|
}
|
|
51
|
53
|
Err(err) => {
|
|
|
@@ -55,6 +57,30 @@ pub fn check_lic(email: &str, version: &str) -> bool {
|
|
55
|
57
|
}
|
|
56
|
58
|
}
|
|
57
|
59
|
|
|
|
60
|
+fn async_check_email(machine: &str, email: &str, version: &str, wait: u64) {
|
|
|
61
|
+ let machine = machine.to_owned();
|
|
|
62
|
+ let email = email.to_owned();
|
|
|
63
|
+ let version = version.to_owned();
|
|
|
64
|
+ std::thread::spawn(move || {
|
|
|
65
|
+ let mut wait = wait;
|
|
|
66
|
+ loop {
|
|
|
67
|
+ let machine = machine.clone();
|
|
|
68
|
+ let email = email.clone();
|
|
|
69
|
+ let version = version.clone();
|
|
|
70
|
+ std::thread::sleep(std::time::Duration::from_secs(wait));
|
|
|
71
|
+ match check_email(machine, email, version) {
|
|
|
72
|
+ Ok(v) => {
|
|
|
73
|
+ wait = v;
|
|
|
74
|
+ }
|
|
|
75
|
+ Err(err) => {
|
|
|
76
|
+ log::error!("{}", err);
|
|
|
77
|
+ std::process::exit(-1);
|
|
|
78
|
+ }
|
|
|
79
|
+ }
|
|
|
80
|
+ }
|
|
|
81
|
+ });
|
|
|
82
|
+}
|
|
|
83
|
+
|
|
58
|
84
|
fn write_lic(lic: &str) {
|
|
59
|
85
|
if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) {
|
|
60
|
86
|
f.write_all(lic.as_bytes()).ok();
|
|
|
@@ -62,8 +88,8 @@ fn write_lic(lic: &str) {
|
|
62
|
88
|
}
|
|
63
|
89
|
}
|
|
64
|
90
|
|
|
65
|
|
-fn check_email(machine: String, email: String, version: String) -> ResultType<u32> {
|
|
66
|
|
- log::info!("Checking email with the server ...");
|
|
|
91
|
+fn check_email(machine: String, email: String, version: String) -> ResultType<u64> {
|
|
|
92
|
+ log::info!("Checking email with the license server ...");
|
|
67
|
93
|
let resp = minreq::post("http://rustdesk.com/api/check-email")
|
|
68
|
94
|
.with_body(
|
|
69
|
95
|
serde_json::to_string(&Post {
|
|
|
@@ -84,7 +110,13 @@ fn check_email(machine: String, email: String, version: String) -> ResultType<u3
|
|
84
|
110
|
bail!("Verification failure");
|
|
85
|
111
|
}
|
|
86
|
112
|
write_lic(&p.machine);
|
|
87
|
|
- Ok(p.next_check_time)
|
|
|
113
|
+ log::info!("License OK");
|
|
|
114
|
+ let mut wait = p.next_check_time;
|
|
|
115
|
+ if wait == 0 {
|
|
|
116
|
+ wait = 3600 * 24 * 30;
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ Ok(wait)
|
|
88
|
120
|
} else {
|
|
89
|
121
|
bail!("Server error: {}", resp.reason_phrase);
|
|
90
|
122
|
}
|