@iobroker/socket-classes 0.4.5 → 0.4.8
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 +9 -0
- package/lib/socketCommands.js +41 -29
- package/lib/socketCommandsAdmin.js +1 -0
- package/lib/socketCommon.js +12 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -69,6 +69,15 @@ io.close();
|
|
|
69
69
|
-->
|
|
70
70
|
|
|
71
71
|
## Changelog
|
|
72
|
+
### 0.4.8 (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
|
+
|
|
78
|
+
### 0.4.6 (2022-06-20)
|
|
79
|
+
* (bluefox) updated `passport`
|
|
80
|
+
|
|
72
81
|
### 0.4.5 (2022-06-20)
|
|
73
82
|
* (bluefox) allow to run socket.io behind reverse proxy
|
|
74
83
|
|
package/lib/socketCommands.js
CHANGED
|
@@ -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
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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,
|
|
1032
|
-
|
|
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)};
|
package/lib/socketCommon.js
CHANGED
|
@@ -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,23 @@ 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
|
-
|
|
111
|
+
if (error && error.message && error.message.includes('authentication failed')) {
|
|
112
|
+
this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
113
|
+
} else {
|
|
114
|
+
this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
115
|
+
}
|
|
111
116
|
}
|
|
112
117
|
});
|
|
118
|
+
|
|
113
119
|
// support of dynamic namespaces (because of reverse proxy)
|
|
114
120
|
this.allNamespaces && this.allNamespaces.on('error', (error, details) => {
|
|
115
121
|
// ignore "failed connection" as it already shown
|
|
116
122
|
if (!error || !error.message || !error.message.includes('failed connection')) {
|
|
117
|
-
|
|
123
|
+
if (error && error.message && error.message.includes('authentication failed')) {
|
|
124
|
+
this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
125
|
+
} else {
|
|
126
|
+
this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
127
|
+
}
|
|
118
128
|
}
|
|
119
129
|
});
|
|
120
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/socket-classes",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "ioBroker server-side web sockets",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "bluefox",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/ioBroker/ioBroker.socket-classes"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"passport": "^0.
|
|
24
|
+
"passport": "^0.6.0",
|
|
25
25
|
"cookie-parser": "^1.4.6",
|
|
26
26
|
"axios": "^0.27.2"
|
|
27
27
|
},
|