@all-smart/all-smart-tools 1.0.3 → 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 -15
- 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
|
}
|
|
@@ -114,8 +135,6 @@ class asTools {
|
|
|
114
135
|
}
|
|
115
136
|
|
|
116
137
|
async activateLicenseKey(){
|
|
117
|
-
this.adapter.log.info(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${this.adapter.config.licenseKey}`);
|
|
118
|
-
this.adapter.log.info(`Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`);
|
|
119
138
|
try {
|
|
120
139
|
const response = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${this.adapter.config.licenseKey}`, {
|
|
121
140
|
headers: {
|
|
@@ -125,7 +144,7 @@ class asTools {
|
|
|
125
144
|
|
|
126
145
|
if(response.data.success === true){
|
|
127
146
|
this.adapter.log.info('License Key activated');
|
|
128
|
-
await this.
|
|
147
|
+
await this.createLocalLicenseCertificate();
|
|
129
148
|
return true;
|
|
130
149
|
} else {
|
|
131
150
|
this.adapter.log.info('License Key activation failed');
|
|
@@ -137,7 +156,7 @@ class asTools {
|
|
|
137
156
|
}
|
|
138
157
|
}
|
|
139
158
|
|
|
140
|
-
async
|
|
159
|
+
async createLocalLicenseCertificate(){
|
|
141
160
|
// get system uuid
|
|
142
161
|
const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
|
|
143
162
|
const systemUuid = systemMeta.native.uuid;
|
|
@@ -146,27 +165,33 @@ class asTools {
|
|
|
146
165
|
// get Major version
|
|
147
166
|
const majorVersion = this.adapter.version.split('.')[0];
|
|
148
167
|
// create license file
|
|
149
|
-
const
|
|
168
|
+
const licenseCertificate = {
|
|
150
169
|
"licenseKey": licenseKey,
|
|
151
170
|
"systemUuid": systemUuid,
|
|
152
171
|
"majorVersion": majorVersion
|
|
153
172
|
}
|
|
154
|
-
// encode license
|
|
155
|
-
const licenseFileEncoded =
|
|
156
|
-
// write license
|
|
157
|
-
|
|
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
|
+
})
|
|
158
181
|
}
|
|
159
182
|
|
|
160
|
-
async
|
|
161
|
-
// read license
|
|
183
|
+
async checkLocalLicenseCertificate(){
|
|
184
|
+
// read license certificate
|
|
162
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;
|
|
163
188
|
// decode license file
|
|
164
|
-
const
|
|
189
|
+
const licenseCertificate = JSON.parse(licenseCertificateEncoded.toString().toString('ascii'));
|
|
165
190
|
// get system uuid
|
|
166
191
|
const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
|
|
167
192
|
const systemUuid = systemMeta.native.uuid;
|
|
168
193
|
// check if license file is valid
|
|
169
|
-
if(
|
|
194
|
+
if(licenseCertificate.systemUuid === systemUuid && licenseCertificate.majorVersion === this.adapter.version.split('.')[0] && licenseCertificate.licenseKey === this.adapter.config.licenseKey){
|
|
170
195
|
return true;
|
|
171
196
|
} else {
|
|
172
197
|
return false;
|