@all-smart/all-smart-tools 1.0.4 → 1.0.10

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 ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
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) => {
@@ -45,10 +66,14 @@ class asTools {
45
66
  async block() {
46
67
  return new Promise(async (resolve, reject) => {
47
68
  const check = async () => {
48
- if (fs.existsSync(__dirname + '/cache')) {
49
- if (await this.checkLocalLicenseFile()) {
50
- this.adapter.log.info('License Key file OK');
69
+ const adapterObject = await this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
70
+ if (adapterObject.native.licenseCertificate) {
71
+ if (await this.checkLocalLicenseCertificate()) {
72
+ this.adapter.log.info('License Certificate OK');
51
73
  resolve(true);
74
+ } else {
75
+ this.adapter.log.warn('There was an error validating the license')
76
+ reject(false);
52
77
  }
53
78
  } else if (await this.checkLicenseKey()) {
54
79
  resolve(true);
@@ -123,7 +148,7 @@ class asTools {
123
148
 
124
149
  if(response.data.success === true){
125
150
  this.adapter.log.info('License Key activated');
126
- await this.createLocalLicenseFile();
151
+ await this.createLocalLicenseCertificate();
127
152
  return true;
128
153
  } else {
129
154
  this.adapter.log.info('License Key activation failed');
@@ -135,7 +160,7 @@ class asTools {
135
160
  }
136
161
  }
137
162
 
138
- async createLocalLicenseFile(){
163
+ async createLocalLicenseCertificate(){
139
164
  // get system uuid
140
165
  const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
141
166
  const systemUuid = systemMeta.native.uuid;
@@ -144,27 +169,36 @@ class asTools {
144
169
  // get Major version
145
170
  const majorVersion = this.adapter.version.split('.')[0];
146
171
  // create license file
147
- const licenseFile = {
172
+ const licenseCertificate = {
148
173
  "licenseKey": licenseKey,
149
174
  "systemUuid": systemUuid,
150
175
  "majorVersion": majorVersion
151
176
  }
152
- // encode license file
153
- const licenseFileEncoded = Buffer.from(JSON.stringify(licenseFile)).toString('base64');
154
- // write license file
155
- fs.writeFileSync(__dirname + '/cache', licenseFileEncoded);
177
+ // encode license certificate
178
+ const licenseCertificateEncoded = Buffer.from(JSON.stringify(licenseCertificate)).toString('base64');
179
+ this.adapter.log.debug(licenseCertificateEncoded);
180
+ // write license certificate
181
+ await this.adapter.extendForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`, {
182
+ native: {
183
+ licenseCertificate: licenseCertificateEncoded
184
+ }
185
+ })
156
186
  }
157
187
 
158
- async checkLocalLicenseFile(){
159
- // read license file
160
- const licenseFileEncoded = fs.readFileSync(__dirname + '/cache');
188
+ async checkLocalLicenseCertificate(){
189
+ // read license certificate
190
+ const adapterObj = await this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
191
+ this.adapter.log.debug(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
192
+ this.adapter.log.debug(JSON.stringify(adapterObj));
193
+ const licenseCertificateEncoded = adapterObj.native.licenseCertificate;
161
194
  // decode license file
162
- const licenseFile = JSON.parse(Buffer.from(licenseFileEncoded.toString(), 'base64').toString('ascii'));
195
+ const licenseCertificate = JSON.parse(Buffer.from(licenseCertificateEncoded, 'base64').toString('ascii'));
196
+ this.adapter.log.info(JSON.stringify(licenseCertificate));
163
197
  // get system uuid
164
198
  const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
165
199
  const systemUuid = systemMeta.native.uuid;
166
200
  // check if license file is valid
167
- if(licenseFile.systemUuid === systemUuid && licenseFile.majorVersion === this.adapter.version.split('.')[0] && licenseFile.licenseKey === this.adapter.config.licenseKey){
201
+ if(licenseCertificate.systemUuid === systemUuid && licenseCertificate.majorVersion === this.adapter.version.split('.')[0] && licenseCertificate.licenseKey === this.adapter.config.licenseKey){
168
202
  return true;
169
203
  } else {
170
204
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@all-smart/all-smart-tools",
3
- "version": "1.0.4",
3
+ "version": "1.0.10",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"