@iobroker/socket-classes 1.0.2 → 1.1.1

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 CHANGED
@@ -87,6 +87,7 @@ io.close();
87
87
  * [setObject](#setobject_w)
88
88
  * [delObject](#delobject_w)
89
89
  * [getStates](#getstates_w)
90
+ * [getForeignStates](#getforeignstates_w)
90
91
  * [getState](#getstate_w)
91
92
  * [setState](#setstate_w)
92
93
  * [getBinaryState](#getbinarystate_w)
@@ -221,6 +222,11 @@ Read states by pattern
221
222
  * pattern *(string)*: optional pattern, like `system.adapter.*` or array of state IDs
222
223
  * callback *(function)*: `function (error, states)`, where `states` is an object like `{'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}`
223
224
 
225
+ ### <a name="getforeignstates_w"></a>getForeignStates(pattern, callback)
226
+ Read all states (which might not belong to this adapter) which match the given pattern
227
+ * pattern *(string)*: pattern like
228
+ * callback *(function)*: `function (error)`
229
+
224
230
  ### <a name="getstate_w"></a>getState(id, callback)
225
231
  Read one state.
226
232
  * id *(string)*: State ID like, 'system.adapter.admin.0.memRss'
@@ -430,6 +436,7 @@ Read all instances of the given adapter, or all instances of all adapters if ada
430
436
  * [getForeignObjects](#getforeignobjects_a)
431
437
  * [delObjects](#delobjects_a)
432
438
  * [getStates](#getstates_a)
439
+ * [getForeignStates](#getforeignstates_a)
433
440
  * [getState](#getstate_a)
434
441
  * [setState](#setstate_a)
435
442
  * [getBinaryState](#getbinarystate_a)
@@ -438,7 +445,6 @@ Read all instances of the given adapter, or all instances of all adapters if ada
438
445
  * [subscribeStates](#subscribestates_a)
439
446
  * [unsubscribe](#unsubscribe_a)
440
447
  * [unsubscribeStates](#unsubscribestates_a)
441
- * [getForeignStates](#getforeignstates_a)
442
448
  * [readFile](#readfile_a)
443
449
  * [readFile64](#readfile64_a)
444
450
  * [writeFile64](#writefile64_a)
@@ -717,6 +723,11 @@ Read states by pattern
717
723
  * pattern *(string)*: optional pattern, like `system.adapter.*` or array of state IDs
718
724
  * callback *(function)*: `function (error, states)`, where `states` is an object like `{'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}`
719
725
 
726
+ ### <a name="getforeignstates_a"></a>getForeignStates(pattern, callback)
727
+ Read all states (which might not belong to this adapter) which match the given pattern
728
+ * pattern *(string)*: pattern like
729
+ * callback *(function)*: `function (error)`
730
+
720
731
  ### <a name="getstate_a"></a>getState(id, callback)
721
732
  Read one state.
722
733
  * id *(string)*: State ID like, 'system.adapter.admin.0.memRss'
@@ -759,11 +770,6 @@ Unsubscribe from state changes by pattern. Same as `unsubscribe`.
759
770
  * pattern *(string)*: pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
760
771
  * callback *(function)*: `function (error)`
761
772
 
762
- ### <a name="getforeignstates_a"></a>getForeignStates(pattern, callback)
763
- Read all states (which might not belong to this adapter) which match the given pattern
764
- * pattern *(string)*: pattern like
765
- * callback *(function)*: `function (error)`
766
-
767
773
  ### <a name="readfile_a"></a>readFile(_adapter, fileName, callback)
768
774
  Read file from ioBroker DB
769
775
  * _adapter *(string)*: instance name, e.g. `vis.0`
@@ -882,6 +888,13 @@ Read all instances of the given adapter, or all instances of all adapters if ada
882
888
  -->
883
889
 
884
890
  ## Changelog
891
+ ### 1.1.1 (2022-12-22)
892
+ * (bluefox) Corrected error with subscribe
893
+
894
+ ### 1.1.0 (2022-12-22)
895
+ * (bluefox) Added user check to many commands
896
+ * (bluefox) Downgrade axios to 0.27.2
897
+
885
898
  ### 1.0.2 (2022-11-08)
886
899
  * (bluefox) Function `getObjects`for web was extended by devices, channels and enums
887
900
 
@@ -121,7 +121,7 @@ class SocketCommands {
121
121
  const files = await this.adapter.readDirAsync(_adapter, name, options);
122
122
  if (files && files.length) {
123
123
  for (let f = 0; f < files.length; f++) {
124
- await this._unlink(_adapter, name + '/' + files[f].file);
124
+ await this._unlink(_adapter, `${name}/${files[f].file}`);
125
125
  }
126
126
  }
127
127
  } catch (error) {
@@ -218,7 +218,7 @@ class SocketCommands {
218
218
 
219
219
  publishFile(socket, id, fileName, size) {
220
220
  if (socket && socket.subscribe && socket.subscribe.fileChange && this._updateSession(socket)) {
221
- const key = id + '####' + fileName;
221
+ const key = `${id}####${fileName}`;
222
222
  return !!socket.subscribe.fileChange.find(sub => {
223
223
  if (sub.regex.test(key)) {
224
224
  socket.emit('fileChange', id, fileName, size);
@@ -237,7 +237,7 @@ class SocketCommands {
237
237
  for (let i = 0; i < s.length; i++) {
238
238
  ids.push(s[i].pattern);
239
239
  }
240
- this.adapter.log.debug('Subscribes: ' + ids.join(', '));
240
+ this.adapter.log.debug(`Subscribes: ${ids.join(', ')}`);
241
241
  } else {
242
242
  this.adapter.log.debug('Subscribes: no subscribes');
243
243
  }
@@ -280,19 +280,21 @@ class SocketCommands {
280
280
  s.push({pattern: key, regex: new RegExp(p)});
281
281
  }
282
282
 
283
+ const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
284
+
283
285
  if (this.subscribes[type][key] === undefined) {
284
286
  this.subscribes[type][key] = 1;
285
287
  if (type === 'stateChange') {
286
- this.adapter.subscribeForeignStates(pattern);
288
+ this.adapter.subscribeForeignStates(pattern, options);
287
289
  } else if (type === 'objectChange') {
288
- this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern);
290
+ this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern, options);
289
291
  } else if (type === 'log') {
290
292
  if (!this.logEnabled && this.adapter.requireLog) {
291
293
  this.logEnabled = true;
292
- this.adapter.requireLog(true);
294
+ this.adapter.requireLog(true, options);
293
295
  }
294
296
  } else if (type === 'fileChange') {
295
- this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(pattern, patternFile);
297
+ this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(pattern, patternFile, options);
296
298
  }
297
299
  } else {
298
300
  this.subscribes[type][key]++;
@@ -317,6 +319,8 @@ class SocketCommands {
317
319
  key = pattern;
318
320
  }
319
321
 
322
+ const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
323
+
320
324
  if (socket && typeof socket === 'object') {
321
325
  if (!socket.subscribe || !socket.subscribe[type]) {
322
326
  return;
@@ -324,26 +328,25 @@ class SocketCommands {
324
328
 
325
329
  for (let i = socket.subscribe[type].length - 1; i >= 0; i--) {
326
330
  if (socket.subscribe[type][i].pattern === key) {
327
-
328
331
  // Remove pattern from global list
329
332
  if (this.subscribes[type][key] !== undefined) {
330
333
  this.subscribes[type][key]--;
331
334
  if (this.subscribes[type][key] <= 0) {
332
335
  if (type === 'stateChange') {
333
336
  //console.log((socket._name || socket.id) + ' unsubscribeForeignStates ' + pattern);
334
- this.adapter.unsubscribeForeignStates(pattern);
337
+ this.adapter.unsubscribeForeignStates(pattern, options);
335
338
  } else if (type === 'objectChange') {
336
339
  //console.log((socket._name || socket.id) + ' unsubscribeForeignObjects ' + pattern);
337
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
340
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, options);
338
341
  } else if (type === 'log') {
339
342
  //console.log((socket._name || socket.id) + ' requireLog false');
340
343
  if (this.logEnabled && this.adapter.requireLog) {
341
344
  this.logEnabled = false;
342
- this.adapter.requireLog(false);
345
+ this.adapter.requireLog(false, options);
343
346
  }
344
347
  } else if (type === 'fileChange') {
345
348
  //console.log((socket._name || socket.id) + ' requireLog false');
346
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile);
349
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
347
350
  }
348
351
  delete this.subscribes[type][pattern];
349
352
  }
@@ -360,16 +363,16 @@ class SocketCommands {
360
363
  this.subscribes[type][key]--;
361
364
  if (this.subscribes[type][key] <= 0) {
362
365
  if (type === 'stateChange') {
363
- this.adapter.unsubscribeForeignStates(pattern);
366
+ this.adapter.unsubscribeForeignStates(pattern, options);
364
367
  } else if (type === 'objectChange') {
365
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
368
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, options);
366
369
  } else if (type === 'log') {
367
370
  if (this.adapter.requireLog && this.logEnabled) {
368
371
  this.logEnabled = false;
369
- this.adapter.requireLog(false);
372
+ this.adapter.requireLog(false, options);
370
373
  }
371
374
  } else if (type === 'fileChange') {
372
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile);
375
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
373
376
  }
374
377
  delete this.subscribes[type][key];
375
378
  }
@@ -378,19 +381,19 @@ class SocketCommands {
378
381
  Object.keys(this.subscribes[type]).forEach(pattern => {
379
382
  if (type === 'stateChange') {
380
383
  //console.log((socket._name || socket.id) + ' unsubscribeForeignStates ' + pattern);
381
- this.adapter.unsubscribeForeignStates(pattern);
384
+ this.adapter.unsubscribeForeignStates(pattern, options);
382
385
  } else if (type === 'objectChange') {
383
386
  //console.log((socket._name || socket.id) + ' unsubscribeForeignObjects ' + pattern);
384
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
387
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, options);
385
388
  } else if (type === 'log') {
386
389
  //console.log((socket._name || socket.id) + ' requireLog false');
387
390
  if (this.adapter.requireLog && this.logEnabled) {
388
391
  this.logEnabled = false;
389
- this.adapter.requireLog(false);
392
+ this.adapter.requireLog(false, options);
390
393
  }
391
394
  } else if (type === 'fileChange') {
392
395
  const [id, fileName] = pattern.split('####');
393
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName);
396
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName, options);
394
397
  }
395
398
  });
396
399
 
@@ -405,26 +408,32 @@ class SocketCommands {
405
408
 
406
409
  if (!type) {
407
410
  // all
408
- return Object.keys(socket.subscribe).forEach(type => this.subscribeSocket(socket, type));
411
+ return Object.keys(socket.subscribe)
412
+ .forEach(type => this.subscribeSocket(socket, type));
409
413
  }
410
414
 
411
415
  if (!socket.subscribe[type]) {
412
416
  return;
413
417
  }
414
418
 
419
+ const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
420
+
415
421
  for (let i = 0; i < socket.subscribe[type].length; i++) {
416
422
  const pattern = socket.subscribe[type][i].pattern;
417
423
  if (this.subscribes[type][pattern] === undefined) {
418
424
  this.subscribes[type][pattern] = 1;
419
425
  if (type === 'stateChange') {
420
- this.adapter.subscribeForeignStates(pattern);
426
+ this.adapter.subscribeForeignStates(pattern, options);
421
427
  } else if (type === 'objectChange') {
422
- this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern);
428
+ this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern, options);
423
429
  } else if (type === 'log') {
424
430
  if (this.adapter.requireLog && !this.logEnabled) {
425
431
  this.logEnabled = true;
426
- this.adapter.requireLog(true);
432
+ this.adapter.requireLog(true, options);
427
433
  }
434
+ } else if (type === 'fileChange') {
435
+ const [id, fileName] = pattern.split('####');
436
+ this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(id, fileName, options);
428
437
  }
429
438
  } else {
430
439
  this.subscribes[type][pattern]++;
@@ -439,27 +448,33 @@ class SocketCommands {
439
448
 
440
449
  if (!type) {
441
450
  // all
442
- return Object.keys(socket.subscribe).forEach(type => this.unsubscribeSocket(socket, type));
451
+ return Object.keys(socket.subscribe)
452
+ .forEach(type => this.unsubscribeSocket(socket, type));
443
453
  }
444
454
 
445
455
  if (!socket.subscribe[type]) {
446
456
  return;
447
457
  }
448
458
 
459
+ const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
460
+
449
461
  for (let i = 0; i < socket.subscribe[type].length; i++) {
450
462
  const pattern = socket.subscribe[type][i].pattern;
451
463
  if (this.subscribes[type][pattern] !== undefined) {
452
464
  this.subscribes[type][pattern]--;
453
465
  if (this.subscribes[type][pattern] <= 0) {
454
466
  if (type === 'stateChange') {
455
- this.adapter.unsubscribeForeignStates(pattern);
467
+ this.adapter.unsubscribeForeignStates(pattern, options);
456
468
  } else if (type === 'objectChange') {
457
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
469
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, options);
458
470
  } else if (type === 'log') {
459
471
  if (this.adapter.requireLog && !this.logEnabled) {
460
472
  this.logEnabled = true;
461
- this.adapter.requireLog(true);
473
+ this.adapter.requireLog(true, options);
462
474
  }
475
+ } else if (type === 'fileChange') {
476
+ const [id, fileName] = pattern.split('####');
477
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName, options);
463
478
  }
464
479
  delete this.subscribes[type][pattern];
465
480
  }
@@ -657,7 +672,7 @@ class SocketCommands {
657
672
  // @param {function} callback - `function (error, {status, statusText}, body)`
658
673
  if (this._checkPermissions(socket, 'httpGet', callback, url)) {
659
674
  axios = axios || require('axios');
660
- this.adapter.log.debug('httpGet: ' + url);
675
+ this.adapter.log.debug(`httpGet: ${url}`);
661
676
  try {
662
677
  axios(url, {
663
678
  responseType: 'arraybuffer',
@@ -913,7 +928,7 @@ class SocketCommands {
913
928
  this.adapter.log.debug('writeFile deprecated. Please use writeFile64');
914
929
  // const buffer = Buffer.from(data64, 'base64');
915
930
  try {
916
- this.adapter.writeFile(_adapter, fileName, data, {user: socket._acl.user}, (error, ...args) =>
931
+ this.adapter.writeFile(_adapter, fileName, data, options, (error, ...args) =>
917
932
  SocketCommands._fixCallback(callback, error, ...args));
918
933
  } catch (error) {
919
934
  this.adapter.log.error('[writeFile] ERROR: ' + error.toString());
@@ -933,7 +948,7 @@ class SocketCommands {
933
948
  .then(() => SocketCommands._fixCallback(callback))
934
949
  .catch(error => SocketCommands._fixCallback(callback, error));
935
950
  } catch (error) {
936
- this.adapter.log.error('[unlink] ERROR: ' + error.toString());
951
+ this.adapter.log.error(`[unlink] ERROR: ${error.toString()}`);
937
952
  SocketCommands._fixCallback(callback, error);
938
953
  }
939
954
  }
@@ -1073,7 +1088,7 @@ class SocketCommands {
1073
1088
  this.adapter.chmodFile(_adapter, fileName, options, (error, ...args) =>
1074
1089
  SocketCommands._fixCallback(callback, error, ...args));
1075
1090
  } catch (error) {
1076
- this.adapter.log.error('[chmodFile] ERROR: ' + error.toString());
1091
+ this.adapter.log.error(`[chmodFile] ERROR: ${error.toString()}`);
1077
1092
  SocketCommands._fixCallback(callback, error);
1078
1093
  }
1079
1094
  }
@@ -1092,7 +1107,7 @@ class SocketCommands {
1092
1107
  this.adapter.chownFile(_adapter, fileName, options, (error, ...args) =>
1093
1108
  SocketCommands._fixCallback(callback, error, ...args));
1094
1109
  } catch (error) {
1095
- this.adapter.log.error('[chownFile] ERROR: ' + error.toString());
1110
+ this.adapter.log.error(`[chownFile] ERROR: ${error.toString()}`);
1096
1111
  SocketCommands._fixCallback(callback, error);
1097
1112
  }
1098
1113
  }
@@ -1108,7 +1123,7 @@ class SocketCommands {
1108
1123
  this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
1109
1124
  SocketCommands._fixCallback(callback, error, ...args));
1110
1125
  } catch (error) {
1111
- this.adapter.log.error('[fileExists] ERROR: ' + error.toString());
1126
+ this.adapter.log.error(`[fileExists] ERROR: ${error.toString()}`);
1112
1127
  SocketCommands._fixCallback(callback, error);
1113
1128
  }
1114
1129
  }
@@ -1144,6 +1159,7 @@ class SocketCommands {
1144
1159
  try {
1145
1160
  this.adapter.getObjectView('system', 'instance',
1146
1161
  {startkey: `system.adapter.${_adapterName}`, endkey: `system.adapter.${_adapterName}\u9999`},
1162
+ {user: socket._acl.user},
1147
1163
  (error, doc) => {
1148
1164
  if (error) {
1149
1165
  callback(error);
@@ -1194,6 +1210,25 @@ class SocketCommands {
1194
1210
  }
1195
1211
  };
1196
1212
 
1213
+ this.commands['getForeignStates'] = (socket, pattern, callback) => {
1214
+ // Read all states (which might not belong to this adapter) which match the given pattern
1215
+ // @param {string} pattern - pattern like
1216
+ // @param {function} callback - `function (error)`
1217
+ if (this._checkPermissions(socket, 'getStates', callback)) {
1218
+ if (typeof callback === 'function') {
1219
+ try {
1220
+ this.adapter.getForeignStates(pattern, {user: socket._acl.user}, (error, ...args) =>
1221
+ SocketCommands._fixCallback(callback, error, ...args));
1222
+ } catch (error) {
1223
+ this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
1224
+ SocketCommands._fixCallback(callback, error);
1225
+ }
1226
+ } else {
1227
+ this.adapter.log.warn('[getForeignStates] Invalid callback')
1228
+ }
1229
+ }
1230
+ };
1231
+
1197
1232
  this.commands['getState'] = (socket, id, callback) => {
1198
1233
  // Read one state.
1199
1234
  // @param {string} id - State ID like, 'system.adapter.admin.0.memRss'
@@ -1250,7 +1285,7 @@ class SocketCommands {
1250
1285
  if (typeof callback === 'function') {
1251
1286
  try {
1252
1287
  if (this.adapter.getForeignBinaryState) {
1253
- this.adapter.getForeignBinaryState(id, (error, data) => {
1288
+ this.adapter.getForeignBinaryState(id, {user: socket._acl.user}, (error, data) => {
1254
1289
  if (data) {
1255
1290
  try {
1256
1291
  data = Buffer.from(data).toString('base64');
@@ -1261,7 +1296,7 @@ class SocketCommands {
1261
1296
  SocketCommands._fixCallback(callback, error, data);
1262
1297
  });
1263
1298
  } else {
1264
- this.adapter.getBinaryState(id, (error, data) => {
1299
+ this.adapter.getBinaryState(id, {user: socket._acl.user}, (error, data) => {
1265
1300
  if (data) {
1266
1301
  try {
1267
1302
  data = Buffer.from(data).toString('base64');
@@ -1273,7 +1308,7 @@ class SocketCommands {
1273
1308
  });
1274
1309
  }
1275
1310
  } catch (error) {
1276
- this.adapter.log.error('[getBinaryState] ERROR: ' + error.toString());
1311
+ this.adapter.log.error(`[getBinaryState] ERROR: ${error.toString()}`);
1277
1312
  SocketCommands._fixCallback(callback, error);
1278
1313
  }
1279
1314
  } else {
@@ -1298,10 +1333,10 @@ class SocketCommands {
1298
1333
 
1299
1334
  try {
1300
1335
  if (this.adapter.setForeignBinaryState) {
1301
- this.adapter.setForeignBinaryState(id, data, (error, ...args) =>
1336
+ this.adapter.setForeignBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1302
1337
  SocketCommands._fixCallback(callback, error, ...args));
1303
1338
  } else {
1304
- this.adapter.setBinaryState(id, data, (error, ...args) =>
1339
+ this.adapter.setBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1305
1340
  SocketCommands._fixCallback(callback, error, ...args));
1306
1341
  }
1307
1342
  } catch (error) {
@@ -1460,7 +1495,7 @@ class SocketCommands {
1460
1495
  try {
1461
1496
  this.adapter.getObjectView(design, search, params, {user: socket._acl.user}, callback);
1462
1497
  } catch (error) {
1463
- this.adapter.log.error('[getObjectView] ERROR: ' + error.toString());
1498
+ this.adapter.log.error(`[getObjectView] ERROR: ${error.toString()}`);
1464
1499
  SocketCommands._fixCallback(callback, error);
1465
1500
  }
1466
1501
  }
@@ -165,7 +165,7 @@ class SocketCommandsAdmin extends SocketCommands {
165
165
  // remove this function when js.controller 4.x will be mainstream
166
166
  _readLicenses(login, password) {
167
167
  const config = {
168
- headers: { Authorization: `Basic ${Buffer.from(login + ':' + password).toString('base64')}` },
168
+ headers: { Authorization: `Basic ${Buffer.from(`${login}:${password}`).toString('base64')}` },
169
169
  timeout: 4000,
170
170
  validateStatus: status => status < 400
171
171
  };
@@ -190,18 +190,18 @@ class SocketCommandsAdmin extends SocketCommands {
190
190
  }
191
191
 
192
192
  // remove this function when js.controller 4.x will be mainstream
193
- _updateLicenses(login, password) {
193
+ _updateLicenses(login, password, options) {
194
194
  // if login and password provided in the message, just try to read without saving it in system.licenses
195
195
  if (login && password) {
196
196
  return this._readLicenses(login, password);
197
197
  } else {
198
198
  // get actual object
199
- return this.adapter.getForeignObjectAsync('system.licenses')
199
+ return this.adapter.getForeignObjectAsync('system.licenses', options)
200
200
  .then(systemLicenses => {
201
201
  // If password and login exist
202
202
  if (systemLicenses && systemLicenses.native && systemLicenses.native.password && systemLicenses.native.login) {
203
203
  // get the secret to decode the password
204
- return this.adapter.getForeignObjectAsync('system.config')
204
+ return this.adapter.getForeignObjectAsync('system.config', options)
205
205
  .then(systemConfig => {
206
206
  // decode the password
207
207
  let password;
@@ -231,7 +231,7 @@ class SocketCommandsAdmin extends SocketCommands {
231
231
  systemLicenses.native.readTime = new Date().toISOString();
232
232
 
233
233
  // save only if object changed
234
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
234
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
235
235
  .then(() => licenses);
236
236
  })
237
237
  .catch(error => {
@@ -241,7 +241,7 @@ class SocketCommandsAdmin extends SocketCommands {
241
241
  if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
242
242
  systemLicenses.native.licenses = [];
243
243
  systemLicenses.native.readTime = new Date().toISOString();
244
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
244
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
245
245
  .then(() => {
246
246
  throw error;
247
247
  });
@@ -257,7 +257,7 @@ class SocketCommandsAdmin extends SocketCommands {
257
257
  if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
258
258
  systemLicenses.native.licenses = [];
259
259
  systemLicenses.native.readTime = new Date().toISOString();
260
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
260
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
261
261
  .then(() => {
262
262
  throw new Error('No password or login');
263
263
  });
@@ -413,7 +413,7 @@ class SocketCommandsAdmin extends SocketCommands {
413
413
  }
414
414
 
415
415
  try {
416
- this.adapter.getForeignObject('system.group.' + group, options, (error, obj) => {
416
+ this.adapter.getForeignObject(`system.group.${group}`, options, (error, obj) => {
417
417
  if (obj) {
418
418
  SocketCommands._fixCallback(callback, 'Group yet exists');
419
419
  } else {
@@ -428,10 +428,10 @@ class SocketCommandsAdmin extends SocketCommands {
428
428
  }
429
429
  };
430
430
  try {
431
- this.adapter.setForeignObject('system.group.' + group, obj, options, error =>
431
+ this.adapter.setForeignObject(`system.group.${group}`, obj, options, error =>
432
432
  SocketCommands._fixCallback(callback, error, obj));
433
433
  } catch (error) {
434
- this.adapter.log.error('[_addGroup] cannot write group: ' + error.toString());
434
+ this.adapter.log.error(`[_addGroup] cannot write group: ${error.toString()}`);
435
435
  SocketCommands._fixCallback(callback, error);
436
436
  }
437
437
  }
@@ -452,11 +452,11 @@ class SocketCommandsAdmin extends SocketCommands {
452
452
  SocketCommands._fixCallback(callback, 'Cannot delete group, while is system group');
453
453
  } else {
454
454
  try {
455
- this.adapter.delForeignObject('system.group.' + group, options, error =>
455
+ this.adapter.delForeignObject(`system.group.${group}`, options, error =>
456
456
  // Remove this group from all users in web client
457
457
  SocketCommands._fixCallback(callback, error));
458
458
  } catch (error) {
459
- this.adapter.log.error('[_delGroup] cannot delete group: ' + error.toString());
459
+ this.adapter.log.error(`[_delGroup] cannot delete group: ${error.toString()}`);
460
460
  SocketCommands._fixCallback(callback, error);
461
461
  }
462
462
  }
@@ -520,7 +520,7 @@ class SocketCommandsAdmin extends SocketCommands {
520
520
  }
521
521
  } else {
522
522
  try {
523
- this.adapter.getObjectList({include_docs: true}, (error, res) => {
523
+ this.adapter.getObjectList({include_docs: true}, {user: socket._acl.user}, (error, res) => {
524
524
  this.adapter.log.info('received all objects');
525
525
  res = res.rows;
526
526
  const objects = {};
@@ -542,7 +542,7 @@ class SocketCommandsAdmin extends SocketCommands {
542
542
  }
543
543
  });
544
544
  } catch (error) {
545
- this.adapter.log.error('[_getAllObjects] ERROR: ' + error.toString());
545
+ this.adapter.log.error(`[_getAllObjects] ERROR: ${error.toString()}`);
546
546
  SocketCommands._fixCallback(callback, error);
547
547
  }
548
548
  }
@@ -705,7 +705,7 @@ class SocketCommandsAdmin extends SocketCommands {
705
705
  for (let f = 0; f < files.length; f++) {
706
706
  try {
707
707
  if (!files[f].endsWith('-audit.json')) {
708
- const stat = fs.lstatSync(fileName + '/' + files[f]);
708
+ const stat = fs.lstatSync(`${fileName}/${files[f]}`);
709
709
  if (!stat.isDirectory()) {
710
710
  result.list.push({
711
711
  fileName: `log/${transport}/${files[f]}`,
@@ -726,7 +726,7 @@ class SocketCommandsAdmin extends SocketCommands {
726
726
  result = {error: 'no file loggers'};
727
727
  }
728
728
  } catch (error) {
729
- this.adapter.log.error('Cannot read logs: ' + error);
729
+ this.adapter.log.error(`Cannot read logs: ${error}`);
730
730
  result = {error};
731
731
  }
732
732
  SocketCommands._fixCallback(callback, result.error, result.list);
@@ -754,7 +754,7 @@ class SocketCommandsAdmin extends SocketCommands {
754
754
  this.adapter.delForeignState(id, {user: socket._acl.user}, (error, ...args) =>
755
755
  SocketCommands._fixCallback(callback, error, ...args));
756
756
  } catch (error) {
757
- this.adapter.log.error('[delState] ERROR: ' + error.toString());
757
+ this.adapter.log.error(`[delState] ERROR: ${error.toString()}`);
758
758
  SocketCommands._fixCallback(callback, error);
759
759
  }
760
760
  }
@@ -776,7 +776,7 @@ class SocketCommandsAdmin extends SocketCommands {
776
776
  this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id});
777
777
  SocketCommands._fixCallback(callback, null);
778
778
  } catch (error) {
779
- this.adapter.log.error('[cmdExec] ERROR: ' + error.toString());
779
+ this.adapter.log.error(`[cmdExec] ERROR: ${error.toString()}`);
780
780
  SocketCommands._fixCallback(callback, error);
781
781
  }
782
782
  }
@@ -825,7 +825,7 @@ class SocketCommandsAdmin extends SocketCommands {
825
825
  SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
826
826
  } else {
827
827
  try {
828
- this.adapter.getForeignObject('system.config', (error, obj) => {
828
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
829
829
  if (obj && obj.native && obj.native.secret) {
830
830
  this.secret = obj.native.secret;
831
831
  SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
@@ -848,7 +848,7 @@ class SocketCommandsAdmin extends SocketCommands {
848
848
  if (this.secret) {
849
849
  SocketCommands._fixCallback(callback, null, this.adapter.encrypt(this.secret, plainText));
850
850
  } else {
851
- this.adapter.getForeignObject('system.config', (error, obj) => {
851
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
852
852
  if (obj && obj.native && obj.native.secret) {
853
853
  this.secret = obj.native.secret;
854
854
  try {
@@ -881,7 +881,7 @@ class SocketCommandsAdmin extends SocketCommands {
881
881
  if (this.adapter.config.auth) {
882
882
  user = socket._acl.user;
883
883
  if (!user.startsWith('system.user.')) {
884
- user = 'system.user.' + user;
884
+ user = `system.user.${user}`;
885
885
  }
886
886
  } else {
887
887
  user = this.adapter.config.defaultUser;
@@ -937,6 +937,7 @@ class SocketCommandsAdmin extends SocketCommands {
937
937
  if (typeof callback === 'function' && this._checkPermissions(socket, 'getObject', callback)) {
938
938
  this.adapter.getObjectView('system', 'adapter',
939
939
  {startkey: `system.adapter.${adapterName || ''}`, endkey: `system.adapter.${adapterName || '\u9999'}`},
940
+ {user: socket._acl.user},
940
941
  (error, doc) =>
941
942
  {
942
943
  if (error) {
@@ -981,7 +982,7 @@ class SocketCommandsAdmin extends SocketCommands {
981
982
  });
982
983
  } else {
983
984
  // remove this branch when js-controller 4.x will be mainstream
984
- this._updateLicenses(login, password)
985
+ this._updateLicenses(login, password, {user: socket._acl.user})
985
986
  .then(licenses => SocketCommands._fixCallback(callback, null, licenses))
986
987
  .catch(error => SocketCommands._fixCallback(callback, error));
987
988
  }
@@ -995,6 +996,7 @@ class SocketCommandsAdmin extends SocketCommands {
995
996
  if (this._checkPermissions(socket, 'getObject', callback)) {
996
997
  this.adapter.getObjectView('system', 'instance',
997
998
  {startkey: `system.adapter.`, endkey: `system.adapter.\u9999`},
999
+ {user: socket._acl.user},
998
1000
  (error, doc) => {
999
1001
  if (error) {
1000
1002
  callback(error);
@@ -1026,6 +1028,7 @@ class SocketCommandsAdmin extends SocketCommands {
1026
1028
  if (this._checkPermissions(socket, 'getObject', callback)) {
1027
1029
  this.adapter.getObjectView('system', 'adapter',
1028
1030
  {startkey: `system.adapter.`, endkey: `system.adapter.\u9999`},
1031
+ {user: socket._acl.user},
1029
1032
  (error, doc) => {
1030
1033
  if (error) {
1031
1034
  callback(error);
@@ -1068,7 +1071,7 @@ class SocketCommandsAdmin extends SocketCommands {
1068
1071
  // Read system config in short form to save bandwidth
1069
1072
  // @param {function} callback - `function (error, systemConfig)`, where `systemConfig` is an object like `{common: {...}, native: {secret: 'aaa'}}`
1070
1073
  if (this._checkPermissions(socket, 'getObject', callback)) {
1071
- this.adapter.getForeignObject('system.config', (error, obj) => {
1074
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
1072
1075
  obj = obj || {};
1073
1076
  const secret = obj && obj.native && obj.native.secret;
1074
1077
  delete obj.native;
@@ -1084,7 +1087,7 @@ class SocketCommandsAdmin extends SocketCommands {
1084
1087
  // Read repositories from cache in short form to save bandwidth
1085
1088
  // @param {function} callback - `function (error, repositories)`, where `repositories` is an object like `{_id: 'system.repositories', common: {...}, native: {repositories: {default: {json: {_repoInfo: {...}}}}}}`
1086
1089
  if (this._checkPermissions(socket, 'getObject', callback)) {
1087
- this.adapter.getForeignObject('system.repositories', (error, obj) => {
1090
+ this.adapter.getForeignObject('system.repositories', {user: socket._acl.user}, (error, obj) => {
1088
1091
  obj && obj.native && obj.native.repositories && Object.keys(obj.native.repositories).forEach(name => {
1089
1092
  if (obj.native.repositories[name].json) {
1090
1093
  // limit information to _repoInfo
@@ -1119,7 +1122,9 @@ class SocketCommandsAdmin extends SocketCommands {
1119
1122
  // @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:[...]}}}]`
1120
1123
  if (this._checkPermissions(socket, 'getObject', callback)) {
1121
1124
  this.adapter.getObjectView('system', 'host',
1122
- {startkey: 'system.host.', endkey: 'system.host.\u9999'}, (error, doc) => {
1125
+ {startkey: 'system.host.', endkey: 'system.host.\u9999'},
1126
+ {user: socket._acl.user},
1127
+ (error, doc) => {
1123
1128
  if (error) {
1124
1129
  callback(error);
1125
1130
  } else {
@@ -1158,29 +1163,6 @@ class SocketCommandsAdmin extends SocketCommands {
1158
1163
  this._initCommandsUser();
1159
1164
  }
1160
1165
 
1161
- __initCommandsStates() {
1162
- super.__initCommandsStates();
1163
-
1164
- this.commands['getForeignStates'] = (socket, pattern, callback) => {
1165
- // Read all states (which might not belong to this adapter) which match the given pattern
1166
- // @param {string} pattern - pattern like
1167
- // @param {function} callback - `function (error)`
1168
- if (this._checkPermissions(socket, 'getStates', callback)) {
1169
- if (typeof callback === 'function') {
1170
- try {
1171
- this.adapter.getForeignStates(pattern, (error, ...args) =>
1172
- SocketCommands._fixCallback(callback, error, ...args));
1173
- } catch (error) {
1174
- this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
1175
- SocketCommands._fixCallback(callback, error);
1176
- }
1177
- } else {
1178
- this.adapter.log.warn('[getForeignStates] Invalid callback')
1179
- }
1180
- }
1181
- };
1182
- }
1183
-
1184
1166
  __initCommandsFiles() {
1185
1167
  super.__initCommandsFiles();
1186
1168
 
@@ -1204,8 +1186,8 @@ class SocketCommandsAdmin extends SocketCommands {
1204
1186
  this.adapter.writeFile(_adapter, fileName, buffer, {user: socket._acl.user}, (error, ...args) =>
1205
1187
  SocketCommands._fixCallback(callback, error, ...args));
1206
1188
  } catch (error) {
1207
- this.adapter.log.error('[writeFile] Cannot convert data: ' + error.toString());
1208
- callback && callback('Cannot convert data: ' + error.toString());
1189
+ this.adapter.log.error(`[writeFile] Cannot convert data: ${error.toString()}`);
1190
+ callback && callback(`Cannot convert data: ${error.toString()}`);
1209
1191
  }
1210
1192
  }
1211
1193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",