homebridge-config-ui-x 5.9.1-beta.8 → 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.
Files changed (169) hide show
  1. package/CHANGELOG.md +14 -6
  2. package/dist/app.module.js +2 -0
  3. package/dist/app.module.js.map +1 -1
  4. package/dist/core/auth/auth.controller.d.ts +2 -5
  5. package/dist/core/config/config.interfaces.d.ts +6 -13
  6. package/dist/core/config/config.service.d.ts +2 -7
  7. package/dist/core/config/config.service.js +2 -9
  8. package/dist/core/config/config.service.js.map +1 -1
  9. package/dist/core/config/config.startup.js +17 -48
  10. package/dist/core/config/config.startup.js.map +1 -1
  11. package/dist/core/feature-flags/feature-flags.registry.js +0 -5
  12. package/dist/core/feature-flags/feature-flags.registry.js.map +1 -1
  13. package/dist/core/homebridge-ipc/homebridge-ipc.service.js +0 -1
  14. package/dist/core/homebridge-ipc/homebridge-ipc.service.js.map +1 -1
  15. package/dist/core/scheduler/scheduler.module.js +8 -0
  16. package/dist/core/scheduler/scheduler.module.js.map +1 -1
  17. package/dist/core/scheduler/scheduler.service.d.ts +12 -1
  18. package/dist/core/scheduler/scheduler.service.js +95 -2
  19. package/dist/core/scheduler/scheduler.service.js.map +1 -1
  20. package/dist/core/spa/spa.filter.d.ts +0 -3
  21. package/dist/core/spa/spa.filter.js +2 -22
  22. package/dist/core/spa/spa.filter.js.map +1 -1
  23. package/dist/globalDefaults.js +0 -3
  24. package/dist/globalDefaults.js.map +1 -1
  25. package/dist/main.js +6 -19
  26. package/dist/main.js.map +1 -1
  27. package/dist/modules/accessories/accessories.controller.d.ts +1 -1
  28. package/dist/modules/accessories/accessories.module.js +0 -2
  29. package/dist/modules/accessories/accessories.module.js.map +1 -1
  30. package/dist/modules/accessories/accessories.service.d.ts +3 -21
  31. package/dist/modules/accessories/accessories.service.js +17 -280
  32. package/dist/modules/accessories/accessories.service.js.map +1 -1
  33. package/dist/modules/child-bridges/child-bridges.interfaces.d.ts +0 -9
  34. package/dist/modules/config-editor/config-editor.controller.d.ts +5 -7
  35. package/dist/modules/config-editor/config-editor.controller.js +61 -59
  36. package/dist/modules/config-editor/config-editor.controller.js.map +1 -1
  37. package/dist/modules/config-editor/config-editor.dto.d.ts +6 -0
  38. package/dist/modules/config-editor/config-editor.dto.js +40 -0
  39. package/dist/modules/config-editor/config-editor.dto.js.map +1 -0
  40. package/dist/modules/config-editor/config-editor.service.d.ts +5 -7
  41. package/dist/modules/config-editor/config-editor.service.js +54 -49
  42. package/dist/modules/config-editor/config-editor.service.js.map +1 -1
  43. package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js +1 -1
  44. package/dist/modules/custom-plugins/plugins-settings-ui/plugins-settings-ui.service.js.map +1 -1
  45. package/dist/modules/plugins/plugins.controller.d.ts +5 -0
  46. package/dist/modules/plugins/plugins.controller.js +51 -2
  47. package/dist/modules/plugins/plugins.controller.js.map +1 -1
  48. package/dist/modules/plugins/plugins.module.js +4 -0
  49. package/dist/modules/plugins/plugins.module.js.map +1 -1
  50. package/dist/modules/plugins/plugins.service.d.ts +13 -2
  51. package/dist/modules/plugins/plugins.service.js +136 -17
  52. package/dist/modules/plugins/plugins.service.js.map +1 -1
  53. package/dist/modules/server/server.controller.d.ts +0 -50
  54. package/dist/modules/server/server.controller.js +2 -201
  55. package/dist/modules/server/server.controller.js.map +1 -1
  56. package/dist/modules/server/server.service.d.ts +0 -48
  57. package/dist/modules/server/server.service.js +31 -503
  58. package/dist/modules/server/server.service.js.map +1 -1
  59. package/dist/modules/status/status.gateway.d.ts +0 -2
  60. package/dist/modules/status/status.interfaces.d.ts +0 -11
  61. package/dist/modules/status/status.service.d.ts +1 -4
  62. package/dist/modules/status/status.service.js +2 -21
  63. package/dist/modules/status/status.service.js.map +1 -1
  64. package/package.json +15 -14
  65. package/public/assets/plugin-ui-utils/ui.js +0 -3
  66. package/public/assets/plugin-ui-utils/ui.js.map +1 -1
  67. package/public/{chunk-HZFYCQBZ.js → chunk-2ATI5RL3.js} +1 -1
  68. package/public/{chunk-HROBMVVC.js → chunk-3TGMHJM3.js} +1 -1
  69. package/public/{chunk-WFVVY4KI.js → chunk-4TYE7FOW.js} +1 -1
  70. package/public/{chunk-DWAKEAKY.js → chunk-5DT3N4NO.js} +1 -1
  71. package/public/{chunk-SEGYMPW4.js → chunk-5FAEMT7K.js} +1 -1
  72. package/public/chunk-6FMRO7HY.js +19 -0
  73. package/public/chunk-6WCXE37R.js +4 -0
  74. package/public/{chunk-EAENKK4C.js → chunk-726EPARV.js} +1 -1
  75. package/public/{chunk-2ZJDZ6SD.js → chunk-ABJURGQA.js} +1 -1
  76. package/public/{chunk-HIP2JJ4B.js → chunk-ALWUQZSW.js} +1 -1
  77. package/public/chunk-ASYRF2UP.js +1 -0
  78. package/public/{chunk-5KJA3LTW.js → chunk-AY5APEAK.js} +1 -1
  79. package/public/{chunk-ETDI4WB6.js → chunk-B57RMJ4J.js} +1 -1
  80. package/public/chunk-BDFSTR4R.js +1 -0
  81. package/public/{chunk-4VJCJCXJ.js → chunk-CKGQSHVZ.js} +1 -1
  82. package/public/{chunk-VINUD5O5.js → chunk-DMDEAXJH.js} +1 -1
  83. package/public/{chunk-WANJM2H4.js → chunk-DN72EAQ5.js} +1 -1
  84. package/public/{chunk-ARZPXRWQ.js → chunk-E3OCSFY5.js} +1 -1
  85. package/public/chunk-ERT4USI6.js +1 -0
  86. package/public/chunk-EZCJGSOY.js +5 -0
  87. package/public/{chunk-QIBWBWTA.js → chunk-FKIJIVEG.js} +1 -1
  88. package/public/{chunk-TCWES5JH.js → chunk-G4HQSJ23.js} +1 -1
  89. package/public/{chunk-R6KWC4OQ.js → chunk-GOWJQFU3.js} +1 -1
  90. package/public/{chunk-RGE5F7TI.js → chunk-H5WFRSS4.js} +1 -1
  91. package/public/chunk-HPLLPVW3.js +1 -0
  92. package/public/chunk-IHZHS7ZW.js +40 -0
  93. package/public/{chunk-ULCLDDZP.js → chunk-IJB6PBR5.js} +1 -1
  94. package/public/{chunk-S2KCQV5B.js → chunk-INEQMM2I.js} +1 -1
  95. package/public/chunk-IR2HMKD2.js +1 -0
  96. package/public/chunk-J3RGEHLW.js +1 -0
  97. package/public/chunk-JEESCTKG.js +16 -0
  98. package/public/{chunk-JXJXX7ID.js → chunk-LFWS6OUH.js} +1 -1
  99. package/public/chunk-LKJ4JJLK.js +1 -0
  100. package/public/{chunk-BEI5ZJFO.js → chunk-MGSFT332.js} +1 -1
  101. package/public/chunk-MJHLBHHD.js +1 -0
  102. package/public/{chunk-RUISJUO6.js → chunk-MK4QUOAX.js} +1 -1
  103. package/public/{chunk-BIKUQ7HD.js → chunk-N7EXU2NV.js} +1 -1
  104. package/public/{chunk-VLJKE3FE.js → chunk-OKTWUEQP.js} +1 -1
  105. package/public/{chunk-IJNJ3FHH.js → chunk-OQU6YMM6.js} +1 -1
  106. package/public/{chunk-6CALBO44.js → chunk-PBN5VTOU.js} +1 -1
  107. package/public/{chunk-GY4XWIFC.js → chunk-QDT36PQN.js} +1 -1
  108. package/public/{chunk-I24Z7SXB.js → chunk-QH66HEIY.js} +1 -1
  109. package/public/{chunk-6I4QMSKL.js → chunk-QONMKSXQ.js} +1 -1
  110. package/public/{chunk-MNT5ZGV3.js → chunk-RFQQSATI.js} +1 -1
  111. package/public/{chunk-GNXYAW2L.js → chunk-RUWA3EFR.js} +1 -1
  112. package/public/{chunk-VNH5MZV2.js → chunk-RV34PNIK.js} +1 -1
  113. package/public/{chunk-E5O5DRJC.js → chunk-RWL56OKC.js} +1 -1
  114. package/public/chunk-S2OEXAQE.js +1 -0
  115. package/public/{chunk-W4KA53M7.js → chunk-SAWH3ANN.js} +1 -1
  116. package/public/{chunk-DNZHARDF.js → chunk-SBHNM2QO.js} +1 -1
  117. package/public/{chunk-HRG6LQHN.js → chunk-SDSUBQRV.js} +1 -1
  118. package/public/{chunk-4D5P6BHP.js → chunk-SQWHIT2O.js} +1 -1
  119. package/public/{chunk-QETY3MXU.js → chunk-STKYISTF.js} +1 -1
  120. package/public/{chunk-H22EEHWT.js → chunk-TDRGDK3T.js} +1 -1
  121. package/public/{chunk-3LCQQJW4.js → chunk-TNZDCJJB.js} +1 -1
  122. package/public/chunk-TTFY54LY.js +1 -0
  123. package/public/chunk-TXPIYSRT.js +50 -0
  124. package/public/{chunk-2JNDNW24.js → chunk-UD5DX3PK.js} +1 -1
  125. package/public/{chunk-GQNXAXF5.js → chunk-UD7BEYXY.js} +1 -1
  126. package/public/{chunk-DO7GP4DT.js → chunk-UX77G732.js} +1 -1
  127. package/public/{chunk-RXMYAQOI.js → chunk-VLO3EC7G.js} +1 -1
  128. package/public/{chunk-MCXMRIGS.js → chunk-WGI4RZDV.js} +1 -1
  129. package/public/{chunk-YFMEPI62.js → chunk-WZOQNFMH.js} +1 -1
  130. package/public/chunk-X4UYQV4U.js +1 -0
  131. package/public/chunk-XDYNVDC3.js +1 -0
  132. package/public/{chunk-G5BHTUT2.js → chunk-XS5676NQ.js} +1 -1
  133. package/public/chunk-YHWOJFWU.js +1 -0
  134. package/public/{chunk-7K67C3PU.js → chunk-Z6SZHO36.js} +1 -1
  135. package/public/index.html +2 -2
  136. package/public/{main-6PZDJ4RZ.js → main-BIEDFTMT.js} +1 -1
  137. package/public/{styles-WNHDEKE4.css → styles-7EFV5QBG.css} +1 -1
  138. package/scripts/extract-plugin-alias.js +2 -53
  139. package/dist/core/spa/spa-html.service.d.ts +0 -5
  140. package/dist/core/spa/spa-html.service.js +0 -32
  141. package/dist/core/spa/spa-html.service.js.map +0 -1
  142. package/dist/core/ssl/ssl-cert-generator.service.d.ts +0 -15
  143. package/dist/core/ssl/ssl-cert-generator.service.js +0 -125
  144. package/dist/core/ssl/ssl-cert-generator.service.js.map +0 -1
  145. package/dist/modules/accessories/accessories.interfaces.d.ts +0 -94
  146. package/dist/modules/accessories/accessories.interfaces.js +0 -2
  147. package/dist/modules/accessories/accessories.interfaces.js.map +0 -1
  148. package/docs/ssl-upload-pr.md +0 -103
  149. package/public/assets/matter.svg +0 -8
  150. package/public/chunk-23KUWEO4.js +0 -1
  151. package/public/chunk-4TGFZOBX.js +0 -1
  152. package/public/chunk-4V523ITW.js +0 -1
  153. package/public/chunk-5ODRL5LA.js +0 -1
  154. package/public/chunk-CJHKCP34.js +0 -1
  155. package/public/chunk-CRWNCWLB.js +0 -4
  156. package/public/chunk-CWOQYOG4.js +0 -50
  157. package/public/chunk-DKMXUJA5.js +0 -1
  158. package/public/chunk-FW3AEHYC.js +0 -1
  159. package/public/chunk-IMMKC4PU.js +0 -52
  160. package/public/chunk-MSJEG33P.js +0 -1
  161. package/public/chunk-Q6MUJSJP.js +0 -1
  162. package/public/chunk-RERUZJD4.js +0 -5
  163. package/public/chunk-RLXU3LMU.js +0 -1
  164. package/public/chunk-SEF2HXUO.js +0 -16
  165. package/public/chunk-T4J24RHT.js +0 -1
  166. package/public/chunk-V3CWCNXE.js +0 -19
  167. package/public/chunk-VP7UJDZQ.js +0 -1
  168. package/public/chunk-XO27BOPF.js +0 -1
  169. 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, 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;
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.toUpperCase());
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
- const hapDevices = await Promise.all(devices.map(async (x) => {
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, protocol } of bridges) {
258
+ for (const { id } of bridges) {
369
259
  try {
370
- await this.deleteSingleDeviceAccessories(id, cachedAccessoriesDir, protocol || 'both');
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 HAP cached accessories...');
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(),