|
|
@@ -6,11 +6,21 @@ use std::path::Path;
|
|
6
|
6
|
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
|
7
|
7
|
pub struct License {
|
|
8
|
8
|
#[serde(default)]
|
|
9
|
|
- pub hostname: String,
|
|
|
9
|
+ hostname: String,
|
|
10
|
10
|
#[serde(default)]
|
|
11
|
|
- pub uid: String,
|
|
|
11
|
+ uid: String,
|
|
12
|
12
|
#[serde(default)]
|
|
13
|
|
- pub mac: String,
|
|
|
13
|
+ mac: String,
|
|
|
14
|
+}
|
|
|
15
|
+
|
|
|
16
|
+#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
|
|
17
|
+pub struct Post {
|
|
|
18
|
+ #[serde(default)]
|
|
|
19
|
+ lic: License,
|
|
|
20
|
+ #[serde(default)]
|
|
|
21
|
+ email: String,
|
|
|
22
|
+ #[serde(default)]
|
|
|
23
|
+ status: String,
|
|
14
|
24
|
}
|
|
15
|
25
|
|
|
16
|
26
|
const LICENSE_FILE: &'static str = ".license.txt";
|
|
|
@@ -32,16 +42,47 @@ pub fn check_lic(email: &str) -> bool {
|
|
32
|
42
|
return false;
|
|
33
|
43
|
}
|
|
34
|
44
|
|
|
|
45
|
+ match check_email(lic.clone(), email.to_owned()) {
|
|
|
46
|
+ Ok(v) => {
|
|
|
47
|
+ if v {
|
|
|
48
|
+ write_lic(&lic);
|
|
|
49
|
+ }
|
|
|
50
|
+ return v;
|
|
|
51
|
+ }
|
|
|
52
|
+ Err(err) => {
|
|
|
53
|
+ log::error!("{}", err);
|
|
|
54
|
+ return false;
|
|
|
55
|
+ }
|
|
|
56
|
+ }
|
|
|
57
|
+}
|
|
|
58
|
+
|
|
|
59
|
+fn write_lic(lic: &License) {
|
|
35
|
60
|
if let Ok(s) = enc_lic(&lic) {
|
|
36
|
|
- if let Ok(mut f) = std::fs::File::create(path) {
|
|
|
61
|
+ if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) {
|
|
37
|
62
|
f.write_all(s.as_bytes()).ok();
|
|
38
|
63
|
f.sync_all().ok();
|
|
39
|
64
|
}
|
|
40
|
65
|
}
|
|
41
|
|
- true
|
|
42
|
66
|
}
|
|
43
|
67
|
|
|
44
|
|
-pub fn get_lic() -> License {
|
|
|
68
|
+fn check_email(lic: License, email: String) -> ResultType<bool> {
|
|
|
69
|
+ use reqwest::blocking::Client;
|
|
|
70
|
+ let p: Post = Client::new()
|
|
|
71
|
+ .post("http://rustdesk.com/api/check-email")
|
|
|
72
|
+ .json(&Post {
|
|
|
73
|
+ lic,
|
|
|
74
|
+ email,
|
|
|
75
|
+ ..Default::default()
|
|
|
76
|
+ })
|
|
|
77
|
+ .send()?
|
|
|
78
|
+ .json()?;
|
|
|
79
|
+ if !p.status.is_empty() {
|
|
|
80
|
+ bail!("{}", p.status);
|
|
|
81
|
+ }
|
|
|
82
|
+ Ok(true)
|
|
|
83
|
+}
|
|
|
84
|
+
|
|
|
85
|
+fn get_lic() -> License {
|
|
45
|
86
|
let hostname = whoami::hostname();
|
|
46
|
87
|
let uid = machine_uid::get().unwrap_or("".to_owned());
|
|
47
|
88
|
let mac = if let Ok(Some(ma)) = mac_address::get_mac_address() {
|
|
|
@@ -52,7 +93,7 @@ pub fn get_lic() -> License {
|
|
52
|
93
|
License { hostname, uid, mac }
|
|
53
|
94
|
}
|
|
54
|
95
|
|
|
55
|
|
-pub fn enc_lic(lic: &License) -> ResultType<String> {
|
|
|
96
|
+fn enc_lic(lic: &License) -> ResultType<String> {
|
|
56
|
97
|
let tmp = serde_json::to_vec::<License>(lic)?;
|
|
57
|
98
|
const SK: &[u64] = &[
|
|
58
|
99
|
139, 164, 88, 86, 6, 123, 221, 248, 96, 36, 106, 207, 99, 124, 27, 196, 5, 159, 58, 253,
|
|
|
@@ -69,7 +110,7 @@ pub fn enc_lic(lic: &License) -> ResultType<String> {
|
|
69
|
110
|
Ok(tmp)
|
|
70
|
111
|
}
|
|
71
|
112
|
|
|
72
|
|
-pub fn dec_lic(s: &str) -> ResultType<License> {
|
|
|
113
|
+fn dec_lic(s: &str) -> ResultType<License> {
|
|
73
|
114
|
let tmp: String = s.chars().rev().collect();
|
|
74
|
115
|
const PK: &[u64] = &[
|
|
75
|
116
|
88, 168, 68, 104, 60, 5, 163, 198, 165, 38, 12, 85, 114, 203, 96, 163, 70, 48, 0, 131, 57,
|