homebridge-config-ui-x 5.9.1-beta.9 → 5.10.0
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 +11 -6
- 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 +6 -19
- 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.service.js +0 -15
- 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 +31 -503
- 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 +15 -14
- package/public/assets/plugin-ui-utils/ui.js +0 -3
- package/public/assets/plugin-ui-utils/ui.js.map +1 -1
- package/public/{chunk-HZFYCQBZ.js → chunk-2ATI5RL3.js} +1 -1
- package/public/{chunk-H7BN2MFG.js → chunk-3TGMHJM3.js} +1 -1
- package/public/{chunk-WFVVY4KI.js → chunk-4TYE7FOW.js} +1 -1
- package/public/{chunk-DWAKEAKY.js → chunk-5DT3N4NO.js} +1 -1
- package/public/{chunk-XTO2AHKJ.js → chunk-5FAEMT7K.js} +1 -1
- package/public/chunk-6FMRO7HY.js +19 -0
- package/public/chunk-6WCXE37R.js +4 -0
- package/public/{chunk-SOVE6NMG.js → chunk-726EPARV.js} +1 -1
- package/public/{chunk-OYP4E7LD.js → chunk-ABJURGQA.js} +1 -1
- package/public/{chunk-SQOLJ3VE.js → chunk-ALWUQZSW.js} +1 -1
- package/public/chunk-ASYRF2UP.js +1 -0
- package/public/{chunk-MNVMBPHV.js → chunk-AY5APEAK.js} +1 -1
- package/public/{chunk-NOBUYLGI.js → chunk-B57RMJ4J.js} +1 -1
- package/public/chunk-BDFSTR4R.js +1 -0
- package/public/{chunk-IJZ5PJH7.js → chunk-CKGQSHVZ.js} +1 -1
- package/public/{chunk-LDVA4PGW.js → chunk-DMDEAXJH.js} +1 -1
- package/public/{chunk-E7CHJVF6.js → chunk-DN72EAQ5.js} +1 -1
- package/public/{chunk-56NTNN7A.js → chunk-E3OCSFY5.js} +1 -1
- package/public/{chunk-KGXF4YD5.js → chunk-ERT4USI6.js} +1 -1
- package/public/chunk-EZCJGSOY.js +5 -0
- package/public/{chunk-3H4EJBIW.js → chunk-FKIJIVEG.js} +1 -1
- package/public/{chunk-7WBNDA43.js → chunk-G4HQSJ23.js} +1 -1
- package/public/{chunk-R6KWC4OQ.js → chunk-GOWJQFU3.js} +1 -1
- package/public/{chunk-QO7DKILC.js → chunk-H5WFRSS4.js} +1 -1
- package/public/chunk-HPLLPVW3.js +1 -0
- package/public/chunk-IHZHS7ZW.js +40 -0
- package/public/{chunk-HZMFFKYB.js → chunk-IJB6PBR5.js} +1 -1
- package/public/{chunk-WCXHI252.js → chunk-INEQMM2I.js} +1 -1
- package/public/chunk-IR2HMKD2.js +1 -0
- package/public/chunk-J3RGEHLW.js +1 -0
- package/public/chunk-JEESCTKG.js +16 -0
- package/public/{chunk-JXJXX7ID.js → chunk-LFWS6OUH.js} +1 -1
- package/public/chunk-LKJ4JJLK.js +1 -0
- package/public/{chunk-7ZJON72I.js → chunk-MGSFT332.js} +1 -1
- package/public/chunk-MJHLBHHD.js +1 -0
- package/public/{chunk-UQEYJ37C.js → chunk-MK4QUOAX.js} +1 -1
- package/public/{chunk-GTGRW7SZ.js → chunk-N7EXU2NV.js} +1 -1
- package/public/{chunk-R3BLBHPZ.js → chunk-OKTWUEQP.js} +1 -1
- package/public/{chunk-IJNJ3FHH.js → chunk-OQU6YMM6.js} +1 -1
- package/public/{chunk-IIVVMKTD.js → chunk-PBN5VTOU.js} +1 -1
- package/public/{chunk-PMIKE7XO.js → chunk-QDT36PQN.js} +1 -1
- package/public/{chunk-I24Z7SXB.js → chunk-QH66HEIY.js} +1 -1
- package/public/{chunk-N67N5JDK.js → chunk-QONMKSXQ.js} +1 -1
- package/public/{chunk-MNT5ZGV3.js → chunk-RFQQSATI.js} +1 -1
- package/public/{chunk-OO2MVDGG.js → chunk-RUWA3EFR.js} +1 -1
- package/public/{chunk-Z473TWB3.js → chunk-RV34PNIK.js} +1 -1
- package/public/{chunk-5H4UKHQO.js → chunk-RWL56OKC.js} +1 -1
- package/public/{chunk-T5MFQC3H.js → chunk-S2OEXAQE.js} +1 -1
- package/public/{chunk-BYBEFFNH.js → chunk-SAWH3ANN.js} +1 -1
- package/public/{chunk-CXUQLNRT.js → chunk-SBHNM2QO.js} +1 -1
- package/public/{chunk-PENFMOAM.js → chunk-SDSUBQRV.js} +1 -1
- package/public/{chunk-JAGGIZOK.js → chunk-SQWHIT2O.js} +1 -1
- package/public/{chunk-AYEBKGOW.js → chunk-STKYISTF.js} +1 -1
- package/public/{chunk-H22EEHWT.js → chunk-TDRGDK3T.js} +1 -1
- package/public/{chunk-W6VJMRO6.js → chunk-TNZDCJJB.js} +1 -1
- package/public/chunk-TTFY54LY.js +1 -0
- package/public/chunk-TXPIYSRT.js +50 -0
- package/public/{chunk-D34BHZAZ.js → chunk-UD5DX3PK.js} +1 -1
- package/public/{chunk-DFSYVZHS.js → chunk-UD7BEYXY.js} +1 -1
- package/public/{chunk-FVPOFMFR.js → chunk-UX77G732.js} +1 -1
- package/public/{chunk-WLNOOGPS.js → chunk-VLO3EC7G.js} +1 -1
- package/public/{chunk-K6MP6J2I.js → chunk-WGI4RZDV.js} +1 -1
- package/public/{chunk-YFMEPI62.js → chunk-WZOQNFMH.js} +1 -1
- package/public/{chunk-TJTVEZ2Q.js → chunk-X4UYQV4U.js} +1 -1
- package/public/chunk-XDYNVDC3.js +1 -0
- package/public/{chunk-RFF7LGZV.js → chunk-XS5676NQ.js} +1 -1
- package/public/chunk-YHWOJFWU.js +1 -0
- package/public/{chunk-7K67C3PU.js → chunk-Z6SZHO36.js} +1 -1
- package/public/index.html +2 -2
- package/public/{main-USYTEC3L.js → main-BIEDFTMT.js} +1 -1
- package/public/{styles-WNHDEKE4.css → styles-7EFV5QBG.css} +1 -1
- 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/ssl-upload-pr.md +0 -103
- package/public/assets/matter.svg +0 -8
- package/public/chunk-2FMEK65B.js +0 -1
- package/public/chunk-4LSPQKBN.js +0 -1
- package/public/chunk-4TJTW5NL.js +0 -52
- package/public/chunk-7X7GKRI7.js +0 -1
- package/public/chunk-GD3BNYBL.js +0 -1
- package/public/chunk-JJMZZNOU.js +0 -19
- package/public/chunk-MGK3CCFB.js +0 -16
- package/public/chunk-NZIBUYDI.js +0 -50
- package/public/chunk-P63CZWFM.js +0 -1
- package/public/chunk-QC5TXGPR.js +0 -1
- package/public/chunk-RERUZJD4.js +0 -5
- package/public/chunk-RZY66DUH.js +0 -1
- package/public/chunk-S6C7GUA2.js +0 -1
- package/public/chunk-T5TGWWEW.js +0 -1
- package/public/chunk-TUSDAICO.js +0 -4
- package/public/chunk-VAU7GXP6.js +0 -1
- package/public/media/matter-P563JGDL.svg +0 -8
|
@@ -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,44 +50,42 @@ 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;
|
|
74
|
+
let bridgesChanged = false;
|
|
89
75
|
if (uiConfig.accessoryControl?.instanceBlacklist?.includes(username)) {
|
|
90
76
|
blacklistChanged = true;
|
|
91
77
|
uiConfig.accessoryControl.instanceBlacklist = uiConfig.accessoryControl.instanceBlacklist
|
|
92
78
|
.filter((x) => x.toUpperCase() !== username);
|
|
93
79
|
}
|
|
80
|
+
let oldBridgeConfig;
|
|
81
|
+
if (uiConfig.bridges && Array.isArray(uiConfig.bridges)) {
|
|
82
|
+
const bridgeIndex = uiConfig.bridges.findIndex(x => x.username?.toUpperCase() === username);
|
|
83
|
+
if (bridgeIndex > -1) {
|
|
84
|
+
bridgesChanged = true;
|
|
85
|
+
oldBridgeConfig = uiConfig.bridges[bridgeIndex];
|
|
86
|
+
uiConfig.bridges.splice(bridgeIndex, 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
94
89
|
if (resetPairingInfo) {
|
|
95
90
|
const pluginBlocks = [
|
|
96
91
|
...(configFile.accessories || []),
|
|
@@ -108,7 +103,13 @@ let ServerService = class ServerService {
|
|
|
108
103
|
});
|
|
109
104
|
if (blacklistChanged) {
|
|
110
105
|
uiConfig.accessoryControl.instanceBlacklist = uiConfig.accessoryControl.instanceBlacklist
|
|
111
|
-
.concat(pluginBlock._bridge.username
|
|
106
|
+
.concat(pluginBlock._bridge.username);
|
|
107
|
+
}
|
|
108
|
+
if (bridgesChanged) {
|
|
109
|
+
uiConfig.bridges.push({
|
|
110
|
+
...oldBridgeConfig,
|
|
111
|
+
username: pluginBlock._bridge.username,
|
|
112
|
+
});
|
|
112
113
|
}
|
|
113
114
|
this.logger.warn(`Bridge ${id} reset: new username: ${pluginBlock._bridge.username} and new pin: ${pluginBlock._bridge.pin}.`);
|
|
114
115
|
}
|
|
@@ -133,10 +134,6 @@ let ServerService = class ServerService {
|
|
|
133
134
|
await unlink(identifierCache);
|
|
134
135
|
this.logger.warn(`Bridge ${id} reset: removed ${identifierCache}.`);
|
|
135
136
|
}
|
|
136
|
-
if (await pathExists(matterPath)) {
|
|
137
|
-
await remove(matterPath);
|
|
138
|
-
this.logger.warn(`Bridge ${id} reset: removed Matter bridge storage at ${matterPath}.`);
|
|
139
|
-
}
|
|
140
137
|
await this.deleteDeviceAccessories(id);
|
|
141
138
|
}
|
|
142
139
|
async restartServer() {
|
|
@@ -180,12 +177,6 @@ let ServerService = class ServerService {
|
|
|
180
177
|
await this.configEditorService.updateConfigFile(configFile);
|
|
181
178
|
await remove(resolve(this.configService.storagePath, 'accessories'));
|
|
182
179
|
await remove(resolve(this.configService.storagePath, 'persist'));
|
|
183
|
-
const deviceId = oldUsername.split(':').join('').toUpperCase();
|
|
184
|
-
const matterPath = join(this.configService.storagePath, 'matter', deviceId);
|
|
185
|
-
if (await pathExists(matterPath)) {
|
|
186
|
-
await remove(matterPath);
|
|
187
|
-
this.logger.warn(`Bridge ${oldUsername} reset: removed Matter bridge storage at ${matterPath}.`);
|
|
188
|
-
}
|
|
189
180
|
this.logger.log('Homebridge bridge reset: accessories and persist directories were removed.');
|
|
190
181
|
}
|
|
191
182
|
async getDevicePairings() {
|
|
@@ -193,68 +184,9 @@ let ServerService = class ServerService {
|
|
|
193
184
|
const devices = (await readdir(persistPath))
|
|
194
185
|
.filter(x => x.match(/AccessoryInfo\.([A-Fa-f0-9]+)\.json$/));
|
|
195
186
|
const configFile = await this.configEditorService.getConfigFile();
|
|
196
|
-
|
|
187
|
+
return Promise.all(devices.map(async (x) => {
|
|
197
188
|
return await this.getDevicePairingById(x.split('.')[1], configFile);
|
|
198
189
|
}));
|
|
199
|
-
const matterExternalDevices = await this.getMatterExternalAccessories(hapDevices);
|
|
200
|
-
return [...hapDevices, ...matterExternalDevices].sort((a, b) => a.name.localeCompare(b.name));
|
|
201
|
-
}
|
|
202
|
-
async getMatterExternalAccessories(hapDevices) {
|
|
203
|
-
const matterPath = join(this.configService.storagePath, 'matter');
|
|
204
|
-
if (!await pathExists(matterPath)) {
|
|
205
|
-
return [];
|
|
206
|
-
}
|
|
207
|
-
const matterDirs = (await readdir(matterPath))
|
|
208
|
-
.filter(x => x.match(/^[A-F0-9]{12}$/));
|
|
209
|
-
const matterExternalDevices = [];
|
|
210
|
-
for (const deviceId of matterDirs) {
|
|
211
|
-
try {
|
|
212
|
-
const hasHapAccessoryInfo = hapDevices.some(d => d._id === deviceId);
|
|
213
|
-
if (hasHapAccessoryInfo) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
const mainBridgeId = this.configService.homebridgeConfig.bridge.username.split(':').join('').toUpperCase();
|
|
217
|
-
if (deviceId.toUpperCase() === mainBridgeId) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const accessoriesPath = join(matterPath, deviceId, 'accessories.json');
|
|
221
|
-
if (!await pathExists(accessoriesPath)) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const accessories = await readJson(accessoriesPath);
|
|
225
|
-
if (!Array.isArray(accessories) || accessories.length === 0) {
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
const accessory = accessories[0];
|
|
229
|
-
const commissioningPath = join(matterPath, deviceId, 'commissioning.json');
|
|
230
|
-
let commissioned = false;
|
|
231
|
-
if (await pathExists(commissioningPath)) {
|
|
232
|
-
const commissioningInfo = await readJson(commissioningPath);
|
|
233
|
-
commissioned = commissioningInfo.commissioned || false;
|
|
234
|
-
}
|
|
235
|
-
const device = {
|
|
236
|
-
_id: deviceId,
|
|
237
|
-
_username: deviceId.match(/.{1,2}/g)?.join(':').toUpperCase() || deviceId,
|
|
238
|
-
_main: false,
|
|
239
|
-
_category: 'other',
|
|
240
|
-
_matter: true,
|
|
241
|
-
_matterOnly: true,
|
|
242
|
-
_isPaired: commissioned,
|
|
243
|
-
_plugin: accessory.plugin,
|
|
244
|
-
name: accessory.displayName || 'Matter External Accessory',
|
|
245
|
-
displayName: accessory.displayName || 'Matter External Accessory',
|
|
246
|
-
manufacturer: accessory.manufacturer || 'Unknown',
|
|
247
|
-
model: accessory.model || 'Unknown',
|
|
248
|
-
serialNumber: accessory.serialNumber || deviceId,
|
|
249
|
-
category: 1,
|
|
250
|
-
};
|
|
251
|
-
matterExternalDevices.push(device);
|
|
252
|
-
}
|
|
253
|
-
catch (e) {
|
|
254
|
-
this.logger.error(`Failed to read Matter external accessory ${deviceId}: ${e.message}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return matterExternalDevices;
|
|
258
190
|
}
|
|
259
191
|
async getDevicePairingById(deviceId, configFile = null) {
|
|
260
192
|
const persistPath = join(this.configService.storagePath, 'persist');
|
|
@@ -287,10 +219,6 @@ let ServerService = class ServerService {
|
|
|
287
219
|
device._isPaired = device.pairedClients && Object.keys(device.pairedClients).length > 0;
|
|
288
220
|
device._setupCode = this.generateSetupCode(device);
|
|
289
221
|
device._couldBeStale = !device._main && device._category === 'bridge' && !pluginBlock;
|
|
290
|
-
device._matter = !!(pluginBlock?._bridge?.matter);
|
|
291
|
-
if (device._matter && pluginBlock && 'accessory' in pluginBlock) {
|
|
292
|
-
this.logger.warn(`Device ${deviceId} has Matter configuration on an accessory-based plugin. Matter is only supported for platform-based plugins.`);
|
|
293
|
-
}
|
|
294
222
|
delete device.signSk;
|
|
295
223
|
delete device.signPk;
|
|
296
224
|
delete device.configHash;
|
|
@@ -304,44 +232,6 @@ let ServerService = class ServerService {
|
|
|
304
232
|
await this.deleteSingleDevicePairing(id, resetPairingInfo);
|
|
305
233
|
return { ok: true };
|
|
306
234
|
}
|
|
307
|
-
async deleteDeviceMatterConfig(id) {
|
|
308
|
-
try {
|
|
309
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
310
|
-
const username = id.includes(':') ? id.toUpperCase() : id.match(/.{1,2}/g)?.join(':').toUpperCase() || id.toUpperCase();
|
|
311
|
-
const pluginBlocks = [
|
|
312
|
-
...(configFile.accessories || []),
|
|
313
|
-
...(configFile.platforms || []),
|
|
314
|
-
]
|
|
315
|
-
.filter((block) => block._bridge?.username?.toUpperCase() === username.toUpperCase());
|
|
316
|
-
const pluginBlock = pluginBlocks.find((block) => block._bridge?.matter);
|
|
317
|
-
if (!pluginBlock) {
|
|
318
|
-
this.logger.error(`Failed to find Matter configuration for child bridge ${id}.`);
|
|
319
|
-
throw new NotFoundException(`Matter configuration not found for bridge ${id}`);
|
|
320
|
-
}
|
|
321
|
-
if ('accessory' in pluginBlock) {
|
|
322
|
-
this.logger.warn(`Removing Matter configuration from accessory-based plugin block for bridge ${id}. Matter is only supported for platform-based plugins.`);
|
|
323
|
-
}
|
|
324
|
-
delete pluginBlock._bridge.matter;
|
|
325
|
-
this.logger.warn(`Bridge ${id} Matter configuration removed from config.json.`);
|
|
326
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
327
|
-
}
|
|
328
|
-
catch (e) {
|
|
329
|
-
if (e instanceof NotFoundException) {
|
|
330
|
-
throw e;
|
|
331
|
-
}
|
|
332
|
-
this.logger.error(`Failed to remove Matter configuration for child bridge ${id} as ${e.message}.`);
|
|
333
|
-
throw new InternalServerErrorException(`Failed to remove Matter configuration: ${e.message}`);
|
|
334
|
-
}
|
|
335
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter storage for bridge ${id}...`);
|
|
336
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
337
|
-
const deviceId = id.includes(':') ? id.split(':').join('').toUpperCase() : id.toUpperCase();
|
|
338
|
-
const matterPath = join(this.configService.storagePath, 'matter', deviceId);
|
|
339
|
-
if (await pathExists(matterPath)) {
|
|
340
|
-
await remove(matterPath);
|
|
341
|
-
this.logger.warn(`Bridge ${id} Matter storage removed at ${matterPath}.`);
|
|
342
|
-
}
|
|
343
|
-
return { ok: true };
|
|
344
|
-
}
|
|
345
235
|
async deleteDevicesPairing(bridges) {
|
|
346
236
|
this.logger.warn(`Shutting down Homebridge before resetting paired bridges ${bridges.map(x => x.id).join(', ')}...`);
|
|
347
237
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
@@ -365,9 +255,9 @@ let ServerService = class ServerService {
|
|
|
365
255
|
this.logger.warn(`Shutting down Homebridge before removing accessories for paired bridges ${bridges.map(x => x.id).join(', ')}...`);
|
|
366
256
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
367
257
|
const cachedAccessoriesDir = join(this.configService.storagePath, 'accessories');
|
|
368
|
-
for (const { id
|
|
258
|
+
for (const { id } of bridges) {
|
|
369
259
|
try {
|
|
370
|
-
await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir
|
|
260
|
+
await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir);
|
|
371
261
|
}
|
|
372
262
|
catch (e) {
|
|
373
263
|
this.logger.error(`Failed to remove accessories for bridge ${id} as ${e.message}.`);
|
|
@@ -448,19 +338,13 @@ let ServerService = class ServerService {
|
|
|
448
338
|
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
449
339
|
this.logger.warn('Shutting down Homebridge before removing cached accessories');
|
|
450
340
|
try {
|
|
451
|
-
this.logger.log('Clearing all
|
|
341
|
+
this.logger.log('Clearing all cached accessories...');
|
|
452
342
|
for (const thisCachedAccessoriesPath of cachedAccessoryPaths) {
|
|
453
343
|
if (await pathExists(thisCachedAccessoriesPath)) {
|
|
454
344
|
await unlink(thisCachedAccessoriesPath);
|
|
455
345
|
this.logger.warn(`Removed ${thisCachedAccessoriesPath}.`);
|
|
456
346
|
}
|
|
457
347
|
}
|
|
458
|
-
const matterDir = join(this.configService.storagePath, 'matter');
|
|
459
|
-
if (await pathExists(matterDir)) {
|
|
460
|
-
this.logger.log('Clearing all Matter cached accessories...');
|
|
461
|
-
await remove(matterDir);
|
|
462
|
-
this.logger.warn(`Removed Matter storage directory at ${matterDir}.`);
|
|
463
|
-
}
|
|
464
348
|
}
|
|
465
349
|
catch (e) {
|
|
466
350
|
this.logger.error(`Failed to clear all cached accessories at ${cachedAccessoriesPath} as ${e.message}.`);
|
|
@@ -469,96 +353,6 @@ let ServerService = class ServerService {
|
|
|
469
353
|
}
|
|
470
354
|
return { ok: true };
|
|
471
355
|
}
|
|
472
|
-
async getMatterAccessories() {
|
|
473
|
-
const matterDir = join(this.configService.storagePath, 'matter');
|
|
474
|
-
if (!await pathExists(matterDir)) {
|
|
475
|
-
return [];
|
|
476
|
-
}
|
|
477
|
-
const matterBridges = (await readdir(matterDir))
|
|
478
|
-
.filter(x => x.match(/^[A-F0-9]+$/));
|
|
479
|
-
const matterAccessories = [];
|
|
480
|
-
await Promise.all(matterBridges.map(async (deviceId) => {
|
|
481
|
-
try {
|
|
482
|
-
const accessoriesPath = join(matterDir, deviceId, 'accessories.json');
|
|
483
|
-
if (await pathExists(accessoriesPath)) {
|
|
484
|
-
const accessories = await readJson(accessoriesPath);
|
|
485
|
-
if (Array.isArray(accessories)) {
|
|
486
|
-
for (const accessory of accessories) {
|
|
487
|
-
accessory.$deviceId = deviceId;
|
|
488
|
-
accessory.$protocol = 'matter';
|
|
489
|
-
matterAccessories.push(accessory);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
this.logger.error(`Failed to read Matter accessories for bridge ${deviceId}: ${e.message}`);
|
|
496
|
-
}
|
|
497
|
-
}));
|
|
498
|
-
return matterAccessories;
|
|
499
|
-
}
|
|
500
|
-
async deleteMatterAccessory(deviceId, uuid) {
|
|
501
|
-
const matterAccessoriesPath = join(this.configService.storagePath, 'matter', deviceId, 'accessories.json');
|
|
502
|
-
if (!await pathExists(matterAccessoriesPath)) {
|
|
503
|
-
this.logger.error(`Matter accessories file not found for bridge ${deviceId}`);
|
|
504
|
-
throw new NotFoundException();
|
|
505
|
-
}
|
|
506
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter accessory ${uuid} from bridge ${deviceId}...`);
|
|
507
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
508
|
-
const matterAccessories = await readJson(matterAccessoriesPath);
|
|
509
|
-
const accessoryIndex = matterAccessories.findIndex(x => x.uuid === uuid);
|
|
510
|
-
if (accessoryIndex > -1) {
|
|
511
|
-
matterAccessories.splice(accessoryIndex, 1);
|
|
512
|
-
await writeJson(matterAccessoriesPath, matterAccessories, { spaces: 2 });
|
|
513
|
-
this.logger.warn(`Removed Matter accessory with UUID ${uuid} from bridge ${deviceId}.`);
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
this.logger.error(`Cannot find Matter accessory with UUID ${uuid} in bridge ${deviceId}.`);
|
|
517
|
-
throw new NotFoundException();
|
|
518
|
-
}
|
|
519
|
-
return { ok: true };
|
|
520
|
-
}
|
|
521
|
-
async deleteMatterAccessories(accessories) {
|
|
522
|
-
this.logger.warn(`Shutting down Homebridge before removing Matter accessories ${accessories.map(x => x.uuid).join(', ')}.`);
|
|
523
|
-
await this.homebridgeIpcService.restartAndWaitForClose();
|
|
524
|
-
const accessoriesByBridge = new Map();
|
|
525
|
-
for (const { deviceId, uuid } of accessories) {
|
|
526
|
-
if (!accessoriesByBridge.has(deviceId)) {
|
|
527
|
-
accessoriesByBridge.set(deviceId, []);
|
|
528
|
-
}
|
|
529
|
-
accessoriesByBridge.get(deviceId).push({ uuid });
|
|
530
|
-
}
|
|
531
|
-
for (const [deviceId, bridgeAccessories] of accessoriesByBridge.entries()) {
|
|
532
|
-
const matterAccessoriesPath = join(this.configService.storagePath, 'matter', deviceId, 'accessories.json');
|
|
533
|
-
try {
|
|
534
|
-
if (!await pathExists(matterAccessoriesPath)) {
|
|
535
|
-
this.logger.error(`Matter accessories file not found for bridge ${deviceId}`);
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
const matterAccessories = await readJson(matterAccessoriesPath);
|
|
539
|
-
for (const { uuid } of bridgeAccessories) {
|
|
540
|
-
try {
|
|
541
|
-
const accessoryIndex = matterAccessories.findIndex(x => x.uuid === uuid);
|
|
542
|
-
if (accessoryIndex > -1) {
|
|
543
|
-
matterAccessories.splice(accessoryIndex, 1);
|
|
544
|
-
this.logger.warn(`Removed Matter accessory with UUID ${uuid} from bridge ${deviceId}.`);
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
this.logger.error(`Cannot find Matter accessory with UUID ${uuid} in bridge ${deviceId}.`);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
catch (e) {
|
|
551
|
-
this.logger.error(`Failed to remove Matter accessory with UUID ${uuid} from bridge ${deviceId} as ${e.message}.`);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
await writeJson(matterAccessoriesPath, matterAccessories, { spaces: 2 });
|
|
555
|
-
}
|
|
556
|
-
catch (e) {
|
|
557
|
-
this.logger.error(`Failed to process Matter accessories for bridge ${deviceId} as ${e.message}.`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
return { ok: true };
|
|
561
|
-
}
|
|
562
356
|
async getSetupCode() {
|
|
563
357
|
if (this.setupCode) {
|
|
564
358
|
return this.setupCode;
|
|
@@ -663,30 +457,6 @@ let ServerService = class ServerService {
|
|
|
663
457
|
}
|
|
664
458
|
return { port };
|
|
665
459
|
}
|
|
666
|
-
async lookupUnusedMatterPort() {
|
|
667
|
-
const min = 5530;
|
|
668
|
-
const max = 5541;
|
|
669
|
-
const config = await this.configEditorService.getConfigFile();
|
|
670
|
-
const usedMatterPorts = new Set();
|
|
671
|
-
if (config.bridge?.matter?.port) {
|
|
672
|
-
usedMatterPorts.add(config.bridge.matter.port);
|
|
673
|
-
}
|
|
674
|
-
for (const block of [...(config.accessories || []), ...(config.platforms || [])]) {
|
|
675
|
-
if (block._bridge?.matter?.port) {
|
|
676
|
-
if ('accessory' in block) {
|
|
677
|
-
this.logger.warn(`Found Matter configuration on accessory-based plugin block, skipping port ${block._bridge.matter.port}`);
|
|
678
|
-
continue;
|
|
679
|
-
}
|
|
680
|
-
usedMatterPorts.add(block._bridge.matter.port);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
for (let port = min; port <= max; port += 1) {
|
|
684
|
-
if (!usedMatterPorts.has(port) && !await tcpCheck(port)) {
|
|
685
|
-
return { port };
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
throw new InternalServerErrorException('No available ports in the Matter port range (5530-5541)');
|
|
689
|
-
}
|
|
690
460
|
async getHomebridgePort() {
|
|
691
461
|
const config = await this.configEditorService.getConfigFile();
|
|
692
462
|
return { port: config.bridge.port };
|
|
@@ -819,248 +589,6 @@ let ServerService = class ServerService {
|
|
|
819
589
|
});
|
|
820
590
|
});
|
|
821
591
|
}
|
|
822
|
-
async uploadSslKeyCert(req) {
|
|
823
|
-
const parts = req.parts ? req.parts() : null;
|
|
824
|
-
const files = [];
|
|
825
|
-
if (parts) {
|
|
826
|
-
for await (const part of parts) {
|
|
827
|
-
if (part.file) {
|
|
828
|
-
files.push(part);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
const single = await req.file();
|
|
834
|
-
if (single?.file) {
|
|
835
|
-
files.push(single);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
if (!files.length) {
|
|
839
|
-
throw new BadRequestException('No files uploaded. Please upload both the private key and certificate files.');
|
|
840
|
-
}
|
|
841
|
-
const readStreamToBuffer = async (stream) => {
|
|
842
|
-
const chunks = [];
|
|
843
|
-
await new Promise((resolvePromise, rejectPromise) => {
|
|
844
|
-
stream.on('data', (d) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(d)));
|
|
845
|
-
stream.on('end', () => resolvePromise());
|
|
846
|
-
stream.on('error', rejectPromise);
|
|
847
|
-
});
|
|
848
|
-
return Buffer.concat(chunks);
|
|
849
|
-
};
|
|
850
|
-
let keyPem = null;
|
|
851
|
-
let certPem = null;
|
|
852
|
-
for (const f of files) {
|
|
853
|
-
if (f.file?.truncated) {
|
|
854
|
-
throw new InternalServerErrorException(`Upload exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`);
|
|
855
|
-
}
|
|
856
|
-
const buf = await readStreamToBuffer(f.file);
|
|
857
|
-
const text = buf.toString('utf8');
|
|
858
|
-
if (/-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/.test(text)) {
|
|
859
|
-
keyPem = buf;
|
|
860
|
-
}
|
|
861
|
-
else if (/-----BEGIN CERTIFICATE-----/.test(text)) {
|
|
862
|
-
certPem = buf;
|
|
863
|
-
}
|
|
864
|
-
else if (f.fieldname === 'key') {
|
|
865
|
-
keyPem = buf;
|
|
866
|
-
}
|
|
867
|
-
else if (f.fieldname === 'cert') {
|
|
868
|
-
certPem = buf;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
if (!keyPem || !certPem) {
|
|
872
|
-
throw new BadRequestException('Both a PEM private key and certificate must be provided.');
|
|
873
|
-
}
|
|
874
|
-
try {
|
|
875
|
-
const x509 = new X509Certificate(certPem);
|
|
876
|
-
const certPub = x509.publicKey.export({ type: 'spki', format: 'der' });
|
|
877
|
-
const priv = createPrivateKey({ key: keyPem });
|
|
878
|
-
const pubFromPriv = createPublicKey(priv).export({ type: 'spki', format: 'der' });
|
|
879
|
-
if (!certPub.equals(pubFromPriv)) {
|
|
880
|
-
throw new BadRequestException('The private key does not match the certificate public key.');
|
|
881
|
-
}
|
|
882
|
-
createSecureContext({ key: keyPem, cert: certPem });
|
|
883
|
-
}
|
|
884
|
-
catch (e) {
|
|
885
|
-
if (e instanceof BadRequestException) {
|
|
886
|
-
throw e;
|
|
887
|
-
}
|
|
888
|
-
throw new BadRequestException(`Invalid key/certificate: ${e?.message || e}`);
|
|
889
|
-
}
|
|
890
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
891
|
-
const keyPath = join(sslDir, 'ui-ssl.key');
|
|
892
|
-
const certPath = join(sslDir, 'ui-ssl.crt');
|
|
893
|
-
const { ensureDir, writeFile } = await import('fs-extra');
|
|
894
|
-
await ensureDir(sslDir);
|
|
895
|
-
await writeFile(keyPath, keyPem);
|
|
896
|
-
await writeFile(certPath, certPem);
|
|
897
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
898
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
899
|
-
if (!uiConfigBlock) {
|
|
900
|
-
throw new InternalServerErrorException('Config platform block not found.');
|
|
901
|
-
}
|
|
902
|
-
if (!uiConfigBlock.ssl) {
|
|
903
|
-
uiConfigBlock.ssl = {};
|
|
904
|
-
}
|
|
905
|
-
uiConfigBlock.ssl.key = keyPath;
|
|
906
|
-
uiConfigBlock.ssl.cert = certPath;
|
|
907
|
-
delete uiConfigBlock.ssl.pfx;
|
|
908
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
909
|
-
uiConfigBlock.ssl.selfSigned = false;
|
|
910
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
911
|
-
return {
|
|
912
|
-
ok: true,
|
|
913
|
-
type: 'keycert',
|
|
914
|
-
keyPath,
|
|
915
|
-
certPath,
|
|
916
|
-
details: 'Certificate and key validated and saved.',
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
async uploadSslPfx(req) {
|
|
920
|
-
let passphrase;
|
|
921
|
-
let filePart;
|
|
922
|
-
if (req.parts) {
|
|
923
|
-
for await (const part of req.parts()) {
|
|
924
|
-
if (part.type === 'file' || part.file) {
|
|
925
|
-
filePart = part;
|
|
926
|
-
}
|
|
927
|
-
else if (part.type === 'field' || part.value) {
|
|
928
|
-
if (part.fieldname === 'passphrase') {
|
|
929
|
-
passphrase = part.value;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
else {
|
|
935
|
-
filePart = await req.file();
|
|
936
|
-
passphrase = req.body?.passphrase;
|
|
937
|
-
}
|
|
938
|
-
if (!filePart) {
|
|
939
|
-
throw new BadRequestException('No PFX file uploaded.');
|
|
940
|
-
}
|
|
941
|
-
if (filePart.file?.truncated) {
|
|
942
|
-
throw new InternalServerErrorException(`Upload exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`);
|
|
943
|
-
}
|
|
944
|
-
const readStreamToBuffer = async (stream) => {
|
|
945
|
-
const chunks = [];
|
|
946
|
-
await new Promise((resolvePromise, rejectPromise) => {
|
|
947
|
-
stream.on('data', (d) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(d)));
|
|
948
|
-
stream.on('end', () => resolvePromise());
|
|
949
|
-
stream.on('error', rejectPromise);
|
|
950
|
-
});
|
|
951
|
-
return Buffer.concat(chunks);
|
|
952
|
-
};
|
|
953
|
-
const pfxBuffer = await readStreamToBuffer(filePart.file);
|
|
954
|
-
try {
|
|
955
|
-
createSecureContext({ pfx: pfxBuffer, passphrase });
|
|
956
|
-
}
|
|
957
|
-
catch (e) {
|
|
958
|
-
throw new BadRequestException(`Invalid PFX or passphrase: ${e?.message || e}`);
|
|
959
|
-
}
|
|
960
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
961
|
-
const pfxPath = join(sslDir, 'ui-ssl.pfx');
|
|
962
|
-
const { ensureDir, writeFile } = await import('fs-extra');
|
|
963
|
-
await ensureDir(sslDir);
|
|
964
|
-
await writeFile(pfxPath, pfxBuffer);
|
|
965
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
966
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
967
|
-
if (!uiConfigBlock) {
|
|
968
|
-
throw new InternalServerErrorException('Config platform block not found.');
|
|
969
|
-
}
|
|
970
|
-
if (!uiConfigBlock.ssl) {
|
|
971
|
-
uiConfigBlock.ssl = {};
|
|
972
|
-
}
|
|
973
|
-
uiConfigBlock.ssl.pfx = pfxPath;
|
|
974
|
-
uiConfigBlock.ssl.passphrase = passphrase || '';
|
|
975
|
-
delete uiConfigBlock.ssl.key;
|
|
976
|
-
delete uiConfigBlock.ssl.cert;
|
|
977
|
-
uiConfigBlock.ssl.selfSigned = false;
|
|
978
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
979
|
-
return {
|
|
980
|
-
ok: true,
|
|
981
|
-
type: 'pfx',
|
|
982
|
-
pfxPath,
|
|
983
|
-
details: 'PFX validated and saved.',
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
async validateCurrentSslConfig() {
|
|
987
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
988
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
989
|
-
const ssl = uiConfigBlock?.ssl || {};
|
|
990
|
-
if (!ssl || (!ssl.selfSigned && !ssl.key && !ssl.cert && !ssl.pfx)) {
|
|
991
|
-
return { ok: true, valid: true, type: 'off', details: 'HTTPS is disabled.' };
|
|
992
|
-
}
|
|
993
|
-
if (ssl.selfSigned) {
|
|
994
|
-
return { ok: true, valid: true, type: 'selfsigned', details: 'Self-signed mode enabled.' };
|
|
995
|
-
}
|
|
996
|
-
try {
|
|
997
|
-
if (ssl.key && ssl.cert) {
|
|
998
|
-
const { readFile } = await import('fs-extra');
|
|
999
|
-
const keyPem = await readFile(ssl.key);
|
|
1000
|
-
const certPem = await readFile(ssl.cert);
|
|
1001
|
-
const x509 = new X509Certificate(certPem);
|
|
1002
|
-
const certPub = x509.publicKey.export({ type: 'spki', format: 'der' });
|
|
1003
|
-
const priv = createPrivateKey({ key: keyPem });
|
|
1004
|
-
const pubFromPriv = createPublicKey(priv).export({ type: 'spki', format: 'der' });
|
|
1005
|
-
if (!certPub.equals(pubFromPriv)) {
|
|
1006
|
-
return { ok: true, valid: false, type: 'keycert', details: 'Private key does not match certificate.' };
|
|
1007
|
-
}
|
|
1008
|
-
createSecureContext({ key: keyPem, cert: certPem });
|
|
1009
|
-
return { ok: true, valid: true, type: 'keycert', details: 'Key and certificate are valid and match.' };
|
|
1010
|
-
}
|
|
1011
|
-
if (ssl.pfx) {
|
|
1012
|
-
const { readFile } = await import('fs-extra');
|
|
1013
|
-
const pfx = await readFile(ssl.pfx);
|
|
1014
|
-
createSecureContext({ pfx, passphrase: ssl.passphrase });
|
|
1015
|
-
return { ok: true, valid: true, type: 'pfx', details: 'PFX file and passphrase are valid.' };
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
catch (e) {
|
|
1019
|
-
return { ok: true, valid: false, type: ssl.pfx ? 'pfx' : 'keycert', details: e?.message || String(e) };
|
|
1020
|
-
}
|
|
1021
|
-
return { ok: true, valid: false, type: 'off', details: 'No SSL configuration found.' };
|
|
1022
|
-
}
|
|
1023
|
-
async generateSelfSignedCertificate(options = {}) {
|
|
1024
|
-
const hostnames = Array.isArray(options.hostnames) && options.hostnames.length
|
|
1025
|
-
? options.hostnames.map(h => String(h).trim()).filter(Boolean)
|
|
1026
|
-
: ['localhost', '127.0.0.1'];
|
|
1027
|
-
const mode = options.mode || 'keycert';
|
|
1028
|
-
const generator = new SslCertGeneratorService();
|
|
1029
|
-
await generator.generateCertificate(hostnames);
|
|
1030
|
-
const sslDir = join(this.configService.storagePath, 'ssl-certs');
|
|
1031
|
-
const keyPath = join(sslDir, 'private-key.pem');
|
|
1032
|
-
const certPath = join(sslDir, 'certificate.pem');
|
|
1033
|
-
const configFile = await this.configEditorService.getConfigFile();
|
|
1034
|
-
const uiConfigBlock = configFile.platforms.find((x) => x.platform === 'config');
|
|
1035
|
-
if (!uiConfigBlock.ssl) {
|
|
1036
|
-
uiConfigBlock.ssl = {};
|
|
1037
|
-
}
|
|
1038
|
-
if (mode === 'keycert') {
|
|
1039
|
-
uiConfigBlock.ssl.key = keyPath;
|
|
1040
|
-
uiConfigBlock.ssl.cert = certPath;
|
|
1041
|
-
delete uiConfigBlock.ssl.pfx;
|
|
1042
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
1043
|
-
uiConfigBlock.ssl.selfSigned = false;
|
|
1044
|
-
uiConfigBlock.ssl.selfSignedHostnames = hostnames;
|
|
1045
|
-
}
|
|
1046
|
-
else {
|
|
1047
|
-
delete uiConfigBlock.ssl.key;
|
|
1048
|
-
delete uiConfigBlock.ssl.cert;
|
|
1049
|
-
delete uiConfigBlock.ssl.pfx;
|
|
1050
|
-
delete uiConfigBlock.ssl.passphrase;
|
|
1051
|
-
uiConfigBlock.ssl.selfSigned = true;
|
|
1052
|
-
uiConfigBlock.ssl.selfSignedHostnames = hostnames;
|
|
1053
|
-
}
|
|
1054
|
-
await this.configEditorService.updateConfigFile(configFile);
|
|
1055
|
-
return {
|
|
1056
|
-
ok: true,
|
|
1057
|
-
type: 'generated',
|
|
1058
|
-
mode,
|
|
1059
|
-
keyPath: mode === 'keycert' ? keyPath : undefined,
|
|
1060
|
-
certPath: mode === 'keycert' ? certPath : undefined,
|
|
1061
|
-
details: `Self-signed certificate generated for ${hostnames.join(', ')}`,
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
592
|
};
|
|
1065
593
|
ServerService = __decorate([
|
|
1066
594
|
Injectable(),
|