@iobroker/socket-classes 2.0.0 → 2.0.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 +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/passportSocket.d.ts +32 -25
- package/dist/lib/passportSocket.js +43 -34
- package/dist/lib/passportSocket.js.map +1 -1
- package/dist/lib/socketAdmin.d.ts +41 -0
- package/dist/lib/socketAdmin.js +213 -0
- package/dist/lib/socketAdmin.js.map +1 -0
- package/dist/lib/socketCommands.d.ts +3 -3
- package/dist/lib/socketCommands.js +1 -10
- package/dist/lib/socketCommands.js.map +1 -1
- package/dist/lib/socketCommandsAdmin.d.ts +9 -3
- package/dist/lib/socketCommandsAdmin.js +8 -6
- package/dist/lib/socketCommandsAdmin.js.map +1 -1
- package/dist/lib/socketCommon.d.ts +11 -9
- package/dist/lib/socketCommon.js +27 -2
- package/dist/lib/socketCommon.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -992,14 +992,14 @@ Unsubscribe from file changes in ioBroker DB
|
|
|
992
992
|
-->
|
|
993
993
|
|
|
994
994
|
## Changelog
|
|
995
|
-
### 2.0.
|
|
995
|
+
### 2.0.3 (2025-02-07)
|
|
996
996
|
* (@GermanBluefox) Code migrated to TypeScript
|
|
997
997
|
|
|
998
998
|
### 1.6.2 (2024-12-01)
|
|
999
999
|
* (@GermanBluefox) Caught the error if no authentication and logout called
|
|
1000
1000
|
|
|
1001
1001
|
### 1.6.1 (2024-10-05)
|
|
1002
|
-
* (@GermanBluefox) Added support
|
|
1002
|
+
* (@GermanBluefox) Added support for iobroker.SocketIO with TypeScript
|
|
1003
1003
|
|
|
1004
1004
|
### 1.5.6 (2024-06-26)
|
|
1005
1005
|
* (@GermanBluefox) Corrected call of getObjectView with null parameter
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import passport from 'passport';
|
|
|
2
2
|
import cookieParser from 'cookie-parser';
|
|
3
3
|
export { SocketCommandsAdmin } from './lib/socketCommandsAdmin';
|
|
4
4
|
export { SocketCommands, type SupportedFeature } from './lib/socketCommands';
|
|
5
|
-
export { SocketCommon } from './lib/socketCommon';
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export { SocketCommon, type Server } from './lib/socketCommon';
|
|
6
|
+
export { SocketAdmin } from './lib/socketAdmin';
|
|
7
|
+
import { authorize as passportSocket, type PassportHttpRequest, type Store } from './lib/passportSocket';
|
|
8
|
+
export { passport, cookieParser, passportSocket, type PassportHttpRequest, type Store };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.passportSocket = exports.cookieParser = exports.passport = exports.SocketCommon = exports.SocketCommands = exports.SocketCommandsAdmin = void 0;
|
|
6
|
+
exports.passportSocket = exports.cookieParser = exports.passport = exports.SocketAdmin = exports.SocketCommon = exports.SocketCommands = exports.SocketCommandsAdmin = void 0;
|
|
7
7
|
const passport_1 = __importDefault(require("passport"));
|
|
8
8
|
exports.passport = passport_1.default;
|
|
9
9
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
@@ -14,6 +14,8 @@ var socketCommands_1 = require("./lib/socketCommands");
|
|
|
14
14
|
Object.defineProperty(exports, "SocketCommands", { enumerable: true, get: function () { return socketCommands_1.SocketCommands; } });
|
|
15
15
|
var socketCommon_1 = require("./lib/socketCommon");
|
|
16
16
|
Object.defineProperty(exports, "SocketCommon", { enumerable: true, get: function () { return socketCommon_1.SocketCommon; } });
|
|
17
|
+
var socketAdmin_1 = require("./lib/socketAdmin");
|
|
18
|
+
Object.defineProperty(exports, "SocketAdmin", { enumerable: true, get: function () { return socketAdmin_1.SocketAdmin; } });
|
|
17
19
|
const passportSocket_1 = require("./lib/passportSocket");
|
|
18
20
|
Object.defineProperty(exports, "passportSocket", { enumerable: true, get: function () { return passportSocket_1.authorize; } });
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAOvB,mBAPF,kBAAQ,CAOE;AANjB,kEAAyC;AAMtB,uBANZ,uBAAY,CAMY;AAL/B,iEAAgE;AAAvD,0HAAA,mBAAmB,OAAA;AAC5B,uDAA6E;AAApE,gHAAA,cAAc,OAAA;AACvB,mDAA+D;AAAtD,4GAAA,YAAY,OAAA;AACrB,iDAAgD;AAAvC,0GAAA,WAAW,OAAA;AACpB,yDAAyG;AACxE,+FADX,0BAAc,OACW"}
|
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type * as express from 'express';
|
|
3
|
+
import type * as passport from 'passport';
|
|
4
|
+
export interface PassportHttpRequest extends IncomingMessage {
|
|
4
5
|
headers: {
|
|
5
6
|
cookie: string;
|
|
6
7
|
};
|
|
8
|
+
query: Record<string, string>;
|
|
9
|
+
cookie: Record<string, string> | undefined;
|
|
10
|
+
sessionID: string;
|
|
11
|
+
user: {
|
|
12
|
+
logged_in: boolean;
|
|
13
|
+
user?: string;
|
|
14
|
+
};
|
|
7
15
|
}
|
|
8
16
|
export interface Store {
|
|
9
|
-
get: (
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
get: (sessionId: string, cb: (err: Error, session: {
|
|
18
|
+
cookie: {
|
|
19
|
+
originalMaxAge: number;
|
|
20
|
+
expires: string;
|
|
21
|
+
httpOnly: boolean;
|
|
22
|
+
path: string;
|
|
23
|
+
};
|
|
24
|
+
passport: {
|
|
25
|
+
user: string;
|
|
12
26
|
};
|
|
13
|
-
}
|
|
27
|
+
}) => void) => void;
|
|
14
28
|
}
|
|
15
|
-
export declare function authorize(
|
|
16
|
-
passport: {
|
|
29
|
+
export declare function authorize(auth: {
|
|
30
|
+
passport: passport.PassportStatic & {
|
|
17
31
|
_key: string;
|
|
18
32
|
};
|
|
19
|
-
cookieParser: (secret: string |
|
|
33
|
+
cookieParser: (secret: string | string[] | undefined, options?: {
|
|
34
|
+
decode?(val: string): string;
|
|
35
|
+
}) => express.RequestHandler;
|
|
20
36
|
checkUser?: (user: string, pass: string, cb: (error: Error | null, result?: {
|
|
21
37
|
logged_in: boolean;
|
|
22
38
|
}) => void) => void;
|
|
23
|
-
fail: (data:
|
|
24
|
-
success: (data:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
url: string;
|
|
30
|
-
query: Record<string, string>;
|
|
31
|
-
cookie: Record<string, string> | undefined;
|
|
32
|
-
sessionID: string;
|
|
33
|
-
user: {
|
|
34
|
-
logged_in: boolean;
|
|
35
|
-
};
|
|
36
|
-
}, accept: (err: Error | null) => void) => void;
|
|
37
|
-
export {};
|
|
39
|
+
fail: (data: PassportHttpRequest, message: string, critical: boolean, accept: (err: boolean) => void) => void;
|
|
40
|
+
success: (data: PassportHttpRequest, accept: (err: boolean) => void) => void;
|
|
41
|
+
secret?: string;
|
|
42
|
+
store?: Store;
|
|
43
|
+
userProperty?: string;
|
|
44
|
+
}): (req: IncomingMessage, accept: (err: boolean) => void) => void;
|
|
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.authorize = authorize;
|
|
6
6
|
function parseCookie(auth, cookieHeader) {
|
|
7
7
|
const cookieParser = auth.cookieParser(auth.secret);
|
|
8
|
+
// Simulate header
|
|
8
9
|
const req = {
|
|
9
10
|
headers: {
|
|
10
11
|
cookie: cookieHeader,
|
|
11
12
|
},
|
|
12
13
|
};
|
|
13
14
|
let result;
|
|
14
|
-
cookieParser(req, {}, err => {
|
|
15
|
+
void cookieParser(req, {}, (err) => {
|
|
15
16
|
if (err) {
|
|
16
17
|
throw new Error(err);
|
|
17
18
|
}
|
|
@@ -20,7 +21,7 @@ function parseCookie(auth, cookieHeader) {
|
|
|
20
21
|
return result;
|
|
21
22
|
}
|
|
22
23
|
function getQuery(url) {
|
|
23
|
-
const query = url.split('?')[1] || '';
|
|
24
|
+
const query = (url || '').split('?')[1] || '';
|
|
24
25
|
const parts = query.split('&');
|
|
25
26
|
const result = {};
|
|
26
27
|
for (let p = 0; p < parts.length; p++) {
|
|
@@ -29,59 +30,67 @@ function getQuery(url) {
|
|
|
29
30
|
}
|
|
30
31
|
return result;
|
|
31
32
|
}
|
|
32
|
-
function authorize(
|
|
33
|
-
const defaults = {
|
|
34
|
-
key: 'connect.sid',
|
|
35
|
-
secret: null,
|
|
36
|
-
store: null,
|
|
37
|
-
userProperty: 'user',
|
|
38
|
-
};
|
|
39
|
-
const auth = Object.assign({}, defaults, options);
|
|
33
|
+
function authorize(auth) {
|
|
40
34
|
if (!auth.passport) {
|
|
41
35
|
throw new Error("passport is required to use require('passport'), please install passport");
|
|
42
36
|
}
|
|
43
37
|
if (!auth.cookieParser) {
|
|
44
38
|
throw new Error("cookieParser is required use require('cookie-parser'), connect.cookieParser or express.cookieParser");
|
|
45
39
|
}
|
|
46
|
-
return function (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
return function (req, accept) {
|
|
41
|
+
const extendedReq = req;
|
|
42
|
+
extendedReq.query = getQuery(extendedReq.url);
|
|
43
|
+
if (auth.checkUser && extendedReq.query.user && extendedReq.query.pass) {
|
|
44
|
+
return auth.checkUser(extendedReq.query.user, extendedReq.query.pass, (error, result) => {
|
|
50
45
|
if (error) {
|
|
51
|
-
return auth.fail(
|
|
46
|
+
return auth.fail(extendedReq, 'Cannot check user', false, accept);
|
|
52
47
|
}
|
|
53
48
|
if (!result) {
|
|
54
|
-
return auth.fail(
|
|
49
|
+
return auth.fail(extendedReq, 'User not found', false, accept);
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
extendedReq.user = result;
|
|
52
|
+
extendedReq.user.user = extendedReq.query.user;
|
|
53
|
+
extendedReq.user.logged_in = true;
|
|
54
|
+
auth.success(extendedReq, accept);
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
57
|
+
extendedReq.cookie = parseCookie(auth, extendedReq.headers.cookie || '');
|
|
58
|
+
if (extendedReq.cookie) {
|
|
59
|
+
extendedReq.sessionID = extendedReq.cookie['connect.sid'] || '';
|
|
64
60
|
}
|
|
65
|
-
|
|
61
|
+
extendedReq.user = {
|
|
66
62
|
logged_in: false,
|
|
67
63
|
};
|
|
68
|
-
auth.store?.get(
|
|
64
|
+
auth.store?.get(extendedReq.sessionID, (err, session) => {
|
|
65
|
+
// session looks like:
|
|
66
|
+
// {
|
|
67
|
+
// cookie: {
|
|
68
|
+
// originalMaxAge: 5999991,
|
|
69
|
+
// expires: '2025-02-07T17:15:06.466Z',
|
|
70
|
+
// httpOnly: true,
|
|
71
|
+
// path: '/',
|
|
72
|
+
// },
|
|
73
|
+
// passport: {
|
|
74
|
+
// user: 'admin',
|
|
75
|
+
// },
|
|
76
|
+
// };
|
|
69
77
|
if (err) {
|
|
70
|
-
return auth.fail(
|
|
78
|
+
return auth.fail(extendedReq, `Error in session store:\n${err.message}`, true, accept);
|
|
71
79
|
}
|
|
72
80
|
if (!session) {
|
|
73
|
-
return auth.fail(
|
|
81
|
+
return auth.fail(extendedReq, 'No session found', false, accept);
|
|
74
82
|
}
|
|
75
|
-
if (!session
|
|
76
|
-
return auth.fail(
|
|
83
|
+
if (!session.passport) {
|
|
84
|
+
return auth.fail(extendedReq, 'Passport was not initialized', true, accept);
|
|
77
85
|
}
|
|
78
|
-
const userKey = session
|
|
79
|
-
if (
|
|
80
|
-
return auth.fail(
|
|
86
|
+
const userKey = session.passport.user;
|
|
87
|
+
if (!userKey) {
|
|
88
|
+
return auth.fail(extendedReq, 'User not authorized through passport. (User Property not found)', false, accept);
|
|
81
89
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
// extendedReq.user
|
|
91
|
+
extendedReq.user = session.passport;
|
|
92
|
+
extendedReq.user.logged_in = true;
|
|
93
|
+
auth.success(extendedReq, accept);
|
|
85
94
|
});
|
|
86
95
|
};
|
|
87
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passportSocket.js","sourceRoot":"","sources":["../../src/lib/passportSocket.ts"],"names":[],"mappings":";AAAA,yGAAyG;AACzG,0EAA0E;;
|
|
1
|
+
{"version":3,"file":"passportSocket.js","sourceRoot":"","sources":["../../src/lib/passportSocket.ts"],"names":[],"mappings":";AAAA,yGAAyG;AACzG,0EAA0E;;AAqF1E,8BAoHC;AA7JD,SAAS,WAAW,CAChB,IAMC,EACD,YAAoB;IAEpB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,kBAAkB;IAClB,MAAM,GAAG,GAAgB;QACrB,OAAO,EAAE;YACL,MAAM,EAAE,YAAY;SACvB;KACJ,CAAC;IAEF,IAAI,MAA0C,CAAC;IAE/C,KAAK,YAAY,CAAC,GAAsB,EAAE,EAAsB,EAAE,CAAC,GAAW,EAAQ,EAAE;QACpF,IAAI,GAAG,EAAE,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QACD,MAAM,GAAG,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,OAAO,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,QAAQ,CAAC,GAAuB;IACrC,MAAM,KAAK,GA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CAAC;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,8BAA8B,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YAChF,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAEtC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC,IAAI,CACZ,WAAW,EACX,iEAAiE,EACjE,KAAK,EACL,MAAM,CACT,CAAC;YACN,CAAC;YAED,mBAAmB;YACnB,WAAW,CAAC,IAAI,GAAG,OAAO,CAAC,QAAiD,CAAC;YAC7E,WAAW,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC,CACJ,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class Socket
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2014-2025 bluefox <dogafox@gmail.com>,
|
|
5
|
+
* MIT License
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { type Server, SocketCommon, type SocketIoOptions, type SocketSettings } from './socketCommon';
|
|
9
|
+
import { type Store } from './passportSocket';
|
|
10
|
+
import type { Socket as WebSocketClient, SocketIO } from '@iobroker/ws-server';
|
|
11
|
+
import type { AddressInfo } from 'node:net';
|
|
12
|
+
import type { SocketSubscribeTypes } from '../types';
|
|
13
|
+
import type { Ratings } from './socketCommands';
|
|
14
|
+
export declare class SocketAdmin extends SocketCommon {
|
|
15
|
+
#private;
|
|
16
|
+
private adminCommands;
|
|
17
|
+
constructor(settings: SocketSettings, adapter: ioBroker.Adapter, objects: Record<string, ioBroker.Object>);
|
|
18
|
+
__getIsNoDisconnect(): boolean;
|
|
19
|
+
__initAuthentication(authOptions: {
|
|
20
|
+
store: Store;
|
|
21
|
+
secret: string;
|
|
22
|
+
}): void;
|
|
23
|
+
__getUserFromSocket(socket: WebSocketClient, callback: (error: string | null, user?: string) => void): void;
|
|
24
|
+
__getClientAddress(socket: WebSocketClient): AddressInfo;
|
|
25
|
+
__updateSession(socket: WebSocketClient): boolean;
|
|
26
|
+
__getSessionID(socket: WebSocketClient): string | null;
|
|
27
|
+
start(server: Server, socketClass: typeof SocketIO, authOptions: {
|
|
28
|
+
store: Store;
|
|
29
|
+
userKey: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
}, socketOptions?: SocketIoOptions): void;
|
|
32
|
+
onThresholdChanged(enabled: boolean): void;
|
|
33
|
+
stateChange(id: string, state: ioBroker.State | null | undefined): void;
|
|
34
|
+
fileChange(id: string, fileName: string, size: number): void;
|
|
35
|
+
repoUpdated(): void;
|
|
36
|
+
objectChange(id: string, obj: ioBroker.Object | null | undefined): void;
|
|
37
|
+
subscribe(type: SocketSubscribeTypes, pattern: string): void;
|
|
38
|
+
subscribeFile(id: string, patternFile: string): void;
|
|
39
|
+
sendCommand(obj: ioBroker.Message): void;
|
|
40
|
+
updateRatings(uuid?: string, isAutoUpdate?: boolean): Promise<Ratings | null>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SocketAdmin = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Class Socket
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2014-2025 bluefox <dogafox@gmail.com>,
|
|
11
|
+
* MIT License
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
const socketCommon_1 = require("./socketCommon");
|
|
15
|
+
const socketCommandsAdmin_1 = require("./socketCommandsAdmin");
|
|
16
|
+
const passport_1 = __importDefault(require("passport"));
|
|
17
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
18
|
+
const passportSocket_1 = require("./passportSocket");
|
|
19
|
+
class SocketAdmin extends socketCommon_1.SocketCommon {
|
|
20
|
+
adminCommands;
|
|
21
|
+
constructor(settings, adapter, objects) {
|
|
22
|
+
super(settings, adapter);
|
|
23
|
+
// user another set of commands for admin
|
|
24
|
+
this.commands = new socketCommandsAdmin_1.SocketCommandsAdmin(adapter, socket => this.__updateSession(socket), this.context, objects);
|
|
25
|
+
this.adminCommands = this.commands;
|
|
26
|
+
}
|
|
27
|
+
__getIsNoDisconnect() {
|
|
28
|
+
// ws does not require disconnect
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
#onAuthorizeSuccess = (data, accept) => {
|
|
32
|
+
this.adapter.log.debug(`successful connection to socket.io from ${(data.socket || data.connection).remoteAddress}`);
|
|
33
|
+
// no error
|
|
34
|
+
accept(false);
|
|
35
|
+
};
|
|
36
|
+
#onAuthorizeFail = (data, message, critical, accept) => {
|
|
37
|
+
setTimeout(() => data.socket.emit(socketCommon_1.SocketCommon.COMMAND_RE_AUTHENTICATE), 100);
|
|
38
|
+
if (critical) {
|
|
39
|
+
this.adapter?.log.info(`failed connection to socket.io from ${(data.socket || data.connection).remoteAddress}: ${message}`);
|
|
40
|
+
}
|
|
41
|
+
// this error will be sent to the user as a special error-package
|
|
42
|
+
// see: http://socket.io/docs/client-api/#socket > error-object
|
|
43
|
+
if (critical) {
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
accept(new Error(message));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
accept(new Error(`failed connection to socket.io: ${message}`));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__initAuthentication(authOptions) {
|
|
53
|
+
this.store = authOptions.store;
|
|
54
|
+
this.server?.use((0, passportSocket_1.authorize)({
|
|
55
|
+
passport: passport_1.default,
|
|
56
|
+
cookieParser: cookie_parser_1.default,
|
|
57
|
+
secret: authOptions.secret, // the session_secret to parse the cookie
|
|
58
|
+
store: authOptions.store, // we NEED to use a sessionstore. no memorystore, please
|
|
59
|
+
success: this.#onAuthorizeSuccess, // *optional* callback on success - read more below
|
|
60
|
+
fail: this.#onAuthorizeFail, // *optional* callback on fail/error - read more below
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
// Extract username from socket
|
|
64
|
+
__getUserFromSocket(socket, callback) {
|
|
65
|
+
if (socket.conn.request.sessionID) {
|
|
66
|
+
socket._secure = true;
|
|
67
|
+
socket._sessionID = socket.conn.request.sessionID;
|
|
68
|
+
// Get user for session
|
|
69
|
+
void this.adapter.getSession(socket.conn.request.sessionID, obj => {
|
|
70
|
+
if (!obj?.passport) {
|
|
71
|
+
if (socket._acl) {
|
|
72
|
+
socket._acl.user = '';
|
|
73
|
+
}
|
|
74
|
+
socket.emit(socketCommon_1.SocketCommon.COMMAND_RE_AUTHENTICATE);
|
|
75
|
+
callback('Cannot detect user');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
callback(null, obj.passport.user ? `system.user.${obj.passport.user}` : '');
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
callback('Cannot detect user');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
__getClientAddress(socket) {
|
|
87
|
+
let address;
|
|
88
|
+
if (socket.connection) {
|
|
89
|
+
address = socket.connection.remoteAddress;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// @ts-expect-error socket.io
|
|
93
|
+
address = socket.ws._socket.remoteAddress;
|
|
94
|
+
}
|
|
95
|
+
// @ts-expect-error socket.io
|
|
96
|
+
if (!address && socket.handshake) {
|
|
97
|
+
// @ts-expect-error socket.io
|
|
98
|
+
address = socket.handshake.address;
|
|
99
|
+
}
|
|
100
|
+
// @ts-expect-error socket.io
|
|
101
|
+
if (!address && socket.conn.request?.connection) {
|
|
102
|
+
// @ts-expect-error socket.io
|
|
103
|
+
address = socket.conn.request.connection.remoteAddress;
|
|
104
|
+
}
|
|
105
|
+
return address;
|
|
106
|
+
}
|
|
107
|
+
// update session ID, but not ofter than 60 seconds
|
|
108
|
+
__updateSession(socket) {
|
|
109
|
+
if (socket._sessionID) {
|
|
110
|
+
const time = Date.now();
|
|
111
|
+
if (socket._lastActivity && time - socket._lastActivity > (this.settings.ttl || 3600) * 1000) {
|
|
112
|
+
this.adapter.log.warn('REAUTHENTICATE!');
|
|
113
|
+
socket.emit(socketCommon_1.SocketCommon.COMMAND_RE_AUTHENTICATE);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
socket._lastActivity = time;
|
|
117
|
+
socket._sessionTimer ||= setTimeout(() => {
|
|
118
|
+
socket._sessionTimer = undefined;
|
|
119
|
+
void this.adapter.getSession(socket._sessionID, obj => {
|
|
120
|
+
if (obj) {
|
|
121
|
+
void this.adapter.setSession(socket._sessionID, this.settings.ttl || 3600, obj);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.adapter.log.warn('REAUTHENTICATE!');
|
|
125
|
+
socket.emit(socketCommon_1.SocketCommon.COMMAND_RE_AUTHENTICATE);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}, 60_000);
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
__getSessionID(socket) {
|
|
133
|
+
return this.settings.auth ? socket.conn.request.sessionID : null;
|
|
134
|
+
}
|
|
135
|
+
start(server, socketClass, authOptions, socketOptions) {
|
|
136
|
+
super.start(server, socketClass, authOptions, socketOptions);
|
|
137
|
+
this.adminCommands.start(thresholdEnabled => this.onThresholdChanged(thresholdEnabled));
|
|
138
|
+
}
|
|
139
|
+
onThresholdChanged(enabled) {
|
|
140
|
+
this.server && this.server.sockets && this.server.sockets.emit('eventsThreshold', enabled);
|
|
141
|
+
}
|
|
142
|
+
stateChange(id, state) {
|
|
143
|
+
this.adminCommands.stateChange(id, state);
|
|
144
|
+
const sockets = this.getSocketsList();
|
|
145
|
+
if (sockets) {
|
|
146
|
+
if (Array.isArray(sockets)) {
|
|
147
|
+
sockets.forEach(socket => this.commands.publish(socket, 'stateChange', id, state));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
Object.values(sockets).forEach(socket => this.commands.publish(socket, 'stateChange', id, state));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
fileChange(id, fileName, size) {
|
|
155
|
+
const sockets = this.getSocketsList();
|
|
156
|
+
if (sockets) {
|
|
157
|
+
if (Array.isArray(sockets)) {
|
|
158
|
+
sockets.forEach(socket => this.commands.publishFile(socket, id, fileName, size));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
Object.values(sockets).forEach(socket => this.commands.publishFile(socket, id, fileName, size));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
repoUpdated() {
|
|
166
|
+
const sockets = this.getSocketsList();
|
|
167
|
+
if (sockets) {
|
|
168
|
+
if (Array.isArray(sockets)) {
|
|
169
|
+
sockets.forEach(socket => this.__updateSession(socket));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
Object.values(sockets).forEach(socket => this.__updateSession(socket));
|
|
173
|
+
}
|
|
174
|
+
this.server?.sockets.emit('repoUpdated');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
objectChange(id, obj) {
|
|
178
|
+
const sockets = this.getSocketsList();
|
|
179
|
+
if (sockets) {
|
|
180
|
+
if (Array.isArray(sockets)) {
|
|
181
|
+
sockets.forEach(socket => this.commands.publish(socket, 'objectChange', id, obj));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
Object.values(sockets).forEach(socket => this.commands.publish(socket, 'objectChange', id, obj));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
subscribe(type, pattern) {
|
|
189
|
+
this.commands.subscribe(null, type, pattern);
|
|
190
|
+
}
|
|
191
|
+
subscribeFile(id, patternFile) {
|
|
192
|
+
this.commands.subscribe(null, 'fileChange', id, patternFile);
|
|
193
|
+
}
|
|
194
|
+
sendCommand(obj) {
|
|
195
|
+
if (this.adminCommands.sendCommand(obj)) {
|
|
196
|
+
const sockets = this.getSocketsList();
|
|
197
|
+
if (sockets) {
|
|
198
|
+
if (Array.isArray(sockets)) {
|
|
199
|
+
sockets.forEach(socket => this.__updateSession(socket));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
Object.values(sockets).forEach(socket => this.__updateSession(socket));
|
|
203
|
+
}
|
|
204
|
+
this.server?.sockets.emit(obj.command, obj.message.id, obj.message.data);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
updateRatings(uuid, isAutoUpdate) {
|
|
209
|
+
return this.adminCommands.updateRatings(uuid, isAutoUpdate);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.SocketAdmin = SocketAdmin;
|
|
213
|
+
//# sourceMappingURL=socketAdmin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketAdmin.js","sourceRoot":"","sources":["../../src/lib/socketAdmin.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;GAMG;AACH,iDAAsG;AACtG,+DAA4D;AAC5D,wDAAgC;AAChC,kEAAyC;AACzC,qDAAmF;AAMnF,MAAa,WAAY,SAAQ,2BAAY;IACjC,aAAa,CAAsB;IAC3C,YAAY,QAAwB,EAAE,OAAyB,EAAE,OAAwC;QACrG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEzB,yCAAyC;QACzC,IAAI,CAAC,QAAQ,GAAG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|
result?: any;
|
|
43
43
|
}) => void) => void) | null;
|
|
44
|
-
states: Record<string, ioBroker.State> |
|
|
44
|
+
states: Record<string, ioBroker.State> | undefined;
|
|
45
45
|
constructor(adapter: ioBroker.Adapter, updateSession: (socket: WebSocketClient) => boolean, context: SocketDataContext);
|
|
46
46
|
/**
|
|
47
47
|
* Convert errors into strings and then call cb
|
|
@@ -52,12 +52,12 @@ export declare class SocketCommands {
|
|
|
52
52
|
*/
|
|
53
53
|
static _fixCallback(callback: SocketCallback | null | undefined, error: string | Error | null | undefined, ...args: any[]): void;
|
|
54
54
|
_checkPermissions(socket: WebSocketClient, command: PermissionCommands, callback: ((error: string | null, ...args: any[]) => void) | undefined, ...args: any[]): boolean;
|
|
55
|
-
publish(socket: WebSocketClient, type: SocketSubscribeTypes, id: string, obj: ioBroker.Object | ioBroker.State): boolean;
|
|
55
|
+
publish(socket: WebSocketClient, type: SocketSubscribeTypes, id: string, obj: ioBroker.Object | ioBroker.State | null | undefined): boolean;
|
|
56
56
|
publishFile(socket: WebSocketClient, id: string, fileName: string, size: number): boolean;
|
|
57
57
|
publishInstanceMessage(socket: WebSocketClient, sourceInstance: string, messageType: string, data: any): boolean;
|
|
58
58
|
_showSubscribes(socket: WebSocketClient, type: SocketSubscribeTypes): void;
|
|
59
59
|
isLogEnabled(): boolean;
|
|
60
|
-
subscribe(socket: WebSocketClient, type: SocketSubscribeTypes, pattern: string, patternFile?: string): void;
|
|
60
|
+
subscribe(socket: WebSocketClient | null, type: SocketSubscribeTypes, pattern: string, patternFile?: string): void;
|
|
61
61
|
unsubscribe(socket: WebSocketClient, type: SocketSubscribeTypes, pattern: string, patternFile?: string): void;
|
|
62
62
|
subscribeSocket(socket: WebSocketClient, type?: SocketSubscribeTypes): void;
|
|
63
63
|
unsubscribeSocket(socket: WebSocketClient, type?: SocketSubscribeTypes): void;
|
|
@@ -68,7 +68,7 @@ class SocketCommands {
|
|
|
68
68
|
#updateSession;
|
|
69
69
|
adapterName;
|
|
70
70
|
_sendToHost;
|
|
71
|
-
states
|
|
71
|
+
states;
|
|
72
72
|
constructor(adapter, updateSession, context) {
|
|
73
73
|
this.adapter = adapter;
|
|
74
74
|
this.#updateSession = updateSession;
|
|
@@ -908,8 +908,6 @@ class SocketCommands {
|
|
|
908
908
|
* @param callback callback `(error?: Error) => void`
|
|
909
909
|
*/
|
|
910
910
|
this.commands.logout = (socket, callback) => {
|
|
911
|
-
// Logout user
|
|
912
|
-
// @param {function} callback - function (error)
|
|
913
911
|
if (socket.id) {
|
|
914
912
|
void this.adapter.destroySession(socket.id, callback);
|
|
915
913
|
}
|
|
@@ -940,8 +938,6 @@ class SocketCommands {
|
|
|
940
938
|
* @param callback callback `(error: string | null | undefined, userPermissions?: SocketACL | null) => void`
|
|
941
939
|
*/
|
|
942
940
|
this.commands.getUserPermissions = (socket, callback) => {
|
|
943
|
-
// Get user permissions
|
|
944
|
-
// @param {function} callback - `function (error, permissions)`
|
|
945
941
|
if (this._checkPermissions(socket, 'getUserPermissions', callback)) {
|
|
946
942
|
if (typeof callback === 'function') {
|
|
947
943
|
callback(null, socket._acl);
|
|
@@ -959,8 +955,6 @@ class SocketCommands {
|
|
|
959
955
|
* @param callback callback `(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void`
|
|
960
956
|
*/
|
|
961
957
|
this.commands.getVersion = (socket, callback) => {
|
|
962
|
-
// Get the adapter version. Not the socket-classes version!
|
|
963
|
-
// @param {function} callback - `function (error, adapterVersion, adapterName)`
|
|
964
958
|
if (this._checkPermissions(socket, 'getVersion', callback)) {
|
|
965
959
|
if (typeof callback === 'function') {
|
|
966
960
|
callback(null, this.adapter.version, this.adapter.name);
|
|
@@ -978,8 +972,6 @@ class SocketCommands {
|
|
|
978
972
|
* @param callback callback `(error: string | Error | null | undefined, version: string | undefined, adapterName: string) => void`
|
|
979
973
|
*/
|
|
980
974
|
this.commands.getAdapterName = (socket, callback) => {
|
|
981
|
-
// Get adapter name. Not the socket-classes version!
|
|
982
|
-
// @param {function} callback - `function (error, adapterVersion)`
|
|
983
975
|
if (this._checkPermissions(socket, 'getAdapterName', callback)) {
|
|
984
976
|
if (typeof callback === 'function') {
|
|
985
977
|
callback(null, this.adapter.name || 'unknown');
|
|
@@ -1963,7 +1955,6 @@ class SocketCommands {
|
|
|
1963
1955
|
* @param callback Callback `(error: string | null) => void`
|
|
1964
1956
|
*/
|
|
1965
1957
|
this.commands.clientUnsubscribe = (socket, targetInstance, messageType, callback) => {
|
|
1966
|
-
// @param {function} callback - `function (error, wasSubscribed)`, target instance MUST NOT acknowledge the un-subscription
|
|
1967
1958
|
const sid = socket.id;
|
|
1968
1959
|
if (!targetInstance.startsWith('system.adapter.')) {
|
|
1969
1960
|
targetInstance = `system.adapter.${targetInstance}`;
|