@iobroker/socket-classes 1.4.2 → 1.4.4
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/README.md +7 -1
- package/lib/socketCommands.js +327 -278
- package/lib/socketCommandsAdmin.js +388 -242
- package/lib/socketCommon.js +76 -52
- package/package.json +6 -5
|
@@ -13,7 +13,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
13
13
|
'getLocationOnDisk',
|
|
14
14
|
'getDevList',
|
|
15
15
|
'getLogs',
|
|
16
|
-
'getHostInfo'
|
|
16
|
+
'getHostInfo'
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
constructor(adapter, updateSession, objects, states) {
|
|
@@ -26,16 +26,15 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
26
26
|
this.cmdSessions = {};
|
|
27
27
|
|
|
28
28
|
this.eventsThreshold = {
|
|
29
|
-
count:
|
|
30
|
-
timeActivated:
|
|
31
|
-
active:
|
|
32
|
-
accidents:
|
|
33
|
-
repeatSeconds:
|
|
34
|
-
value:
|
|
35
|
-
checkInterval:
|
|
29
|
+
count: 0,
|
|
30
|
+
timeActivated: 0,
|
|
31
|
+
active: false,
|
|
32
|
+
accidents: 0,
|
|
33
|
+
repeatSeconds: 3, // how many seconds continuously must be number of events > value
|
|
34
|
+
value: parseInt(adapter.config.thresholdValue, 10) || 200, // how many events allowed in one check interval
|
|
35
|
+
checkInterval: 1000 // duration of one check interval
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
this.cache = {};
|
|
40
39
|
this.cacheGB = null; // cache garbage collector
|
|
41
40
|
// do not send too many state updates
|
|
@@ -70,9 +69,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
try {
|
|
73
|
-
const response = await axios.get(`https://rating.iobroker.net/rating?uuid=${uuid}`, {
|
|
72
|
+
const response = await axios.get(`https://rating.iobroker.net/rating?uuid=${uuid}`, {
|
|
73
|
+
timeout: 15000,
|
|
74
|
+
validateStatus: status => status < 400
|
|
75
|
+
});
|
|
74
76
|
this.adapter._ratings = response.data;
|
|
75
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
!this.adapter._ratings ||
|
|
79
|
+
typeof this.adapter._ratings !== 'object' ||
|
|
80
|
+
Array.isArray(this.adapter._ratings)
|
|
81
|
+
) {
|
|
76
82
|
this.adapter._ratings = {};
|
|
77
83
|
}
|
|
78
84
|
this.adapter._ratings.uuid = uuid;
|
|
@@ -82,32 +88,35 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
82
88
|
this.adapter.ratingTimeout && clearTimeout(this.adapter.ratingTimeout);
|
|
83
89
|
this.adapter.ratingTimeout = setTimeout(() => {
|
|
84
90
|
this.adapter.ratingTimeout = null;
|
|
85
|
-
this.updateRatings(uuid, true)
|
|
86
|
-
.then(() => this.adapter.log.info('Adapter rating updated'));
|
|
91
|
+
this.updateRatings(uuid, true).then(() => this.adapter.log.info('Adapter rating updated'));
|
|
87
92
|
}, 24 * 3600000);
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
return this.adapter._ratings;
|
|
91
96
|
} catch (error) {
|
|
92
|
-
this.adapter.log.warn(
|
|
97
|
+
this.adapter.log.warn(
|
|
98
|
+
'Cannot update rating: ' + (error.response ? error.response.data : error.message || error.code)
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
_readInstanceConfig(id, user, isTab, configs) {
|
|
97
104
|
return new Promise(resolve =>
|
|
98
|
-
this.adapter.getForeignObject(`system.adapter.${id}`, {user}, (error, obj) => {
|
|
105
|
+
this.adapter.getForeignObject(`system.adapter.${id}`, { user }, (error, obj) => {
|
|
99
106
|
if (obj && obj.common) {
|
|
100
107
|
const instance = id.split('.').pop();
|
|
101
108
|
const config = {
|
|
102
109
|
id,
|
|
103
|
-
title:
|
|
104
|
-
desc:
|
|
105
|
-
color:
|
|
106
|
-
url:
|
|
107
|
-
|
|
110
|
+
title: obj.common.titleLang || obj.common.title,
|
|
111
|
+
desc: obj.common.desc,
|
|
112
|
+
color: obj.common.color,
|
|
113
|
+
url: `/adapter/${obj.common.name}/${isTab ? 'tab' : 'index'}${
|
|
114
|
+
!isTab && obj.common.materialize ? '_m' : ''
|
|
115
|
+
}.html${instance ? `?${instance}` : ''}`,
|
|
116
|
+
icon: obj.common.icon,
|
|
108
117
|
materialize: obj.common.materialize,
|
|
109
|
-
jsonConfig:
|
|
110
|
-
version:
|
|
118
|
+
jsonConfig: obj.common.jsonConfig,
|
|
119
|
+
version: obj.common.version
|
|
111
120
|
};
|
|
112
121
|
if (isTab) {
|
|
113
122
|
config.tab = true;
|
|
@@ -123,14 +132,18 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
123
132
|
configs.push(config);
|
|
124
133
|
}
|
|
125
134
|
resolve();
|
|
126
|
-
})
|
|
135
|
+
})
|
|
136
|
+
);
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
_sendToHost(host, command, message, callback) {
|
|
130
140
|
const hash = `${host}_${command}`;
|
|
131
141
|
if (!message && SocketCommandsAdmin.ALLOW_CACHE.includes(command) && this.cache[hash]) {
|
|
132
142
|
if (Date.now() - this.cache[hash].ts < 500) {
|
|
133
|
-
return
|
|
143
|
+
return (
|
|
144
|
+
typeof callback === 'function' &&
|
|
145
|
+
setImmediate(data => callback(data), JSON.parse(this.cache[hash].res))
|
|
146
|
+
);
|
|
134
147
|
} else {
|
|
135
148
|
delete this.cache[hash];
|
|
136
149
|
}
|
|
@@ -139,20 +152,22 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
139
152
|
try {
|
|
140
153
|
this.adapter.sendToHost(host, command, message, res => {
|
|
141
154
|
if (!message && SocketCommandsAdmin.ALLOW_CACHE.includes(command)) {
|
|
142
|
-
this.cache[hash] = {ts: Date.now(), res: JSON.stringify(res)};
|
|
143
|
-
|
|
144
|
-
this.cacheGB =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
this.cache[hash] = { ts: Date.now(), res: JSON.stringify(res) };
|
|
156
|
+
|
|
157
|
+
this.cacheGB =
|
|
158
|
+
this.cacheGB ||
|
|
159
|
+
setInterval(() => {
|
|
160
|
+
const commands = Object.keys(this.cache);
|
|
161
|
+
commands.forEach(cmd => {
|
|
162
|
+
if (Date.now() - this.cache[cmd].ts > 500) {
|
|
163
|
+
delete this.cache[cmd];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
if (!commands.length) {
|
|
167
|
+
clearInterval(this.cacheGB);
|
|
168
|
+
this.cacheGB = null;
|
|
149
169
|
}
|
|
150
|
-
});
|
|
151
|
-
if (!commands.length) {
|
|
152
|
-
clearInterval(this.cacheGB);
|
|
153
|
-
this.cacheGB = null;
|
|
154
|
-
}
|
|
155
|
-
}, 2000);
|
|
170
|
+
}, 2000);
|
|
156
171
|
}
|
|
157
172
|
typeof callback === 'function' && setImmediate(() => callback(res));
|
|
158
173
|
});
|
|
@@ -170,17 +185,27 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
170
185
|
validateStatus: status => status < 400
|
|
171
186
|
};
|
|
172
187
|
|
|
173
|
-
return axios
|
|
188
|
+
return axios
|
|
189
|
+
.get(`https://iobroker.net:3001/api/v1/licenses`, config)
|
|
174
190
|
.then(response => {
|
|
175
191
|
if (response.data && response.data.length) {
|
|
176
192
|
const now = Date.now();
|
|
177
|
-
response.data = response.data.filter(
|
|
193
|
+
response.data = response.data.filter(
|
|
194
|
+
license =>
|
|
195
|
+
!license.validTill ||
|
|
196
|
+
license.validTill === '0000-00-00 00:00:00' ||
|
|
197
|
+
new Date(license.validTill).getTime() > now
|
|
198
|
+
);
|
|
178
199
|
}
|
|
179
200
|
return response.data;
|
|
180
201
|
})
|
|
181
202
|
.catch(error => {
|
|
182
203
|
if (error.response) {
|
|
183
|
-
throw new Error(
|
|
204
|
+
throw new Error(
|
|
205
|
+
(error.response.data && error.response.data.error) ||
|
|
206
|
+
error.response.data ||
|
|
207
|
+
error.response.status
|
|
208
|
+
);
|
|
184
209
|
} else if (error.request) {
|
|
185
210
|
throw new Error('no response');
|
|
186
211
|
} else {
|
|
@@ -196,76 +221,100 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
196
221
|
return this._readLicenses(login, password);
|
|
197
222
|
} else {
|
|
198
223
|
// get actual object
|
|
199
|
-
return this.adapter.getForeignObjectAsync('system.licenses', options)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
return this.adapter.getForeignObjectAsync('system.licenses', options).then(systemLicenses => {
|
|
225
|
+
// If password and login exist
|
|
226
|
+
if (
|
|
227
|
+
systemLicenses &&
|
|
228
|
+
systemLicenses.native &&
|
|
229
|
+
systemLicenses.native.password &&
|
|
230
|
+
systemLicenses.native.login
|
|
231
|
+
) {
|
|
232
|
+
// get the secret to decode the password
|
|
233
|
+
return this.adapter
|
|
234
|
+
.getForeignObjectAsync('system.config', options)
|
|
235
|
+
.then(systemConfig => {
|
|
236
|
+
// decode the password
|
|
237
|
+
let password;
|
|
238
|
+
try {
|
|
239
|
+
password = this.adapter.decrypt(
|
|
240
|
+
systemConfig.native.secret,
|
|
241
|
+
systemLicenses.native.password
|
|
242
|
+
);
|
|
243
|
+
} catch {
|
|
244
|
+
throw new Error('Cannot decode password');
|
|
245
|
+
}
|
|
213
246
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
247
|
+
// read licenses from iobroker.net
|
|
248
|
+
return this._readLicenses(systemLicenses.native.login, password);
|
|
249
|
+
})
|
|
250
|
+
.then(licenses => {
|
|
251
|
+
// save licenses to system.licenses and remember the time
|
|
252
|
+
// merge the information together
|
|
253
|
+
const oldLicenses = systemLicenses.native.licenses || [];
|
|
254
|
+
systemLicenses.native.licenses = licenses;
|
|
255
|
+
oldLicenses.forEach(oldLicense => {
|
|
256
|
+
if (oldLicense.usedBy) {
|
|
257
|
+
const newLicense = licenses.find(item => item.json === oldLicense.json);
|
|
258
|
+
if (newLicense) {
|
|
259
|
+
newLicense.usedBy = oldLicense.usedBy;
|
|
228
260
|
}
|
|
229
|
-
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
230
263
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
264
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
265
|
+
|
|
266
|
+
// save only if an object changed
|
|
267
|
+
return this.adapter
|
|
268
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
269
|
+
.then(() => licenses);
|
|
270
|
+
})
|
|
271
|
+
.catch(error => {
|
|
272
|
+
// if password is invalid
|
|
273
|
+
if (
|
|
274
|
+
error.message.includes('Authentication required') ||
|
|
275
|
+
error.message.includes('Cannot decode password')
|
|
276
|
+
) {
|
|
277
|
+
// clear existing licenses if exist
|
|
278
|
+
if (
|
|
279
|
+
systemLicenses &&
|
|
280
|
+
systemLicenses.native &&
|
|
281
|
+
systemLicenses.native.licenses &&
|
|
282
|
+
systemLicenses.native.licenses.length
|
|
283
|
+
) {
|
|
284
|
+
systemLicenses.native.licenses = [];
|
|
285
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
286
|
+
return this.adapter
|
|
287
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
288
|
+
.then(() => {
|
|
289
|
+
throw error;
|
|
290
|
+
});
|
|
251
291
|
} else {
|
|
252
292
|
throw error;
|
|
253
293
|
}
|
|
294
|
+
} else {
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
// if password or login are empty => clear existing licenses if exist
|
|
300
|
+
if (
|
|
301
|
+
systemLicenses &&
|
|
302
|
+
systemLicenses.native &&
|
|
303
|
+
systemLicenses.native.licenses &&
|
|
304
|
+
systemLicenses.native.licenses.length
|
|
305
|
+
) {
|
|
306
|
+
systemLicenses.native.licenses = [];
|
|
307
|
+
systemLicenses.native.readTime = new Date().toISOString();
|
|
308
|
+
return this.adapter
|
|
309
|
+
.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
310
|
+
.then(() => {
|
|
311
|
+
throw new Error('No password or login');
|
|
254
312
|
});
|
|
255
313
|
} else {
|
|
256
|
-
|
|
257
|
-
if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
|
|
258
|
-
systemLicenses.native.licenses = [];
|
|
259
|
-
systemLicenses.native.readTime = new Date().toISOString();
|
|
260
|
-
return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
|
|
261
|
-
.then(() => {
|
|
262
|
-
throw new Error('No password or login');
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
throw new Error('No password or login');
|
|
266
|
-
}
|
|
314
|
+
throw new Error('No password or login');
|
|
267
315
|
}
|
|
268
|
-
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
269
318
|
}
|
|
270
319
|
}
|
|
271
320
|
|
|
@@ -277,15 +326,19 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
277
326
|
this.eventsThreshold.timeActivated = 0;
|
|
278
327
|
this.adapter.log.info('Subscribe to all states again');
|
|
279
328
|
|
|
280
|
-
setTimeout(async() => {
|
|
329
|
+
setTimeout(async () => {
|
|
281
330
|
this.onThresholdChanged && this.onThresholdChanged(false);
|
|
282
|
-
|
|
331
|
+
try {
|
|
332
|
+
await this.adapter.unsubscribeForeignStatesAsync('system.adapter.*');
|
|
333
|
+
} catch (e) {
|
|
334
|
+
this.adapter.log.error(`Cannot unsubscribe "system.adapter.*": ${e.message}`);
|
|
335
|
+
}
|
|
283
336
|
|
|
284
337
|
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
285
338
|
try {
|
|
286
|
-
await this.adapter.subscribeForeignStatesAsync(pattern)
|
|
339
|
+
await this.adapter.subscribeForeignStatesAsync(pattern);
|
|
287
340
|
} catch (e) {
|
|
288
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
341
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
289
342
|
}
|
|
290
343
|
}
|
|
291
344
|
}, 50);
|
|
@@ -297,20 +350,26 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
297
350
|
this.eventsThreshold.active = true;
|
|
298
351
|
|
|
299
352
|
setTimeout(async () => {
|
|
300
|
-
this.adapter.log.info(
|
|
353
|
+
this.adapter.log.info(
|
|
354
|
+
`Unsubscribe from all states, except system's, because over ${this.eventsThreshold.repeatSeconds} seconds the number of events is over ${this.eventsThreshold.value} (in last second ${this.eventsThreshold.count})`
|
|
355
|
+
);
|
|
301
356
|
this.eventsThreshold.timeActivated = Date.now();
|
|
302
357
|
|
|
303
358
|
this.onThresholdChanged && this.onThresholdChanged(true);
|
|
304
359
|
|
|
305
360
|
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
306
361
|
try {
|
|
307
|
-
await this.adapter.unsubscribeForeignStatesAsync(pattern)
|
|
362
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern);
|
|
308
363
|
} catch (e) {
|
|
309
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
364
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
310
365
|
}
|
|
311
366
|
}
|
|
312
367
|
|
|
313
|
-
|
|
368
|
+
try {
|
|
369
|
+
await this.adapter.subscribeForeignStatesAsync('system.adapter.*');
|
|
370
|
+
} catch (e) {
|
|
371
|
+
this.adapter.log.error(`Cannot subscribe "system.adapter.*": ${e.message}`);
|
|
372
|
+
}
|
|
314
373
|
}, 100);
|
|
315
374
|
}
|
|
316
375
|
}
|
|
@@ -322,7 +381,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
322
381
|
}
|
|
323
382
|
|
|
324
383
|
if (!user.match(/^[-.A-Za-züäößÖÄÜа-яА-Я@+$§0-9=?!&# ]+$/)) {
|
|
325
|
-
return SocketCommands._fixCallback(
|
|
384
|
+
return SocketCommands._fixCallback(
|
|
385
|
+
callback,
|
|
386
|
+
'Invalid characters in the name. Only following special characters are allowed: -@+$§=?!&# and letters'
|
|
387
|
+
);
|
|
326
388
|
}
|
|
327
389
|
|
|
328
390
|
try {
|
|
@@ -331,21 +393,26 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
331
393
|
SocketCommands._fixCallback(callback, 'User yet exists');
|
|
332
394
|
} else {
|
|
333
395
|
try {
|
|
334
|
-
this.adapter.setForeignObject(
|
|
396
|
+
this.adapter.setForeignObject(
|
|
397
|
+
`system.user.${user}`,
|
|
398
|
+
{
|
|
335
399
|
type: 'user',
|
|
336
400
|
common: {
|
|
337
401
|
name: user,
|
|
338
402
|
enabled: true,
|
|
339
403
|
groups: []
|
|
340
404
|
}
|
|
341
|
-
},
|
|
405
|
+
},
|
|
406
|
+
options,
|
|
407
|
+
() => {
|
|
342
408
|
try {
|
|
343
409
|
this.adapter.setPassword(user, pw, options, callback);
|
|
344
410
|
} catch (error) {
|
|
345
411
|
this.adapter.log.error(`[_addUser] cannot set password: ${error.toString()}`);
|
|
346
412
|
SocketCommands._fixCallback(callback, error);
|
|
347
413
|
}
|
|
348
|
-
}
|
|
414
|
+
}
|
|
415
|
+
);
|
|
349
416
|
} catch (error) {
|
|
350
417
|
this.adapter.log.error(`[_addUser] cannot save user: ${error.toString()}`);
|
|
351
418
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -370,7 +437,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
370
437
|
try {
|
|
371
438
|
this.adapter.delForeignObject(`system.user.${user}`, options, error =>
|
|
372
439
|
// Remove this user from all groups in web client
|
|
373
|
-
SocketCommands._fixCallback(callback, error)
|
|
440
|
+
SocketCommands._fixCallback(callback, error)
|
|
441
|
+
);
|
|
374
442
|
} catch (error) {
|
|
375
443
|
this.adapter.log.error(`[_delUser] cannot delete user: ${error.toString()}`);
|
|
376
444
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -404,7 +472,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
404
472
|
group = group.substring(0, 1).toLowerCase() + group.substring(1);
|
|
405
473
|
|
|
406
474
|
if (!group.match(/^[-.A-Za-züäößÖÄÜа-яА-Я@+$§0-9=?!&#_ ]+$/)) {
|
|
407
|
-
return SocketCommands._fixCallback(
|
|
475
|
+
return SocketCommands._fixCallback(
|
|
476
|
+
callback,
|
|
477
|
+
'Invalid characters in the group name. Only following special characters are allowed: -@+$§=?!&# and letters'
|
|
478
|
+
);
|
|
408
479
|
}
|
|
409
480
|
|
|
410
481
|
try {
|
|
@@ -413,7 +484,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
413
484
|
SocketCommands._fixCallback(callback, 'Group yet exists');
|
|
414
485
|
} else {
|
|
415
486
|
obj = {
|
|
416
|
-
_id:
|
|
487
|
+
_id: 'system.group.' + group,
|
|
417
488
|
type: 'group',
|
|
418
489
|
common: {
|
|
419
490
|
name,
|
|
@@ -424,7 +495,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
424
495
|
};
|
|
425
496
|
try {
|
|
426
497
|
this.adapter.setForeignObject(`system.group.${group}`, obj, options, error =>
|
|
427
|
-
SocketCommands._fixCallback(callback, error, obj)
|
|
498
|
+
SocketCommands._fixCallback(callback, error, obj)
|
|
499
|
+
);
|
|
428
500
|
} catch (error) {
|
|
429
501
|
this.adapter.log.error(`[_addGroup] cannot write group: ${error.toString()}`);
|
|
430
502
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -449,7 +521,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
449
521
|
try {
|
|
450
522
|
this.adapter.delForeignObject(`system.group.${group}`, options, error =>
|
|
451
523
|
// Remove this group from all users in the web client
|
|
452
|
-
SocketCommands._fixCallback(callback, error)
|
|
524
|
+
SocketCommands._fixCallback(callback, error)
|
|
525
|
+
);
|
|
453
526
|
} catch (error) {
|
|
454
527
|
this.adapter.log.error(`[_delGroup] cannot delete group: ${error.toString()}`);
|
|
455
528
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -500,12 +573,17 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
500
573
|
|
|
501
574
|
if (this._checkPermissions(socket, 'getObjects', callback)) {
|
|
502
575
|
if (this.objects) {
|
|
503
|
-
if (
|
|
576
|
+
if (
|
|
577
|
+
socket._acl &&
|
|
504
578
|
socket._acl.user !== 'system.user.admin' &&
|
|
505
|
-
!socket._acl.groups.includes('system.group.administrator')
|
|
579
|
+
!socket._acl.groups.includes('system.group.administrator')
|
|
580
|
+
) {
|
|
506
581
|
const result = {};
|
|
507
582
|
for (const id in this.objects) {
|
|
508
|
-
if (
|
|
583
|
+
if (
|
|
584
|
+
this.objects.hasOwnProperty(id) &&
|
|
585
|
+
SocketCommandsAdmin._checkObject(this.objects[id], socket._acl, 4 /* 'read' */)
|
|
586
|
+
) {
|
|
509
587
|
result[id] = this.objects[id];
|
|
510
588
|
}
|
|
511
589
|
}
|
|
@@ -515,14 +593,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
515
593
|
}
|
|
516
594
|
} else {
|
|
517
595
|
try {
|
|
518
|
-
this.adapter.getObjectList({include_docs: true}, {user: socket._acl.user}, (error, res) => {
|
|
596
|
+
this.adapter.getObjectList({ include_docs: true }, { user: socket._acl.user }, (error, res) => {
|
|
519
597
|
this.adapter.log.info('received all objects');
|
|
520
598
|
res = res.rows;
|
|
521
599
|
const objects = {};
|
|
522
600
|
|
|
523
|
-
if (
|
|
601
|
+
if (
|
|
602
|
+
socket._acl &&
|
|
524
603
|
socket._acl.user !== 'system.user.admin' &&
|
|
525
|
-
!socket._acl.groups.includes('system.group.administrator')
|
|
604
|
+
!socket._acl.groups.includes('system.group.administrator')
|
|
605
|
+
) {
|
|
526
606
|
for (let i = 0; i < res.length; i++) {
|
|
527
607
|
if (SocketCommandsAdmin._checkObject(res[i].doc, socket._acl, 4 /* 'read' */)) {
|
|
528
608
|
objects[res[i].doc._id] = res[i].doc;
|
|
@@ -551,8 +631,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
551
631
|
// @param {string} pass - user password
|
|
552
632
|
// @param {function} callback - `function (error)`
|
|
553
633
|
if (this._checkPermissions(socket, 'addUser', callback, user)) {
|
|
554
|
-
this._addUser(user, pass, {user: socket._acl.user}, (error, ...args) =>
|
|
555
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
634
|
+
this._addUser(user, pass, { user: socket._acl.user }, (error, ...args) =>
|
|
635
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
636
|
+
);
|
|
556
637
|
}
|
|
557
638
|
};
|
|
558
639
|
|
|
@@ -561,8 +642,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
561
642
|
// @param {string} user - user name, like 'benjamin
|
|
562
643
|
// @param {function} callback - `function (error)`
|
|
563
644
|
if (this._checkPermissions(socket, 'delUser', callback, user)) {
|
|
564
|
-
this._delUser(user, {user: socket._acl.user}, (error, ...args) =>
|
|
565
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
645
|
+
this._delUser(user, { user: socket._acl.user }, (error, ...args) =>
|
|
646
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
647
|
+
);
|
|
566
648
|
}
|
|
567
649
|
};
|
|
568
650
|
|
|
@@ -573,8 +655,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
573
655
|
// @param {object} acl - optional access control list object, like `{"object":{"list":true,"read":true,"write":false,"delete":false},"state":{"list":true,"read":true,"write":true,"create":true,"delete":false},"users":{"list":true,"read":true,"write":false,"create":false,"delete":false},"other":{"execute":false,"http":true,"sendto":false},"file":{"list":true,"read":true,"write":false,"create":false,"delete":false}}`
|
|
574
656
|
// @param {function} callback - `function (error)`
|
|
575
657
|
if (this._checkPermissions(socket, 'addGroup', callback, group)) {
|
|
576
|
-
this._addGroup(group, desc, acl, {user: socket._acl.user}, (error, ...args) =>
|
|
577
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
658
|
+
this._addGroup(group, desc, acl, { user: socket._acl.user }, (error, ...args) =>
|
|
659
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
660
|
+
);
|
|
578
661
|
}
|
|
579
662
|
};
|
|
580
663
|
|
|
@@ -583,8 +666,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
583
666
|
// @param {string} group - group name, like 'users`
|
|
584
667
|
// @param {function} callback - `function (error)`
|
|
585
668
|
if (this._checkPermissions(socket, 'delGroup', callback, group)) {
|
|
586
|
-
this._delGroup(group, {user: socket._acl.user}, (error, ...args) =>
|
|
587
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
669
|
+
this._delGroup(group, { user: socket._acl.user }, (error, ...args) =>
|
|
670
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
671
|
+
);
|
|
588
672
|
}
|
|
589
673
|
};
|
|
590
674
|
|
|
@@ -595,8 +679,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
595
679
|
// @param {function} callback - `function (error)`
|
|
596
680
|
if (user === socket._acl.user || this._checkPermissions(socket, 'changePassword', callback, user)) {
|
|
597
681
|
try {
|
|
598
|
-
this.adapter.setPassword(user, pass, {user: socket._acl.user}, (error, ...args) =>
|
|
599
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
682
|
+
this.adapter.setPassword(user, pass, { user: socket._acl.user }, (error, ...args) =>
|
|
683
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
684
|
+
);
|
|
600
685
|
} catch (error) {
|
|
601
686
|
this.adapter.log.error(`[_changePassword] ERROR: ${error.toString()}`);
|
|
602
687
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -615,16 +700,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
615
700
|
}
|
|
616
701
|
if (this._checkPermissions(socket, 'getHostByIp', ip)) {
|
|
617
702
|
try {
|
|
618
|
-
this.adapter.getObjectView('system', 'host', {}, {user: socket._acl.user}, (error, data) => {
|
|
703
|
+
this.adapter.getObjectView('system', 'host', {}, { user: socket._acl.user }, (error, data) => {
|
|
619
704
|
if (data && data.rows && data.rows.length) {
|
|
620
705
|
for (let i = 0; i < data.rows.length; i++) {
|
|
621
706
|
const obj = data.rows[i].value;
|
|
622
707
|
// if we requested specific name
|
|
623
708
|
if (obj.common.hostname === ip) {
|
|
624
709
|
return callback(ip, obj);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (obj.native.hardware && obj.native.hardware.networkInterfaces) {
|
|
710
|
+
}
|
|
711
|
+
// try to find this IP in the list
|
|
712
|
+
else if (obj.native.hardware && obj.native.hardware.networkInterfaces) {
|
|
628
713
|
const net = obj.native.hardware.networkInterfaces;
|
|
629
714
|
for (const eth in net) {
|
|
630
715
|
if (!Object.prototype.hasOwnProperty.call(net, eth)) {
|
|
@@ -673,7 +758,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
673
758
|
if (this._checkPermissions(socket, 'readLogs', callback)) {
|
|
674
759
|
let timeout = setTimeout(() => {
|
|
675
760
|
if (timeout) {
|
|
676
|
-
let result = {list: []};
|
|
761
|
+
let result = { list: [] };
|
|
677
762
|
|
|
678
763
|
// deliver the file list
|
|
679
764
|
try {
|
|
@@ -681,7 +766,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
681
766
|
// detect file log
|
|
682
767
|
if (config && config.log && config.log.transport) {
|
|
683
768
|
for (const transport in config.log.transport) {
|
|
684
|
-
if (
|
|
769
|
+
if (
|
|
770
|
+
Object.prototype.hasOwnProperty.call(config.log.transport, transport) &&
|
|
771
|
+
config.log.transport[transport].type === 'file'
|
|
772
|
+
) {
|
|
685
773
|
let fileName = config.log.transport[transport].filename || 'log/';
|
|
686
774
|
const parts = fileName.replace(/\\/g, '/').split('/');
|
|
687
775
|
parts.pop();
|
|
@@ -711,18 +799,20 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
711
799
|
} catch (_error) {
|
|
712
800
|
// push unchecked
|
|
713
801
|
// result.list.push('log/' + transport + '/' + files[f]);
|
|
714
|
-
this.adapter.log.error(
|
|
802
|
+
this.adapter.log.error(
|
|
803
|
+
`Cannot check file: ${fileName}/${files[f]}`
|
|
804
|
+
);
|
|
715
805
|
}
|
|
716
806
|
}
|
|
717
807
|
}
|
|
718
808
|
}
|
|
719
809
|
}
|
|
720
810
|
} else {
|
|
721
|
-
result = {error: 'no file loggers'};
|
|
811
|
+
result = { error: 'no file loggers' };
|
|
722
812
|
}
|
|
723
813
|
} catch (error) {
|
|
724
814
|
this.adapter.log.error(`Cannot read logs: ${error}`);
|
|
725
|
-
result = {error};
|
|
815
|
+
result = { error };
|
|
726
816
|
}
|
|
727
817
|
SocketCommands._fixCallback(callback, result.error, result.list);
|
|
728
818
|
}
|
|
@@ -746,8 +836,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
746
836
|
delete this.states[id];
|
|
747
837
|
}
|
|
748
838
|
try {
|
|
749
|
-
this.adapter.delForeignState(id, {user: socket._acl.user}, (error, ...args) =>
|
|
750
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
839
|
+
this.adapter.delForeignState(id, { user: socket._acl.user }, (error, ...args) =>
|
|
840
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
841
|
+
);
|
|
751
842
|
} catch (error) {
|
|
752
843
|
this.adapter.log.error(`[delState] ERROR: ${error.toString()}`);
|
|
753
844
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -766,9 +857,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
766
857
|
if (this._checkPermissions(socket, 'cmdExec', callback, cmd)) {
|
|
767
858
|
this.adapter.log.debug(`cmdExec on ${host}(${id}): ${cmd}`);
|
|
768
859
|
// remember socket for this ID.
|
|
769
|
-
this.cmdSessions[id] = {socket};
|
|
860
|
+
this.cmdSessions[id] = { socket };
|
|
770
861
|
try {
|
|
771
|
-
this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id});
|
|
862
|
+
this.adapter.sendToHost(host, 'cmdExec', { data: cmd, id });
|
|
772
863
|
SocketCommands._fixCallback(callback, null);
|
|
773
864
|
} catch (error) {
|
|
774
865
|
this.adapter.log.error(`[cmdExec] ERROR: ${error.toString()}`);
|
|
@@ -792,8 +883,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
792
883
|
// @param {boolean} update - if true, the ratings will be read from central server, if false from local cache
|
|
793
884
|
// @param {function} callback - `function (error, ratings)`, where `ratings` is object like `{accuweather: {rating: {r: 3.33, c: 3}, 1.2.1: {r: 3, c: 1}},…}`
|
|
794
885
|
if (update || !this.adapter._ratings) {
|
|
795
|
-
this.updateRatings()
|
|
796
|
-
.then(() => SocketCommands._fixCallback(callback, null, this.adapter._ratings));
|
|
886
|
+
this.updateRatings().then(() => SocketCommands._fixCallback(callback, null, this.adapter._ratings));
|
|
797
887
|
} else {
|
|
798
888
|
SocketCommands._fixCallback(callback, null, this.adapter._ratings);
|
|
799
889
|
}
|
|
@@ -813,10 +903,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
813
903
|
SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
|
|
814
904
|
} else {
|
|
815
905
|
try {
|
|
816
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
906
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
817
907
|
if (obj && obj.native && obj.native.secret) {
|
|
818
908
|
this.secret = obj.native.secret;
|
|
819
|
-
SocketCommands._fixCallback(
|
|
909
|
+
SocketCommands._fixCallback(
|
|
910
|
+
callback,
|
|
911
|
+
null,
|
|
912
|
+
this.adapter.decrypt(this.secret, encryptedText)
|
|
913
|
+
);
|
|
820
914
|
} else {
|
|
821
915
|
this.adapter.log.error(`No system.config found: ${error}`);
|
|
822
916
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -836,7 +930,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
836
930
|
if (this.secret) {
|
|
837
931
|
SocketCommands._fixCallback(callback, null, this.adapter.encrypt(this.secret, plainText));
|
|
838
932
|
} else {
|
|
839
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
933
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
840
934
|
if (obj && obj.native && obj.native.secret) {
|
|
841
935
|
this.secret = obj.native.secret;
|
|
842
936
|
try {
|
|
@@ -876,44 +970,59 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
876
970
|
}
|
|
877
971
|
|
|
878
972
|
if (this.adapter.config.accessLimit) {
|
|
879
|
-
const configs
|
|
973
|
+
const configs = [];
|
|
880
974
|
const promises = [];
|
|
881
|
-
this.adapter.config.accessAllowedConfigs.forEach(id =>
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
975
|
+
this.adapter.config.accessAllowedConfigs.forEach(id =>
|
|
976
|
+
promises.push(this._readInstanceConfig(id, user, false, configs))
|
|
977
|
+
);
|
|
978
|
+
this.adapter.config.accessAllowedTabs.forEach(id =>
|
|
979
|
+
promises.push(this._readInstanceConfig(id, user, true, configs))
|
|
980
|
+
);
|
|
981
|
+
|
|
982
|
+
Promise.all(promises).then(() => {
|
|
983
|
+
callback(null, {
|
|
984
|
+
strict: true,
|
|
985
|
+
configs
|
|
890
986
|
});
|
|
987
|
+
});
|
|
891
988
|
} else {
|
|
892
|
-
this.adapter.getObjectView(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
989
|
+
this.adapter.getObjectView(
|
|
990
|
+
'system',
|
|
991
|
+
'instance',
|
|
992
|
+
{ startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' },
|
|
993
|
+
{ user },
|
|
994
|
+
(error, doc) => {
|
|
995
|
+
const promises = [];
|
|
996
|
+
const configs = [];
|
|
997
|
+
if (!error && doc.rows.length) {
|
|
998
|
+
for (let i = 0; i < doc.rows.length; i++) {
|
|
999
|
+
const obj = doc.rows[i].value;
|
|
1000
|
+
if (obj.common.noConfig && !obj.common.adminTab) {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (!obj.common.enabled) {
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
if (!obj.common.noConfig) {
|
|
1007
|
+
promises.push(
|
|
1008
|
+
this._readInstanceConfig(
|
|
1009
|
+
obj._id.substring('system.adapter.'.length),
|
|
1010
|
+
user,
|
|
1011
|
+
false,
|
|
1012
|
+
configs
|
|
1013
|
+
)
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
906
1016
|
}
|
|
907
1017
|
}
|
|
908
|
-
|
|
909
|
-
Promise.all(promises)
|
|
910
|
-
.then(() =>
|
|
1018
|
+
Promise.all(promises).then(() =>
|
|
911
1019
|
callback(null, {
|
|
912
1020
|
strict: false,
|
|
913
|
-
configs
|
|
1021
|
+
configs
|
|
914
1022
|
})
|
|
915
1023
|
);
|
|
916
|
-
|
|
1024
|
+
}
|
|
1025
|
+
);
|
|
917
1026
|
}
|
|
918
1027
|
}
|
|
919
1028
|
};
|
|
@@ -923,27 +1032,39 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
923
1032
|
// @param {string} adapterName - optional adapter name
|
|
924
1033
|
// @param {function} callback - `function (error, results)`, where `results` is array of objects like `{_id: 'system.adapter.javascript', common: {...}}`
|
|
925
1034
|
if (typeof callback === 'function' && this._checkPermissions(socket, 'getObject', callback)) {
|
|
926
|
-
this.adapter.getObjectView(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
(error, doc) =>
|
|
1035
|
+
this.adapter.getObjectView(
|
|
1036
|
+
'system',
|
|
1037
|
+
'adapter',
|
|
930
1038
|
{
|
|
1039
|
+
startkey: `system.adapter.${adapterName || ''}`,
|
|
1040
|
+
endkey: `system.adapter.${adapterName || '\u9999'}`
|
|
1041
|
+
},
|
|
1042
|
+
{ user: socket._acl.user },
|
|
1043
|
+
(error, doc) => {
|
|
931
1044
|
if (error) {
|
|
932
1045
|
callback(error);
|
|
933
1046
|
} else {
|
|
934
|
-
callback(
|
|
935
|
-
|
|
936
|
-
.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1047
|
+
callback(
|
|
1048
|
+
null,
|
|
1049
|
+
doc.rows
|
|
1050
|
+
.filter(
|
|
1051
|
+
obj =>
|
|
1052
|
+
obj &&
|
|
1053
|
+
(!adapterName || (obj.common && obj.common.name === this.adapterName))
|
|
1054
|
+
)
|
|
1055
|
+
.map(item => {
|
|
1056
|
+
const obj = item.value;
|
|
1057
|
+
if (obj.common) {
|
|
1058
|
+
delete obj.common.news;
|
|
1059
|
+
delete obj.native;
|
|
1060
|
+
}
|
|
1061
|
+
this._fixAdminUI(obj);
|
|
1062
|
+
return obj;
|
|
1063
|
+
})
|
|
1064
|
+
);
|
|
945
1065
|
}
|
|
946
|
-
}
|
|
1066
|
+
}
|
|
1067
|
+
);
|
|
947
1068
|
}
|
|
948
1069
|
};
|
|
949
1070
|
|
|
@@ -961,7 +1082,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
961
1082
|
}
|
|
962
1083
|
}, 7000);
|
|
963
1084
|
|
|
964
|
-
this._sendToHost(this.adapter.common.host, 'updateLicenses', {login, password}, result => {
|
|
1085
|
+
this._sendToHost(this.adapter.common.host, 'updateLicenses', { login, password }, result => {
|
|
965
1086
|
if (timeout) {
|
|
966
1087
|
clearTimeout(timeout);
|
|
967
1088
|
timeout = null;
|
|
@@ -970,7 +1091,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
970
1091
|
});
|
|
971
1092
|
} else {
|
|
972
1093
|
// remove this branch when js-controller 4.x will be mainstream
|
|
973
|
-
this._updateLicenses(login, password, {user: socket._acl.user})
|
|
1094
|
+
this._updateLicenses(login, password, { user: socket._acl.user })
|
|
974
1095
|
.then(licenses => SocketCommands._fixCallback(callback, null, licenses))
|
|
975
1096
|
.catch(error => SocketCommands._fixCallback(callback, error));
|
|
976
1097
|
}
|
|
@@ -982,9 +1103,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
982
1103
|
// @param {function} callback - `function (error, results)`, where `results` is an object like `{'system.adapter.javascript.0': {adminTab, name, icon, enabled}}`
|
|
983
1104
|
if (typeof callback === 'function') {
|
|
984
1105
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
985
|
-
this.adapter.getObjectView(
|
|
986
|
-
|
|
987
|
-
|
|
1106
|
+
this.adapter.getObjectView(
|
|
1107
|
+
'system',
|
|
1108
|
+
'instance',
|
|
1109
|
+
{ startkey: `system.adapter.`, endkey: `system.adapter.\u9999` },
|
|
1110
|
+
{ user: socket._acl.user },
|
|
988
1111
|
(error, doc) => {
|
|
989
1112
|
if (error) {
|
|
990
1113
|
callback(error);
|
|
@@ -998,13 +1121,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
998
1121
|
adminTab: obj.common.adminTab,
|
|
999
1122
|
name: obj.common.name,
|
|
1000
1123
|
icon: obj.common.icon,
|
|
1001
|
-
enabled: obj.common.enabled
|
|
1124
|
+
enabled: obj.common.enabled
|
|
1002
1125
|
};
|
|
1003
1126
|
});
|
|
1004
1127
|
|
|
1005
1128
|
callback(null, result);
|
|
1006
1129
|
}
|
|
1007
|
-
}
|
|
1130
|
+
}
|
|
1131
|
+
);
|
|
1008
1132
|
}
|
|
1009
1133
|
}
|
|
1010
1134
|
};
|
|
@@ -1014,9 +1138,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1014
1138
|
// @param {function} callback - `function (error, results)`, where `results` is an object like `{'javascript': {icon, v: '1.0.1', iv: 'ignoredVersion}}`
|
|
1015
1139
|
if (typeof callback === 'function') {
|
|
1016
1140
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1017
|
-
this.adapter.getObjectView(
|
|
1018
|
-
|
|
1019
|
-
|
|
1141
|
+
this.adapter.getObjectView(
|
|
1142
|
+
'system',
|
|
1143
|
+
'adapter',
|
|
1144
|
+
{ startkey: `system.adapter.`, endkey: `system.adapter.\u9999` },
|
|
1145
|
+
{ user: socket._acl.user },
|
|
1020
1146
|
(error, doc) => {
|
|
1021
1147
|
if (error) {
|
|
1022
1148
|
callback(error);
|
|
@@ -1027,7 +1153,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1027
1153
|
doc.rows.forEach(item => {
|
|
1028
1154
|
const obj = item.value;
|
|
1029
1155
|
if (obj && obj.common && obj.common.name) {
|
|
1030
|
-
result[obj.common.name] = {icon: obj.common.icon, v: obj.common.version};
|
|
1156
|
+
result[obj.common.name] = { icon: obj.common.icon, v: obj.common.version };
|
|
1031
1157
|
if (obj.common.ignoreVersion) {
|
|
1032
1158
|
result[obj.common.name].iv = obj.common.ignoreVersion;
|
|
1033
1159
|
}
|
|
@@ -1036,7 +1162,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1036
1162
|
|
|
1037
1163
|
callback(null, result);
|
|
1038
1164
|
}
|
|
1039
|
-
}
|
|
1165
|
+
}
|
|
1166
|
+
);
|
|
1040
1167
|
}
|
|
1041
1168
|
}
|
|
1042
1169
|
};
|
|
@@ -1048,7 +1175,7 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1048
1175
|
if (this._checkPermissions(socket, 'sendToHost', callback)) {
|
|
1049
1176
|
this._sendToHost(host, 'getInstalled', null, data => {
|
|
1050
1177
|
const result = {};
|
|
1051
|
-
Object.keys(data).forEach(name => result[name] = {version: data[name].version});
|
|
1178
|
+
Object.keys(data).forEach(name => (result[name] = { version: data[name].version }));
|
|
1052
1179
|
callback(result);
|
|
1053
1180
|
});
|
|
1054
1181
|
}
|
|
@@ -1059,12 +1186,12 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1059
1186
|
// Read system config in short form to save bandwidth
|
|
1060
1187
|
// @param {function} callback - `function (error, systemConfig)`, where `systemConfig` is an object like `{common: {...}, native: {secret: 'aaa'}}`
|
|
1061
1188
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1062
|
-
this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
|
|
1189
|
+
this.adapter.getForeignObject('system.config', { user: socket._acl.user }, (error, obj) => {
|
|
1063
1190
|
obj = obj || {};
|
|
1064
1191
|
const secret = obj && obj.native && obj.native.secret;
|
|
1065
1192
|
delete obj.native;
|
|
1066
1193
|
if (secret) {
|
|
1067
|
-
obj.native = {secret};
|
|
1194
|
+
obj.native = { secret };
|
|
1068
1195
|
}
|
|
1069
1196
|
callback(error, obj);
|
|
1070
1197
|
});
|
|
@@ -1075,15 +1202,18 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1075
1202
|
// Read repositories from cache in short form to save bandwidth
|
|
1076
1203
|
// @param {function} callback - `function (error, repositories)`, where `repositories` is an object like `{_id: 'system.repositories', common: {...}, native: {repositories: {default: {json: {_repoInfo: {...}}}}}}`
|
|
1077
1204
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1078
|
-
this.adapter.getForeignObject('system.repositories', {user: socket._acl.user}, (error, obj) => {
|
|
1079
|
-
obj &&
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1205
|
+
this.adapter.getForeignObject('system.repositories', { user: socket._acl.user }, (error, obj) => {
|
|
1206
|
+
obj &&
|
|
1207
|
+
obj.native &&
|
|
1208
|
+
obj.native.repositories &&
|
|
1209
|
+
Object.keys(obj.native.repositories).forEach(name => {
|
|
1210
|
+
if (obj.native.repositories[name].json) {
|
|
1211
|
+
// limit information to _repoInfo
|
|
1212
|
+
obj.native.repositories[name].json = {
|
|
1213
|
+
_repoInfo: obj.native.repositories[name].json._repoInfo
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1087
1217
|
callback(error, obj);
|
|
1088
1218
|
});
|
|
1089
1219
|
}
|
|
@@ -1096,10 +1226,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1096
1226
|
this._sendToHost(host, 'getRepository', null, data => {
|
|
1097
1227
|
// Extract only the version and icon
|
|
1098
1228
|
const result = {};
|
|
1099
|
-
data &&
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1229
|
+
data &&
|
|
1230
|
+
Object.keys(data).forEach(
|
|
1231
|
+
name =>
|
|
1232
|
+
(result[name] = {
|
|
1233
|
+
version: data[name].version,
|
|
1234
|
+
icon: data[name].extIcon
|
|
1235
|
+
})
|
|
1236
|
+
);
|
|
1103
1237
|
callback(result);
|
|
1104
1238
|
});
|
|
1105
1239
|
}
|
|
@@ -1109,9 +1243,11 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1109
1243
|
// Read all hosts in short form to save bandwidth
|
|
1110
1244
|
// @param {function} callback - `function (error, hosts)`, where `hosts` is an array of objects like `[{_id:'system.host.raspi',common:{name:'raspi',icon:'icon',color:'blue',installedVersion:'2.1.0'},native:{hardware:{networkInterfaces:[...]}}}]`
|
|
1111
1245
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1112
|
-
this.adapter.getObjectView(
|
|
1113
|
-
|
|
1114
|
-
|
|
1246
|
+
this.adapter.getObjectView(
|
|
1247
|
+
'system',
|
|
1248
|
+
'host',
|
|
1249
|
+
{ startkey: 'system.host.', endkey: 'system.host.\u9999' },
|
|
1250
|
+
{ user: socket._acl.user },
|
|
1115
1251
|
(error, doc) => {
|
|
1116
1252
|
if (error) {
|
|
1117
1253
|
callback(error);
|
|
@@ -1131,15 +1267,20 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1131
1267
|
},
|
|
1132
1268
|
native: {
|
|
1133
1269
|
hardware: {
|
|
1134
|
-
networkInterfaces:
|
|
1270
|
+
networkInterfaces:
|
|
1271
|
+
(host.native &&
|
|
1272
|
+
host.native.hardware &&
|
|
1273
|
+
host.native.hardware.networkInterfaces) ||
|
|
1274
|
+
undefined
|
|
1135
1275
|
}
|
|
1136
1276
|
}
|
|
1137
1277
|
});
|
|
1138
1278
|
}
|
|
1139
|
-
})
|
|
1279
|
+
});
|
|
1140
1280
|
callback(null, result);
|
|
1141
1281
|
}
|
|
1142
|
-
}
|
|
1282
|
+
}
|
|
1283
|
+
);
|
|
1143
1284
|
}
|
|
1144
1285
|
};
|
|
1145
1286
|
}
|
|
@@ -1164,15 +1305,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1164
1305
|
if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
|
|
1165
1306
|
if (typeof options === 'function') {
|
|
1166
1307
|
callback = options;
|
|
1167
|
-
options = {user: socket._acl.user};
|
|
1308
|
+
options = { user: socket._acl.user };
|
|
1168
1309
|
}
|
|
1169
1310
|
options = options || {};
|
|
1170
1311
|
options.user = socket._acl.user;
|
|
1171
1312
|
|
|
1172
1313
|
try {
|
|
1173
1314
|
const buffer = Buffer.from(data64, 'base64');
|
|
1174
|
-
this.adapter.writeFile(_adapter, fileName, buffer, {user: socket._acl.user}, (error, ...args) =>
|
|
1175
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1315
|
+
this.adapter.writeFile(_adapter, fileName, buffer, { user: socket._acl.user }, (error, ...args) =>
|
|
1316
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1317
|
+
);
|
|
1176
1318
|
} catch (error) {
|
|
1177
1319
|
this.adapter.log.error(`[writeFile] Cannot convert data: ${error.toString()}`);
|
|
1178
1320
|
callback && callback(`Cannot convert data: ${error.toString()}`);
|
|
@@ -1188,14 +1330,14 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1188
1330
|
// Read absolutely all objects
|
|
1189
1331
|
// @param {function} callback - `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
1190
1332
|
return this._getAllObjects(socket, callback);
|
|
1191
|
-
}
|
|
1333
|
+
};
|
|
1192
1334
|
|
|
1193
1335
|
// Identical to getAllObjects
|
|
1194
1336
|
this.commands['getObjects'] = (socket, callback) => {
|
|
1195
1337
|
// Read absolutely all objects. Same as `getAllObjects`.
|
|
1196
1338
|
// @param {function} callback - `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
1197
1339
|
return this._getAllObjects(socket, callback);
|
|
1198
|
-
}
|
|
1340
|
+
};
|
|
1199
1341
|
|
|
1200
1342
|
this.commands['extendObject'] = (socket, id, obj, callback) => {
|
|
1201
1343
|
// Extend the existing object
|
|
@@ -1204,8 +1346,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1204
1346
|
// @param {function} callback - `function (error)`
|
|
1205
1347
|
if (this._checkPermissions(socket, 'extendObject', callback, id)) {
|
|
1206
1348
|
try {
|
|
1207
|
-
this.adapter.extendForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>
|
|
1208
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1349
|
+
this.adapter.extendForeignObject(id, obj, { user: socket._acl.user }, (error, ...args) =>
|
|
1350
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1351
|
+
);
|
|
1209
1352
|
} catch (error) {
|
|
1210
1353
|
this.adapter.log.error(`[extendObject] ERROR: ${error}`);
|
|
1211
1354
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1226,8 +1369,9 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1226
1369
|
|
|
1227
1370
|
if (typeof callback === 'function') {
|
|
1228
1371
|
try {
|
|
1229
|
-
this.adapter.getForeignObjects(pattern, type, {user: socket._acl.user}, (error, ...args) =>
|
|
1230
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1372
|
+
this.adapter.getForeignObjects(pattern, type, { user: socket._acl.user }, (error, ...args) =>
|
|
1373
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1374
|
+
);
|
|
1231
1375
|
} catch (error) {
|
|
1232
1376
|
this.adapter.log.error(`[extendObject] ERROR: ${error}`);
|
|
1233
1377
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1255,7 +1399,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1255
1399
|
try {
|
|
1256
1400
|
// options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1257
1401
|
this.adapter.delForeignObject(id, options, (error, ...args) =>
|
|
1258
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1402
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1403
|
+
);
|
|
1259
1404
|
} catch (error) {
|
|
1260
1405
|
this.adapter.log.error(`[delObject] ERROR: ${error}`);
|
|
1261
1406
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1276,7 +1421,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1276
1421
|
options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1277
1422
|
try {
|
|
1278
1423
|
this.adapter.delForeignObject(id, options, (error, ...args) =>
|
|
1279
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1424
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1425
|
+
);
|
|
1280
1426
|
} catch (error) {
|
|
1281
1427
|
this.adapter.log.error(`[delObjects] ERROR: ${error}`);
|
|
1282
1428
|
SocketCommands._fixCallback(callback, error);
|