@all-smart/all-smart-tools 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/vcs.xml +6 -0
- package/main.js +40 -13
- package/package.json +1 -1
package/.idea/vcs.xml
ADDED
package/main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const axios = require('axios').default;
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const { exec } = require('child_process');
|
|
3
4
|
|
|
4
5
|
const baseUrl = 'https://www.all-smart.net';
|
|
5
6
|
const key1 = 'ck_440f2f1282170f72411ac1072bfcfb4103dbd71d';
|
|
@@ -12,11 +13,15 @@ class asTools {
|
|
|
12
13
|
this.licenseInvalidMassage = false;
|
|
13
14
|
this.reCheckTimeout = null;
|
|
14
15
|
this.adapter.on("message", this.onMessage.bind(this));
|
|
16
|
+
|
|
17
|
+
this.isLxc = false;
|
|
18
|
+
this.isDocker = false;
|
|
15
19
|
this.main();
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
async main() {
|
|
19
|
-
|
|
23
|
+
this.checkLxc();
|
|
24
|
+
this.checkDocker();
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
async onMessage(obj) {
|
|
@@ -30,6 +35,22 @@ class asTools {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
38
|
+
checkLxc(){
|
|
39
|
+
exec('cat /proc/self/mountinfo | grep lxc', (error, stdout, stderr) => {
|
|
40
|
+
if(stdout.length > 0) {
|
|
41
|
+
this.isLxc = true;
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
checkDocker(){
|
|
47
|
+
exec('ls /.dockerenv', (error, stdout, stderr) => {
|
|
48
|
+
if(error !== null && error !== undefined) {
|
|
49
|
+
this.isDocker = true;
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
async checkObjectsUpdate(){
|
|
34
55
|
|
|
35
56
|
return this.block().then((isValid) => {
|
|
@@ -46,7 +67,7 @@ class asTools {
|
|
|
46
67
|
return new Promise(async (resolve, reject) => {
|
|
47
68
|
const check = async () => {
|
|
48
69
|
if (fs.existsSync(__dirname + '/cache')) {
|
|
49
|
-
if (await this.
|
|
70
|
+
if (await this.checkLocalLicenseCertificate()) {
|
|
50
71
|
this.adapter.log.info('License Key file OK');
|
|
51
72
|
resolve(true);
|
|
52
73
|
}
|
|
@@ -123,7 +144,7 @@ class asTools {
|
|
|
123
144
|
|
|
124
145
|
if(response.data.success === true){
|
|
125
146
|
this.adapter.log.info('License Key activated');
|
|
126
|
-
await this.
|
|
147
|
+
await this.createLocalLicenseCertificate();
|
|
127
148
|
return true;
|
|
128
149
|
} else {
|
|
129
150
|
this.adapter.log.info('License Key activation failed');
|
|
@@ -135,7 +156,7 @@ class asTools {
|
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
|
|
138
|
-
async
|
|
159
|
+
async createLocalLicenseCertificate(){
|
|
139
160
|
// get system uuid
|
|
140
161
|
const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
|
|
141
162
|
const systemUuid = systemMeta.native.uuid;
|
|
@@ -144,27 +165,33 @@ class asTools {
|
|
|
144
165
|
// get Major version
|
|
145
166
|
const majorVersion = this.adapter.version.split('.')[0];
|
|
146
167
|
// create license file
|
|
147
|
-
const
|
|
168
|
+
const licenseCertificate = {
|
|
148
169
|
"licenseKey": licenseKey,
|
|
149
170
|
"systemUuid": systemUuid,
|
|
150
171
|
"majorVersion": majorVersion
|
|
151
172
|
}
|
|
152
|
-
// encode license
|
|
153
|
-
const licenseFileEncoded =
|
|
154
|
-
// write license
|
|
155
|
-
|
|
173
|
+
// encode license certificate
|
|
174
|
+
const licenseFileEncoded = JSON.stringify(licenseCertificate).toString('base64');
|
|
175
|
+
// write license certificate
|
|
176
|
+
await this.adapter.extendForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`, {
|
|
177
|
+
native: {
|
|
178
|
+
licenseCertificate: licenseFileEncoded
|
|
179
|
+
}
|
|
180
|
+
})
|
|
156
181
|
}
|
|
157
182
|
|
|
158
|
-
async
|
|
159
|
-
// read license
|
|
183
|
+
async checkLocalLicenseCertificate(){
|
|
184
|
+
// read license certificate
|
|
160
185
|
const licenseFileEncoded = fs.readFileSync(__dirname + '/cache');
|
|
186
|
+
const adapterObj = this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`)
|
|
187
|
+
const licenseCertificateEncoded = adapterObj.native.licenseCertificate;
|
|
161
188
|
// decode license file
|
|
162
|
-
const
|
|
189
|
+
const licenseCertificate = JSON.parse(licenseCertificateEncoded.toString().toString('ascii'));
|
|
163
190
|
// get system uuid
|
|
164
191
|
const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
|
|
165
192
|
const systemUuid = systemMeta.native.uuid;
|
|
166
193
|
// check if license file is valid
|
|
167
|
-
if(
|
|
194
|
+
if(licenseCertificate.systemUuid === systemUuid && licenseCertificate.majorVersion === this.adapter.version.split('.')[0] && licenseCertificate.licenseKey === this.adapter.config.licenseKey){
|
|
168
195
|
return true;
|
|
169
196
|
} else {
|
|
170
197
|
return false;
|