homebridge-config-ui-x 5.9.1-beta.10 → 5.9.1-beta.12

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +2 -6
  2. package/dist/core/auth/auth.controller.d.ts +0 -4
  3. package/dist/core/config/config.interfaces.d.ts +0 -14
  4. package/dist/core/config/config.service.d.ts +0 -6
  5. package/dist/core/config/config.service.js +0 -8
  6. package/dist/core/config/config.service.js.map +1 -1
  7. package/dist/core/config/config.startup.js +17 -48
  8. package/dist/core/config/config.startup.js.map +1 -1
  9. package/dist/core/feature-flags/feature-flags.registry.js +0 -5
  10. package/dist/core/feature-flags/feature-flags.registry.js.map +1 -1
  11. package/dist/core/homebridge-ipc/homebridge-ipc.service.js +0 -1
  12. package/dist/core/homebridge-ipc/homebridge-ipc.service.js.map +1 -1
  13. package/dist/core/spa/spa.filter.d.ts +0 -3
  14. package/dist/core/spa/spa.filter.js +2 -22
  15. package/dist/core/spa/spa.filter.js.map +1 -1
  16. package/dist/globalDefaults.js +0 -3
  17. package/dist/globalDefaults.js.map +1 -1
  18. package/dist/main.js +6 -19
  19. package/dist/main.js.map +1 -1
  20. package/dist/modules/accessories/accessories.controller.d.ts +1 -1
  21. package/dist/modules/accessories/accessories.module.js +0 -2
  22. package/dist/modules/accessories/accessories.module.js.map +1 -1
  23. package/dist/modules/accessories/accessories.service.d.ts +3 -21
  24. package/dist/modules/accessories/accessories.service.js +17 -280
  25. package/dist/modules/accessories/accessories.service.js.map +1 -1
  26. package/dist/modules/child-bridges/child-bridges.interfaces.d.ts +0 -9
  27. package/dist/modules/config-editor/config-editor.controller.d.ts +0 -4
  28. package/dist/modules/config-editor/config-editor.controller.js +0 -64
  29. package/dist/modules/config-editor/config-editor.controller.js.map +1 -1
  30. package/dist/modules/config-editor/config-editor.service.d.ts +1 -6
  31. package/dist/modules/config-editor/config-editor.service.js +1 -45
  32. package/dist/modules/config-editor/config-editor.service.js.map +1 -1
  33. package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js +1 -1
  34. package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js.map +1 -1
  35. package/dist/modules/plugins/plugins.service.js +0 -15
  36. package/dist/modules/plugins/plugins.service.js.map +1 -1
  37. package/dist/modules/server/server.controller.d.ts +0 -50
  38. package/dist/modules/server/server.controller.js +2 -201
  39. package/dist/modules/server/server.controller.js.map +1 -1
  40. package/dist/modules/server/server.service.d.ts +0 -48
  41. package/dist/modules/server/server.service.js +14 -502
  42. package/dist/modules/server/server.service.js.map +1 -1
  43. package/dist/modules/status/status.gateway.d.ts +0 -2
  44. package/dist/modules/status/status.interfaces.d.ts +0 -11
  45. package/dist/modules/status/status.service.d.ts +1 -4
  46. package/dist/modules/status/status.service.js +2 -21
  47. package/dist/modules/status/status.service.js.map +1 -1
  48. package/package.json +11 -16
  49. package/public/3rdpartylicenses.txt +26 -26
  50. package/public/assets/plugin-ui-utils/ui.js +0 -3
  51. package/public/assets/plugin-ui-utils/ui.js.map +1 -1
  52. package/public/{chunk-HZFYCQBZ.js → chunk-2ATI5RL3.js} +1 -1
  53. package/public/chunk-2VVYEOZH.js +50 -0
  54. package/public/{chunk-WFVVY4KI.js → chunk-4TYE7FOW.js} +1 -1
  55. package/public/{chunk-AU2Q4PYM.js → chunk-54RJ6AKS.js} +1 -1
  56. package/public/{chunk-DWAKEAKY.js → chunk-5DT3N4NO.js} +1 -1
  57. package/public/{chunk-IA43FDJ7.js → chunk-5MVRHG7M.js} +1 -1
  58. package/public/{chunk-XS55KH6X.js → chunk-63TNBV3O.js} +1 -1
  59. package/public/{chunk-R2WI5YTX.js → chunk-6VNRMNFA.js} +1 -1
  60. package/public/chunk-7HSZXHMN.js +40 -0
  61. package/public/chunk-7QF2URS5.js +1 -0
  62. package/public/chunk-AIXRAHY2.js +1 -0
  63. package/public/chunk-AKML53DH.js +1 -0
  64. package/public/{chunk-PHND6FV5.js → chunk-AKV4YRXI.js} +1 -1
  65. package/public/{chunk-7SZF43OV.js → chunk-ANRFLI7E.js} +1 -1
  66. package/public/{chunk-LOQEG2RD.js → chunk-ASZU634C.js} +1 -1
  67. package/public/chunk-BSFEVCY3.js +1 -0
  68. package/public/{chunk-4AG5CIDJ.js → chunk-BWPTEYXZ.js} +1 -1
  69. package/public/{chunk-5CCE4FIL.js → chunk-CU254YRC.js} +1 -1
  70. package/public/chunk-DAPFTL2Y.js +1 -0
  71. package/public/chunk-DPB25XJI.js +1 -0
  72. package/public/{chunk-XQCLQKCG.js → chunk-E3OCSFY5.js} +2 -2
  73. package/public/{chunk-SVVZYE76.js → chunk-E5LX6E3G.js} +1 -1
  74. package/public/{chunk-KGXF4YD5.js → chunk-ERT4USI6.js} +1 -1
  75. package/public/chunk-EZCJGSOY.js +5 -0
  76. package/public/chunk-FGA4OENW.js +1 -0
  77. package/public/{chunk-UZHUIPNT.js → chunk-GCYJX7GC.js} +1 -1
  78. package/public/{chunk-R6KWC4OQ.js → chunk-GOWJQFU3.js} +1 -1
  79. package/public/chunk-HCC2KBUY.js +1 -0
  80. package/public/{chunk-DGS32J2V.js → chunk-HGMIM4E6.js} +1 -1
  81. package/public/{chunk-Q7T3F2Y7.js → chunk-HNXADRNJ.js} +1 -1
  82. package/public/{chunk-5RBSMCFS.js → chunk-JVAR26S7.js} +1 -1
  83. package/public/{chunk-U3NNN7U4.js → chunk-KG5T64V2.js} +1 -1
  84. package/public/chunk-KK37GVBX.js +1 -0
  85. package/public/chunk-KQTU4JBF.js +1 -0
  86. package/public/chunk-L6DTBXY4.js +16 -0
  87. package/public/{chunk-JXJXX7ID.js → chunk-LFWS6OUH.js} +1 -1
  88. package/public/chunk-LTM4W2TA.js +1 -0
  89. package/public/{chunk-NTFDKV64.js → chunk-M7WVLDM3.js} +1 -1
  90. package/public/chunk-MI45PHQH.js +1 -0
  91. package/public/chunk-MMCLG4OJ.js +19 -0
  92. package/public/{chunk-WHSTHY5K.js → chunk-MXOXFFLF.js} +1 -1
  93. package/public/chunk-N7S2RWMN.js +2 -0
  94. package/public/{chunk-TJ6P7UCH.js → chunk-NTXS5BGJ.js} +1 -1
  95. package/public/{chunk-IJNJ3FHH.js → chunk-OQU6YMM6.js} +1 -1
  96. package/public/chunk-P5WG2YXV.js +1 -0
  97. package/public/{chunk-IHMVNP7Y.js → chunk-PK7IE6OR.js} +1 -1
  98. package/public/{chunk-T3SFHTRG.js → chunk-PXKFN4ZG.js} +1 -1
  99. package/public/{chunk-2VYE34OE.js → chunk-PYHS4AY4.js} +1 -1
  100. package/public/{chunk-I24Z7SXB.js → chunk-QH66HEIY.js} +1 -1
  101. package/public/{chunk-XQACD65E.js → chunk-QVZDLFUU.js} +1 -1
  102. package/public/{chunk-MNT5ZGV3.js → chunk-RFQQSATI.js} +1 -1
  103. package/public/{chunk-H22EEHWT.js → chunk-TDRGDK3T.js} +1 -1
  104. package/public/{chunk-W6VJMRO6.js → chunk-TNZDCJJB.js} +1 -1
  105. package/public/{chunk-2UCXG3TD.js → chunk-U32CJETH.js} +1 -1
  106. package/public/chunk-U5AUOB3D.js +1 -0
  107. package/public/{chunk-UBLR5WZR.js → chunk-UMYW77W6.js} +1 -1
  108. package/public/{chunk-RDOYYGV5.js → chunk-URSQPWRM.js} +1 -1
  109. package/public/chunk-UUT274CZ.js +1 -0
  110. package/public/{chunk-4H57TZAE.js → chunk-VQ2XHF4Q.js} +1 -1
  111. package/public/{chunk-YFMEPI62.js → chunk-WZOQNFMH.js} +1 -1
  112. package/public/{chunk-ZSWIXPXA.js → chunk-X2WYT5HG.js} +1 -1
  113. package/public/chunk-XMF7DJVM.js +1 -0
  114. package/public/{chunk-CT6TS63V.js → chunk-XVI5FFJ7.js} +1 -1
  115. package/public/{chunk-PF7M52WR.js → chunk-YNBX7NOO.js} +1 -1
  116. package/public/{chunk-7K67C3PU.js → chunk-Z6SZHO36.js} +1 -1
  117. package/public/chunk-ZBMKWQKQ.js +4 -0
  118. package/public/{chunk-7RXQUWCY.js → chunk-ZOS76UV6.js} +1 -1
  119. package/public/{chunk-IM4LXJ36.js → chunk-ZUX5NA5M.js} +1 -1
  120. package/public/index.html +2 -2
  121. package/public/{main-WFXBCXTF.js → main-W63LNLHG.js} +1 -1
  122. package/public/{styles-WNHDEKE4.css → styles-7EFV5QBG.css} +1 -1
  123. package/scripts/extract-plugin-alias.js +2 -53
  124. package/TODO-MATTER.md +0 -15
  125. package/dist/core/spa/spa-html.service.d.ts +0 -5
  126. package/dist/core/spa/spa-html.service.js +0 -32
  127. package/dist/core/spa/spa-html.service.js.map +0 -1
  128. package/dist/core/ssl/ssl-cert-generator.service.d.ts +0 -15
  129. package/dist/core/ssl/ssl-cert-generator.service.js +0 -125
  130. package/dist/core/ssl/ssl-cert-generator.service.js.map +0 -1
  131. package/dist/modules/accessories/accessories.interfaces.d.ts +0 -94
  132. package/dist/modules/accessories/accessories.interfaces.js +0 -2
  133. package/dist/modules/accessories/accessories.interfaces.js.map +0 -1
  134. package/docs/ssl-upload-pr.md +0 -103
  135. package/public/assets/matter.svg +0 -8
  136. package/public/chunk-6O32KEYY.js +0 -1
  137. package/public/chunk-7PEOCUE2.js +0 -16
  138. package/public/chunk-AEYQANK4.js +0 -68
  139. package/public/chunk-AZIULTML.js +0 -1
  140. package/public/chunk-B63E4PTS.js +0 -19
  141. package/public/chunk-DZVJNQPQ.js +0 -1
  142. package/public/chunk-E26RJWMZ.js +0 -4
  143. package/public/chunk-J4AYRIB4.js +0 -1
  144. package/public/chunk-K73OEMZP.js +0 -1
  145. package/public/chunk-KAZYWBPX.js +0 -1
  146. package/public/chunk-KN2SQNGB.js +0 -1
  147. package/public/chunk-LN3BMCV4.js +0 -1
  148. package/public/chunk-M3HVG4RQ.js +0 -1
  149. package/public/chunk-PFWD43QS.js +0 -2
  150. package/public/chunk-PSYU6RB3.js +0 -1
  151. package/public/chunk-QKKTMQUU.js +0 -1
  152. package/public/chunk-QT6XPFQS.js +0 -1
  153. package/public/chunk-R44T3ZI7.js +0 -50
  154. package/public/chunk-RERUZJD4.js +0 -5
  155. package/public/chunk-S5IG2PNV.js +0 -1
  156. package/public/chunk-VNXIDOPC.js +0 -1
  157. package/public/chunk-XMBCOKOA.js +0 -1
  158. package/public/chunk-Z4E6BJST.js +0 -1
  159. 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,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, protocol = 'both') {
57
- if (protocol === 'hap' || protocol === 'both') {
58
- const cachedAccessories = join(cachedAccessoriesDir, `cachedAccessories.${id}`);
59
- const cachedAccessoriesBackup = join(cachedAccessoriesDir, `.cachedAccessories.${id}.bak`);
60
- if (await pathExists(cachedAccessories)) {
61
- await unlink(cachedAccessories);
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 (protocol === 'matter' || protocol === 'both') {
70
- const deviceId = id.split(':').join('').toUpperCase();
71
- const matterPath = join(this.configService.storagePath, 'matter', deviceId);
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.includes(':') ? id.toUpperCase() : id.match(/.{1,2}/g)?.join(':').toUpperCase() || id.toUpperCase();
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
  if (uiConfig.accessoryControl?.instanceBlacklist?.includes(username)) {
@@ -133,10 +118,6 @@ let ServerService = class ServerService {
133
118
  await unlink(identifierCache);
134
119
  this.logger.warn(`Bridge ${id} reset: removed ${identifierCache}.`);
135
120
  }
136
- if (await pathExists(matterPath)) {
137
- await remove(matterPath);
138
- this.logger.warn(`Bridge ${id} reset: removed Matter bridge storage at ${matterPath}.`);
139
- }
140
121
  await this.deleteDeviceAccessories(id);
141
122
  }
142
123
  async restartServer() {
@@ -180,12 +161,6 @@ let ServerService = class ServerService {
180
161
  await this.configEditorService.updateConfigFile(configFile);
181
162
  await remove(resolve(this.configService.storagePath, 'accessories'));
182
163
  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
164
  this.logger.log('Homebridge bridge reset: accessories and persist directories were removed.');
190
165
  }
191
166
  async getDevicePairings() {
@@ -193,68 +168,9 @@ let ServerService = class ServerService {
193
168
  const devices = (await readdir(persistPath))
194
169
  .filter(x => x.match(/AccessoryInfo\.([A-Fa-f0-9]+)\.json$/));
195
170
  const configFile = await this.configEditorService.getConfigFile();
196
- const hapDevices = await Promise.all(devices.map(async (x) => {
171
+ return Promise.all(devices.map(async (x) => {
197
172
  return await this.getDevicePairingById(x.split('.')[1], configFile);
198
173
  }));
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
174
  }
259
175
  async getDevicePairingById(deviceId, configFile = null) {
260
176
  const persistPath = join(this.configService.storagePath, 'persist');
@@ -287,10 +203,6 @@ let ServerService = class ServerService {
287
203
  device._isPaired = device.pairedClients && Object.keys(device.pairedClients).length > 0;
288
204
  device._setupCode = this.generateSetupCode(device);
289
205
  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
206
  delete device.signSk;
295
207
  delete device.signPk;
296
208
  delete device.configHash;
@@ -304,44 +216,6 @@ let ServerService = class ServerService {
304
216
  await this.deleteSingleDevicePairing(id, resetPairingInfo);
305
217
  return { ok: true };
306
218
  }
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
219
  async deleteDevicesPairing(bridges) {
346
220
  this.logger.warn(`Shutting down Homebridge before resetting paired bridges ${bridges.map(x => x.id).join(', ')}...`);
347
221
  await this.homebridgeIpcService.restartAndWaitForClose();
@@ -365,9 +239,9 @@ let ServerService = class ServerService {
365
239
  this.logger.warn(`Shutting down Homebridge before removing accessories for paired bridges ${bridges.map(x => x.id).join(', ')}...`);
366
240
  await this.homebridgeIpcService.restartAndWaitForClose();
367
241
  const cachedAccessoriesDir = join(this.configService.storagePath, 'accessories');
368
- for (const { id, protocol } of bridges) {
242
+ for (const { id } of bridges) {
369
243
  try {
370
- await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir, protocol || 'both');
244
+ await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir);
371
245
  }
372
246
  catch (e) {
373
247
  this.logger.error(`Failed to remove accessories for bridge ${id} as ${e.message}.`);
@@ -448,19 +322,13 @@ let ServerService = class ServerService {
448
322
  await this.homebridgeIpcService.restartAndWaitForClose();
449
323
  this.logger.warn('Shutting down Homebridge before removing cached accessories');
450
324
  try {
451
- this.logger.log('Clearing all HAP cached accessories...');
325
+ this.logger.log('Clearing all cached accessories...');
452
326
  for (const thisCachedAccessoriesPath of cachedAccessoryPaths) {
453
327
  if (await pathExists(thisCachedAccessoriesPath)) {
454
328
  await unlink(thisCachedAccessoriesPath);
455
329
  this.logger.warn(`Removed ${thisCachedAccessoriesPath}.`);
456
330
  }
457
331
  }
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
332
  }
465
333
  catch (e) {
466
334
  this.logger.error(`Failed to clear all cached accessories at ${cachedAccessoriesPath} as ${e.message}.`);
@@ -469,96 +337,6 @@ let ServerService = class ServerService {
469
337
  }
470
338
  return { ok: true };
471
339
  }
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
340
  async getSetupCode() {
563
341
  if (this.setupCode) {
564
342
  return this.setupCode;
@@ -663,30 +441,6 @@ let ServerService = class ServerService {
663
441
  }
664
442
  return { port };
665
443
  }
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
444
  async getHomebridgePort() {
691
445
  const config = await this.configEditorService.getConfigFile();
692
446
  return { port: config.bridge.port };
@@ -819,248 +573,6 @@ let ServerService = class ServerService {
819
573
  });
820
574
  });
821
575
  }
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
576
  };
1065
577
  ServerService = __decorate([
1066
578
  Injectable(),