@iobroker/socket-classes 1.4.1 → 1.4.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/README.md +7 -1
- package/lib/socketCommands.js +328 -225
- package/lib/socketCommandsAdmin.js +379 -241
- package/lib/socketCommon.js +76 -52
- package/package.json +6 -5
package/lib/socketCommands.js
CHANGED
|
@@ -6,65 +6,65 @@ let zipFiles = null;
|
|
|
6
6
|
class SocketCommands {
|
|
7
7
|
static ERROR_PERMISSION = 'permissionError';
|
|
8
8
|
static COMMANDS_PERMISSIONS = {
|
|
9
|
-
getObject:
|
|
10
|
-
getObjects:
|
|
11
|
-
getObjectView:
|
|
12
|
-
setObject:
|
|
13
|
-
requireLog:
|
|
14
|
-
delObject:
|
|
15
|
-
extendObject:
|
|
16
|
-
getHostByIp:
|
|
17
|
-
subscribeObjects:
|
|
18
|
-
unsubscribeObjects: {type: 'object',
|
|
19
|
-
|
|
20
|
-
getStates:
|
|
21
|
-
getState:
|
|
22
|
-
setState:
|
|
23
|
-
delState:
|
|
24
|
-
createState:
|
|
25
|
-
subscribe:
|
|
26
|
-
unsubscribe:
|
|
27
|
-
getStateHistory:
|
|
28
|
-
getVersion:
|
|
29
|
-
getAdapterName:
|
|
30
|
-
|
|
31
|
-
addUser:
|
|
32
|
-
delUser:
|
|
33
|
-
addGroup:
|
|
34
|
-
delGroup:
|
|
35
|
-
changePassword:
|
|
36
|
-
|
|
37
|
-
httpGet:
|
|
38
|
-
cmdExec:
|
|
39
|
-
sendTo:
|
|
40
|
-
sendToHost:
|
|
41
|
-
readLogs:
|
|
42
|
-
|
|
43
|
-
readDir:
|
|
44
|
-
createFile:
|
|
45
|
-
writeFile:
|
|
46
|
-
readFile:
|
|
47
|
-
fileExists:
|
|
48
|
-
deleteFile:
|
|
49
|
-
readFile64:
|
|
50
|
-
writeFile64:
|
|
51
|
-
unlink:
|
|
52
|
-
rename:
|
|
53
|
-
mkdir:
|
|
54
|
-
chmodFile:
|
|
55
|
-
chownFile:
|
|
56
|
-
subscribeFiles:
|
|
57
|
-
unsubscribeFiles:
|
|
58
|
-
|
|
59
|
-
authEnabled:
|
|
60
|
-
disconnect:
|
|
61
|
-
listPermissions:
|
|
62
|
-
getUserPermissions: {type: 'object',
|
|
9
|
+
getObject: { type: 'object', operation: 'read' },
|
|
10
|
+
getObjects: { type: 'object', operation: 'list' },
|
|
11
|
+
getObjectView: { type: 'object', operation: 'list' },
|
|
12
|
+
setObject: { type: 'object', operation: 'write' },
|
|
13
|
+
requireLog: { type: 'object', operation: 'write' }, // just mapping to some command
|
|
14
|
+
delObject: { type: 'object', operation: 'delete' },
|
|
15
|
+
extendObject: { type: 'object', operation: 'write' },
|
|
16
|
+
getHostByIp: { type: 'object', operation: 'list' },
|
|
17
|
+
subscribeObjects: { type: 'object', operation: 'read' },
|
|
18
|
+
unsubscribeObjects: { type: 'object', operation: 'read' },
|
|
19
|
+
|
|
20
|
+
getStates: { type: 'state', operation: 'list' },
|
|
21
|
+
getState: { type: 'state', operation: 'read' },
|
|
22
|
+
setState: { type: 'state', operation: 'write' },
|
|
23
|
+
delState: { type: 'state', operation: 'delete' },
|
|
24
|
+
createState: { type: 'state', operation: 'create' },
|
|
25
|
+
subscribe: { type: 'state', operation: 'read' },
|
|
26
|
+
unsubscribe: { type: 'state', operation: 'read' },
|
|
27
|
+
getStateHistory: { type: 'state', operation: 'read' },
|
|
28
|
+
getVersion: { type: '', operation: '' },
|
|
29
|
+
getAdapterName: { type: '', operation: '' },
|
|
30
|
+
|
|
31
|
+
addUser: { type: 'users', operation: 'create' },
|
|
32
|
+
delUser: { type: 'users', operation: 'delete' },
|
|
33
|
+
addGroup: { type: 'users', operation: 'create' },
|
|
34
|
+
delGroup: { type: 'users', operation: 'delete' },
|
|
35
|
+
changePassword: { type: 'users', operation: 'write' },
|
|
36
|
+
|
|
37
|
+
httpGet: { type: 'other', operation: 'http' },
|
|
38
|
+
cmdExec: { type: 'other', operation: 'execute' },
|
|
39
|
+
sendTo: { type: 'other', operation: 'sendto' },
|
|
40
|
+
sendToHost: { type: 'other', operation: 'sendto' },
|
|
41
|
+
readLogs: { type: 'other', operation: 'execute' },
|
|
42
|
+
|
|
43
|
+
readDir: { type: 'file', operation: 'list' },
|
|
44
|
+
createFile: { type: 'file', operation: 'create' },
|
|
45
|
+
writeFile: { type: 'file', operation: 'write' },
|
|
46
|
+
readFile: { type: 'file', operation: 'read' },
|
|
47
|
+
fileExists: { type: 'file', operation: 'read' },
|
|
48
|
+
deleteFile: { type: 'file', operation: 'delete' },
|
|
49
|
+
readFile64: { type: 'file', operation: 'read' },
|
|
50
|
+
writeFile64: { type: 'file', operation: 'write' },
|
|
51
|
+
unlink: { type: 'file', operation: 'delete' },
|
|
52
|
+
rename: { type: 'file', operation: 'write' },
|
|
53
|
+
mkdir: { type: 'file', operation: 'write' },
|
|
54
|
+
chmodFile: { type: 'file', operation: 'write' },
|
|
55
|
+
chownFile: { type: 'file', operation: 'write' },
|
|
56
|
+
subscribeFiles: { type: 'file', operation: 'read' },
|
|
57
|
+
unsubscribeFiles: { type: 'file', operation: 'read' },
|
|
58
|
+
|
|
59
|
+
authEnabled: { type: '', operation: '' },
|
|
60
|
+
disconnect: { type: '', operation: '' },
|
|
61
|
+
listPermissions: { type: '', operation: '' },
|
|
62
|
+
getUserPermissions: { type: 'object', operation: 'read' }
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
constructor(adapter, updateSession) {
|
|
66
|
-
this.adapter
|
|
67
|
-
this.commands
|
|
66
|
+
this.adapter = adapter;
|
|
67
|
+
this.commands = {};
|
|
68
68
|
this.subscribes = {};
|
|
69
69
|
this.logEnabled = false;
|
|
70
70
|
this.clientSubscribes = {};
|
|
@@ -167,11 +167,17 @@ class SocketCommands {
|
|
|
167
167
|
if (SocketCommands.COMMANDS_PERMISSIONS[command]) {
|
|
168
168
|
// If permission required
|
|
169
169
|
if (SocketCommands.COMMANDS_PERMISSIONS[command].type) {
|
|
170
|
-
if (
|
|
171
|
-
socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type]
|
|
170
|
+
if (
|
|
171
|
+
socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type] &&
|
|
172
|
+
socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type][
|
|
173
|
+
SocketCommands.COMMANDS_PERMISSIONS[command].operation
|
|
174
|
+
]
|
|
175
|
+
) {
|
|
172
176
|
return true;
|
|
173
177
|
} else {
|
|
174
|
-
this.adapter.log.warn(
|
|
178
|
+
this.adapter.log.warn(
|
|
179
|
+
`No permission for "${socket._acl.user}" to call ${command}. Need "${SocketCommands.COMMANDS_PERMISSIONS[command].type}"."${SocketCommands.COMMANDS_PERMISSIONS[command].operation}"`
|
|
180
|
+
);
|
|
175
181
|
}
|
|
176
182
|
} else {
|
|
177
183
|
return true;
|
|
@@ -191,7 +197,7 @@ class SocketCommands {
|
|
|
191
197
|
arg
|
|
192
198
|
});
|
|
193
199
|
} else {
|
|
194
|
-
socket.emit(SocketCommands.ERROR_PERMISSION, {command, arg});
|
|
200
|
+
socket.emit(SocketCommands.ERROR_PERMISSION, { command, arg });
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
203
|
return false;
|
|
@@ -232,7 +238,8 @@ class SocketCommands {
|
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
publishInstanceMessage(socket, sourceInstance, messageType, data) {
|
|
235
|
-
if (
|
|
241
|
+
if (
|
|
242
|
+
this.clientSubscribes[socket.id] &&
|
|
236
243
|
this.clientSubscribes[socket.id][sourceInstance] &&
|
|
237
244
|
this.clientSubscribes[socket.id][sourceInstance].includes(messageType)
|
|
238
245
|
) {
|
|
@@ -241,7 +248,11 @@ class SocketCommands {
|
|
|
241
248
|
}
|
|
242
249
|
|
|
243
250
|
// inform instance about missing subscription
|
|
244
|
-
this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {
|
|
251
|
+
this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {
|
|
252
|
+
type: messageType,
|
|
253
|
+
sid: socket.id,
|
|
254
|
+
reason: 'no one subscribed'
|
|
255
|
+
});
|
|
245
256
|
return false;
|
|
246
257
|
}
|
|
247
258
|
|
|
@@ -262,7 +273,7 @@ class SocketCommands {
|
|
|
262
273
|
return this.logEnabled;
|
|
263
274
|
}
|
|
264
275
|
|
|
265
|
-
|
|
276
|
+
subscribe(socket, type, pattern, patternFile) {
|
|
266
277
|
if (!pattern) {
|
|
267
278
|
return this.adapter.log.warn('Empty pattern on subscribe!');
|
|
268
279
|
}
|
|
@@ -282,8 +293,8 @@ class SocketCommands {
|
|
|
282
293
|
try {
|
|
283
294
|
p = pattern2RegEx(key);
|
|
284
295
|
} catch (e) {
|
|
285
|
-
this.adapter.log.error(`Invalid pattern on subscribe: ${e.message}`)
|
|
286
|
-
return
|
|
296
|
+
this.adapter.log.error(`Invalid pattern on subscribe: ${e.message}`);
|
|
297
|
+
return;
|
|
287
298
|
}
|
|
288
299
|
|
|
289
300
|
if (p === null) {
|
|
@@ -298,24 +309,24 @@ class SocketCommands {
|
|
|
298
309
|
if (s.find(item => item.pattern === key)) {
|
|
299
310
|
return;
|
|
300
311
|
}
|
|
301
|
-
s.push({pattern: key, regex: new RegExp(p)});
|
|
312
|
+
s.push({ pattern: key, regex: new RegExp(p) });
|
|
302
313
|
}
|
|
303
314
|
|
|
304
|
-
const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
|
|
315
|
+
const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
|
|
305
316
|
|
|
306
317
|
if (this.subscribes[type][key] === undefined) {
|
|
307
318
|
this.subscribes[type][key] = 1;
|
|
308
319
|
if (type === 'stateChange') {
|
|
309
320
|
try {
|
|
310
|
-
|
|
321
|
+
this.adapter.subscribeForeignStatesAsync(pattern, options);
|
|
311
322
|
} catch (e) {
|
|
312
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
323
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
313
324
|
}
|
|
314
325
|
} else if (type === 'objectChange') {
|
|
315
326
|
try {
|
|
316
|
-
this.adapter.
|
|
327
|
+
this.adapter.subscribeForeignObjectsAsync(pattern, options);
|
|
317
328
|
} catch (e) {
|
|
318
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
329
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
319
330
|
}
|
|
320
331
|
} else if (type === 'log') {
|
|
321
332
|
if (!this.logEnabled && this.adapter.requireLog) {
|
|
@@ -324,15 +335,15 @@ class SocketCommands {
|
|
|
324
335
|
}
|
|
325
336
|
} else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
|
|
326
337
|
try {
|
|
327
|
-
|
|
338
|
+
this.adapter.subscribeForeignFiles(pattern, patternFile, options);
|
|
328
339
|
} catch (e) {
|
|
329
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
340
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
330
341
|
}
|
|
331
342
|
}
|
|
332
343
|
} else {
|
|
333
344
|
this.subscribes[type][key]++;
|
|
334
345
|
}
|
|
335
|
-
}
|
|
346
|
+
}
|
|
336
347
|
|
|
337
348
|
async unsubscribe(socket, type, pattern, patternFile) {
|
|
338
349
|
if (!pattern) {
|
|
@@ -352,7 +363,7 @@ class SocketCommands {
|
|
|
352
363
|
key = pattern;
|
|
353
364
|
}
|
|
354
365
|
|
|
355
|
-
const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
|
|
366
|
+
const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
|
|
356
367
|
|
|
357
368
|
if (socket && typeof socket === 'object') {
|
|
358
369
|
if (!socket.subscribe || !socket.subscribe[type]) {
|
|
@@ -367,26 +378,26 @@ class SocketCommands {
|
|
|
367
378
|
if (this.subscribes[type][key] <= 0) {
|
|
368
379
|
if (type === 'stateChange') {
|
|
369
380
|
try {
|
|
370
|
-
|
|
381
|
+
this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
371
382
|
} catch (e) {
|
|
372
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
383
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
373
384
|
}
|
|
374
385
|
} else if (type === 'objectChange') {
|
|
375
386
|
try {
|
|
376
|
-
this.adapter.
|
|
387
|
+
this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
377
388
|
} catch (e) {
|
|
378
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
389
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
379
390
|
}
|
|
380
391
|
} else if (type === 'log') {
|
|
381
392
|
if (this.logEnabled && this.adapter.requireLog) {
|
|
382
393
|
this.logEnabled = false;
|
|
383
394
|
this.adapter.requireLog(false, options);
|
|
384
395
|
}
|
|
385
|
-
} else if (type === 'fileChange') {
|
|
396
|
+
} else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
|
|
386
397
|
try {
|
|
387
|
-
this.adapter.unsubscribeForeignFiles
|
|
398
|
+
this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
|
|
388
399
|
} catch (e) {
|
|
389
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
400
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
390
401
|
}
|
|
391
402
|
}
|
|
392
403
|
delete this.subscribes[type][pattern];
|
|
@@ -405,44 +416,44 @@ class SocketCommands {
|
|
|
405
416
|
if (this.subscribes[type][key] <= 0) {
|
|
406
417
|
if (type === 'stateChange') {
|
|
407
418
|
try {
|
|
408
|
-
|
|
419
|
+
this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
409
420
|
} catch (e) {
|
|
410
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
421
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
411
422
|
}
|
|
412
423
|
} else if (type === 'objectChange') {
|
|
413
424
|
try {
|
|
414
|
-
this.adapter.
|
|
425
|
+
this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
415
426
|
} catch (e) {
|
|
416
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
427
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
417
428
|
}
|
|
418
429
|
} else if (type === 'log') {
|
|
419
430
|
if (this.adapter.requireLog && this.logEnabled) {
|
|
420
431
|
this.logEnabled = false;
|
|
421
432
|
this.adapter.requireLog(false, options);
|
|
422
433
|
}
|
|
423
|
-
} else if (type === 'fileChange') {
|
|
434
|
+
} else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
|
|
424
435
|
try {
|
|
425
|
-
this.adapter.unsubscribeForeignFiles
|
|
436
|
+
this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
|
|
426
437
|
} catch (e) {
|
|
427
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
438
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
428
439
|
}
|
|
429
440
|
}
|
|
430
441
|
delete this.subscribes[type][key];
|
|
431
442
|
}
|
|
432
443
|
}
|
|
433
444
|
} else {
|
|
434
|
-
|
|
445
|
+
for (const pattern of Object.keys(this.subscribes[type])) {
|
|
435
446
|
if (type === 'stateChange') {
|
|
436
447
|
try {
|
|
437
|
-
|
|
448
|
+
this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
438
449
|
} catch (e) {
|
|
439
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
450
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
440
451
|
}
|
|
441
452
|
} else if (type === 'objectChange') {
|
|
442
453
|
try {
|
|
443
|
-
this.adapter.
|
|
454
|
+
this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
444
455
|
} catch (e) {
|
|
445
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
456
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
446
457
|
}
|
|
447
458
|
} else if (type === 'log') {
|
|
448
459
|
// console.log((socket._name || socket.id) + ' requireLog false');
|
|
@@ -450,19 +461,19 @@ class SocketCommands {
|
|
|
450
461
|
this.logEnabled = false;
|
|
451
462
|
this.adapter.requireLog(false, options);
|
|
452
463
|
}
|
|
453
|
-
} else if (type === 'fileChange') {
|
|
464
|
+
} else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
|
|
454
465
|
const [id, fileName] = pattern.split('####');
|
|
455
466
|
try {
|
|
456
|
-
this.adapter.unsubscribeForeignFiles
|
|
467
|
+
this.adapter.unsubscribeForeignFiles(id, fileName, options);
|
|
457
468
|
} catch (e) {
|
|
458
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
469
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
459
470
|
}
|
|
460
471
|
}
|
|
461
472
|
}
|
|
462
473
|
|
|
463
|
-
this.subscribes[type] = {}
|
|
474
|
+
this.subscribes[type] = {};
|
|
464
475
|
}
|
|
465
|
-
}
|
|
476
|
+
}
|
|
466
477
|
|
|
467
478
|
async subscribeSocket(socket, type) {
|
|
468
479
|
if (!socket || !socket.subscribe) {
|
|
@@ -471,15 +482,14 @@ class SocketCommands {
|
|
|
471
482
|
|
|
472
483
|
if (!type) {
|
|
473
484
|
// all
|
|
474
|
-
return Object.keys(socket.subscribe)
|
|
475
|
-
.forEach(type => this.subscribeSocket(socket, type));
|
|
485
|
+
return Object.keys(socket.subscribe).forEach(type => this.subscribeSocket(socket, type));
|
|
476
486
|
}
|
|
477
487
|
|
|
478
488
|
if (!socket.subscribe[type]) {
|
|
479
489
|
return;
|
|
480
490
|
}
|
|
481
491
|
|
|
482
|
-
const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
|
|
492
|
+
const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
|
|
483
493
|
|
|
484
494
|
for (let i = 0; i < socket.subscribe[type].length; i++) {
|
|
485
495
|
const pattern = socket.subscribe[type][i].pattern;
|
|
@@ -487,27 +497,27 @@ class SocketCommands {
|
|
|
487
497
|
this.subscribes[type][pattern] = 1;
|
|
488
498
|
if (type === 'stateChange') {
|
|
489
499
|
try {
|
|
490
|
-
|
|
500
|
+
this.adapter.subscribeForeignStatesAsync(pattern, options);
|
|
491
501
|
} catch (e) {
|
|
492
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
502
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
493
503
|
}
|
|
494
504
|
} else if (type === 'objectChange') {
|
|
495
505
|
try {
|
|
496
|
-
this.adapter.
|
|
506
|
+
this.adapter.subscribeForeignObjectsAsync(pattern, options);
|
|
497
507
|
} catch (e) {
|
|
498
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
508
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
499
509
|
}
|
|
500
510
|
} else if (type === 'log') {
|
|
501
511
|
if (this.adapter.requireLog && !this.logEnabled) {
|
|
502
512
|
this.logEnabled = true;
|
|
503
513
|
this.adapter.requireLog(true, options);
|
|
504
514
|
}
|
|
505
|
-
} else if (type === 'fileChange') {
|
|
515
|
+
} else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
|
|
506
516
|
const [id, fileName] = pattern.split('####');
|
|
507
517
|
try {
|
|
508
|
-
this.adapter.subscribeForeignFiles
|
|
518
|
+
this.adapter.subscribeForeignFiles(id, fileName, options);
|
|
509
519
|
} catch (e) {
|
|
510
|
-
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
520
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
|
|
511
521
|
}
|
|
512
522
|
}
|
|
513
523
|
} else {
|
|
@@ -525,15 +535,14 @@ class SocketCommands {
|
|
|
525
535
|
|
|
526
536
|
if (!type) {
|
|
527
537
|
// all
|
|
528
|
-
return Object.keys(socket.subscribe)
|
|
529
|
-
.forEach(type => this.unsubscribeSocket(socket, type));
|
|
538
|
+
return Object.keys(socket.subscribe).forEach(type => this.unsubscribeSocket(socket, type));
|
|
530
539
|
}
|
|
531
540
|
|
|
532
541
|
if (!socket.subscribe[type]) {
|
|
533
542
|
return;
|
|
534
543
|
}
|
|
535
544
|
|
|
536
|
-
const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
|
|
545
|
+
const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
|
|
537
546
|
|
|
538
547
|
for (let i = 0; i < socket.subscribe[type].length; i++) {
|
|
539
548
|
const pattern = socket.subscribe[type][i].pattern;
|
|
@@ -542,27 +551,27 @@ class SocketCommands {
|
|
|
542
551
|
if (this.subscribes[type][pattern] <= 0) {
|
|
543
552
|
if (type === 'stateChange') {
|
|
544
553
|
try {
|
|
545
|
-
|
|
554
|
+
this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
546
555
|
} catch (e) {
|
|
547
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
556
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
548
557
|
}
|
|
549
558
|
} else if (type === 'objectChange') {
|
|
550
559
|
try {
|
|
551
|
-
this.adapter.
|
|
560
|
+
this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
552
561
|
} catch (e) {
|
|
553
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
562
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
554
563
|
}
|
|
555
564
|
} else if (type === 'log') {
|
|
556
565
|
if (this.adapter.requireLog && !this.logEnabled) {
|
|
557
566
|
this.logEnabled = true;
|
|
558
567
|
this.adapter.requireLog(true, options);
|
|
559
568
|
}
|
|
560
|
-
} else if (type === 'fileChange') {
|
|
569
|
+
} else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
|
|
561
570
|
const [id, fileName] = pattern.split('####');
|
|
562
571
|
try {
|
|
563
|
-
this.adapter.unsubscribeForeignFiles
|
|
572
|
+
this.adapter.unsubscribeForeignFiles(id, fileName, options);
|
|
564
573
|
} catch (e) {
|
|
565
|
-
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
574
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
|
|
566
575
|
}
|
|
567
576
|
}
|
|
568
577
|
delete this.subscribes[type][pattern];
|
|
@@ -679,7 +688,12 @@ class SocketCommands {
|
|
|
679
688
|
obj.common.adminUI.tab = 'html';
|
|
680
689
|
}
|
|
681
690
|
|
|
682
|
-
obj.common.adminUI &&
|
|
691
|
+
obj.common.adminUI &&
|
|
692
|
+
this.adapter.log.debug(
|
|
693
|
+
`Please add to "${obj._id.replace(/\.\d+$/, '')}" common.adminUI=${JSON.stringify(
|
|
694
|
+
obj.common.adminUI
|
|
695
|
+
)}`
|
|
696
|
+
);
|
|
683
697
|
}
|
|
684
698
|
}
|
|
685
699
|
|
|
@@ -736,7 +750,11 @@ class SocketCommands {
|
|
|
736
750
|
if (feature === 'INSTANCE_MESSAGES') {
|
|
737
751
|
SocketCommands._fixCallback(callback, null, true);
|
|
738
752
|
} else {
|
|
739
|
-
SocketCommands._fixCallback(
|
|
753
|
+
SocketCommands._fixCallback(
|
|
754
|
+
callback,
|
|
755
|
+
null,
|
|
756
|
+
this.adapter.supportsFeature && this.adapter.supportsFeature(feature)
|
|
757
|
+
);
|
|
740
758
|
}
|
|
741
759
|
};
|
|
742
760
|
|
|
@@ -757,7 +775,8 @@ class SocketCommands {
|
|
|
757
775
|
options.aggregate = options.aggregate || 'none';
|
|
758
776
|
try {
|
|
759
777
|
this.adapter.getHistory(id, options, (error, ...args) =>
|
|
760
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
778
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
779
|
+
);
|
|
761
780
|
} catch (error) {
|
|
762
781
|
this.adapter.log.error(`[getHistory] ERROR: ${error.toString()}`);
|
|
763
782
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -779,7 +798,9 @@ class SocketCommands {
|
|
|
779
798
|
timeout: 15000,
|
|
780
799
|
validateStatus: status => status < 400
|
|
781
800
|
})
|
|
782
|
-
.then(result =>
|
|
801
|
+
.then(result =>
|
|
802
|
+
callback(null, { status: result.status, statusText: result.statusText }, result.data)
|
|
803
|
+
)
|
|
783
804
|
.catch(error => callback(error));
|
|
784
805
|
} catch (error) {
|
|
785
806
|
callback(error);
|
|
@@ -796,17 +817,32 @@ class SocketCommands {
|
|
|
796
817
|
// @param {function} callback - `function (result)`
|
|
797
818
|
if (this._checkPermissions(socket, 'sendTo', callback, command)) {
|
|
798
819
|
try {
|
|
799
|
-
this.adapter.sendTo(
|
|
800
|
-
|
|
801
|
-
|
|
820
|
+
this.adapter.sendTo(
|
|
821
|
+
adapterInstance,
|
|
822
|
+
command,
|
|
823
|
+
message,
|
|
824
|
+
res => typeof callback === 'function' && setImmediate(() => callback(res))
|
|
825
|
+
);
|
|
802
826
|
} catch (error) {
|
|
803
|
-
typeof callback === 'function' && setImmediate(() => callback({error}));
|
|
827
|
+
typeof callback === 'function' && setImmediate(() => callback({ error }));
|
|
804
828
|
}
|
|
805
829
|
}
|
|
806
830
|
};
|
|
807
831
|
|
|
808
832
|
// following commands are protected and require the extra permissions
|
|
809
|
-
const protectedCommands = [
|
|
833
|
+
const protectedCommands = [
|
|
834
|
+
'cmdExec',
|
|
835
|
+
'getLocationOnDisk',
|
|
836
|
+
'getDiagData',
|
|
837
|
+
'getDevList',
|
|
838
|
+
'delLogs',
|
|
839
|
+
'writeDirAsZip',
|
|
840
|
+
'writeObjectsAsZip',
|
|
841
|
+
'readObjectsAsZip',
|
|
842
|
+
'checkLogging',
|
|
843
|
+
'updateMultihost',
|
|
844
|
+
'rebuildAdapter'
|
|
845
|
+
];
|
|
810
846
|
|
|
811
847
|
this.commands['sendToHost'] = (socket, host, command, message, callback) => {
|
|
812
848
|
// Send a message to the specific host.
|
|
@@ -815,7 +851,14 @@ class SocketCommands {
|
|
|
815
851
|
// @param {string} command - command name
|
|
816
852
|
// @param {object} message - the message is command-specific
|
|
817
853
|
// @param {function} callback - `function (result)`
|
|
818
|
-
if (
|
|
854
|
+
if (
|
|
855
|
+
this._checkPermissions(
|
|
856
|
+
socket,
|
|
857
|
+
protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost',
|
|
858
|
+
callback,
|
|
859
|
+
command
|
|
860
|
+
)
|
|
861
|
+
) {
|
|
819
862
|
// Try to decode this file locally as redis has a limitation for files bigger than 20MB
|
|
820
863
|
if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
|
|
821
864
|
let buffer;
|
|
@@ -823,7 +866,7 @@ class SocketCommands {
|
|
|
823
866
|
buffer = Buffer.from(message.data, 'base64');
|
|
824
867
|
} catch (error) {
|
|
825
868
|
this.adapter.log.error(`Cannot convert data: ${error.toString()}`);
|
|
826
|
-
return callback && callback({error: `Cannot convert data: ${error.toString()}`});
|
|
869
|
+
return callback && callback({ error: `Cannot convert data: ${error.toString()}` });
|
|
827
870
|
}
|
|
828
871
|
|
|
829
872
|
zipFiles = zipFiles || utils.commonTools.zipFiles;
|
|
@@ -930,8 +973,9 @@ class SocketCommands {
|
|
|
930
973
|
// @param {function} callback - `function (error, data, mimeType)`
|
|
931
974
|
if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
|
|
932
975
|
try {
|
|
933
|
-
this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
|
|
934
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
976
|
+
this.adapter.readFile(_adapter, fileName, { user: socket._acl.user }, (error, ...args) =>
|
|
977
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
978
|
+
);
|
|
935
979
|
} catch (error) {
|
|
936
980
|
this.adapter.log.error(`[readFile] ERROR: ${error.toString()}`);
|
|
937
981
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -946,11 +990,15 @@ class SocketCommands {
|
|
|
946
990
|
// @param {function} callback - `function (error, base64, mimeType)`
|
|
947
991
|
if (this._checkPermissions(socket, 'readFile64', callback, fileName)) {
|
|
948
992
|
try {
|
|
949
|
-
this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, buffer, type) => {
|
|
993
|
+
this.adapter.readFile(_adapter, fileName, { user: socket._acl.user }, (error, buffer, type) => {
|
|
950
994
|
let data64;
|
|
951
995
|
if (buffer) {
|
|
952
996
|
try {
|
|
953
|
-
if (
|
|
997
|
+
if (
|
|
998
|
+
type === 'application/json' ||
|
|
999
|
+
type === 'application/json5' ||
|
|
1000
|
+
fileName.toLowerCase().endsWith('.json5')
|
|
1001
|
+
) {
|
|
954
1002
|
data64 = Buffer.from(encodeURIComponent(buffer)).toString('base64');
|
|
955
1003
|
} else {
|
|
956
1004
|
if (typeof buffer === 'string') {
|
|
@@ -987,7 +1035,7 @@ class SocketCommands {
|
|
|
987
1035
|
// @param {function} callback - `function (error)`
|
|
988
1036
|
if (typeof options === 'function') {
|
|
989
1037
|
callback = options;
|
|
990
|
-
options = {user: socket._acl.user};
|
|
1038
|
+
options = { user: socket._acl.user };
|
|
991
1039
|
}
|
|
992
1040
|
|
|
993
1041
|
options = options || {};
|
|
@@ -1002,7 +1050,8 @@ class SocketCommands {
|
|
|
1002
1050
|
try {
|
|
1003
1051
|
const buffer = Buffer.from(data64, 'base64');
|
|
1004
1052
|
this.adapter.writeFile(_adapter, fileName, buffer, options, (error, ...args) =>
|
|
1005
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1053
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1054
|
+
);
|
|
1006
1055
|
} catch (error) {
|
|
1007
1056
|
this.adapter.log.error(`[writeFile64] Cannot convert data: ${error.toString()}`);
|
|
1008
1057
|
SocketCommands._fixCallback(callback, `Cannot convert data: ${error.toString()}`);
|
|
@@ -1021,7 +1070,7 @@ class SocketCommands {
|
|
|
1021
1070
|
if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
|
|
1022
1071
|
if (typeof options === 'function') {
|
|
1023
1072
|
callback = options;
|
|
1024
|
-
options = {user: socket._acl.user};
|
|
1073
|
+
options = { user: socket._acl.user };
|
|
1025
1074
|
}
|
|
1026
1075
|
options = options || {};
|
|
1027
1076
|
options.user = socket._acl.user;
|
|
@@ -1029,7 +1078,8 @@ class SocketCommands {
|
|
|
1029
1078
|
// const buffer = Buffer.from(data64, 'base64');
|
|
1030
1079
|
try {
|
|
1031
1080
|
this.adapter.writeFile(_adapter, fileName, data, options, (error, ...args) =>
|
|
1032
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1081
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1082
|
+
);
|
|
1033
1083
|
} catch (error) {
|
|
1034
1084
|
this.adapter.log.error(`[writeFile] ERROR: ${error.toString()}`);
|
|
1035
1085
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1044,7 +1094,7 @@ class SocketCommands {
|
|
|
1044
1094
|
// @param {function} callback - `function (error)`
|
|
1045
1095
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
1046
1096
|
try {
|
|
1047
|
-
this._unlink(_adapter, name, {user: socket._acl.user})
|
|
1097
|
+
this._unlink(_adapter, name, { user: socket._acl.user })
|
|
1048
1098
|
.then(() => SocketCommands._fixCallback(callback))
|
|
1049
1099
|
.catch(error => SocketCommands._fixCallback(callback, error));
|
|
1050
1100
|
} catch (error) {
|
|
@@ -1061,8 +1111,9 @@ class SocketCommands {
|
|
|
1061
1111
|
// @param {function} callback - `function (error)`
|
|
1062
1112
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
1063
1113
|
try {
|
|
1064
|
-
this.adapter.unlink(_adapter, name, {user: socket._acl.user}, (error, ...args) =>
|
|
1065
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1114
|
+
this.adapter.unlink(_adapter, name, { user: socket._acl.user }, (error, ...args) =>
|
|
1115
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1116
|
+
);
|
|
1066
1117
|
} catch (error) {
|
|
1067
1118
|
this.adapter.log.error(`[deleteFile] ERROR: ${error.toString()}`);
|
|
1068
1119
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1077,7 +1128,7 @@ class SocketCommands {
|
|
|
1077
1128
|
// @param {function} callback - `function (error)`
|
|
1078
1129
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
1079
1130
|
try {
|
|
1080
|
-
this._unlink(_adapter, name, {user: socket._acl.user})
|
|
1131
|
+
this._unlink(_adapter, name, { user: socket._acl.user })
|
|
1081
1132
|
.then(() => SocketCommands._fixCallback(callback, null))
|
|
1082
1133
|
.catch(error => SocketCommands._fixCallback(callback, error));
|
|
1083
1134
|
} catch (error) {
|
|
@@ -1095,8 +1146,9 @@ class SocketCommands {
|
|
|
1095
1146
|
// @param {function} callback - `function (error)`
|
|
1096
1147
|
if (this._checkPermissions(socket, 'rename', callback, oldName)) {
|
|
1097
1148
|
try {
|
|
1098
|
-
this.adapter.rename(_adapter, oldName, newName, {user: socket._acl.user}, (error, ...args) =>
|
|
1099
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1149
|
+
this.adapter.rename(_adapter, oldName, newName, { user: socket._acl.user }, (error, ...args) =>
|
|
1150
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1151
|
+
);
|
|
1100
1152
|
} catch (error) {
|
|
1101
1153
|
this.adapter.log.error(`[renameFile] ERROR: ${error.toString()}`);
|
|
1102
1154
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1112,7 +1164,7 @@ class SocketCommands {
|
|
|
1112
1164
|
// @param {function} callback - `function (error)`
|
|
1113
1165
|
if (this._checkPermissions(socket, 'rename', callback, oldName)) {
|
|
1114
1166
|
try {
|
|
1115
|
-
this._rename(_adapter, oldName, newName, {user: socket._acl.user})
|
|
1167
|
+
this._rename(_adapter, oldName, newName, { user: socket._acl.user })
|
|
1116
1168
|
.then(() => SocketCommands._fixCallback(callback))
|
|
1117
1169
|
.catch(error => SocketCommands._fixCallback(callback, error));
|
|
1118
1170
|
} catch (error) {
|
|
@@ -1129,8 +1181,9 @@ class SocketCommands {
|
|
|
1129
1181
|
// @param {function} callback - `function (error)`
|
|
1130
1182
|
if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
|
|
1131
1183
|
try {
|
|
1132
|
-
this.adapter.mkdir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
|
|
1133
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1184
|
+
this.adapter.mkdir(_adapter, dirName, { user: socket._acl.user }, (error, ...args) =>
|
|
1185
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1186
|
+
);
|
|
1134
1187
|
} catch (error) {
|
|
1135
1188
|
this.adapter.log.error(`[mkdir] ERROR: ${error.toString()}`);
|
|
1136
1189
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1157,8 +1210,9 @@ class SocketCommands {
|
|
|
1157
1210
|
|
|
1158
1211
|
if (this._checkPermissions(socket, 'readDir', callback, dirName)) {
|
|
1159
1212
|
try {
|
|
1160
|
-
this.adapter.readDir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
|
|
1161
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1213
|
+
this.adapter.readDir(_adapter, dirName, { user: socket._acl.user }, (error, ...args) =>
|
|
1214
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1215
|
+
);
|
|
1162
1216
|
} catch (error) {
|
|
1163
1217
|
this.adapter.log.error(`[readDir] ERROR: ${error.toString()}`);
|
|
1164
1218
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1186,7 +1240,8 @@ class SocketCommands {
|
|
|
1186
1240
|
if (this._checkPermissions(socket, 'chmodFile', callback, fileName)) {
|
|
1187
1241
|
try {
|
|
1188
1242
|
this.adapter.chmodFile(_adapter, fileName, options, (error, ...args) =>
|
|
1189
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1243
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1244
|
+
);
|
|
1190
1245
|
} catch (error) {
|
|
1191
1246
|
this.adapter.log.error(`[chmodFile] ERROR: ${error.toString()}`);
|
|
1192
1247
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1205,7 +1260,8 @@ class SocketCommands {
|
|
|
1205
1260
|
options.user = socket._acl.user;
|
|
1206
1261
|
try {
|
|
1207
1262
|
this.adapter.chownFile(_adapter, fileName, options, (error, ...args) =>
|
|
1208
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1263
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1264
|
+
);
|
|
1209
1265
|
} catch (error) {
|
|
1210
1266
|
this.adapter.log.error(`[chownFile] ERROR: ${error.toString()}`);
|
|
1211
1267
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1220,8 +1276,9 @@ class SocketCommands {
|
|
|
1220
1276
|
// @param {function} callback - `function (error, isExist)`
|
|
1221
1277
|
if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
|
|
1222
1278
|
try {
|
|
1223
|
-
this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
|
|
1224
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1279
|
+
this.adapter.fileExists(_adapter, fileName, { user: socket._acl.user }, (error, ...args) =>
|
|
1280
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1281
|
+
);
|
|
1225
1282
|
} catch (error) {
|
|
1226
1283
|
this.adapter.log.error(`[fileExists] ERROR: ${error.toString()}`);
|
|
1227
1284
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1235,7 +1292,7 @@ class SocketCommands {
|
|
|
1235
1292
|
// @param {string} pattern - file name pattern, e.g. `main/*.json`
|
|
1236
1293
|
// @param {function} callback - `function (error)`
|
|
1237
1294
|
return this._subscribeFiles(socket, id, pattern, callback);
|
|
1238
|
-
}
|
|
1295
|
+
};
|
|
1239
1296
|
|
|
1240
1297
|
this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => {
|
|
1241
1298
|
// Unsubscribe from file changes in ioBroker DB
|
|
@@ -1244,7 +1301,7 @@ class SocketCommands {
|
|
|
1244
1301
|
// @param {function} callback - `function (error)`
|
|
1245
1302
|
|
|
1246
1303
|
return this._unsubscribeFiles(socket, id, pattern, callback);
|
|
1247
|
-
}
|
|
1304
|
+
};
|
|
1248
1305
|
|
|
1249
1306
|
this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
|
|
1250
1307
|
// Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
|
|
@@ -1252,31 +1309,44 @@ class SocketCommands {
|
|
|
1252
1309
|
// @param {function} callback - `function (error, instanceList)`, where instanceList is an array of instance objects, e.g. `{_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}`
|
|
1253
1310
|
if (typeof callback === 'function') {
|
|
1254
1311
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1255
|
-
let _adapterName =
|
|
1312
|
+
let _adapterName =
|
|
1313
|
+
adapterName !== undefined && adapterName !== null ? adapterName : this.adapterName || '';
|
|
1256
1314
|
if (_adapterName) {
|
|
1257
1315
|
_adapterName += '.';
|
|
1258
1316
|
}
|
|
1259
1317
|
try {
|
|
1260
|
-
this.adapter.getObjectView(
|
|
1261
|
-
|
|
1262
|
-
|
|
1318
|
+
this.adapter.getObjectView(
|
|
1319
|
+
'system',
|
|
1320
|
+
'instance',
|
|
1321
|
+
{
|
|
1322
|
+
startkey: `system.adapter.${_adapterName}`,
|
|
1323
|
+
endkey: `system.adapter.${_adapterName}\u9999`
|
|
1324
|
+
},
|
|
1325
|
+
{ user: socket._acl.user },
|
|
1263
1326
|
(error, doc) => {
|
|
1264
1327
|
if (error) {
|
|
1265
1328
|
callback(error);
|
|
1266
1329
|
} else {
|
|
1267
|
-
callback(
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1330
|
+
callback(
|
|
1331
|
+
null,
|
|
1332
|
+
doc.rows
|
|
1333
|
+
.map(item => {
|
|
1334
|
+
const obj = item.value;
|
|
1335
|
+
if (obj.common) {
|
|
1336
|
+
delete obj.common.news;
|
|
1337
|
+
}
|
|
1338
|
+
this._fixAdminUI(obj);
|
|
1339
|
+
return obj;
|
|
1340
|
+
})
|
|
1341
|
+
.filter(
|
|
1342
|
+
obj =>
|
|
1343
|
+
obj &&
|
|
1344
|
+
(!adapterName || (obj.common && obj.common.name === adapterName))
|
|
1345
|
+
)
|
|
1346
|
+
);
|
|
1277
1347
|
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1348
|
+
}
|
|
1349
|
+
);
|
|
1280
1350
|
} catch (error) {
|
|
1281
1351
|
this.adapter.log.error(`[getAdapterInstances] ERROR: ${error.toString()}`);
|
|
1282
1352
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1298,14 +1368,15 @@ class SocketCommands {
|
|
|
1298
1368
|
}
|
|
1299
1369
|
if (typeof callback === 'function') {
|
|
1300
1370
|
try {
|
|
1301
|
-
this.adapter.getForeignStates(pattern || '*', {user: socket._acl.user}, (error, ...args) =>
|
|
1302
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1371
|
+
this.adapter.getForeignStates(pattern || '*', { user: socket._acl.user }, (error, ...args) =>
|
|
1372
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1373
|
+
);
|
|
1303
1374
|
} catch (error) {
|
|
1304
1375
|
this.adapter.log.error(`[getStates] ERROR: ${error.toString()}`);
|
|
1305
1376
|
SocketCommands._fixCallback(callback, error);
|
|
1306
1377
|
}
|
|
1307
1378
|
} else {
|
|
1308
|
-
this.adapter.log.warn('[getStates] Invalid callback')
|
|
1379
|
+
this.adapter.log.warn('[getStates] Invalid callback');
|
|
1309
1380
|
}
|
|
1310
1381
|
}
|
|
1311
1382
|
};
|
|
@@ -1317,14 +1388,15 @@ class SocketCommands {
|
|
|
1317
1388
|
if (this._checkPermissions(socket, 'getStates', callback)) {
|
|
1318
1389
|
if (typeof callback === 'function') {
|
|
1319
1390
|
try {
|
|
1320
|
-
this.adapter.getForeignStates(pattern, {user: socket._acl.user}, (error, ...args) =>
|
|
1321
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1391
|
+
this.adapter.getForeignStates(pattern, { user: socket._acl.user }, (error, ...args) =>
|
|
1392
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1393
|
+
);
|
|
1322
1394
|
} catch (error) {
|
|
1323
1395
|
this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
|
|
1324
1396
|
SocketCommands._fixCallback(callback, error);
|
|
1325
1397
|
}
|
|
1326
1398
|
} else {
|
|
1327
|
-
this.adapter.log.warn('[getForeignStates] Invalid callback')
|
|
1399
|
+
this.adapter.log.warn('[getForeignStates] Invalid callback');
|
|
1328
1400
|
}
|
|
1329
1401
|
}
|
|
1330
1402
|
};
|
|
@@ -1339,8 +1411,9 @@ class SocketCommands {
|
|
|
1339
1411
|
callback(null, this.states[id]);
|
|
1340
1412
|
} else {
|
|
1341
1413
|
try {
|
|
1342
|
-
this.adapter.getForeignState(id, {user: socket._acl.user}, (error, ...args) =>
|
|
1343
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1414
|
+
this.adapter.getForeignState(id, { user: socket._acl.user }, (error, ...args) =>
|
|
1415
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1416
|
+
);
|
|
1344
1417
|
} catch (error) {
|
|
1345
1418
|
this.adapter.log.error(`[getState] ERROR: ${error.toString()}`);
|
|
1346
1419
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1359,7 +1432,7 @@ class SocketCommands {
|
|
|
1359
1432
|
// @param {function} callback - `function (error, state)`, where `state` is an object like `{val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}`
|
|
1360
1433
|
if (this._checkPermissions(socket, 'setState', callback, id)) {
|
|
1361
1434
|
if (typeof state !== 'object') {
|
|
1362
|
-
state = {val: state};
|
|
1435
|
+
state = { val: state };
|
|
1363
1436
|
}
|
|
1364
1437
|
|
|
1365
1438
|
// clear cache
|
|
@@ -1368,8 +1441,9 @@ class SocketCommands {
|
|
|
1368
1441
|
}
|
|
1369
1442
|
|
|
1370
1443
|
try {
|
|
1371
|
-
this.adapter.setForeignState(id, state, {user: socket._acl.user}, (error, ...args) =>
|
|
1372
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1444
|
+
this.adapter.setForeignState(id, state, { user: socket._acl.user }, (error, ...args) =>
|
|
1445
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1446
|
+
);
|
|
1373
1447
|
} catch (error) {
|
|
1374
1448
|
this.adapter.log.error(`[setState] ERROR: ${error.toString()}`);
|
|
1375
1449
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1385,23 +1459,27 @@ class SocketCommands {
|
|
|
1385
1459
|
if (typeof callback === 'function') {
|
|
1386
1460
|
try {
|
|
1387
1461
|
if (this.adapter.getForeignBinaryState) {
|
|
1388
|
-
this.adapter.getForeignBinaryState(id, {user: socket._acl.user}, (error, data) => {
|
|
1462
|
+
this.adapter.getForeignBinaryState(id, { user: socket._acl.user }, (error, data) => {
|
|
1389
1463
|
if (data) {
|
|
1390
1464
|
try {
|
|
1391
1465
|
data = Buffer.from(data).toString('base64');
|
|
1392
1466
|
} catch (error) {
|
|
1393
|
-
this.adapter.log.error(
|
|
1467
|
+
this.adapter.log.error(
|
|
1468
|
+
`[getBinaryState] Cannot convert data: ${error.toString()}`
|
|
1469
|
+
);
|
|
1394
1470
|
}
|
|
1395
1471
|
}
|
|
1396
1472
|
SocketCommands._fixCallback(callback, error, data);
|
|
1397
1473
|
});
|
|
1398
1474
|
} else {
|
|
1399
|
-
this.adapter.getBinaryState(id, {user: socket._acl.user}, (error, data) => {
|
|
1475
|
+
this.adapter.getBinaryState(id, { user: socket._acl.user }, (error, data) => {
|
|
1400
1476
|
if (data) {
|
|
1401
1477
|
try {
|
|
1402
1478
|
data = Buffer.from(data).toString('base64');
|
|
1403
1479
|
} catch (error) {
|
|
1404
|
-
this.adapter.log.error(
|
|
1480
|
+
this.adapter.log.error(
|
|
1481
|
+
`[getBinaryState] Cannot convert data: ${error.toString()}`
|
|
1482
|
+
);
|
|
1405
1483
|
}
|
|
1406
1484
|
}
|
|
1407
1485
|
SocketCommands._fixCallback(callback, error, data);
|
|
@@ -1412,7 +1490,7 @@ class SocketCommands {
|
|
|
1412
1490
|
SocketCommands._fixCallback(callback, error);
|
|
1413
1491
|
}
|
|
1414
1492
|
} else {
|
|
1415
|
-
this.adapter.log.warn('[getBinaryState] Invalid callback')
|
|
1493
|
+
this.adapter.log.warn('[getBinaryState] Invalid callback');
|
|
1416
1494
|
}
|
|
1417
1495
|
}
|
|
1418
1496
|
};
|
|
@@ -1426,18 +1504,20 @@ class SocketCommands {
|
|
|
1426
1504
|
if (typeof callback === 'function') {
|
|
1427
1505
|
let data = null;
|
|
1428
1506
|
try {
|
|
1429
|
-
data = Buffer.from(base64, 'base64')
|
|
1507
|
+
data = Buffer.from(base64, 'base64');
|
|
1430
1508
|
} catch (error) {
|
|
1431
1509
|
this.adapter.log.warn(`[setBinaryState] Cannot convert base64 data: ${error.toString()}`);
|
|
1432
1510
|
}
|
|
1433
1511
|
|
|
1434
1512
|
try {
|
|
1435
1513
|
if (this.adapter.setForeignBinaryState) {
|
|
1436
|
-
this.adapter.setForeignBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
|
|
1437
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1514
|
+
this.adapter.setForeignBinaryState(id, data, { user: socket._acl.user }, (error, ...args) =>
|
|
1515
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1516
|
+
);
|
|
1438
1517
|
} else {
|
|
1439
|
-
this.adapter.setBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
|
|
1440
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1518
|
+
this.adapter.setBinaryState(id, data, { user: socket._acl.user }, (error, ...args) =>
|
|
1519
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1520
|
+
);
|
|
1441
1521
|
}
|
|
1442
1522
|
} catch (error) {
|
|
1443
1523
|
this.adapter.log.error(`[setBinaryState] ERROR: ${error.toString()}`);
|
|
@@ -1485,7 +1565,7 @@ class SocketCommands {
|
|
|
1485
1565
|
// @param {function} callback - `function (error, obj)`
|
|
1486
1566
|
if (this._checkPermissions(socket, 'getObject', callback, id)) {
|
|
1487
1567
|
try {
|
|
1488
|
-
this.adapter.getForeignObject(id, {user: socket._acl.user}, (error, obj) => {
|
|
1568
|
+
this.adapter.getForeignObject(id, { user: socket._acl.user }, (error, obj) => {
|
|
1489
1569
|
// overload language from current instance
|
|
1490
1570
|
if (this.adapter._language && id === 'system.config' && obj.common) {
|
|
1491
1571
|
obj.common.language = this.adapter._language;
|
|
@@ -1514,8 +1594,9 @@ class SocketCommands {
|
|
|
1514
1594
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1515
1595
|
if (typeof callback === 'function') {
|
|
1516
1596
|
try {
|
|
1517
|
-
this.adapter.getForeignObjects(list, {user: socket._acl.user}, (error, objs) =>
|
|
1518
|
-
SocketCommands._fixCallback(callback, error, objs)
|
|
1597
|
+
this.adapter.getForeignObjects(list, { user: socket._acl.user }, (error, objs) =>
|
|
1598
|
+
SocketCommands._fixCallback(callback, error, objs)
|
|
1599
|
+
);
|
|
1519
1600
|
} catch (error) {
|
|
1520
1601
|
this.adapter.log.error(`[getObjects] ERROR: ${error.toString()}`);
|
|
1521
1602
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1527,24 +1608,38 @@ class SocketCommands {
|
|
|
1527
1608
|
} else if (this._checkPermissions(socket, 'getObjects', callback)) {
|
|
1528
1609
|
try {
|
|
1529
1610
|
if (typeof callback === 'function') {
|
|
1530
|
-
this.adapter.getForeignObjects(
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1611
|
+
this.adapter.getForeignObjects(
|
|
1612
|
+
'*',
|
|
1613
|
+
'state',
|
|
1614
|
+
'rooms',
|
|
1615
|
+
{ user: socket._acl.user },
|
|
1616
|
+
async (error, objs) => {
|
|
1617
|
+
try {
|
|
1618
|
+
const channels = await this.adapter.getForeignObjectsAsync('*', 'channel', null, {
|
|
1619
|
+
user: socket._acl.user
|
|
1620
|
+
});
|
|
1621
|
+
const devices = await this.adapter.getForeignObjectsAsync('*', 'device', null, {
|
|
1622
|
+
user: socket._acl.user
|
|
1623
|
+
});
|
|
1624
|
+
const enums = await this.adapter.getForeignObjectsAsync('*', 'enum', null, {
|
|
1625
|
+
user: socket._acl.user
|
|
1626
|
+
});
|
|
1627
|
+
const config = await this.adapter.getForeignObjectAsync('system.config', {
|
|
1628
|
+
user: socket._acl.user
|
|
1629
|
+
});
|
|
1630
|
+
Object.assign(objs, channels, devices, enums);
|
|
1631
|
+
objs['system.config'] = config;
|
|
1632
|
+
} catch (e) {
|
|
1633
|
+
this.adapter.log.error(`[getObjects] ERROR: ${e.toString()}`);
|
|
1634
|
+
}
|
|
1635
|
+
// overload language
|
|
1636
|
+
if (this.adapter._language && objs['system.config'] && objs['system.config'].common) {
|
|
1637
|
+
objs['system.config'].common.language = this.adapter._language;
|
|
1638
|
+
}
|
|
1545
1639
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1640
|
+
SocketCommands._fixCallback(callback, error, objs);
|
|
1641
|
+
}
|
|
1642
|
+
);
|
|
1548
1643
|
} else {
|
|
1549
1644
|
this.adapter.log.warn('[getObjects] Invalid callback');
|
|
1550
1645
|
}
|
|
@@ -1612,7 +1707,7 @@ class SocketCommands {
|
|
|
1612
1707
|
if (typeof callback === 'function') {
|
|
1613
1708
|
if (this._checkPermissions(socket, 'getObjectView', callback, search)) {
|
|
1614
1709
|
try {
|
|
1615
|
-
this.adapter.getObjectView(design, search, params, {user: socket._acl.user}, callback);
|
|
1710
|
+
this.adapter.getObjectView(design, search, params, { user: socket._acl.user }, callback);
|
|
1616
1711
|
} catch (error) {
|
|
1617
1712
|
this.adapter.log.error(`[getObjectView] ERROR: ${error.toString()}`);
|
|
1618
1713
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1630,8 +1725,9 @@ class SocketCommands {
|
|
|
1630
1725
|
// @param {function} callback - `function (error)`
|
|
1631
1726
|
if (this._checkPermissions(socket, 'setObject', callback, id)) {
|
|
1632
1727
|
try {
|
|
1633
|
-
this.adapter.setForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>
|
|
1634
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1728
|
+
this.adapter.setForeignObject(id, obj, { user: socket._acl.user }, (error, ...args) =>
|
|
1729
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1730
|
+
);
|
|
1635
1731
|
} catch (error) {
|
|
1636
1732
|
this.adapter.log.error(`[setObject] ERROR: ${error.toString()}`);
|
|
1637
1733
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1648,8 +1744,9 @@ class SocketCommands {
|
|
|
1648
1744
|
if (id.startsWith('flot.') || id.startsWith('fullcalendar.')) {
|
|
1649
1745
|
if (this._checkPermissions(socket, 'delObject', callback, id)) {
|
|
1650
1746
|
try {
|
|
1651
|
-
this.adapter.delForeignObject(id, {user: socket._acl.user}, (error, ...args) =>
|
|
1652
|
-
SocketCommands._fixCallback(callback, error, ...args)
|
|
1747
|
+
this.adapter.delForeignObject(id, { user: socket._acl.user }, (error, ...args) =>
|
|
1748
|
+
SocketCommands._fixCallback(callback, error, ...args)
|
|
1749
|
+
);
|
|
1653
1750
|
} catch (error) {
|
|
1654
1751
|
this.adapter.log.error(`[delObject] ERROR: ${error.toString()}`);
|
|
1655
1752
|
SocketCommands._fixCallback(callback, error);
|
|
@@ -1681,8 +1778,9 @@ class SocketCommands {
|
|
|
1681
1778
|
this.clientSubscribes[sid][targetInstance].push(messageType);
|
|
1682
1779
|
}
|
|
1683
1780
|
// inform instance about new subscription
|
|
1684
|
-
this.adapter.sendTo(targetInstance, 'clientSubscribe', {type: messageType, sid, data}, result =>
|
|
1685
|
-
SocketCommands._fixCallback(callback, null, result)
|
|
1781
|
+
this.adapter.sendTo(targetInstance, 'clientSubscribe', { type: messageType, sid, data }, result =>
|
|
1782
|
+
SocketCommands._fixCallback(callback, null, result)
|
|
1783
|
+
);
|
|
1686
1784
|
};
|
|
1687
1785
|
|
|
1688
1786
|
this.commands['clientUnsubscribe'] = (socket, targetInstance, messageType, callback) => {
|
|
@@ -1701,7 +1799,11 @@ class SocketCommands {
|
|
|
1701
1799
|
if (pos !== -1) {
|
|
1702
1800
|
this.clientSubscribes[sid][targetInstance].splice(pos, 1);
|
|
1703
1801
|
// inform instance about unsubscription
|
|
1704
|
-
this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
|
|
1802
|
+
this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
|
|
1803
|
+
type: [messageType],
|
|
1804
|
+
sid,
|
|
1805
|
+
reason: 'client'
|
|
1806
|
+
});
|
|
1705
1807
|
SocketCommands._fixCallback(callback, null, true);
|
|
1706
1808
|
return;
|
|
1707
1809
|
}
|
|
@@ -1722,9 +1824,9 @@ class SocketCommands {
|
|
|
1722
1824
|
if (this.clientSubscribes[socketId]) {
|
|
1723
1825
|
Object.keys(this.clientSubscribes[socketId]).forEach(targetInstance => {
|
|
1724
1826
|
this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
|
|
1725
|
-
|
|
1827
|
+
type: this.clientSubscribes[socketId][targetInstance],
|
|
1726
1828
|
sid: socketId,
|
|
1727
|
-
reason: 'disconnect'
|
|
1829
|
+
reason: 'disconnect'
|
|
1728
1830
|
});
|
|
1729
1831
|
});
|
|
1730
1832
|
delete this.clientSubscribes[socketId];
|
|
@@ -1732,12 +1834,13 @@ class SocketCommands {
|
|
|
1732
1834
|
}
|
|
1733
1835
|
|
|
1734
1836
|
applyCommands(socket) {
|
|
1735
|
-
Object.keys(this.commands)
|
|
1736
|
-
|
|
1837
|
+
Object.keys(this.commands).forEach(command =>
|
|
1838
|
+
socket.on(command, (...args) => {
|
|
1737
1839
|
if (this._updateSession(socket)) {
|
|
1738
1840
|
this.commands[command](socket, ...args);
|
|
1739
1841
|
}
|
|
1740
|
-
})
|
|
1842
|
+
})
|
|
1843
|
+
);
|
|
1741
1844
|
}
|
|
1742
1845
|
|
|
1743
1846
|
destroy() {
|