@all-smart/all-smart-tools 1.0.13 → 1.0.15
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/deployment.xml +1 -10
- package/LICENSE.MD +3 -3
- package/main.js +79 -24
- package/package.json +2 -2
- package/.idea/webServers.xml +0 -10
package/.idea/deployment.xml
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<project version="4">
|
|
3
|
-
<component name="PublishConfigData" autoUpload="Always"
|
|
3
|
+
<component name="PublishConfigData" autoUpload="Always" remoteFilesAllowedToDisappearOnAutoupload="false" confirmBeforeUploading="false">
|
|
4
4
|
<option name="confirmBeforeUploading" value="false" />
|
|
5
|
-
<serverData>
|
|
6
|
-
<paths name="local">
|
|
7
|
-
<serverdata>
|
|
8
|
-
<mappings>
|
|
9
|
-
<mapping deploy="/" local="$PROJECT_DIR$" web="/" />
|
|
10
|
-
</mappings>
|
|
11
|
-
</serverdata>
|
|
12
|
-
</paths>
|
|
13
|
-
</serverData>
|
|
14
5
|
<option name="myAutoUpload" value="ALWAYS" />
|
|
15
6
|
</component>
|
|
16
7
|
</project>
|
package/LICENSE.MD
CHANGED
|
@@ -40,9 +40,9 @@ and the **Licensee**
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
10. __Signature__
|
|
43
|
-
This
|
|
43
|
+
This Agr13eement shall automatically come into force as soon as the Licensee uses the "ALL SMART Tools" software.
|
|
44
44
|
|
|
45
45
|
LICENSOR
|
|
46
46
|
Christoph Gerle
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
Dorfstr. 10
|
|
48
|
+
86842 Türkheim, Germany
|
package/main.js
CHANGED
|
@@ -107,39 +107,85 @@ class asTools {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
async checkLicenseKey(){
|
|
110
|
-
|
|
110
|
+
if (!this.adapter.config.licenseKey || typeof this.adapter.config.licenseKey !== 'string' || this.adapter.config.licenseKey.trim() === '') {
|
|
111
|
+
this.adapter.log.warn('License Key is empty');
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
try {
|
|
116
|
+
const licenseKey = encodeURIComponent(this.adapter.config.licenseKey.trim());
|
|
117
|
+
let responseValidate;
|
|
118
|
+
try {
|
|
119
|
+
responseValidate = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/${licenseKey}`, {
|
|
120
|
+
headers: {
|
|
121
|
+
authorization: `Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`,
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
} catch (e) {
|
|
125
|
+
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
|
|
126
|
+
this.adapter.log.warn('License Key not found (404)');
|
|
127
|
+
} else {
|
|
128
|
+
this.adapter.log.error('Error during license key validation: ' + e.message);
|
|
115
129
|
}
|
|
116
|
-
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
117
132
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
133
|
+
if (!responseValidate.data || !responseValidate.data.success || !responseValidate.data.data || Array.isArray(responseValidate.data.data)) {
|
|
134
|
+
this.adapter.log.warn('License Key not found or invalid response from server');
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
123
137
|
|
|
124
|
-
|
|
138
|
+
if (!responseValidate.data.data.productId) {
|
|
139
|
+
this.adapter.log.info('License has no product ID assigned, skipping product check.');
|
|
140
|
+
return await this.handleActivationStatus(responseValidate.data.data);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let responseProduct;
|
|
144
|
+
try {
|
|
145
|
+
responseProduct = await axios.get(`${baseUrl}/wp-json/wc/v3/products/${responseValidate.data.data.productId}`, {
|
|
146
|
+
headers: {
|
|
147
|
+
authorization: `Basic ${Buffer.from(`${key3}:${key4}`).toString('base64')}`
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
} catch (e) {
|
|
151
|
+
this.adapter.log.warn(`Could not fetch product details for ID ${responseValidate.data.data.productId}: ${e.message}`);
|
|
152
|
+
// If product details cannot be fetched, we skip the product name check instead of failing completely.
|
|
153
|
+
// This avoids the 404 issue when a product is deleted or API keys have no access, but the license is valid.
|
|
154
|
+
this.adapter.log.info('Skipping product name and version check due to missing product details.');
|
|
155
|
+
return await this.handleActivationStatus(responseValidate.data.data);
|
|
156
|
+
}
|
|
125
157
|
|
|
126
|
-
const
|
|
127
|
-
const
|
|
158
|
+
const majorVersion = this.adapter.version.split('.')[0];
|
|
159
|
+
const productNameFull = responseProduct.data.name || '';
|
|
160
|
+
const productName = productNameFull.split(' ')[0].toLowerCase().replace('iobroker.', '');
|
|
161
|
+
const productVersionMatch = productNameFull.match(/[v|V](\d+)/);
|
|
162
|
+
const productVersion = productVersionMatch ? productVersionMatch[1] : productNameFull.split(' ')[1]?.replace(/[v|V]/g, '');
|
|
128
163
|
|
|
129
164
|
if(productName.trim() !== this.adapter.name.trim() || productVersion !== majorVersion){
|
|
130
|
-
this.adapter.log.
|
|
165
|
+
this.adapter.log.warn(`License Key is not valid for this product. Expected ${this.adapter.name} v${majorVersion}, but license is for ${productName} v${productVersion}`);
|
|
131
166
|
this.adapter.disable();
|
|
132
167
|
return false;
|
|
133
168
|
}
|
|
134
169
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
170
|
+
return await this.handleActivationStatus(responseValidate.data.data);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
this.adapter.log.error('Unexpected error during license check: ' + e.message);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async handleActivationStatus(data) {
|
|
179
|
+
if(data.timesActivated === null || data.timesActivated < data.timesActivatedMax){
|
|
180
|
+
this.adapter.log.info('License Key is not activated yet');
|
|
181
|
+
return await this.activateLicenseKey();
|
|
182
|
+
} else if(data.timesActivated >= data.timesActivatedMax){
|
|
183
|
+
this.adapter.log.warn('License Key was already activated (max activations reached)');
|
|
184
|
+
this.adapter.stop();
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
143
189
|
|
|
144
190
|
// await this.createLocalLicenseFile(); Why here? This has to be in activateLicenseKey
|
|
145
191
|
// return true;
|
|
@@ -152,8 +198,13 @@ class asTools {
|
|
|
152
198
|
}
|
|
153
199
|
|
|
154
200
|
async activateLicenseKey(){
|
|
201
|
+
if (!this.adapter.config.licenseKey || typeof this.adapter.config.licenseKey !== 'string' || this.adapter.config.licenseKey.trim() === '') {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
155
205
|
try {
|
|
156
|
-
const
|
|
206
|
+
const licenseKey = encodeURIComponent(this.adapter.config.licenseKey.trim());
|
|
207
|
+
const response = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${licenseKey}`, {
|
|
157
208
|
headers: {
|
|
158
209
|
authorization: `Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`,
|
|
159
210
|
}
|
|
@@ -168,7 +219,11 @@ class asTools {
|
|
|
168
219
|
return false;
|
|
169
220
|
}
|
|
170
221
|
} catch (e) {
|
|
171
|
-
|
|
222
|
+
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
|
|
223
|
+
this.adapter.log.warn('License Key activation failed: Key not found (404)');
|
|
224
|
+
} else {
|
|
225
|
+
this.adapter.log.debug('Error license key activation: ' + e);
|
|
226
|
+
}
|
|
172
227
|
return false;
|
|
173
228
|
}
|
|
174
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@all-smart/all-smart-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"main": "main.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "Christoph Gerle",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE.MD",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"axios": "
|
|
12
|
+
"axios": "1.20.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {},
|
|
15
15
|
"description": ""
|
package/.idea/webServers.xml
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="WebServers">
|
|
4
|
-
<option name="servers">
|
|
5
|
-
<webServer id="d117c297-54c1-40da-9610-cce0b85b1a74" name="local" url="http://localhost">
|
|
6
|
-
<fileTransfer mountedRoot="$PROJECT_DIR$/../ioBroker.we-are-one/node_modules/all-smart-tools" accessType="MOUNT" port="0" />
|
|
7
|
-
</webServer>
|
|
8
|
-
</option>
|
|
9
|
-
</component>
|
|
10
|
-
</project>
|