homebridge-config-ui-x 5.11.2-beta.9 → 5.11.2
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/CHANGELOG.md +3 -21
- package/dist/core/auth/auth.controller.d.ts +0 -4
- package/dist/core/config/config.interfaces.d.ts +0 -14
- package/dist/core/config/config.service.d.ts +0 -6
- package/dist/core/config/config.service.js +0 -8
- package/dist/core/config/config.service.js.map +1 -1
- package/dist/core/config/config.startup.js +17 -48
- package/dist/core/config/config.startup.js.map +1 -1
- package/dist/core/feature-flags/feature-flags.registry.js +0 -5
- package/dist/core/feature-flags/feature-flags.registry.js.map +1 -1
- package/dist/core/homebridge-ipc/homebridge-ipc.service.js +0 -1
- package/dist/core/homebridge-ipc/homebridge-ipc.service.js.map +1 -1
- package/dist/core/spa/spa.filter.d.ts +0 -3
- package/dist/core/spa/spa.filter.js +2 -22
- package/dist/core/spa/spa.filter.js.map +1 -1
- package/dist/globalDefaults.js +0 -3
- package/dist/globalDefaults.js.map +1 -1
- package/dist/main.js +4 -18
- package/dist/main.js.map +1 -1
- package/dist/modules/accessories/accessories.controller.d.ts +1 -1
- package/dist/modules/accessories/accessories.module.js +0 -2
- package/dist/modules/accessories/accessories.module.js.map +1 -1
- package/dist/modules/accessories/accessories.service.d.ts +3 -21
- package/dist/modules/accessories/accessories.service.js +17 -280
- package/dist/modules/accessories/accessories.service.js.map +1 -1
- package/dist/modules/child-bridges/child-bridges.interfaces.d.ts +0 -9
- package/dist/modules/config-editor/config-editor.controller.d.ts +0 -4
- package/dist/modules/config-editor/config-editor.controller.js +0 -64
- package/dist/modules/config-editor/config-editor.controller.js.map +1 -1
- package/dist/modules/config-editor/config-editor.service.d.ts +1 -6
- package/dist/modules/config-editor/config-editor.service.js +1 -45
- package/dist/modules/config-editor/config-editor.service.js.map +1 -1
- package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js +1 -1
- package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js.map +1 -1
- package/dist/modules/plugins/plugins.module.js +1 -1
- package/dist/modules/plugins/plugins.service.js +2 -17
- package/dist/modules/plugins/plugins.service.js.map +1 -1
- package/dist/modules/server/server.controller.d.ts +0 -50
- package/dist/modules/server/server.controller.js +2 -201
- package/dist/modules/server/server.controller.js.map +1 -1
- package/dist/modules/server/server.service.d.ts +0 -48
- package/dist/modules/server/server.service.js +14 -502
- package/dist/modules/server/server.service.js.map +1 -1
- package/dist/modules/status/status.gateway.d.ts +0 -2
- package/dist/modules/status/status.interfaces.d.ts +0 -11
- package/dist/modules/status/status.service.d.ts +1 -4
- package/dist/modules/status/status.service.js +2 -21
- package/dist/modules/status/status.service.js.map +1 -1
- package/package.json +5 -7
- package/public/3rdpartylicenses.txt +620 -594
- package/public/assets/plugin-ui-utils/ui.js +0 -3
- package/public/assets/plugin-ui-utils/ui.js.map +1 -1
- package/public/chunk-2BB4D4TW.js +1 -0
- package/public/chunk-2GCZ3AMH.js +1 -0
- package/public/chunk-2K5FWBCK.js +8 -0
- package/public/chunk-2LQBMVWH.js +1 -0
- package/public/chunk-34ZN4GVA.js +3 -0
- package/public/chunk-3JW6FD5V.js +1 -0
- package/public/chunk-57XTQ6PK.js +1 -0
- package/public/chunk-5DBV5PYR.js +19 -0
- package/public/chunk-5GKTPXPE.js +1 -0
- package/public/chunk-5X7ARCKG.js +5 -0
- package/public/chunk-67HOYJJ2.js +1 -0
- package/public/chunk-6MZHUZRT.js +4 -0
- package/public/chunk-77CMUO6J.js +1 -0
- package/public/chunk-7LJYL7EH.js +1 -0
- package/public/chunk-7TFBELRD.js +1 -0
- package/public/chunk-AXOHPUQR.js +1 -0
- package/public/chunk-BMAZBLAT.js +1 -0
- package/public/chunk-C554TVZA.js +2 -0
- package/public/chunk-DGDNSN6I.js +1 -0
- package/public/chunk-E6RSPO2D.js +1 -0
- package/public/chunk-ESQ665GW.js +5 -0
- package/public/chunk-G4QH622U.js +5 -0
- package/public/chunk-GKPR5M7S.js +1 -0
- package/public/chunk-GT7UMMFF.js +2 -0
- package/public/chunk-HBIQJCSE.js +1 -0
- package/public/{chunk-BMOLDRJ3.js → chunk-JLZ5WU6N.js} +1 -1
- package/public/chunk-JSZIAFBJ.js +1 -0
- package/public/chunk-JWQRV434.js +1 -0
- package/public/chunk-JX72JCMA.js +1 -0
- package/public/chunk-KT26K4DO.js +1 -0
- package/public/chunk-L63FND3A.js +1 -0
- package/public/chunk-LSXTHVKB.js +1 -0
- package/public/chunk-N5VXONVW.js +1 -0
- package/public/{chunk-H7F7H5MW.js → chunk-N6JGA2PG.js} +1 -1
- package/public/chunk-NVCJ3EJS.js +1 -0
- package/public/chunk-OPJZWDSO.js +1 -0
- package/public/chunk-OXBXHVWY.js +8 -0
- package/public/chunk-QHROK73U.js +50 -0
- package/public/chunk-QNEXPAIT.js +1 -0
- package/public/chunk-R2G2YWV4.js +51 -0
- package/public/chunk-RCNF365Q.js +1 -0
- package/public/chunk-RT6EDRIH.js +1 -0
- package/public/chunk-RWM6K46M.js +1 -0
- package/public/chunk-SVVR6UMH.js +1 -0
- package/public/chunk-UI4U37MO.js +1 -0
- package/public/chunk-ULKYNDD3.js +16 -0
- package/public/chunk-UPZ5UT6G.js +1 -0
- package/public/chunk-UQFIBBEZ.js +1 -0
- package/public/chunk-UWUTC3BD.js +1 -0
- package/public/chunk-UZ6QYM64.js +1 -0
- package/public/{chunk-IDVQIBZN.js → chunk-VKHX6FUQ.js} +2 -52
- package/public/chunk-VM2MV3DC.js +1 -0
- package/public/chunk-VM6FMRHY.js +1 -0
- package/public/chunk-VYK3U745.js +1 -0
- package/public/chunk-VZJJWHRX.js +1 -0
- package/public/chunk-WHC4E7WY.js +1 -0
- package/public/chunk-WJKVPIP2.js +1 -0
- package/public/chunk-WOBQOQPU.js +1 -0
- package/public/chunk-WTGHGHPV.js +1 -0
- package/public/chunk-WY6UQ47H.js +1 -0
- package/public/chunk-X4ZEQSRY.js +4 -0
- package/public/{chunk-TJXF3MRO.js → chunk-XVO5247V.js} +1 -1
- package/public/chunk-XWNU2MFJ.js +1 -0
- package/public/chunk-YD3GJ2C6.js +1 -0
- package/public/chunk-YUEGV7HK.js +4 -0
- package/public/chunk-ZLRFR32W.js +1 -0
- package/public/chunk-ZZ5IX26U.js +40 -0
- package/public/chunk-ZZQEWRDE.js +1 -0
- package/public/index.html +2 -2
- package/public/main-VKVUZHHA.js +1 -0
- package/public/polyfills-5KWHJ7II.js +2 -0
- package/public/styles-7EFV5QBG.css +1 -0
- package/scripts/extract-plugin-alias.js +2 -53
- package/dist/core/spa/spa-html.service.d.ts +0 -5
- package/dist/core/spa/spa-html.service.js +0 -32
- package/dist/core/spa/spa-html.service.js.map +0 -1
- package/dist/core/ssl/ssl-cert-generator.service.d.ts +0 -15
- package/dist/core/ssl/ssl-cert-generator.service.js +0 -125
- package/dist/core/ssl/ssl-cert-generator.service.js.map +0 -1
- package/dist/modules/accessories/accessories.interfaces.d.ts +0 -94
- package/dist/modules/accessories/accessories.interfaces.js +0 -2
- package/dist/modules/accessories/accessories.interfaces.js.map +0 -1
- package/docs/matter-todo.md +0 -15
- package/docs/ssl-upload-pr.md +0 -103
- package/public/assets/matter.svg +0 -8
- package/public/chunk-2OWZ4XP5.js +0 -5
- package/public/chunk-3N7C33O4.js +0 -1
- package/public/chunk-4UVYLGCZ.js +0 -1
- package/public/chunk-4XUH7NXA.js +0 -1
- package/public/chunk-52X3LPJH.js +0 -1
- package/public/chunk-5R6AJZGA.js +0 -1
- package/public/chunk-6CBJSM3U.js +0 -4
- package/public/chunk-6DLZEENG.js +0 -1
- package/public/chunk-6QWPGE2L.js +0 -1
- package/public/chunk-77S5CL3V.js +0 -1
- package/public/chunk-7BMHIIBT.js +0 -1
- package/public/chunk-7JIIKSDG.js +0 -1
- package/public/chunk-7WKZ7EMI.js +0 -1
- package/public/chunk-7WUBDTA6.js +0 -1
- package/public/chunk-A2MXGFJ6.js +0 -1
- package/public/chunk-AWTSOXJ2.js +0 -2
- package/public/chunk-B46EWHBD.js +0 -1
- package/public/chunk-B4AJQJMI.js +0 -1
- package/public/chunk-B75B723G.js +0 -1
- package/public/chunk-BBBDRQZR.js +0 -1
- package/public/chunk-BQRKHSGH.js +0 -1
- package/public/chunk-BXRCPOIK.js +0 -1
- package/public/chunk-BZ3XB6O4.js +0 -1
- package/public/chunk-CKURAGOR.js +0 -1
- package/public/chunk-CMERG3AC.js +0 -1
- package/public/chunk-CPT52C2F.js +0 -1
- package/public/chunk-DFG4HJK5.js +0 -1
- package/public/chunk-DPITSP7F.js +0 -5
- package/public/chunk-DSSLC7R5.js +0 -1
- package/public/chunk-ETWBSGPI.js +0 -1
- package/public/chunk-F635TFLI.js +0 -1
- package/public/chunk-GJG6QZ7P.js +0 -1
- package/public/chunk-GU5F3H4I.js +0 -1
- package/public/chunk-GVFAT25G.js +0 -3
- package/public/chunk-H4WASUXW.js +0 -1
- package/public/chunk-HBUIXUR3.js +0 -12
- package/public/chunk-HN6QQBDC.js +0 -1
- package/public/chunk-HUTYOGRH.js +0 -4
- package/public/chunk-HYHFIPBC.js +0 -1
- package/public/chunk-IBUR2RIO.js +0 -1
- package/public/chunk-IDJSTIFL.js +0 -1
- package/public/chunk-IP6FLYVL.js +0 -1
- package/public/chunk-IPI77WYV.js +0 -1
- package/public/chunk-J2DDS6ED.js +0 -1
- package/public/chunk-J6ND4K5Q.js +0 -1
- package/public/chunk-JUQRWAIR.js +0 -1
- package/public/chunk-JWGWPSC6.js +0 -1
- package/public/chunk-JWUEJV6S.js +0 -1
- package/public/chunk-K7PJFUH4.js +0 -1
- package/public/chunk-KFPYUDGJ.js +0 -1
- package/public/chunk-KIRW7NMH.js +0 -1
- package/public/chunk-KV4RQA3A.js +0 -1
- package/public/chunk-LAVT57X4.js +0 -1
- package/public/chunk-LI37IF2Z.js +0 -1
- package/public/chunk-LKJRMUOE.js +0 -1
- package/public/chunk-LLNAB3NM.js +0 -35
- package/public/chunk-LO72RI4S.js +0 -1
- package/public/chunk-LVQWSVHA.js +0 -1
- package/public/chunk-LZ7S7WKH.js +0 -1
- package/public/chunk-LZTSIWKP.js +0 -19
- package/public/chunk-MDHWQ5V2.js +0 -8
- package/public/chunk-MJP4XVUI.js +0 -1
- package/public/chunk-N3SESV2P.js +0 -1
- package/public/chunk-NAICVRJH.js +0 -1
- package/public/chunk-NCFDA3W4.js +0 -1
- package/public/chunk-OS475ZQO.js +0 -1
- package/public/chunk-OVQGZ4C6.js +0 -2
- package/public/chunk-PAZUAFSZ.js +0 -1
- package/public/chunk-PD3Q2PZE.js +0 -1
- package/public/chunk-PEUDPLH6.js +0 -1
- package/public/chunk-PRGOUVRO.js +0 -1
- package/public/chunk-PYPOWROR.js +0 -2
- package/public/chunk-QE7VI3JB.js +0 -1
- package/public/chunk-QES44GQE.js +0 -1
- package/public/chunk-R2CO54AK.js +0 -19
- package/public/chunk-R6MQZ2DW.js +0 -1
- package/public/chunk-RESZLSD7.js +0 -1
- package/public/chunk-RGWFM4OK.js +0 -1
- package/public/chunk-RI4GLH22.js +0 -1
- package/public/chunk-RP5JPYDI.js +0 -1
- package/public/chunk-RT25QBCQ.js +0 -1
- package/public/chunk-RVWZNTDJ.js +0 -1
- package/public/chunk-RXDY2NMJ.js +0 -1
- package/public/chunk-SDRRZFEQ.js +0 -1
- package/public/chunk-SPC2DLZR.js +0 -3
- package/public/chunk-TCJMUYCJ.js +0 -16
- package/public/chunk-TCUQZ3QO.js +0 -1
- package/public/chunk-TQBVDY26.js +0 -1
- package/public/chunk-U24HWDVU.js +0 -1
- package/public/chunk-U2NM4L2D.js +0 -1
- package/public/chunk-UFVCK77E.js +0 -68
- package/public/chunk-UWYTPKKV.js +0 -1
- package/public/chunk-V2TVR4X3.js +0 -1
- package/public/chunk-VKR3GG6K.js +0 -1
- package/public/chunk-W4WAFNIS.js +0 -1
- package/public/chunk-W55SP3LJ.js +0 -1
- package/public/chunk-WP3AD6W5.js +0 -1
- package/public/chunk-WU7URLRW.js +0 -1
- package/public/chunk-X6RWNTC7.js +0 -1
- package/public/chunk-XPFMPBEG.js +0 -1
- package/public/chunk-Y3PXWRYQ.js +0 -1
- package/public/chunk-Y5WP66WK.js +0 -1
- package/public/chunk-YCQCWGBG.js +0 -1
- package/public/chunk-YHBVXMFX.js +0 -1
- package/public/chunk-Z5PUNNUZ.js +0 -1
- package/public/chunk-ZAWMHW3P.js +0 -1
- package/public/chunk-ZCGZM7LU.js +0 -1
- package/public/chunk-ZSFO6PRU.js +0 -4
- package/public/main-EZDP2TWN.js +0 -1
- package/public/media/matter-P563JGDL.svg +0 -8
- package/public/polyfills-34U4WL3Z.js +0 -1
- package/public/styles-CT2LPGES.css +0 -1
|
@@ -12,13 +12,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { Buffer } from 'node:buffer';
|
|
14
14
|
import { exec, spawn } from 'node:child_process';
|
|
15
|
-
import { createPrivateKey, createPublicKey, X509Certificate } from 'node:crypto';
|
|
16
15
|
import { createWriteStream } from 'node:fs';
|
|
17
16
|
import { readdir, unlink } from 'node:fs/promises';
|
|
18
17
|
import { extname, join, resolve } from 'node:path';
|
|
19
18
|
import process from 'node:process';
|
|
20
19
|
import { pipeline } from 'node:stream';
|
|
21
|
-
import { createSecureContext } from 'node:tls';
|
|
22
20
|
import { promisify } from 'node:util';
|
|
23
21
|
import { Categories } from '@homebridge/hap-client/dist/hap-types.js';
|
|
24
22
|
import { BadRequestException, Inject, Injectable, InternalServerErrorException, NotFoundException, ServiceUnavailableException, } from '@nestjs/common';
|
|
@@ -29,7 +27,6 @@ import { check as tcpCheck } from 'tcp-port-used';
|
|
|
29
27
|
import { ConfigService } from '../../core/config/config.service.js';
|
|
30
28
|
import { HomebridgeIpcService } from '../../core/homebridge-ipc/homebridge-ipc.service.js';
|
|
31
29
|
import { Logger } from '../../core/logger/logger.service.js';
|
|
32
|
-
import { SslCertGeneratorService } from '../../core/ssl/ssl-cert-generator.service.js';
|
|
33
30
|
import { AccessoriesService } from '../accessories/accessories.service.js';
|
|
34
31
|
import { ConfigEditorService } from '../config-editor/config-editor.service.js';
|
|
35
32
|
const pump = promisify(pipeline);
|
|
@@ -53,37 +50,25 @@ let ServerService = class ServerService {
|
|
|
53
50
|
this.accessoryId = this.configService.homebridgeConfig.bridge.username.split(':').join('');
|
|
54
51
|
this.accessoryInfoPath = join(this.configService.storagePath, 'persist', `AccessoryInfo.${this.accessoryId}.json`);
|
|
55
52
|
}
|
|
56
|
-
async deleteSingleDeviceAccessories(id, cachedAccessoriesDir
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.logger.warn(`Bridge ${id} HAP accessory removal: removed ${cachedAccessories}.`);
|
|
63
|
-
}
|
|
64
|
-
if (await pathExists(cachedAccessoriesBackup)) {
|
|
65
|
-
await unlink(cachedAccessoriesBackup);
|
|
66
|
-
this.logger.warn(`Bridge ${id} HAP accessory removal: removed ${cachedAccessoriesBackup}.`);
|
|
67
|
-
}
|
|
53
|
+
async deleteSingleDeviceAccessories(id, cachedAccessoriesDir) {
|
|
54
|
+
const cachedAccessories = join(cachedAccessoriesDir, `cachedAccessories.${id}`);
|
|
55
|
+
const cachedAccessoriesBackup = join(cachedAccessoriesDir, `.cachedAccessories.${id}.bak`);
|
|
56
|
+
if (await pathExists(cachedAccessories)) {
|
|
57
|
+
await unlink(cachedAccessories);
|
|
58
|
+
this.logger.warn(`Bridge ${id} accessory removal: removed ${cachedAccessories}.`);
|
|
68
59
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (await pathExists(matterPath)) {
|
|
73
|
-
await remove(matterPath);
|
|
74
|
-
this.logger.warn(`Bridge ${id} Matter accessory removal: removed Matter bridge storage at ${matterPath}.`);
|
|
75
|
-
}
|
|
60
|
+
if (await pathExists(cachedAccessoriesBackup)) {
|
|
61
|
+
await unlink(cachedAccessoriesBackup);
|
|
62
|
+
this.logger.warn(`Bridge ${id} accessory removal: removed ${cachedAccessoriesBackup}.`);
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
65
|
async deleteSingleDevicePairing(id, resetPairingInfo) {
|
|
79
66
|
const persistPath = join(this.configService.storagePath, 'persist');
|
|
80
67
|
const accessoryInfo = join(persistPath, `AccessoryInfo.${id}.json`);
|
|
81
68
|
const identifierCache = join(persistPath, `IdentifierCache.${id}.json`);
|
|
82
|
-
const deviceId = id.includes(':') ? id.split(':').join('').toUpperCase() : id.toUpperCase();
|
|
83
|
-
const matterPath = join(this.configService.storagePath, 'matter', deviceId);
|
|
84
69
|
try {
|
|
85
70
|
const configFile = await this.configEditorService.getConfigFile();
|
|
86
|
-
const username = id.
|
|
71
|
+
const username = id.match(/.{1,2}/g).join(':').toUpperCase();
|
|
87
72
|
const uiConfig = configFile.platforms.find(x => x.platform === 'config');
|
|
88
73
|
let blacklistChanged = false;
|
|
89
74
|
let bridgesChanged = false;
|
|
@@ -149,10 +134,6 @@ let ServerService = class ServerService {
|
|
|
149
134
|
await unlink(identifierCache);
|
|
150
135
|
this.logger.warn(`Bridge ${id} reset: removed ${identifierCache}.`);
|
|
151
136
|
}
|
|
152
|
-
if (await pathExists(matterPath)) {
|
|
153
|
-
await remove(matterPath);
|
|
154
|
-
this.logger.warn(`Bridge ${id} reset: removed Matter bridge storage at ${matterPath}.`);
|
|
155
|
-
}
|
|
156
137
|
await this.deleteDeviceAccessories(id);
|
|
157
138
|
}
|
|
158
139
|
async restartServer() {
|
|
@@ -196,12 +177,6 @@ let ServerService = class ServerService {
|
|
|
196
177
|
await this.configEditorService.updateConfigFile(configFile);
|
|
197
178
|
await remove(resolve(this.configService.storagePath, 'accessories'));
|
|
198
179
|
await remove(resolve(this.configService.storagePath, 'persist'));
|
|
199
|
-
const deviceId = oldUsername.split(':').join('').toUpperCase();
|
|
200
|
-
const matterPath = join(this.configService.storagePath, 'matter', deviceId);
|
|
201
|
-
if (await pathExists(matterPath)) {
|
|
202
|
-
await remove(matterPath);
|
|
203
|
-
this.logger.warn(`Bridge ${oldUsername} reset: removed Matter bridge storage at ${matterPath}.`);
|
|
204
|
-
}
|
|
205
180
|
this.logger.log('Homebridge bridge reset: accessories and persist directories were removed.');
|
|
206
181
|
}
|
|
207
182
|
async getDevicePairings() {
|
|
@@ -209,68 +184,9 @@ let ServerService = class ServerService {
|
|
|
209
184
|
const devices = (await readdir(persistPath))
|
|
210
185
|
.filter(x => x.match(/AccessoryInfo\.([A-Fa-f0-9]+)\.json$/));
|
|
211
186
|
const configFile = await this.configEditorService.getConfigFile();
|
|
212
|
-
|
|
187
|
+
return Promise.all(devices.map(async (x) => {
|
|
213
188
|
return await this.getDevicePairingById(x.split('.')[1], configFile);
|
|
214
189
|
}));
|
|
215
|
-
const matterExternalDevices = await this.getMatterExternalAccessories(hapDevices);
|
|
216
|
-
return [...hapDevices, ...matterExternalDevices].sort((a, b) => a.name.localeCompare(b.name));
|
|
217
|
-
}
|
|
218
|
-
async getMatterExternalAccessories(hapDevices) {
|
|
219
|
-
const matterPath = join(this.configService.storagePath, 'matter');
|
|
220
|
-
if (!await pathExists(matterPath)) {
|
|
221
|
-
return [];
|
|
222
|
-
}
|
|
223
|
-
const matterDirs = (await readdir(matterPath))
|
|
224
|
-
.filter(x => x.match(/^[A-F0-9]{12}$/));
|
|
225
|
-
const matterExternalDevices = [];
|
|
226
|
-
for (const deviceId of matterDirs) {
|
|
227
|
-
try {
|
|
228
|
-
const hasHapAccessoryInfo = hapDevices.some(d => d._id === deviceId);
|
|
229
|
-
if (hasHapAccessoryInfo) {
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
const mainBridgeId = this.configService.homebridgeConfig.bridge.username.split(':').join('').toUpperCase();
|
|
233
|
-
if (deviceId.toUpperCase() === mainBridgeId) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
const accessoriesPath = join(matterPath, deviceId, 'accessories.json');
|
|
237
|
-
if (!await pathExists(accessoriesPath)) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
const accessories = await readJson(accessoriesPath);
|
|
241
|
-
if (!Array.isArray(accessories) || accessories.length === 0) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
const accessory = accessories[0];
|
|
245
|
-
const commissioningPath = join(matterPath, deviceId, 'commissioning.json');
|
|
246
|
-
let commissioned = false;
|
|
247
|
-
if (await pathExists(commissioningPath)) {
|
|
248
|
-
const commissioningInfo = await readJson(commissioningPath);
|
|
249
|
-
commissioned = commissioningInfo.commissioned || false;
|
|
250
|
-
}
|
|
251
|
-
const device = {
|
|
252
|
-
_id: deviceId,
|
|
253
|
-
_username: deviceId.match(/.{1,2}/g)?.join(':').toUpperCase() || deviceId,
|
|
254
|
-
_main: false,
|
|
255
|
-
_category: 'other',
|
|
256
|
-
_matter: true,
|
|
257
|
-
_matterOnly: true,
|
|
258
|
-
_isPaired: commissioned,
|
|
259
|
-
_plugin: accessory.plugin,
|
|
260
|
-
name: accessory.displayName || 'Matter External Accessory',
|
|
261
|
-
displayName: accessory.displayName || 'Matter External Accessory',
|
|
262
|
-
manufacturer: accessory.manufacturer || 'Unknown',
|
|
263
|
-
model: accessory.model || 'Unknown',
|
|
264
|
-
serialNumber: accessory.serialNumber || deviceId,
|
|
265
|
-
category: 1,
|
|
266
|
-
};
|
|
267
|
-
matterExternalDevices.push(device);
|
|
268
|
-
}
|
|
269
|
-
catch (e) {
|
|
270
|
-
this.logger.error(`Failed to read Matter external accessory ${deviceId}: ${e.message}`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return matterExternalDevices;
|
|
274
190
|
}
|
|
275
191
|
async getDevicePairingById(deviceId, configFile = null) {
|
|
276
192
|
const persistPath = join(this.configService.storagePath, 'persist');
|
|
@@ -303,10 +219,6 @@ let ServerService = class ServerService {
|
|
|
303
219
|
device._isPaired = device.pairedClients && Object.keys(device.pairedClients).length > 0;
|
|
304
220
|
device._setupCode = this.generateSetupCode(device);
|
|
305
221
|
device._couldBeStale = !device._main && device._category === 'bridge' && !pluginBlock;
|
|
306
|
-
device._matter = !!(pluginBlock?._bridge?.matter);
|
|
307
|
-
if (device._matter && pluginBlock && 'accessory' in pluginBlock) {
|
|
308
|
-
this.logger.warn(`Device ${deviceId} has Matter configuration on an accessory-based plugin. Matter is only supported for platform-based plugins.`);
|
|
309
|
-
}
|
|
310
222
|
delete device.signSk;
|
|
311
223
|
delete device.signPk;
|
|
312
224
|
delete device.configHash;
|
|
@@ -320,44 +232,6 @@ let ServerService = class ServerService {
|
|
|
320
232
|
await this.deleteSingleDevicePairing(id, resetPairingInfo);
|
|
321
233
|
return { ok: true };
|
|
322
234
|
}
|
|
323
|
-
async deleteDeviceMatterConfig(id) {
|
|
324
|
-
try {
|
|
325
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
326
|
-
const username = id.includes(':') ? id.toUpperCase() : id.match(/.{1,2}/g)?.join(':').toUpperCase() || id.toUpperCase();
|
|
327
|
-
const pluginBlocks = [
|
|
328
|
-
...(configFile.accessories || []),
|
|
329
|
-
...(configFile.platforms || []),
|
|
330
|
-
]
|
|
331
|
-
.filter((block) => block._bridge?.username?.toUpperCase() === username.toUpperCase());
|
|
332
|
-
const pluginBlock = pluginBlocks.find((block) => block._bridge?.matter);
|
|
333
|
-
if (!pluginBlock) {
|
|
334
|
-
this.logger.error(`Failed to find Matter configuration for child bridge ${id}.`);
|
|
335
|
-
throw new NotFoundException(`Matter configuration not found for bridge ${id}`);
|
|
336
|
-
}
|
|
337
|
-
if ('accessory' in pluginBlock) {
|
|
338
|
-
this.logger.warn(`Removing Matter configuration from accessory-based plugin block for bridge ${id}. Matter is only supported for platform-based plugins.`);
|
|
339
|
-
}
|
|
340
|
-
delete pluginBlock._bridge.matter;
|
|
341
|
-
this.logger.warn(`Bridge ${id} Matter configuration removed from config.json.`);
|
|
342
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
343
|
-
}
|
|
344
|
-
catch (e) {
|
|
345
|
-
if (e instanceof NotFoundException) {
|
|
346
|
-
throw e;
|
|
347
|
-
}
|
|
348
|
-
this.logger.error(`Failed to remove Matter configuration for child bridge ${id} as ${e.message}.`);
|
|
349
|
-
throw new InternalServerErrorException(`Failed to remove Matter configuration: ${e.message}`);
|
|
350
|
-
}
|
|
351
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter storage for bridge ${id}...`);
|
|
352
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
353
|
-
const deviceId = id.includes(':') ? id.split(':').join('').toUpperCase() : id.toUpperCase();
|
|
354
|
-
const matterPath = join(this.configService.storagePath, 'matter', deviceId);
|
|
355
|
-
if (await pathExists(matterPath)) {
|
|
356
|
-
await remove(matterPath);
|
|
357
|
-
this.logger.warn(`Bridge ${id} Matter storage removed at ${matterPath}.`);
|
|
358
|
-
}
|
|
359
|
-
return { ok: true };
|
|
360
|
-
}
|
|
361
235
|
async deleteDevicesPairing(bridges) {
|
|
362
236
|
this.logger.warn(`Shutting down Homebridge before resetting paired bridges ${bridges.map(x => x.id).join(', ')}...`);
|
|
363
237
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
@@ -381,9 +255,9 @@ let ServerService = class ServerService {
|
|
|
381
255
|
this.logger.warn(`Shutting down Homebridge before removing accessories for paired bridges ${bridges.map(x => x.id).join(', ')}...`);
|
|
382
256
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
383
257
|
const cachedAccessoriesDir = join(this.configService.storagePath, 'accessories');
|
|
384
|
-
for (const { id
|
|
258
|
+
for (const { id } of bridges) {
|
|
385
259
|
try {
|
|
386
|
-
await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir
|
|
260
|
+
await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir);
|
|
387
261
|
}
|
|
388
262
|
catch (e) {
|
|
389
263
|
this.logger.error(`Failed to remove accessories for bridge ${id} as ${e.message}.`);
|
|
@@ -464,19 +338,13 @@ let ServerService = class ServerService {
|
|
|
464
338
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
465
339
|
this.logger.warn('Shutting down Homebridge before removing cached accessories');
|
|
466
340
|
try {
|
|
467
|
-
this.logger.log('Clearing all
|
|
341
|
+
this.logger.log('Clearing all cached accessories...');
|
|
468
342
|
for (const thisCachedAccessoriesPath of cachedAccessoryPaths) {
|
|
469
343
|
if (await pathExists(thisCachedAccessoriesPath)) {
|
|
470
344
|
await unlink(thisCachedAccessoriesPath);
|
|
471
345
|
this.logger.warn(`Removed ${thisCachedAccessoriesPath}.`);
|
|
472
346
|
}
|
|
473
347
|
}
|
|
474
|
-
const matterDir = join(this.configService.storagePath, 'matter');
|
|
475
|
-
if (await pathExists(matterDir)) {
|
|
476
|
-
this.logger.log('Clearing all Matter cached accessories...');
|
|
477
|
-
await remove(matterDir);
|
|
478
|
-
this.logger.warn(`Removed Matter storage directory at ${matterDir}.`);
|
|
479
|
-
}
|
|
480
348
|
}
|
|
481
349
|
catch (e) {
|
|
482
350
|
this.logger.error(`Failed to clear all cached accessories at ${cachedAccessoriesPath} as ${e.message}.`);
|
|
@@ -485,96 +353,6 @@ let ServerService = class ServerService {
|
|
|
485
353
|
}
|
|
486
354
|
return { ok: true };
|
|
487
355
|
}
|
|
488
|
-
async getMatterAccessories() {
|
|
489
|
-
const matterDir = join(this.configService.storagePath, 'matter');
|
|
490
|
-
if (!await pathExists(matterDir)) {
|
|
491
|
-
return [];
|
|
492
|
-
}
|
|
493
|
-
const matterBridges = (await readdir(matterDir))
|
|
494
|
-
.filter(x => x.match(/^[A-F0-9]+$/));
|
|
495
|
-
const matterAccessories = [];
|
|
496
|
-
await Promise.all(matterBridges.map(async (deviceId) => {
|
|
497
|
-
try {
|
|
498
|
-
const accessoriesPath = join(matterDir, deviceId, 'accessories.json');
|
|
499
|
-
if (await pathExists(accessoriesPath)) {
|
|
500
|
-
const accessories = await readJson(accessoriesPath);
|
|
501
|
-
if (Array.isArray(accessories)) {
|
|
502
|
-
for (const accessory of accessories) {
|
|
503
|
-
accessory.$deviceId = deviceId;
|
|
504
|
-
accessory.$protocol = 'matter';
|
|
505
|
-
matterAccessories.push(accessory);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
catch (e) {
|
|
511
|
-
this.logger.error(`Failed to read Matter accessories for bridge ${deviceId}: ${e.message}`);
|
|
512
|
-
}
|
|
513
|
-
}));
|
|
514
|
-
return matterAccessories;
|
|
515
|
-
}
|
|
516
|
-
async deleteMatterAccessory(deviceId, uuid) {
|
|
517
|
-
const matterAccessoriesPath = join(this.configService.storagePath, 'matter', deviceId, 'accessories.json');
|
|
518
|
-
if (!await pathExists(matterAccessoriesPath)) {
|
|
519
|
-
this.logger.error(`Matter accessories file not found for bridge ${deviceId}`);
|
|
520
|
-
throw new NotFoundException();
|
|
521
|
-
}
|
|
522
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter accessory ${uuid} from bridge ${deviceId}...`);
|
|
523
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
524
|
-
const matterAccessories = await readJson(matterAccessoriesPath);
|
|
525
|
-
const accessoryIndex = matterAccessories.findIndex(x => x.uuid === uuid);
|
|
526
|
-
if (accessoryIndex > -1) {
|
|
527
|
-
matterAccessories.splice(accessoryIndex, 1);
|
|
528
|
-
await writeJson(matterAccessoriesPath, matterAccessories, { spaces: 2 });
|
|
529
|
-
this.logger.warn(`Removed Matter accessory with UUID ${uuid} from bridge ${deviceId}.`);
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
this.logger.error(`Cannot find Matter accessory with UUID ${uuid} in bridge ${deviceId}.`);
|
|
533
|
-
throw new NotFoundException();
|
|
534
|
-
}
|
|
535
|
-
return { ok: true };
|
|
536
|
-
}
|
|
537
|
-
async deleteMatterAccessories(accessories) {
|
|
538
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter accessories ${accessories.map(x => x.uuid).join(', ')}.`);
|
|
539
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
540
|
-
const accessoriesByBridge = new Map();
|
|
541
|
-
for (const { deviceId, uuid } of accessories) {
|
|
542
|
-
if (!accessoriesByBridge.has(deviceId)) {
|
|
543
|
-
accessoriesByBridge.set(deviceId, []);
|
|
544
|
-
}
|
|
545
|
-
accessoriesByBridge.get(deviceId).push({ uuid });
|
|
546
|
-
}
|
|
547
|
-
for (const [deviceId, bridgeAccessories] of accessoriesByBridge.entries()) {
|
|
548
|
-
const matterAccessoriesPath = join(this.configService.storagePath, 'matter', deviceId, 'accessories.json');
|
|
549
|
-
try {
|
|
550
|
-
if (!await pathExists(matterAccessoriesPath)) {
|
|
551
|
-
this.logger.error(`Matter accessories file not found for bridge ${deviceId}`);
|
|
552
|
-
continue;
|
|
553
|
-
}
|
|
554
|
-
const matterAccessories = await readJson(matterAccessoriesPath);
|
|
555
|
-
for (const { uuid } of bridgeAccessories) {
|
|
556
|
-
try {
|
|
557
|
-
const accessoryIndex = matterAccessories.findIndex(x => x.uuid === uuid);
|
|
558
|
-
if (accessoryIndex > -1) {
|
|
559
|
-
matterAccessories.splice(accessoryIndex, 1);
|
|
560
|
-
this.logger.warn(`Removed Matter accessory with UUID ${uuid} from bridge ${deviceId}.`);
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
this.logger.error(`Cannot find Matter accessory with UUID ${uuid} in bridge ${deviceId}.`);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
catch (e) {
|
|
567
|
-
this.logger.error(`Failed to remove Matter accessory with UUID ${uuid} from bridge ${deviceId} as ${e.message}.`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
await writeJson(matterAccessoriesPath, matterAccessories, { spaces: 2 });
|
|
571
|
-
}
|
|
572
|
-
catch (e) {
|
|
573
|
-
this.logger.error(`Failed to process Matter accessories for bridge ${deviceId} as ${e.message}.`);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return { ok: true };
|
|
577
|
-
}
|
|
578
356
|
async getSetupCode() {
|
|
579
357
|
if (this.setupCode) {
|
|
580
358
|
return this.setupCode;
|
|
@@ -679,30 +457,6 @@ let ServerService = class ServerService {
|
|
|
679
457
|
}
|
|
680
458
|
return { port };
|
|
681
459
|
}
|
|
682
|
-
async lookupUnusedMatterPort() {
|
|
683
|
-
const min = 5530;
|
|
684
|
-
const max = 5541;
|
|
685
|
-
const config = await this.configEditorService.getConfigFile();
|
|
686
|
-
const usedMatterPorts = new Set();
|
|
687
|
-
if (config.bridge?.matter?.port) {
|
|
688
|
-
usedMatterPorts.add(config.bridge.matter.port);
|
|
689
|
-
}
|
|
690
|
-
for (const block of [...(config.accessories || []), ...(config.platforms || [])]) {
|
|
691
|
-
if (block._bridge?.matter?.port) {
|
|
692
|
-
if ('accessory' in block) {
|
|
693
|
-
this.logger.warn(`Found Matter configuration on accessory-based plugin block, skipping port ${block._bridge.matter.port}`);
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
usedMatterPorts.add(block._bridge.matter.port);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
for (let port = min; port <= max; port += 1) {
|
|
700
|
-
if (!usedMatterPorts.has(port) && !await tcpCheck(port)) {
|
|
701
|
-
return { port };
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
throw new InternalServerErrorException('No available ports in the Matter port range (5530-5541)');
|
|
705
|
-
}
|
|
706
460
|
async getHomebridgePort() {
|
|
707
461
|
const config = await this.configEditorService.getConfigFile();
|
|
708
462
|
return { port: config.bridge.port };
|
|
@@ -835,248 +589,6 @@ let ServerService = class ServerService {
|
|
|
835
589
|
});
|
|
836
590
|
});
|
|
837
591
|
}
|
|
838
|
-
async uploadSslKeyCert(req) {
|
|
839
|
-
const parts = req.parts ? req.parts() : null;
|
|
840
|
-
const files = [];
|
|
841
|
-
if (parts) {
|
|
842
|
-
for await (const part of parts) {
|
|
843
|
-
if (part.file) {
|
|
844
|
-
files.push(part);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
const single = await req.file();
|
|
850
|
-
if (single?.file) {
|
|
851
|
-
files.push(single);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
if (!files.length) {
|
|
855
|
-
throw new BadRequestException('No files uploaded. Please upload both the private key and certificate files.');
|
|
856
|
-
}
|
|
857
|
-
const readStreamToBuffer = async (stream) => {
|
|
858
|
-
const chunks = [];
|
|
859
|
-
await new Promise((resolvePromise, rejectPromise) => {
|
|
860
|
-
stream.on('data', (d) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(d)));
|
|
861
|
-
stream.on('end', () => resolvePromise());
|
|
862
|
-
stream.on('error', rejectPromise);
|
|
863
|
-
});
|
|
864
|
-
return Buffer.concat(chunks);
|
|
865
|
-
};
|
|
866
|
-
let keyPem = null;
|
|
867
|
-
let certPem = null;
|
|
868
|
-
for (const f of files) {
|
|
869
|
-
if (f.file?.truncated) {
|
|
870
|
-
throw new InternalServerErrorException(`Upload exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`);
|
|
871
|
-
}
|
|
872
|
-
const buf = await readStreamToBuffer(f.file);
|
|
873
|
-
const text = buf.toString('utf8');
|
|
874
|
-
if (/-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/.test(text)) {
|
|
875
|
-
keyPem = buf;
|
|
876
|
-
}
|
|
877
|
-
else if (/-----BEGIN CERTIFICATE-----/.test(text)) {
|
|
878
|
-
certPem = buf;
|
|
879
|
-
}
|
|
880
|
-
else if (f.fieldname === 'key') {
|
|
881
|
-
keyPem = buf;
|
|
882
|
-
}
|
|
883
|
-
else if (f.fieldname === 'cert') {
|
|
884
|
-
certPem = buf;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
if (!keyPem || !certPem) {
|
|
888
|
-
throw new BadRequestException('Both a PEM private key and certificate must be provided.');
|
|
889
|
-
}
|
|
890
|
-
try {
|
|
891
|
-
const x509 = new X509Certificate(certPem);
|
|
892
|
-
const certPub = x509.publicKey.export({ type: 'spki', format: 'der' });
|
|
893
|
-
const priv = createPrivateKey({ key: keyPem });
|
|
894
|
-
const pubFromPriv = createPublicKey(priv).export({ type: 'spki', format: 'der' });
|
|
895
|
-
if (!certPub.equals(pubFromPriv)) {
|
|
896
|
-
throw new BadRequestException('The private key does not match the certificate public key.');
|
|
897
|
-
}
|
|
898
|
-
createSecureContext({ key: keyPem, cert: certPem });
|
|
899
|
-
}
|
|
900
|
-
catch (e) {
|
|
901
|
-
if (e instanceof BadRequestException) {
|
|
902
|
-
throw e;
|
|
903
|
-
}
|
|
904
|
-
throw new BadRequestException(`Invalid key/certificate: ${e?.message || e}`);
|
|
905
|
-
}
|
|
906
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
907
|
-
const keyPath = join(sslDir, 'ui-ssl.key');
|
|
908
|
-
const certPath = join(sslDir, 'ui-ssl.crt');
|
|
909
|
-
const { ensureDir, writeFile } = await import('fs-extra');
|
|
910
|
-
await ensureDir(sslDir);
|
|
911
|
-
await writeFile(keyPath, keyPem);
|
|
912
|
-
await writeFile(certPath, certPem);
|
|
913
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
914
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
915
|
-
if (!uiConfigBlock) {
|
|
916
|
-
throw new InternalServerErrorException('Config platform block not found.');
|
|
917
|
-
}
|
|
918
|
-
if (!uiConfigBlock.ssl) {
|
|
919
|
-
uiConfigBlock.ssl = {};
|
|
920
|
-
}
|
|
921
|
-
uiConfigBlock.ssl.key = keyPath;
|
|
922
|
-
uiConfigBlock.ssl.cert = certPath;
|
|
923
|
-
delete uiConfigBlock.ssl.pfx;
|
|
924
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
925
|
-
uiConfigBlock.ssl.selfSigned = false;
|
|
926
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
927
|
-
return {
|
|
928
|
-
ok: true,
|
|
929
|
-
type: 'keycert',
|
|
930
|
-
keyPath,
|
|
931
|
-
certPath,
|
|
932
|
-
details: 'Certificate and key validated and saved.',
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
async uploadSslPfx(req) {
|
|
936
|
-
let passphrase;
|
|
937
|
-
let filePart;
|
|
938
|
-
if (req.parts) {
|
|
939
|
-
for await (const part of req.parts()) {
|
|
940
|
-
if (part.type === 'file' || part.file) {
|
|
941
|
-
filePart = part;
|
|
942
|
-
}
|
|
943
|
-
else if (part.type === 'field' || part.value) {
|
|
944
|
-
if (part.fieldname === 'passphrase') {
|
|
945
|
-
passphrase = part.value;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
else {
|
|
951
|
-
filePart = await req.file();
|
|
952
|
-
passphrase = req.body?.passphrase;
|
|
953
|
-
}
|
|
954
|
-
if (!filePart) {
|
|
955
|
-
throw new BadRequestException('No PFX file uploaded.');
|
|
956
|
-
}
|
|
957
|
-
if (filePart.file?.truncated) {
|
|
958
|
-
throw new InternalServerErrorException(`Upload exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`);
|
|
959
|
-
}
|
|
960
|
-
const readStreamToBuffer = async (stream) => {
|
|
961
|
-
const chunks = [];
|
|
962
|
-
await new Promise((resolvePromise, rejectPromise) => {
|
|
963
|
-
stream.on('data', (d) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(d)));
|
|
964
|
-
stream.on('end', () => resolvePromise());
|
|
965
|
-
stream.on('error', rejectPromise);
|
|
966
|
-
});
|
|
967
|
-
return Buffer.concat(chunks);
|
|
968
|
-
};
|
|
969
|
-
const pfxBuffer = await readStreamToBuffer(filePart.file);
|
|
970
|
-
try {
|
|
971
|
-
createSecureContext({ pfx: pfxBuffer, passphrase });
|
|
972
|
-
}
|
|
973
|
-
catch (e) {
|
|
974
|
-
throw new BadRequestException(`Invalid PFX or passphrase: ${e?.message || e}`);
|
|
975
|
-
}
|
|
976
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
977
|
-
const pfxPath = join(sslDir, 'ui-ssl.pfx');
|
|
978
|
-
const { ensureDir, writeFile } = await import('fs-extra');
|
|
979
|
-
await ensureDir(sslDir);
|
|
980
|
-
await writeFile(pfxPath, pfxBuffer);
|
|
981
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
982
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
983
|
-
if (!uiConfigBlock) {
|
|
984
|
-
throw new InternalServerErrorException('Config platform block not found.');
|
|
985
|
-
}
|
|
986
|
-
if (!uiConfigBlock.ssl) {
|
|
987
|
-
uiConfigBlock.ssl = {};
|
|
988
|
-
}
|
|
989
|
-
uiConfigBlock.ssl.pfx = pfxPath;
|
|
990
|
-
uiConfigBlock.ssl.passphrase = passphrase || '';
|
|
991
|
-
delete uiConfigBlock.ssl.key;
|
|
992
|
-
delete uiConfigBlock.ssl.cert;
|
|
993
|
-
uiConfigBlock.ssl.selfSigned = false;
|
|
994
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
995
|
-
return {
|
|
996
|
-
ok: true,
|
|
997
|
-
type: 'pfx',
|
|
998
|
-
pfxPath,
|
|
999
|
-
details: 'PFX validated and saved.',
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
async validateCurrentSslConfig() {
|
|
1003
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
1004
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
1005
|
-
const ssl = uiConfigBlock?.ssl || {};
|
|
1006
|
-
if (!ssl || (!ssl.selfSigned && !ssl.key && !ssl.cert && !ssl.pfx)) {
|
|
1007
|
-
return { ok: true, valid: true, type: 'off', details: 'HTTPS is disabled.' };
|
|
1008
|
-
}
|
|
1009
|
-
if (ssl.selfSigned) {
|
|
1010
|
-
return { ok: true, valid: true, type: 'selfsigned', details: 'Self-signed mode enabled.' };
|
|
1011
|
-
}
|
|
1012
|
-
try {
|
|
1013
|
-
if (ssl.key && ssl.cert) {
|
|
1014
|
-
const { readFile } = await import('fs-extra');
|
|
1015
|
-
const keyPem = await readFile(ssl.key);
|
|
1016
|
-
const certPem = await readFile(ssl.cert);
|
|
1017
|
-
const x509 = new X509Certificate(certPem);
|
|
1018
|
-
const certPub = x509.publicKey.export({ type: 'spki', format: 'der' });
|
|
1019
|
-
const priv = createPrivateKey({ key: keyPem });
|
|
1020
|
-
const pubFromPriv = createPublicKey(priv).export({ type: 'spki', format: 'der' });
|
|
1021
|
-
if (!certPub.equals(pubFromPriv)) {
|
|
1022
|
-
return { ok: true, valid: false, type: 'keycert', details: 'Private key does not match certificate.' };
|
|
1023
|
-
}
|
|
1024
|
-
createSecureContext({ key: keyPem, cert: certPem });
|
|
1025
|
-
return { ok: true, valid: true, type: 'keycert', details: 'Key and certificate are valid and match.' };
|
|
1026
|
-
}
|
|
1027
|
-
if (ssl.pfx) {
|
|
1028
|
-
const { readFile } = await import('fs-extra');
|
|
1029
|
-
const pfx = await readFile(ssl.pfx);
|
|
1030
|
-
createSecureContext({ pfx, passphrase: ssl.passphrase });
|
|
1031
|
-
return { ok: true, valid: true, type: 'pfx', details: 'PFX file and passphrase are valid.' };
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
catch (e) {
|
|
1035
|
-
return { ok: true, valid: false, type: ssl.pfx ? 'pfx' : 'keycert', details: e?.message || String(e) };
|
|
1036
|
-
}
|
|
1037
|
-
return { ok: true, valid: false, type: 'off', details: 'No SSL configuration found.' };
|
|
1038
|
-
}
|
|
1039
|
-
async generateSelfSignedCertificate(options = {}) {
|
|
1040
|
-
const hostnames = Array.isArray(options.hostnames) && options.hostnames.length
|
|
1041
|
-
? options.hostnames.map(h => String(h).trim()).filter(Boolean)
|
|
1042
|
-
: ['localhost', '127.0.0.1'];
|
|
1043
|
-
const mode = options.mode || 'keycert';
|
|
1044
|
-
const generator = new SslCertGeneratorService();
|
|
1045
|
-
await generator.generateCertificate(hostnames);
|
|
1046
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
1047
|
-
const keyPath = join(sslDir, 'private-key.pem');
|
|
1048
|
-
const certPath = join(sslDir, 'certificate.pem');
|
|
1049
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
1050
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
1051
|
-
if (!uiConfigBlock.ssl) {
|
|
1052
|
-
uiConfigBlock.ssl = {};
|
|
1053
|
-
}
|
|
1054
|
-
if (mode === 'keycert') {
|
|
1055
|
-
uiConfigBlock.ssl.key = keyPath;
|
|
1056
|
-
uiConfigBlock.ssl.cert = certPath;
|
|
1057
|
-
delete uiConfigBlock.ssl.pfx;
|
|
1058
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
1059
|
-
delete uiConfigBlock.ssl.selfSigned;
|
|
1060
|
-
delete uiConfigBlock.ssl.selfSignedHostnames;
|
|
1061
|
-
}
|
|
1062
|
-
else {
|
|
1063
|
-
delete uiConfigBlock.ssl.key;
|
|
1064
|
-
delete uiConfigBlock.ssl.cert;
|
|
1065
|
-
delete uiConfigBlock.ssl.pfx;
|
|
1066
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
1067
|
-
uiConfigBlock.ssl.selfSigned = true;
|
|
1068
|
-
uiConfigBlock.ssl.selfSignedHostnames = hostnames;
|
|
1069
|
-
}
|
|
1070
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
1071
|
-
return {
|
|
1072
|
-
ok: true,
|
|
1073
|
-
type: 'generated',
|
|
1074
|
-
mode,
|
|
1075
|
-
keyPath: mode === 'keycert' ? keyPath : undefined,
|
|
1076
|
-
certPath: mode === 'keycert' ? certPath : undefined,
|
|
1077
|
-
details: `Self-signed certificate generated for ${hostnames.join(', ')}`,
|
|
1078
|
-
};
|
|
1079
|
-
}
|
|
1080
592
|
};
|
|
1081
593
|
ServerService = __decorate([
|
|
1082
594
|
Injectable(),
|