@all-smart/all-smart-tools 1.0.1 → 1.0.3
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/main.js +23 -26
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -10,7 +10,6 @@ class asTools {
|
|
|
10
10
|
constructor(adapter) {
|
|
11
11
|
this.adapter = adapter;
|
|
12
12
|
this.licenseInvalidMassage = false;
|
|
13
|
-
this.licenseReCheckCount = 0;
|
|
14
13
|
this.reCheckTimeout = null;
|
|
15
14
|
this.adapter.on("message", this.onMessage.bind(this));
|
|
16
15
|
this.main();
|
|
@@ -33,50 +32,45 @@ class asTools {
|
|
|
33
32
|
|
|
34
33
|
async checkObjectsUpdate(){
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
return this.block().then((isValid) => {
|
|
36
|
+
if(isValid){
|
|
37
|
+
this.adapter.log.info('License Key is valid');
|
|
38
|
+
return true;
|
|
39
|
+
} else {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async block() {
|
|
47
46
|
return new Promise(async (resolve, reject) => {
|
|
48
47
|
const check = async () => {
|
|
49
|
-
// look for license file
|
|
50
48
|
if (fs.existsSync(__dirname + '/cache')) {
|
|
51
49
|
if (await this.checkLocalLicenseFile()) {
|
|
50
|
+
this.adapter.log.info('License Key file OK');
|
|
52
51
|
resolve(true);
|
|
53
52
|
}
|
|
54
|
-
} else if (await this.checkLicenseKey(
|
|
55
|
-
this.licenseReCheckCount = 0;
|
|
53
|
+
} else if (await this.checkLicenseKey()) {
|
|
56
54
|
resolve(true);
|
|
57
55
|
} else {
|
|
58
|
-
|
|
59
|
-
if (this.
|
|
60
|
-
this.adapter.log.warn('License Key
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} else {
|
|
64
|
-
if (this.licenseInvalidMassage === false) {
|
|
65
|
-
this.adapter.log.warn('License Key is invalid');
|
|
66
|
-
this.licenseInvalidMassage = true;
|
|
67
|
-
}
|
|
68
|
-
if (this.reCheckTimeout) clearTimeout(this.reCheckTimeout);
|
|
69
|
-
setTimeout(check, 60 * 1000);
|
|
56
|
+
|
|
57
|
+
if (this.licenseInvalidMassage === false) {
|
|
58
|
+
this.adapter.log.warn('License Key is invalid');
|
|
59
|
+
this.licenseInvalidMassage = true;
|
|
60
|
+
this.adapter.disable();
|
|
70
61
|
}
|
|
62
|
+
if (this.reCheckTimeout) clearTimeout(this.reCheckTimeout);
|
|
63
|
+
this.reCheckTimeout = setTimeout(check, 60 * 1000);
|
|
71
64
|
}
|
|
72
65
|
};
|
|
73
66
|
|
|
74
|
-
|
|
67
|
+
check();
|
|
75
68
|
});
|
|
76
69
|
}
|
|
77
70
|
|
|
78
71
|
async checkLicenseKey(){
|
|
79
72
|
try {
|
|
73
|
+
|
|
80
74
|
const responseValidate = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/${this.adapter.config.licenseKey}`, {
|
|
81
75
|
headers: {
|
|
82
76
|
authorization: `Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`,
|
|
@@ -96,6 +90,7 @@ class asTools {
|
|
|
96
90
|
|
|
97
91
|
if(productName.trim() !== this.adapter.name.trim() || productVersion !== majorVersion){
|
|
98
92
|
this.adapter.log.info('License Key is not valid for this product');
|
|
93
|
+
this.adapter.disable();
|
|
99
94
|
return false;
|
|
100
95
|
}
|
|
101
96
|
|
|
@@ -104,7 +99,7 @@ class asTools {
|
|
|
104
99
|
return await this.activateLicenseKey();
|
|
105
100
|
} else if(responseValidate.data.data.timesActivated === responseValidate.data.data.timesActivatedMax){
|
|
106
101
|
this.adapter.log.info('License Key was already activated');
|
|
107
|
-
this.
|
|
102
|
+
this.adapter.stop();
|
|
108
103
|
return false;
|
|
109
104
|
}
|
|
110
105
|
|
|
@@ -119,6 +114,8 @@ class asTools {
|
|
|
119
114
|
}
|
|
120
115
|
|
|
121
116
|
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')}`);
|
|
122
119
|
try {
|
|
123
120
|
const response = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${this.adapter.config.licenseKey}`, {
|
|
124
121
|
headers: {
|