iobroker.eos-admin 9.0.34 → 9.0.35
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/NEXOWATT_EOS_BUILD_INFO.json +13 -10
- package/README.md +10 -4
- package/adminWww/.vite/manifest.json +39 -39
- package/adminWww/NEXOWATT_EOS_FRONTEND_MANIFEST.json +107 -107
- package/adminWww/assets/{AdapterUpdateDialog-5L75o18m.js → AdapterUpdateDialog-DH6S-kWX.js} +1 -1
- package/adminWww/assets/{Adapters-FcghjF7E.js → Adapters-CIlqSF5B.js} +1 -1
- package/adminWww/assets/{ConfigManager-BnHarBfH.js → ConfigManager-BhVBfM-q.js} +1 -1
- package/adminWww/assets/{Enums-BjLbLLQL.js → Enums-3H97czGs.js} +1 -1
- package/adminWww/assets/{Fields-DDE1hVOa.js → Fields-vWLKiuvO.js} +1 -1
- package/adminWww/assets/{Files-CDjnR4q6.js → Files-wmjjMXYM.js} +1 -1
- package/adminWww/assets/{Hosts-CJKQaNrD.js → Hosts-Bk-xmI98.js} +1 -1
- package/adminWww/assets/{Instances-DZNl369k.js → Instances-Db6Vgh62.js} +1 -1
- package/adminWww/assets/{Intro-CjAmMGDB.js → Intro-Dc3wAG9V.js} +1 -1
- package/adminWww/assets/{Logs-rUAV7SwM.js → Logs-CPbEGWNq.js} +1 -1
- package/adminWww/assets/{Objects-CqOH6rT_.js → Objects-DJB-2468.js} +1 -1
- package/adminWww/assets/{Overview-BOtXqsMy.js → Overview-DdvghCLQ.js} +1 -1
- package/adminWww/assets/{State-C8ncThop.js → State-0UzpgKYj.js} +1 -1
- package/adminWww/assets/{UsedResources-lUYJqy4F.js → UsedResources-Bcmo58YD.js} +1 -1
- package/adminWww/assets/{Users-CK1Cax82.js → Users-BGHf3Rox.js} +1 -1
- package/adminWww/assets/{bootstrap-CC0Qr-kr.js → bootstrap-qkrk_CAn.js} +3 -3
- package/adminWww/assets/{hostInit-DqGL6nY8.js → hostInit-DlGqatlv.js} +1 -1
- package/adminWww/assets/{icons-material-07rWS63O.js → icons-material-CUNq6tdT.js} +1 -1
- package/adminWww/assets/{index-BhhkToP2.js → index-BrtKq3UN.js} +2 -2
- package/adminWww/assets/{installSVGRenderer-B4-7lSQZ.js → installSVGRenderer-DujLjpXt.js} +1 -1
- package/adminWww/assets/{mf-entry-bootstrap-0-1afd2287.js → mf-entry-bootstrap-0-3e1cd85c.js} +2 -2
- package/adminWww/index.html +23 -23
- package/adminWww/mf-manifest.json +1 -1
- package/adminWww/mf-stats.json +1 -1
- package/adminWww/remoteEntry-eos-9.0.35.js +12 -0
- package/adminWww/remoteEntry.js +1 -1
- package/build/lib/eosDashboardProcessStatus.js +191 -0
- package/build/lib/eosDashboardProcessStatus.js.map +1 -0
- package/build/lib/eosKiosk.js +1 -0
- package/build/lib/eosKiosk.js.map +1 -1
- package/build/lib/eosModuleHost.js +17 -6
- package/build/lib/eosModuleHost.js.map +1 -1
- package/build/lib/eosModuleHttp.js +18 -3
- package/build/lib/eosModuleHttp.js.map +1 -1
- package/build/lib/eosModuleProcess.js +17 -0
- package/build/lib/eosModuleProcess.js.map +1 -1
- package/build/lib/eosModuleProcessWorker.js +22 -1
- package/build/lib/eosModuleProcessWorker.js.map +1 -1
- package/build/lib/eosRuntimeControl.js +6 -0
- package/build/lib/eosRuntimeControl.js.map +1 -1
- package/build/lib/eosRuntimeHealth.js +50 -1
- package/build/lib/eosRuntimeHealth.js.map +1 -1
- package/build/lib/eosSupervisorNotifications.js +169 -0
- package/build/lib/eosSupervisorNotifications.js.map +1 -0
- package/build/lib/eosUiProcess.js +1 -0
- package/build/lib/eosUiProcess.js.map +1 -1
- package/build/lib/web.js +5 -0
- package/build/lib/web.js.map +1 -1
- package/docs/README.md +1 -0
- package/docs/reports/unified-9.0.35/PRUEFBERICHT.md +51 -0
- package/docs/reports/unified-9.0.35/PRUEFERGEBNISSE.json +112 -0
- package/docs/reports/unified-9.0.35/raw/INDEX.json +282 -0
- package/docs/reports/unified-9.0.35/raw/backend.log +5 -0
- package/docs/reports/unified-9.0.35/raw/browser-lp-detail.log +1 -0
- package/docs/reports/unified-9.0.35/raw/browser-lp-feedback.log +1 -0
- package/docs/reports/unified-9.0.35/raw/cold-ocpp-22.log +108 -0
- package/docs/reports/unified-9.0.35/raw/cold-ocpp-24.log +24 -0
- package/docs/reports/unified-9.0.35/raw/core-final-node22.log +1439 -0
- package/docs/reports/unified-9.0.35/raw/core-final-node24.log +1381 -0
- package/docs/reports/unified-9.0.35/raw/dashboard-de-en-nl.json +716 -0
- package/docs/reports/unified-9.0.35/raw/device-chain-closed-fixed.json +98 -0
- package/docs/reports/unified-9.0.35/raw/device-chain-rst-fixed.json +98 -0
- package/docs/reports/unified-9.0.35/raw/device-chain.json +93 -0
- package/docs/reports/unified-9.0.35/raw/ee-fusion-final.log +12 -0
- package/docs/reports/unified-9.0.35/raw/eebus-monitor-browser.json +1 -0
- package/docs/reports/unified-9.0.35/raw/eebus-monitor-node22.log +206 -0
- package/docs/reports/unified-9.0.35/raw/eebus-monitor-node24.log +39 -0
- package/docs/reports/unified-9.0.35/raw/fixtures-verification.log +44 -0
- package/docs/reports/unified-9.0.35/raw/frontend.log +152 -0
- package/docs/reports/unified-9.0.35/raw/installer.log +26 -0
- package/docs/reports/unified-9.0.35/raw/legacy-mail-setup-browser.log +1 -0
- package/docs/reports/unified-9.0.35/raw/lint.log +45 -0
- package/docs/reports/unified-9.0.35/raw/live-ems-loss.log +10 -0
- package/docs/reports/unified-9.0.35/raw/modules.log +5 -0
- package/docs/reports/unified-9.0.35/raw/node22-mira-reconnect-integrity.log +452 -0
- package/docs/reports/unified-9.0.35/raw/node22-mira.log +222 -0
- package/docs/reports/unified-9.0.35/raw/node22-system-status.log +213 -0
- package/docs/reports/unified-9.0.35/raw/node22-tests-final.log +18137 -0
- package/docs/reports/unified-9.0.35/raw/node22-version.log +1 -0
- package/docs/reports/unified-9.0.35/raw/node24-mira-reconnect-integrity.log +79 -0
- package/docs/reports/unified-9.0.35/raw/node24-mira.log +41 -0
- package/docs/reports/unified-9.0.35/raw/node24-system-status.log +40 -0
- package/docs/reports/unified-9.0.35/raw/node24-tests-final.log +3019 -0
- package/docs/reports/unified-9.0.35/raw/node24-version.log +1 -0
- package/docs/reports/unified-9.0.35/raw/notifications-legacy-node22.log +1 -0
- package/docs/reports/unified-9.0.35/raw/notifications-legacy-node24.log +1 -0
- package/docs/reports/unified-9.0.35/raw/notifications-node22.log +67 -0
- package/docs/reports/unified-9.0.35/raw/notifications-node24.log +17 -0
- package/docs/reports/unified-9.0.35/raw/npm-runtime-audit.json +77 -0
- package/docs/reports/unified-9.0.35/raw/ocpp-dashboard-stations-node22.log +110 -0
- package/docs/reports/unified-9.0.35/raw/ocpp-dashboard-stations-node24.log +106 -0
- package/docs/reports/unified-9.0.35/raw/ocpp-history-node22.log +561 -0
- package/docs/reports/unified-9.0.35/raw/ocpp-history-node24.log +98 -0
- package/docs/reports/unified-9.0.35/raw/poll-life-node22.log +38 -0
- package/docs/reports/unified-9.0.35/raw/poll-life-node24.log +12 -0
- package/docs/reports/unified-9.0.35/raw/qa-source-check.log +2 -0
- package/docs/reports/unified-9.0.35/raw/release-metadata.log +13 -0
- package/docs/reports/unified-9.0.35/raw/sbom.log +8 -0
- package/docs/reports/unified-9.0.35/raw/typecheck.log +5 -0
- package/docs/reports/unified-9.0.35/raw/ui-runtime.log +8 -0
- package/docs/reports/unified-9.0.35/raw/vergleich-9.0.33.json +29 -0
- package/docs/reports/unified-9.0.35/raw/vergleich-9.0.34.json +249 -0
- package/docs/reports/unified-9.0.35/raw/vorher-9.0.33-chromium.json +286 -0
- package/docs/reports/unified-9.0.35/raw/vorher-9.0.34-chromium.json +291 -0
- package/docs/start/START_HIER_9.0.35.md +27 -0
- package/io-package.json +8 -8
- package/modules/devices/contracts.d.ts +1 -0
- package/modules/devices/index.js +20 -1
- package/modules/devices/lib/deviceRuntime.js +19 -0
- package/modules/devices/lib/drivers/modbus.js +11 -6
- package/modules/devices/lib/drivers/ovumMira.js +7 -3
- package/modules/devices/test/ovumMiraTransport.test.js +40 -1
- package/modules/eebus/README.md +8 -0
- package/modules/eebus/admin/index.js +29 -2
- package/modules/eebus/build/index.js +28 -3
- package/modules/eebus/build/lib/eebusRuntime.js +17 -2
- package/modules/eebus/build/lib/partnerMonitor.js +160 -0
- package/modules/eebus/build/lib/shipEndpoint.js +4 -0
- package/modules/eebus/build/lib/stateDefinitions.js +1 -0
- package/modules/eebus/src/index.ts +23 -3
- package/modules/eebus/src/lib/eebusRuntime.ts +20 -2
- package/modules/eebus/src/lib/partnerMonitor.ts +127 -0
- package/modules/eebus/src/lib/shipEndpoint.ts +5 -0
- package/modules/eebus/src/lib/stateDefinitions.ts +1 -0
- package/modules/eebus/test/partner-monitor.test.js +82 -0
- package/modules/eebus/test/security.test.js +17 -0
- package/modules/ocpp/README.md +9 -1
- package/modules/ocpp/build/index.js +137 -10
- package/modules/ocpp/build/stationHistory.js +113 -0
- package/modules/ocpp/ocpp/freshness.d.ts +3 -0
- package/modules/ocpp/ocpp/freshness.js +6 -0
- package/modules/ocpp/provenance.json +3 -2
- package/modules/ocpp/runtime.d.ts +1 -0
- package/modules/ocpp/runtime.js +23 -1
- package/modules/ocpp/src/index.ts +163 -12
- package/modules/ocpp/src/stationHistory.ts +119 -0
- package/modules/ocpp/test/hosted.test.cjs +161 -0
- package/package.json +7 -5
- package/release-manifests/unified/build-environment.cdx.json +6 -6
- package/release-manifests/unified/files.json +220 -140
- package/release-manifests/unified/frontend.cdx.json +6 -6
- package/release-manifests/unified/installer.cdx.json +6 -6
- package/release-manifests/unified/obsolete-admin-assets.json +83 -0
- package/release-manifests/unified/runtime.cdx.json +30 -30
- package/release-manifests/unified/validation.json +15 -15
- package/tools/eos-release-manifest.cjs +1 -1
- package/ui/io-package.json +5 -1
- package/ui/lib/notification-mail.js +235 -40
- package/ui/lib/notification-policy.js +41 -14
- package/ui/package.json +2 -1
- package/ui/www/app.js +91 -11
- package/ui/www/dashboard-lp-status.js +4 -11
- package/ui/www/dashboard-process-status.js +202 -0
- package/ui/www/i18n/en.json +23 -0
- package/ui/www/i18n/nl.json +20 -0
- package/ui/www/index.html +10 -5
- package/ui/www/live-display.js +101 -9
- package/ui/www/manifest.webmanifest +2 -2
- package/ui/www/settings.html +2 -2
- package/ui/www/styles.css +4 -0
- package/adminWww/remoteEntry-eos-9.0.34.js +0 -12
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/** @param {string} id @returns {HTMLInputElement} */
|
|
8
8
|
const inputElement = id => { const found = element(id); if (!(found instanceof HTMLInputElement)) throw new Error('EEBUS_UI_INPUT'); return found; };
|
|
9
9
|
/** @typedef {[string, string, 'checkbox'|'number'|'text'|'password', boolean|number|string, number?, number?]} Field */
|
|
10
|
-
/** @typedef {{id:string,name:string,ski:string,fingerprint:string,trusted:boolean,state:string}} Device */
|
|
10
|
+
/** @typedef {{id:string,name:string,ski:string,fingerprint:string,trusted:boolean,state:string,canMonitor:boolean,monitorPaused:boolean,monitorName:string}} Device */
|
|
11
11
|
/** @typedef {{running:boolean,shipPort:number|undefined,commandDryRun:boolean,localSki:string,certificateFingerprint:string,devices:Device[]}} Details */
|
|
12
12
|
/** @typedef {{csrfToken?:string,configurationRevision?:string,config:Record<string,unknown>,status:{reason:string,state:string,details:Details}}} ApiData */
|
|
13
13
|
/** @param {unknown} value @returns {value is Record<string,unknown>} */
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
const data = record(status.details) ? status.details : status;
|
|
22
22
|
const devices = (Array.isArray(data.devices) ? data.devices.slice(0, 128) : []).filter(record).map(device => ({
|
|
23
23
|
id: String(device.id || ''), name: String(device.name || ''), ski: String(device.ski || ''),
|
|
24
|
-
fingerprint: String(device.fingerprint || ''), trusted: device.trusted === true, state: String(device.state || '')
|
|
24
|
+
fingerprint: String(device.fingerprint || ''), trusted: device.trusted === true, state: String(device.state || ''),
|
|
25
|
+
canMonitor: device.canMonitor === true, monitorPaused: device.monitorPaused === true, monitorName: String(device.monitorName || '') }));
|
|
25
26
|
return { csrfToken: typeof raw.csrfToken === 'string' ? raw.csrfToken : undefined,
|
|
26
27
|
configurationRevision: typeof raw.configurationRevision === 'string' ? raw.configurationRevision : undefined,
|
|
27
28
|
config: record(raw.config) ? raw.config : {}, status: { reason: String(status.reason || ''), state: String(status.state || ''),
|
|
@@ -138,6 +139,32 @@
|
|
|
138
139
|
await render(); message('Geräteaktion verarbeitet.');
|
|
139
140
|
})); card.append(button);
|
|
140
141
|
}
|
|
142
|
+
const monitor = document.createElement('fieldset');
|
|
143
|
+
const legend = document.createElement('legend'); legend.textContent = 'Dauerhafte Verbindungsüberwachung'; monitor.append(legend);
|
|
144
|
+
const monitorState = document.createElement('p');
|
|
145
|
+
monitorState.textContent = device.monitorName
|
|
146
|
+
? (device.monitorPaused ? 'Überwachung pausiert. Nach dem Verbinden hier erneut aktivieren.' : 'Aktiv · ' + device.monitorName)
|
|
147
|
+
: 'Aus. Die Überwachung kann nach erfolgreichem, freigegebenem SHIP-Datenaustausch aktiviert werden.';
|
|
148
|
+
monitor.append(monitorState);
|
|
149
|
+
const label = document.createElement('label'); label.textContent = 'Anzeigename in Dashboard und Benachrichtigungen ';
|
|
150
|
+
const displayName = document.createElement('input'); displayName.type = 'text'; displayName.maxLength = 64;
|
|
151
|
+
displayName.value = device.monitorName; displayName.placeholder = 'z. B. Wärmepumpe West'; label.append(displayName); monitor.append(label);
|
|
152
|
+
const apply = document.createElement('button'); apply.type = 'button';
|
|
153
|
+
apply.disabled = !details.running || !device.canMonitor || !device.trusted;
|
|
154
|
+
apply.textContent = !device.monitorName || device.monitorPaused ? 'Überwachung aktivieren' : 'Anzeigenamen speichern';
|
|
155
|
+
apply.addEventListener('click', () => operation(async () => {
|
|
156
|
+
const name = displayName.value.trim(); if (!name) throw new Error('Bitte einen lokalen Anzeigenamen eingeben.');
|
|
157
|
+
await request('/command','POST',{command:'device.monitor',payload:{deviceId:device.id,enabled:true,name}});
|
|
158
|
+
await render(); message('Überwachung gespeichert.');
|
|
159
|
+
})); monitor.append(apply);
|
|
160
|
+
if (device.monitorName) {
|
|
161
|
+
const clear = document.createElement('button'); clear.type = 'button'; clear.textContent = 'Überwachung entfernen'; clear.disabled = !details.running;
|
|
162
|
+
clear.addEventListener('click', () => operation(async () => {
|
|
163
|
+
await request('/command','POST',{command:'device.monitor',payload:{deviceId:device.id,enabled:false}});
|
|
164
|
+
await render(); message('Überwachung entfernt.');
|
|
165
|
+
})); monitor.append(clear);
|
|
166
|
+
}
|
|
167
|
+
card.append(monitor);
|
|
141
168
|
list.append(card);
|
|
142
169
|
}
|
|
143
170
|
}
|
|
@@ -5,6 +5,7 @@ exports.validateConfig = validateConfig;
|
|
|
5
5
|
exports.migrateLegacyConfig = migrateLegacyConfig;
|
|
6
6
|
exports.preflightLegacyConfig = preflightLegacyConfig;
|
|
7
7
|
exports.createHostedModule = createHostedModule;
|
|
8
|
+
const partnerMonitor_1 = require("./lib/partnerMonitor");
|
|
8
9
|
const config_1 = require("./lib/config");
|
|
9
10
|
const eebusRuntime_1 = require("./lib/eebusRuntime");
|
|
10
11
|
const identityManager_1 = require("./lib/identityManager");
|
|
@@ -159,15 +160,25 @@ function createHostedModule(options) {
|
|
|
159
160
|
async command(name, payload) {
|
|
160
161
|
if (!running || !runtime || stopping || !options.canOperate())
|
|
161
162
|
throw new Error('EEBUS_NOT_RUNNING');
|
|
162
|
-
if (!actions
|
|
163
|
+
if ((!Object.hasOwn(actions, name) && name !== 'device.monitor') || !payload || typeof payload !== 'object' || Array.isArray(payload))
|
|
163
164
|
throw new Error('EEBUS_COMMAND_INVALID');
|
|
164
165
|
const deviceId = payload.deviceId;
|
|
165
|
-
if (typeof deviceId !== 'string' || !/^[A-Fa-f0-9]{40}$/.test(deviceId)
|
|
166
|
+
if (typeof deviceId !== 'string' || !/^[A-Fa-f0-9]{40}$/.test(deviceId))
|
|
167
|
+
throw new Error('EEBUS_DEVICE_UNKNOWN');
|
|
168
|
+
const observed = runtime.getNodes().some(node => node.safeId === deviceId);
|
|
169
|
+
if (!observed && !(name === 'device.monitor' && runtime.partnerMonitor.list().some(peer => peer.id === deviceId)))
|
|
166
170
|
throw new Error('EEBUS_DEVICE_UNKNOWN');
|
|
167
171
|
if (inFlight >= 16)
|
|
168
172
|
throw new Error('EEBUS_COMMAND_BUSY');
|
|
169
173
|
inFlight++;
|
|
170
174
|
try {
|
|
175
|
+
if (name === 'device.monitor') {
|
|
176
|
+
const data = payload;
|
|
177
|
+
if (typeof data.enabled !== 'boolean')
|
|
178
|
+
throw new Error('EEBUS_COMMAND_INVALID');
|
|
179
|
+
await runtime.partnerMonitor.configure(deviceId, data.name, data.enabled);
|
|
180
|
+
return { accepted: options.canOperate() && !stopping };
|
|
181
|
+
}
|
|
171
182
|
await runtime.handleStateChange(`${adapter.namespace}.devices.${deviceId}.${actions[name]}`, { val: true, ack: false, ts: Date.now(), lc: Date.now(), from: adapter.namespace });
|
|
172
183
|
return { accepted: options.canOperate() && !stopping };
|
|
173
184
|
}
|
|
@@ -175,7 +186,13 @@ function createHostedModule(options) {
|
|
|
175
186
|
inFlight--;
|
|
176
187
|
}
|
|
177
188
|
},
|
|
189
|
+
getDashboardDeviceHealth() {
|
|
190
|
+
if (!running || stopping || !runtime || !options.canOperate())
|
|
191
|
+
return (0, partnerMonitor_1.emptyReport)(selected.enabled === false);
|
|
192
|
+
return runtime.partnerMonitor.report();
|
|
193
|
+
},
|
|
178
194
|
async getStatus() {
|
|
195
|
+
const monitored = new Map((runtime?.partnerMonitor.list() || []).map(p => [p.id, p]));
|
|
179
196
|
const nodes = runtime?.getNodes() || [];
|
|
180
197
|
const devices = [];
|
|
181
198
|
for (const node of nodes.slice(0, 128)) {
|
|
@@ -184,9 +201,17 @@ function createHostedModule(options) {
|
|
|
184
201
|
adapter.getStateAsync(`devices.${node.safeId}.connection.shipState`),
|
|
185
202
|
adapter.getStateAsync(`devices.${node.safeId}.pairing.remoteFingerprint`),
|
|
186
203
|
]);
|
|
187
|
-
|
|
204
|
+
const entry = monitored.get(node.safeId);
|
|
205
|
+
monitored.delete(node.safeId);
|
|
206
|
+
devices.push({ monitorName: entry?.name || '', monitorPaused: entry?.paused === true, canMonitor: runtime?.canMonitorPartner(node.safeId) === true,
|
|
207
|
+
id: node.safeId, name: node.name.slice(0, 128), ski: node.ski, fingerprint: String(fingerprint?.val || ''),
|
|
188
208
|
trusted: trust?.val === true, connected: connection?.val === 'data-exchange', state: String(connection?.val || 'discovered') });
|
|
189
209
|
}
|
|
210
|
+
// A monitored peer can be removed here even before it advertises after a restart.
|
|
211
|
+
for (const entry of monitored.values())
|
|
212
|
+
devices.push({ id: entry.id, name: entry.name, ski: entry.id, fingerprint: '',
|
|
213
|
+
trusted: false, connected: false, state: 'Nicht verbunden', monitorName: entry.name, monitorPaused: entry.paused, canMonitor: false });
|
|
214
|
+
devices.sort((a, b) => Number(!!b.monitorName) - Number(!!a.monitorName));
|
|
190
215
|
return { running, localSki: identity?.localSki || '', certificateFingerprint: identity?.certificateFingerprint || '',
|
|
191
216
|
shipPort: config.shipPort, commandDryRun: config.commandDryRun, devices };
|
|
192
217
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EebusRuntime = void 0;
|
|
4
|
+
const partnerMonitor_1 = require("./partnerMonitor");
|
|
4
5
|
const discoveryService_1 = require("./discoveryService");
|
|
5
6
|
const shipEndpoint_1 = require("./shipEndpoint");
|
|
6
7
|
const spineParser_1 = require("./spineParser");
|
|
@@ -14,6 +15,7 @@ class EebusRuntime {
|
|
|
14
15
|
config;
|
|
15
16
|
identity;
|
|
16
17
|
objectFactory;
|
|
18
|
+
partnerMonitor;
|
|
17
19
|
nodes = new Map();
|
|
18
20
|
discovery;
|
|
19
21
|
endpoint;
|
|
@@ -34,9 +36,11 @@ class EebusRuntime {
|
|
|
34
36
|
this.identity = identity;
|
|
35
37
|
this.objectFactory = objectFactory;
|
|
36
38
|
this.autoAcceptNewDevices = config.autoAcceptNewDevices;
|
|
39
|
+
this.partnerMonitor = new partnerMonitor_1.PartnerMonitor(adapter, id => this.canMonitorPartner(id));
|
|
37
40
|
}
|
|
38
41
|
async start() {
|
|
39
42
|
this.stopping = false;
|
|
43
|
+
await this.partnerMonitor.load();
|
|
40
44
|
this.endpoint = new shipEndpoint_1.ShipEndpoint(this.adapter, { ...this.config, autoAcceptNewDevices: this.autoAcceptNewDevices }, this.identity, async (deviceId, message) => this.handleIncomingMessage(deviceId, message), async (node) => this.handleDiscoveredNode(node), async (deviceId, state, role, connected, error) => this.handleConnectionState(deviceId, state, role, connected, error), async (deviceId) => this.handleDataExchangeReady(deviceId), async (deviceId, request) => this.handlePairingRequest(deviceId, request), async (deviceId) => this.isTrusted(deviceId));
|
|
41
45
|
const endpointStarted = await this.endpoint.start();
|
|
42
46
|
if (this.config.shipServerEnabled && !endpointStarted)
|
|
@@ -108,11 +112,14 @@ class EebusRuntime {
|
|
|
108
112
|
async handleStateChange(id, state) {
|
|
109
113
|
if (id.endsWith('.pairing.trusted') || id.endsWith('.pairing.pinnedFingerprint')) {
|
|
110
114
|
const match = id.match(/devices\.([^.]+)\.pairing\./);
|
|
111
|
-
if (match && id.endsWith('.pinnedFingerprint'))
|
|
115
|
+
if (match && id.endsWith('.pinnedFingerprint')) {
|
|
112
116
|
this.endpoint?.invalidateCertificate(match[1], state?.val);
|
|
117
|
+
await this.partnerMonitor.pinChanged(match[1], state?.val);
|
|
118
|
+
}
|
|
113
119
|
if (match && (!state || (id.endsWith('.trusted') && state.val !== true))) {
|
|
114
120
|
this.trustCache.delete(match[1]);
|
|
115
121
|
this.endpoint?.disconnect(match[1]);
|
|
122
|
+
await this.partnerMonitor.pause(match[1]);
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
if (!state || state.ack || this.stopping || this.adapter.canOperate?.() === false)
|
|
@@ -134,8 +141,11 @@ class EebusRuntime {
|
|
|
134
141
|
return;
|
|
135
142
|
}
|
|
136
143
|
if (command.channel === 'control' && command.stateName === 'disconnect') {
|
|
137
|
-
if (Boolean(command.value))
|
|
144
|
+
if (Boolean(command.value)) {
|
|
145
|
+
const paused = this.partnerMonitor.pause(command.deviceId);
|
|
138
146
|
this.endpoint?.disconnect(command.deviceId);
|
|
147
|
+
await paused;
|
|
148
|
+
}
|
|
139
149
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.control.disconnect`, { val: false, ack: true });
|
|
140
150
|
return;
|
|
141
151
|
}
|
|
@@ -166,6 +176,7 @@ class EebusRuntime {
|
|
|
166
176
|
}
|
|
167
177
|
else {
|
|
168
178
|
this.endpoint?.rejectDevice(command.deviceId);
|
|
179
|
+
await this.partnerMonitor.pause(command.deviceId);
|
|
169
180
|
}
|
|
170
181
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.pairing.approve`, { val: false, ack: true });
|
|
171
182
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.pairing.reject`, { val: false, ack: true });
|
|
@@ -238,6 +249,7 @@ class EebusRuntime {
|
|
|
238
249
|
await this.objectFactory.publishGlobalPairingCounts(Array.from(this.nodes.keys()));
|
|
239
250
|
}
|
|
240
251
|
async handleDataExchangeReady(deviceId) {
|
|
252
|
+
this.partnerMonitor.observed(deviceId);
|
|
241
253
|
// Prime the trust decision before the first time-critical CLS write arrives.
|
|
242
254
|
// The control path can then use the in-memory cache without an object DB read.
|
|
243
255
|
if (!this.trustCache.has(deviceId)) {
|
|
@@ -840,6 +852,9 @@ class EebusRuntime {
|
|
|
840
852
|
},
|
|
841
853
|
};
|
|
842
854
|
}
|
|
855
|
+
canMonitorPartner(id) {
|
|
856
|
+
return !this.stopping && this.adapter.canOperate?.() !== false && this.endpoint?.hasAuthorizedExchange(id) === true;
|
|
857
|
+
}
|
|
843
858
|
getNodes() { return Array.from(this.nodes.values()).map(node => ({ ...node })); }
|
|
844
859
|
periodic(key, work) {
|
|
845
860
|
if (this.stopping || this.busy.has(key))
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartnerMonitor = void 0;
|
|
4
|
+
exports.emptyReport = emptyReport;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const objectId = 'pairing.monitoredPartners';
|
|
7
|
+
const startupGraceMs = 120_000;
|
|
8
|
+
const pinValue = (v) => typeof v === 'string' && /^[a-f0-9]{64}$/i.test(v.replace(/:/g, '')) ? v.replace(/:/g, '').toUpperCase() : '';
|
|
9
|
+
function friendlyName(value) {
|
|
10
|
+
return typeof value === 'string' && value === value.trim() && value.length <= 64 &&
|
|
11
|
+
/\p{L}/u.test(value) && /^[\p{L}\p{M}\p{N} _()-]+$/u.test(value) &&
|
|
12
|
+
!/[a-f\d]{16,}|(?:[a-f\d]{2}-){5}[a-f\d]{2}/i.test(value) && !/\d{9,}/.test(value);
|
|
13
|
+
}
|
|
14
|
+
const safeId = (v) => typeof v === 'string' && /^[a-f\d]{40}$/i.test(v);
|
|
15
|
+
const key = (id) => (0, node_crypto_1.createHash)('sha256').update('eebus:' + id.toLowerCase()).digest('hex');
|
|
16
|
+
function emptyReport(known) {
|
|
17
|
+
return { state: known ? 'ok' : 'unknown', offline: [], totalOffline: 0,
|
|
18
|
+
tracked: [], complete: known };
|
|
19
|
+
}
|
|
20
|
+
/** Names are local installer input. Discovery metadata, peer addresses and certificates never feed the customer report. */
|
|
21
|
+
class PartnerMonitor {
|
|
22
|
+
store;
|
|
23
|
+
live;
|
|
24
|
+
now;
|
|
25
|
+
partners = new Map();
|
|
26
|
+
confirmed = new Set();
|
|
27
|
+
suppressed = new Set();
|
|
28
|
+
known = false;
|
|
29
|
+
startedAt = 0;
|
|
30
|
+
pending = Promise.resolve();
|
|
31
|
+
constructor(store, live, now = () => performance.now()) {
|
|
32
|
+
this.store = store;
|
|
33
|
+
this.live = live;
|
|
34
|
+
this.now = now;
|
|
35
|
+
}
|
|
36
|
+
async load() {
|
|
37
|
+
this.startedAt = this.now();
|
|
38
|
+
try {
|
|
39
|
+
const state = await this.store.getStateAsync(objectId);
|
|
40
|
+
if (state?.ack === false)
|
|
41
|
+
throw Error();
|
|
42
|
+
const rows = state?.val == null ? [] : JSON.parse(String(state.val));
|
|
43
|
+
if (!Array.isArray(rows) || rows.length > 128)
|
|
44
|
+
throw Error();
|
|
45
|
+
const restored = new Map();
|
|
46
|
+
for (const item of rows) {
|
|
47
|
+
if (!item || !safeId(item.id) || !friendlyName(item.name) || !pinValue(item.pin) || typeof item.paused !== 'boolean' || restored.has(item.id))
|
|
48
|
+
throw Error();
|
|
49
|
+
const row = { id: item.id.toUpperCase(), key: key(item.id), name: item.name, pin: pinValue(item.pin), paused: item.paused };
|
|
50
|
+
if (restored.has(row.id))
|
|
51
|
+
throw Error();
|
|
52
|
+
restored.set(row.id, row);
|
|
53
|
+
}
|
|
54
|
+
// Verify locally approved pairing on restart even when the peer is currently absent.
|
|
55
|
+
const monitored = Array.from(restored.values()).filter(row => !row.paused);
|
|
56
|
+
let changed = false;
|
|
57
|
+
for (let start = 0; start < monitored.length; start += 8) {
|
|
58
|
+
await Promise.all(monitored.slice(start, start + 8).map(async (row) => {
|
|
59
|
+
if (await this.trustedPin(row.id) !== row.pin) {
|
|
60
|
+
row.paused = true;
|
|
61
|
+
changed = true;
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
if (changed)
|
|
66
|
+
await this.save(restored);
|
|
67
|
+
else
|
|
68
|
+
this.partners = restored;
|
|
69
|
+
this.known = true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
this.known = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async trustedPin(id) {
|
|
76
|
+
const [trust, pin] = await Promise.all(['trusted', 'pinnedFingerprint'].map(field => this.store.getStateAsync('devices.' + id + '.pairing.' + field)));
|
|
77
|
+
return trust?.val === true && trust.ack !== false && pin?.ack !== false ? pinValue(pin?.val) : '';
|
|
78
|
+
}
|
|
79
|
+
change(write) {
|
|
80
|
+
const op = this.pending.then(write);
|
|
81
|
+
this.pending = op.catch(() => { });
|
|
82
|
+
return op;
|
|
83
|
+
}
|
|
84
|
+
async save(next) {
|
|
85
|
+
await this.store.setStateAsync(objectId, { val: JSON.stringify(Array.from(next.values(), ({ id, name, pin, paused }) => ({ id, name, pin, paused }))), ack: true });
|
|
86
|
+
this.partners = next;
|
|
87
|
+
}
|
|
88
|
+
async configure(id, name, enabled) {
|
|
89
|
+
if (!safeId(id))
|
|
90
|
+
throw new Error('EEBUS_MONITOR_DEVICE');
|
|
91
|
+
id = id.toUpperCase();
|
|
92
|
+
return this.change(async () => {
|
|
93
|
+
if (!this.known)
|
|
94
|
+
throw new Error('EEBUS_MONITOR_STORAGE_UNAVAILABLE');
|
|
95
|
+
const next = new Map(this.partners);
|
|
96
|
+
if (enabled) {
|
|
97
|
+
if (!friendlyName(name))
|
|
98
|
+
throw new Error('EEBUS_MONITOR_LOCAL_NAME');
|
|
99
|
+
const pin = this.live(id) ? await this.trustedPin(id) : '';
|
|
100
|
+
if (!pin || !this.live(id))
|
|
101
|
+
throw new Error('EEBUS_MONITOR_PAIRED_SESSION_REQUIRED');
|
|
102
|
+
if (!next.has(id) && next.size >= 128)
|
|
103
|
+
throw new Error('EEBUS_MONITOR_CAPACITY');
|
|
104
|
+
next.set(id, { id, key: key(id), name, pin, paused: false });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
next.delete(id);
|
|
108
|
+
}
|
|
109
|
+
await this.save(next);
|
|
110
|
+
if (enabled)
|
|
111
|
+
this.confirmed.add(id);
|
|
112
|
+
else
|
|
113
|
+
this.confirmed.delete(id);
|
|
114
|
+
this.suppressed.delete(id);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
pinChanged(id, value) {
|
|
118
|
+
const row = this.partners.get(id.toUpperCase());
|
|
119
|
+
return row && !row.paused && row.pin !== pinValue(value) ? this.pause(id) : Promise.resolve();
|
|
120
|
+
}
|
|
121
|
+
pause(id) {
|
|
122
|
+
id = id.toUpperCase();
|
|
123
|
+
this.suppressed.add(id);
|
|
124
|
+
return this.change(async () => {
|
|
125
|
+
const row = this.partners.get(id);
|
|
126
|
+
if (row && !row.paused) {
|
|
127
|
+
const next = new Map(this.partners);
|
|
128
|
+
next.set(id, { ...row, paused: true });
|
|
129
|
+
await this.save(next);
|
|
130
|
+
}
|
|
131
|
+
this.suppressed.delete(id);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
observed(id) { if (this.partners.has(id.toUpperCase()) && this.live(id))
|
|
135
|
+
this.confirmed.add(id.toUpperCase()); }
|
|
136
|
+
list() { return Array.from(this.partners.values(), ({ id, name, paused }) => ({ id, name, paused })); }
|
|
137
|
+
report() {
|
|
138
|
+
const report = emptyReport(this.known);
|
|
139
|
+
if (!this.known)
|
|
140
|
+
return report;
|
|
141
|
+
for (const row of this.partners.values()) {
|
|
142
|
+
const active = this.live(row.id);
|
|
143
|
+
const state = row.paused || this.suppressed.has(row.id) ? 'disabled' : active ? 'online' :
|
|
144
|
+
this.confirmed.has(row.id) || this.now() - this.startedAt >= startupGraceMs ? 'offline' : 'unknown';
|
|
145
|
+
if (state === 'online')
|
|
146
|
+
this.confirmed.add(row.id);
|
|
147
|
+
report.tracked.push({ key: row.key, name: row.name, state });
|
|
148
|
+
if (state === 'unknown' && report.state === 'ok')
|
|
149
|
+
report.state = 'unknown';
|
|
150
|
+
if (state === 'offline') {
|
|
151
|
+
report.state = 'fault';
|
|
152
|
+
report.totalOffline++;
|
|
153
|
+
if (report.offline.length < 12)
|
|
154
|
+
report.offline.push({ name: row.name });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return report;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.PartnerMonitor = PartnerMonitor;
|
|
@@ -211,6 +211,10 @@ class ShipEndpoint {
|
|
|
211
211
|
if (session && fingerprint !== session.remoteFingerprint)
|
|
212
212
|
this.disconnect(deviceId);
|
|
213
213
|
}
|
|
214
|
+
hasAuthorizedExchange(deviceId) {
|
|
215
|
+
const peer = this.sessions.get(deviceId);
|
|
216
|
+
return !!peer?.authorized && peer.dataExchangeReady && this.isSocketOpen(peer.socket) && !this.stopping;
|
|
217
|
+
}
|
|
214
218
|
hasObservedPeer(deviceId) {
|
|
215
219
|
const session = this.sessions.get(deviceId);
|
|
216
220
|
return !!session?.remoteFingerprint && this.isSocketOpen(session.socket);
|
|
@@ -27,6 +27,7 @@ exports.discoveryStates = [
|
|
|
27
27
|
{ id: 'lastDiscovery', name: 'Last discovery event', type: 'string', role: 'json', read: true, write: false },
|
|
28
28
|
];
|
|
29
29
|
exports.globalPairingStates = [
|
|
30
|
+
{ id: 'monitoredPartners', name: 'Installer-configured EEBus partner supervision', type: 'string', role: 'json', read: true, write: false, def: '[]' },
|
|
30
31
|
{
|
|
31
32
|
id: 'autoAcceptNewDevices',
|
|
32
33
|
name: 'Auto accept new devices for field testing',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { emptyReport } from './lib/partnerMonitor';
|
|
1
2
|
import { EebusConfig, getConfig } from './lib/config';
|
|
2
3
|
import { EebusRuntime } from './lib/eebusRuntime';
|
|
3
4
|
import { IdentityManager } from './lib/identityManager';
|
|
@@ -130,17 +131,30 @@ export function createHostedModule(options: Options) {
|
|
|
130
131
|
},
|
|
131
132
|
async command(name: string, payload: unknown): Promise<{ accepted: boolean }> {
|
|
132
133
|
if (!running || !runtime || stopping || !options.canOperate()) throw new Error('EEBUS_NOT_RUNNING');
|
|
133
|
-
if (!actions
|
|
134
|
+
if ((!Object.hasOwn(actions,name) && name !== 'device.monitor') || !payload || typeof payload !== 'object' || Array.isArray(payload)) throw new Error('EEBUS_COMMAND_INVALID');
|
|
134
135
|
const deviceId = (payload as Record<string, unknown>).deviceId;
|
|
135
|
-
if (typeof deviceId !== 'string' || !/^[A-Fa-f0-9]{40}$/.test(deviceId)
|
|
136
|
+
if (typeof deviceId !== 'string' || !/^[A-Fa-f0-9]{40}$/.test(deviceId)) throw new Error('EEBUS_DEVICE_UNKNOWN');
|
|
137
|
+
const observed = runtime.getNodes().some(node => node.safeId === deviceId);
|
|
138
|
+
if (!observed && !(name === 'device.monitor' && runtime.partnerMonitor.list().some(peer => peer.id === deviceId))) throw new Error('EEBUS_DEVICE_UNKNOWN');
|
|
136
139
|
if (inFlight >= 16) throw new Error('EEBUS_COMMAND_BUSY');
|
|
137
140
|
inFlight++;
|
|
138
141
|
try {
|
|
142
|
+
if (name === 'device.monitor') {
|
|
143
|
+
const data = payload as Record<string,unknown>;
|
|
144
|
+
if (typeof data.enabled !== 'boolean') throw new Error('EEBUS_COMMAND_INVALID');
|
|
145
|
+
await runtime.partnerMonitor.configure(deviceId, data.name, data.enabled);
|
|
146
|
+
return { accepted: options.canOperate() && !stopping };
|
|
147
|
+
}
|
|
139
148
|
await runtime.handleStateChange(`${adapter.namespace}.devices.${deviceId}.${actions[name]}`, { val: true, ack: false, ts: Date.now(), lc: Date.now(), from: adapter.namespace });
|
|
140
149
|
return { accepted: options.canOperate() && !stopping };
|
|
141
150
|
} finally { inFlight--; }
|
|
142
151
|
},
|
|
152
|
+
getDashboardDeviceHealth() {
|
|
153
|
+
if (!running || stopping || !runtime || !options.canOperate()) return emptyReport(selected.enabled === false);
|
|
154
|
+
return runtime.partnerMonitor.report();
|
|
155
|
+
},
|
|
143
156
|
async getStatus() {
|
|
157
|
+
const monitored = new Map((runtime?.partnerMonitor.list() || []).map(p=>[p.id,p]));
|
|
144
158
|
const nodes = runtime?.getNodes() || [];
|
|
145
159
|
const devices = [];
|
|
146
160
|
for (const node of nodes.slice(0, 128)) {
|
|
@@ -149,9 +163,15 @@ export function createHostedModule(options: Options) {
|
|
|
149
163
|
adapter.getStateAsync(`devices.${node.safeId}.connection.shipState`),
|
|
150
164
|
adapter.getStateAsync(`devices.${node.safeId}.pairing.remoteFingerprint`),
|
|
151
165
|
]);
|
|
152
|
-
|
|
166
|
+
const entry=monitored.get(node.safeId); monitored.delete(node.safeId);
|
|
167
|
+
devices.push({ monitorName:entry?.name || '', monitorPaused:entry?.paused === true, canMonitor:runtime?.canMonitorPartner(node.safeId) === true,
|
|
168
|
+
id: node.safeId, name: node.name.slice(0, 128), ski: node.ski, fingerprint: String(fingerprint?.val || ''),
|
|
153
169
|
trusted: trust?.val === true, connected: connection?.val === 'data-exchange', state: String(connection?.val || 'discovered') });
|
|
154
170
|
}
|
|
171
|
+
// A monitored peer can be removed here even before it advertises after a restart.
|
|
172
|
+
for (const entry of monitored.values()) devices.push({ id:entry.id, name:entry.name, ski:entry.id, fingerprint:'',
|
|
173
|
+
trusted:false, connected:false, state:'Nicht verbunden', monitorName:entry.name, monitorPaused:entry.paused, canMonitor:false });
|
|
174
|
+
devices.sort((a,b)=>Number(!!b.monitorName)-Number(!!a.monitorName));
|
|
155
175
|
return { running, localSki: identity?.localSki || '', certificateFingerprint: identity?.certificateFingerprint || '',
|
|
156
176
|
shipPort: config.shipPort, commandDryRun: config.commandDryRun, devices };
|
|
157
177
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PartnerMonitor } from './partnerMonitor';
|
|
1
2
|
import { EebusConfig } from './config';
|
|
2
3
|
import { DiscoveryService } from './discoveryService';
|
|
3
4
|
import { DeviceClass, DeviceCommand, DiscoveredShipNode, EebusIdentity, ShipConnectionState } from './eebusTypes';
|
|
@@ -30,6 +31,7 @@ interface ClsSourceRuntimeState {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export class EebusRuntime {
|
|
34
|
+
public readonly partnerMonitor: PartnerMonitor;
|
|
33
35
|
private readonly nodes = new Map<string, DiscoveredShipNode>();
|
|
34
36
|
private discovery?: DiscoveryService;
|
|
35
37
|
private endpoint?: ShipEndpoint;
|
|
@@ -52,10 +54,12 @@ export class EebusRuntime {
|
|
|
52
54
|
private readonly objectFactory: ObjectFactory,
|
|
53
55
|
) {
|
|
54
56
|
this.autoAcceptNewDevices = config.autoAcceptNewDevices;
|
|
57
|
+
this.partnerMonitor = new PartnerMonitor(adapter, id => this.canMonitorPartner(id));
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
public async start(): Promise<void> {
|
|
58
61
|
this.stopping = false;
|
|
62
|
+
await this.partnerMonitor.load();
|
|
59
63
|
this.endpoint = new ShipEndpoint(
|
|
60
64
|
this.adapter,
|
|
61
65
|
{ ...this.config, autoAcceptNewDevices: this.autoAcceptNewDevices },
|
|
@@ -144,10 +148,14 @@ export class EebusRuntime {
|
|
|
144
148
|
public async handleStateChange(id: string, state: ioBroker.State | null | undefined): Promise<void> {
|
|
145
149
|
if (id.endsWith('.pairing.trusted') || id.endsWith('.pairing.pinnedFingerprint')) {
|
|
146
150
|
const match = id.match(/devices\.([^.]+)\.pairing\./);
|
|
147
|
-
if (match && id.endsWith('.pinnedFingerprint'))
|
|
151
|
+
if (match && id.endsWith('.pinnedFingerprint')) {
|
|
152
|
+
this.endpoint?.invalidateCertificate(match[1], state?.val);
|
|
153
|
+
await this.partnerMonitor.pinChanged(match[1], state?.val);
|
|
154
|
+
}
|
|
148
155
|
if (match && (!state || (id.endsWith('.trusted') && state.val !== true))) {
|
|
149
156
|
this.trustCache.delete(match[1]);
|
|
150
157
|
this.endpoint?.disconnect(match[1]);
|
|
158
|
+
await this.partnerMonitor.pause(match[1]);
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
161
|
if (!state || state.ack || this.stopping || this.adapter.canOperate?.() === false) return;
|
|
@@ -171,7 +179,11 @@ export class EebusRuntime {
|
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
if (command.channel === 'control' && command.stateName === 'disconnect') {
|
|
174
|
-
if (Boolean(command.value))
|
|
182
|
+
if (Boolean(command.value)) {
|
|
183
|
+
const paused = this.partnerMonitor.pause(command.deviceId);
|
|
184
|
+
this.endpoint?.disconnect(command.deviceId);
|
|
185
|
+
await paused;
|
|
186
|
+
}
|
|
175
187
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.control.disconnect`, { val: false, ack: true });
|
|
176
188
|
return;
|
|
177
189
|
}
|
|
@@ -198,6 +210,7 @@ export class EebusRuntime {
|
|
|
198
210
|
}
|
|
199
211
|
} else {
|
|
200
212
|
this.endpoint?.rejectDevice(command.deviceId);
|
|
213
|
+
await this.partnerMonitor.pause(command.deviceId);
|
|
201
214
|
}
|
|
202
215
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.pairing.approve`, { val: false, ack: true });
|
|
203
216
|
await this.adapter.setStateAsync(`devices.${command.deviceId}.pairing.reject`, { val: false, ack: true });
|
|
@@ -286,6 +299,7 @@ export class EebusRuntime {
|
|
|
286
299
|
}
|
|
287
300
|
|
|
288
301
|
private async handleDataExchangeReady(deviceId: string): Promise<void> {
|
|
302
|
+
this.partnerMonitor.observed(deviceId);
|
|
289
303
|
// Prime the trust decision before the first time-critical CLS write arrives.
|
|
290
304
|
// The control path can then use the in-memory cache without an object DB read.
|
|
291
305
|
if (!this.trustCache.has(deviceId)) {
|
|
@@ -979,6 +993,10 @@ export class EebusRuntime {
|
|
|
979
993
|
};
|
|
980
994
|
}
|
|
981
995
|
|
|
996
|
+
public canMonitorPartner(id:string): boolean {
|
|
997
|
+
return !this.stopping && this.adapter.canOperate?.() !== false && this.endpoint?.hasAuthorizedExchange(id) === true;
|
|
998
|
+
}
|
|
999
|
+
|
|
982
1000
|
public getNodes(): DiscoveredShipNode[] { return Array.from(this.nodes.values()).map(node => ({ ...node })); }
|
|
983
1001
|
|
|
984
1002
|
private periodic(key: string, work: () => Promise<void>): void {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const objectId = 'pairing.monitoredPartners';
|
|
4
|
+
const startupGraceMs = 120_000;
|
|
5
|
+
type State = 'online' | 'offline' | 'unknown' | 'disabled';
|
|
6
|
+
type Partner = { id:string; key:string; name:string; pin:string; paused:boolean };
|
|
7
|
+
const pinValue = (v:unknown):string => typeof v === 'string' && /^[a-f0-9]{64}$/i.test(v.replace(/:/g,'')) ? v.replace(/:/g,'').toUpperCase() : '';
|
|
8
|
+
interface Store {
|
|
9
|
+
getStateAsync(id:string): Promise<{val:unknown;ack?:boolean} | null | undefined>;
|
|
10
|
+
setStateAsync(id:string, value:{val:string;ack:true}): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
function friendlyName(value:unknown): value is string {
|
|
13
|
+
return typeof value === 'string' && value === value.trim() && value.length <= 64 &&
|
|
14
|
+
/\p{L}/u.test(value) && /^[\p{L}\p{M}\p{N} _()-]+$/u.test(value) &&
|
|
15
|
+
!/[a-f\d]{16,}|(?:[a-f\d]{2}-){5}[a-f\d]{2}/i.test(value) && !/\d{9,}/.test(value);
|
|
16
|
+
}
|
|
17
|
+
const safeId = (v:unknown):v is string => typeof v==='string' && /^[a-f\d]{40}$/i.test(v);
|
|
18
|
+
const key = (id:string) => createHash('sha256').update('eebus:'+id.toLowerCase()).digest('hex');
|
|
19
|
+
export function emptyReport(known:boolean) {
|
|
20
|
+
return {state:known?'ok':'unknown',offline:[] as {name:string}[],totalOffline:0,
|
|
21
|
+
tracked:[] as {key:string;name:string;state:State}[],complete:known};
|
|
22
|
+
}
|
|
23
|
+
/** Names are local installer input. Discovery metadata, peer addresses and certificates never feed the customer report. */
|
|
24
|
+
export class PartnerMonitor {
|
|
25
|
+
private partners = new Map<string,Partner>();
|
|
26
|
+
private confirmed = new Set<string>();
|
|
27
|
+
private suppressed = new Set<string>();
|
|
28
|
+
private known = false;
|
|
29
|
+
private startedAt = 0;
|
|
30
|
+
private pending:Promise<void> = Promise.resolve();
|
|
31
|
+
constructor(private store:Store, private live:(id:string)=>boolean, private now=()=>performance.now()) {}
|
|
32
|
+
|
|
33
|
+
async load(): Promise<void> {
|
|
34
|
+
this.startedAt = this.now();
|
|
35
|
+
try {
|
|
36
|
+
const state = await this.store.getStateAsync(objectId);
|
|
37
|
+
if (state?.ack === false) throw Error();
|
|
38
|
+
const rows:unknown = state?.val == null ? [] : JSON.parse(String(state.val));
|
|
39
|
+
if (!Array.isArray(rows) || rows.length>128) throw Error();
|
|
40
|
+
const restored = new Map<string,Partner>();
|
|
41
|
+
for (const item of rows) {
|
|
42
|
+
if (!item || !safeId(item.id) || !friendlyName(item.name) || !pinValue(item.pin) || typeof item.paused!=='boolean' || restored.has(item.id)) throw Error();
|
|
43
|
+
const row = {id:item.id.toUpperCase(), key:key(item.id), name:item.name, pin:pinValue(item.pin), paused:item.paused};
|
|
44
|
+
if (restored.has(row.id)) throw Error();
|
|
45
|
+
restored.set(row.id,row);
|
|
46
|
+
}
|
|
47
|
+
// Verify locally approved pairing on restart even when the peer is currently absent.
|
|
48
|
+
const monitored = Array.from(restored.values()).filter(row=>!row.paused);
|
|
49
|
+
let changed = false;
|
|
50
|
+
for (let start=0; start<monitored.length; start+=8) {
|
|
51
|
+
await Promise.all(monitored.slice(start,start+8).map(async row => {
|
|
52
|
+
if (await this.trustedPin(row.id) !== row.pin) { row.paused = true; changed = true; }
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
if (changed) await this.save(restored);
|
|
56
|
+
else this.partners = restored;
|
|
57
|
+
this.known = true;
|
|
58
|
+
} catch { this.known = false; }
|
|
59
|
+
}
|
|
60
|
+
private async trustedPin(id:string) {
|
|
61
|
+
const [trust,pin] = await Promise.all(['trusted','pinnedFingerprint'].map(field=>
|
|
62
|
+
this.store.getStateAsync('devices.'+id+'.pairing.'+field)));
|
|
63
|
+
return trust?.val===true && trust.ack!==false && pin?.ack!==false ? pinValue(pin?.val) : '';
|
|
64
|
+
}
|
|
65
|
+
private change(write:()=>Promise<void>):Promise<void> {
|
|
66
|
+
const op = this.pending.then(write);
|
|
67
|
+
this.pending = op.catch(()=>{});
|
|
68
|
+
return op;
|
|
69
|
+
}
|
|
70
|
+
private async save(next:Map<string,Partner>):Promise<void> {
|
|
71
|
+
await this.store.setStateAsync(objectId,{val:JSON.stringify(Array.from(next.values(), ({id,name,pin,paused})=>({id,name,pin,paused}))),ack:true});
|
|
72
|
+
this.partners = next;
|
|
73
|
+
}
|
|
74
|
+
async configure(id:string, name:unknown, enabled:boolean):Promise<void> {
|
|
75
|
+
if (!safeId(id)) throw new Error('EEBUS_MONITOR_DEVICE');
|
|
76
|
+
id=id.toUpperCase();
|
|
77
|
+
return this.change(async()=>{
|
|
78
|
+
if (!this.known) throw new Error('EEBUS_MONITOR_STORAGE_UNAVAILABLE');
|
|
79
|
+
const next = new Map(this.partners);
|
|
80
|
+
if (enabled) {
|
|
81
|
+
if (!friendlyName(name)) throw new Error('EEBUS_MONITOR_LOCAL_NAME');
|
|
82
|
+
const pin = this.live(id) ? await this.trustedPin(id) : '';
|
|
83
|
+
if (!pin || !this.live(id)) throw new Error('EEBUS_MONITOR_PAIRED_SESSION_REQUIRED');
|
|
84
|
+
if (!next.has(id) && next.size>=128) throw new Error('EEBUS_MONITOR_CAPACITY');
|
|
85
|
+
next.set(id,{id,key:key(id),name,pin,paused:false});
|
|
86
|
+
} else { next.delete(id); }
|
|
87
|
+
await this.save(next);
|
|
88
|
+
if (enabled) this.confirmed.add(id); else this.confirmed.delete(id);
|
|
89
|
+
this.suppressed.delete(id);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
pinChanged(id:string, value:unknown):Promise<void> {
|
|
93
|
+
const row=this.partners.get(id.toUpperCase());
|
|
94
|
+
return row && !row.paused && row.pin!==pinValue(value) ? this.pause(id) : Promise.resolve();
|
|
95
|
+
}
|
|
96
|
+
pause(id:string):Promise<void> {
|
|
97
|
+
id=id.toUpperCase();
|
|
98
|
+
this.suppressed.add(id);
|
|
99
|
+
return this.change(async()=>{
|
|
100
|
+
const row=this.partners.get(id);
|
|
101
|
+
if (row && !row.paused) {
|
|
102
|
+
const next=new Map(this.partners); next.set(id,{...row,paused:true});
|
|
103
|
+
await this.save(next);
|
|
104
|
+
}
|
|
105
|
+
this.suppressed.delete(id);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
observed(id:string):void { if (this.partners.has(id.toUpperCase()) && this.live(id)) this.confirmed.add(id.toUpperCase()); }
|
|
109
|
+
list() {return Array.from(this.partners.values(),({id,name,paused})=>({id,name,paused}));}
|
|
110
|
+
report() {
|
|
111
|
+
const report=emptyReport(this.known);
|
|
112
|
+
if (!this.known) return report;
|
|
113
|
+
for (const row of this.partners.values()) {
|
|
114
|
+
const active=this.live(row.id);
|
|
115
|
+
const state:State=row.paused || this.suppressed.has(row.id)?'disabled':active?'online':
|
|
116
|
+
this.confirmed.has(row.id) || this.now()-this.startedAt>=startupGraceMs?'offline':'unknown';
|
|
117
|
+
if (state==='online') this.confirmed.add(row.id);
|
|
118
|
+
report.tracked.push({key:row.key,name:row.name,state});
|
|
119
|
+
if (state==='unknown' && report.state==='ok') report.state='unknown';
|
|
120
|
+
if (state==='offline') {
|
|
121
|
+
report.state='fault'; report.totalOffline++;
|
|
122
|
+
if (report.offline.length<12) report.offline.push({name:row.name});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return report;
|
|
126
|
+
}
|
|
127
|
+
}
|