@iobroker/socket-classes 0.4.6 → 0.4.9

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
@@ -69,6 +69,12 @@ io.close();
69
69
  -->
70
70
 
71
71
  ## Changelog
72
+ ### 0.4.9 (2022-06-20)
73
+ * (bluefox) Do not show error with failed authentication
74
+
75
+ ### 0.4.7 (2022-06-20)
76
+ * (bluefox) Allowed to overload system language
77
+
72
78
  ### 0.4.6 (2022-06-20)
73
79
  * (bluefox) updated `passport`
74
80
 
@@ -217,6 +217,10 @@ class SocketCommands {
217
217
  if (socket && socket.subscribe && socket.subscribe[type] && this._updateSession(socket)) {
218
218
  return !!socket.subscribe[type].find(sub => {
219
219
  if (sub.regex.test(id)) {
220
+ // replace language
221
+ if (this.adapter._language && id === 'system.config' && obj.common) {
222
+ obj.common.language = this.adapter._language;
223
+ }
220
224
  socket.emit(type, id, obj);
221
225
  return true;
222
226
  }
@@ -622,34 +626,32 @@ class SocketCommands {
622
626
  // host can answer following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo,
623
627
  // delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
624
628
  if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', callback, command)) {
625
- if (this.sendToHost) {
626
- this.sendToHost(host, command, message, callback);
627
- } else {
628
- // Try to decode this file locally as redis has a limitation for files bigger than 20MB
629
- if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
630
- if (!zipFiles) {
631
- const utils = require('@iobroker/adapter-core'); // Get common adapter utils
632
- zipFiles = require(utils.controllerDir + '/lib/zipFiles.js');
633
- }
634
- zipFiles
635
- .writeDirAsZip(
636
- this.adapter, // normally we have to pass here the internal "objects" object, but as
637
- // only writeFile is used, and it has the same name we can pass here the
638
- // adapter, which has the function with the same name and arguments
639
- message.id,
640
- message.name,
641
- Buffer.from(message.data, 'base64'),
642
- message.options,
643
- error => callback({ error }) // this is for back compatibility with js-controller@4.0 or older
644
- )
645
- .then(() => callback({}))
646
- .catch(error => {
647
- this.adapter.log.error(`Cannot write zip file as folder: ${error}`);
648
- callback({ error });
649
- });
650
- } else {
651
- this.adapter.sendToHost(host, command, message, callback);
629
+ // Try to decode this file locally as redis has a limitation for files bigger than 20MB
630
+ if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
631
+ if (!zipFiles) {
632
+ const utils = require('@iobroker/adapter-core'); // Get common adapter utils
633
+ zipFiles = require(utils.controllerDir + '/lib/zipFiles.js');
652
634
  }
635
+ zipFiles
636
+ .writeDirAsZip(
637
+ this.adapter, // normally we have to pass here the internal "objects" object, but as
638
+ // only writeFile is used, and it has the same name we can pass here the
639
+ // adapter, which has the function with the same name and arguments
640
+ message.id,
641
+ message.name,
642
+ Buffer.from(message.data, 'base64'),
643
+ message.options,
644
+ error => callback({ error }) // this is for back compatibility with js-controller@4.0 or older
645
+ )
646
+ .then(() => callback({}))
647
+ .catch(error => {
648
+ this.adapter.log.error(`Cannot write zip file as folder: ${error}`);
649
+ callback({ error });
650
+ });
651
+ } else if (this._sendToHost) {
652
+ this._sendToHost(host, command, message, callback);
653
+ } else {
654
+ this.adapter.sendToHost(host, command, message, callback);
653
655
  }
654
656
  }
655
657
  };
@@ -1028,8 +1030,13 @@ class SocketCommands {
1028
1030
  __initCommandsObjects() {
1029
1031
  this.commands['getObject'] = (socket, id, callback) => {
1030
1032
  if (this._checkPermissions(socket, 'getObject', callback, id)) {
1031
- this.adapter.getForeignObject(id, {user: socket._acl.user}, (err, ...args) =>
1032
- SocketCommands._fixCallback(callback, err, ...args));
1033
+ this.adapter.getForeignObject(id, {user: socket._acl.user}, (err, obj) => {
1034
+ // overload language from current instance
1035
+ if (this.adapter._language && id === 'system.config' && obj.common) {
1036
+ obj.common.language = this.adapter._language;
1037
+ }
1038
+ SocketCommands._fixCallback(callback, err, obj);
1039
+ });
1033
1040
  }
1034
1041
  };
1035
1042
 
@@ -1038,6 +1045,11 @@ class SocketCommands {
1038
1045
  if (this._checkPermissions(socket, 'getObjects', callback)) {
1039
1046
  this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, (err, objs) => {
1040
1047
  if (typeof callback === 'function') {
1048
+ // overload language
1049
+ if (this.adapter._language && objs['system.config'] && objs['system.config'].common) {
1050
+ objs['system.config'].common.language = this.adapter._language;
1051
+ }
1052
+
1041
1053
  callback(err, objs);
1042
1054
  } else {
1043
1055
  this.adapter.log.warn('[getObjects] Invalid callback');
@@ -171,6 +171,7 @@ class SocketCommandsAdmin extends SocketCommands {
171
171
  delete this.cache[hash];
172
172
  }
173
173
  }
174
+
174
175
  this.adapter.sendToHost(host, command, message, res => {
175
176
  if (!message && SocketCommandsAdmin.ALLOW_CACHE.includes(command)) {
176
177
  this.cache[hash] = {ts: Date.now(), res: JSON.stringify(res)};
@@ -18,6 +18,7 @@ class SocketCommon {
18
18
  this.infoTimeout = null;
19
19
  this.eventHandlers = {};
20
20
  this.store = null; // will be set in __initAuthentication
21
+ this.adapter._language = this.settings.language;
21
22
  }
22
23
 
23
24
  __getIsNoDisconnect() {
@@ -107,14 +108,25 @@ class SocketCommon {
107
108
  this.server.on('error', (error, details) => {
108
109
  // ignore "failed connection" as it already shown
109
110
  if (!error || !error.message || !error.message.includes('failed connection')) {
110
- this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
111
+ if ((error && error.message && error.message.includes('authentication failed') ||
112
+ (details && details.includes('authentication failed')))
113
+ ) {
114
+ this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
115
+ } else {
116
+ this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
117
+ }
111
118
  }
112
119
  });
120
+
113
121
  // support of dynamic namespaces (because of reverse proxy)
114
122
  this.allNamespaces && this.allNamespaces.on('error', (error, details) => {
115
123
  // ignore "failed connection" as it already shown
116
124
  if (!error || !error.message || !error.message.includes('failed connection')) {
117
- this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
125
+ if (error && error.message && error.message.includes('authentication failed')) {
126
+ this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
127
+ } else {
128
+ this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
129
+ }
118
130
  }
119
131
  });
120
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "0.4.6",
3
+ "version": "0.4.9",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",