iobroker.eos-admin 7.9.98 → 7.9.100
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/INSTALL_TEST_V7.9.100.md +11 -0
- package/MERGE_UPDATE_README_V7.9.100.md +5 -0
- package/NEXOWATT_EOS_BUILD_INFO.json +20 -20
- package/PUBLISH_STABLE_V7.9.100.md +15 -0
- package/README.md +6 -16
- package/README_STABILITY_V7.9.100.md +3 -0
- package/RELEASE_ACCEPTANCE_V7.9.100.md +11 -0
- package/RELEASE_NOTES_V7.9.100.md +11 -0
- package/adminWww/assets/Intro-DkwRiz1n-v84.js +2 -2
- package/adminWww/assets/bootstrap-COulQZax-v84.js +2 -2
- package/adminWww/css/eos-auto-update.css +4 -0
- package/adminWww/css/eos-ems-overview.css +3 -5
- package/adminWww/css/nexowatt-native-shell.css +26 -112
- package/adminWww/index.html +21 -18
- package/adminWww/js/eos-account-management.js +19 -28
- package/adminWww/js/eos-assistant.js +1 -1
- package/adminWww/js/eos-auto-update.js +78 -0
- package/adminWww/js/eos-ems-overview.js +2 -3
- package/adminWww/js/eos-release-watch.js +77 -0
- package/adminWww/js/eos-role-bootstrap.js +11 -8
- package/adminWww/js/eos-role-ui.js +2 -2
- package/adminWww/js/nexowatt-native-shell.js +1 -1
- package/adminWww/static/js/nexowatt-stable-login.js +3 -3
- package/adminWww/static/js/{nexowatt-stable-v98.js → nexowatt-stable-v100.js} +2 -2
- package/build/lib/eosAutoUpdate.js +43 -0
- package/build/lib/eosPassword.js +62 -0
- package/build/lib/eosRequestSecurity.js +31 -0
- package/build/lib/web.js +194 -151
- package/build/main.js +2 -1
- package/io-package.json +7 -11
- package/package.json +23 -13
- package/src/lib/eosAutoUpdate.ts +320 -0
- package/tools/nexowatt-account-management-selftest.cjs +19 -15
- package/tools/nexowatt-apply-ems-overview.cjs +2 -4
- package/tools/nexowatt-auto-update-selftest.cjs +34 -0
- package/tools/nexowatt-cache-update-selftest.cjs +12 -0
- package/tools/nexowatt-clean-legacy-runtime.cjs +1 -1
- package/tools/nexowatt-ems-overview-selftest.cjs +1 -1
- package/tools/nexowatt-login-layout-selftest.cjs +11 -11
- package/tools/nexowatt-merge-update-selftest.cjs +1 -1
- package/tools/nexowatt-modern-ui-selftest.cjs +2 -2
- package/tools/nexowatt-password-write-selftest.cjs +42 -44
- package/tools/nexowatt-request-security-selftest.cjs +11 -0
- package/tools/nexowatt-runtime-cleanup-selftest.cjs +6 -6
- package/tools/nexowatt-stable-v100-selftest.cjs +27 -0
- package/tools/nexowatt-sync-release-version.cjs +1 -42
- package/tools/nexowatt-ui-overview-runtime-selftest.cjs +3 -1
- package/tools/nexowatt-validate-package.cjs +23 -23
- package/tools/nexowatt-version-sync-selftest.cjs +1 -18
- package/INSTALL_TEST_V7.9.98.md +0 -39
- package/MERGE_UPDATE_README_V7.9.98.md +0 -29
- package/PUBLISH_STABLE_V7.9.98.md +0 -33
- package/README_STABILITY_V7.9.98.md +0 -22
- package/RELEASE_ACCEPTANCE_V7.9.98.md +0 -48
- package/RELEASE_NOTES_V7.9.98.md +0 -32
- package/tools/nexowatt-account-password-flow-selftest.cjs +0 -186
- package/tools/nexowatt-stable-v98-selftest.cjs +0 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const VERSION = '
|
|
4
|
+
const VERSION = 'v100-first-login-password-persisted';
|
|
5
5
|
const script = document.currentScript || document.querySelector('script[src*="eos-role-bootstrap.js"]');
|
|
6
6
|
const entry = script?.dataset?.eosEntry || '';
|
|
7
7
|
let launched = false;
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
required: 'Bitte beide Passwortfelder ausfüllen.', mismatch: 'Die Passwörter stimmen nicht überein.',
|
|
81
81
|
length: min => `Das Passwort muss mindestens ${min} Zeichen lang sein.`, complexity: 'Groß-/Kleinbuchstabe, Zahl und Sonderzeichen sind erforderlich.',
|
|
82
82
|
easy: 'Das Passwort ist zu leicht oder enthält den Kontonamen.', generic: 'Das Passwort konnte nicht gespeichert werden.', success: 'Passwort gespeichert. Die Anmeldung wird neu gestartet …',
|
|
83
|
+
backendErrors: { invalidRequest: 'Die Sicherheitsbestätigung fehlt. Bitte erneut anmelden.', invalidRequestOrigin: 'Die Sitzung oder aufgerufene Adresse hat sich geändert. Bitte erneut anmelden.', passwordApiUnavailable: 'Die ioBroker-Passwortverwaltung ist nicht verfügbar.', passwordNotPersisted: 'Das Passwort wurde nicht im ioBroker-Benutzerkonto gespeichert.', passwordVerificationFailed: 'Das neue Passwort wurde geschrieben, aber nicht als gültige Anmeldung bestätigt.', passwordMetadataNotPersisted: 'Das Passwort wurde gespeichert, aber der Erstanmeldungsstatus konnte nicht abgeschlossen werden.', passwordSetupFailed: 'Das Passwort konnte serverseitig nicht gespeichert werden. Bitte das EOS-Systemlog prüfen.' },
|
|
83
84
|
securityTitle: 'Zugriff wird geprüft', securityIntro: 'Die sichere Anmeldung wird gerade geprüft. Die Oberfläche bleibt gesperrt, bis die Berechtigungen eindeutig geladen wurden.',
|
|
84
85
|
securityRetry: 'Jetzt erneut prüfen', securityLogout: 'Zur Anmeldung', securityAuto: seconds => `Automatischer neuer Versuch in ${seconds} Sekunden …`,
|
|
85
86
|
claimLauncher: 'Erstanmeldung', claimTitle: 'Konto erstmals aktivieren',
|
|
@@ -99,6 +100,7 @@
|
|
|
99
100
|
required: 'Please complete both password fields.', mismatch: 'The passwords do not match.',
|
|
100
101
|
length: min => `The password must contain at least ${min} characters.`, complexity: 'Upper/lower case, a number and a special character are required.',
|
|
101
102
|
easy: 'The password is too easy or contains the account name.', generic: 'The password could not be saved.', success: 'Password saved. Restarting sign-in …',
|
|
103
|
+
backendErrors: { invalidRequest: 'The security confirmation is missing. Sign in again.', invalidRequestOrigin: 'The session or address changed. Sign in again.', passwordApiUnavailable: 'The ioBroker password service is unavailable.', passwordNotPersisted: 'The password was not persisted in the ioBroker user account.', passwordVerificationFailed: 'The new password was written but could not be verified as a valid login.', passwordMetadataNotPersisted: 'The password was saved, but the first-login status could not be completed.', passwordSetupFailed: 'The password could not be saved on the server. Check the EOS system log.' },
|
|
102
104
|
securityTitle: 'Checking access', securityIntro: 'The secure sign-in is being verified. The interface stays locked until the permissions are loaded unambiguously.',
|
|
103
105
|
securityRetry: 'Check again now', securityLogout: 'Return to sign-in', securityAuto: seconds => `Retrying automatically in ${seconds} seconds …`,
|
|
104
106
|
claimLauncher: 'First sign-in', claimTitle: 'Activate account for the first time',
|
|
@@ -118,6 +120,7 @@
|
|
|
118
120
|
required: 'Vul beide wachtwoordvelden in.', mismatch: 'De wachtwoorden zijn niet gelijk.',
|
|
119
121
|
length: min => `Het wachtwoord moet minimaal ${min} tekens bevatten.`, complexity: 'Hoofdletter, kleine letter, cijfer en speciaal teken zijn verplicht.',
|
|
120
122
|
easy: 'Het wachtwoord is te eenvoudig of bevat de accountnaam.', generic: 'Het wachtwoord kon niet worden opgeslagen.', success: 'Wachtwoord opgeslagen. De aanmelding wordt opnieuw gestart …',
|
|
123
|
+
backendErrors: { invalidRequest: 'De beveiligingsbevestiging ontbreekt. Meld opnieuw aan.', invalidRequestOrigin: 'De sessie of het adres is gewijzigd. Meld opnieuw aan.', passwordApiUnavailable: 'De ioBroker-wachtwoordservice is niet beschikbaar.', passwordNotPersisted: 'Het wachtwoord is niet in het ioBroker-gebruikersaccount opgeslagen.', passwordVerificationFailed: 'Het nieuwe wachtwoord is geschreven maar kon niet als geldige aanmelding worden bevestigd.', passwordMetadataNotPersisted: 'Het wachtwoord is opgeslagen, maar de eerste-aanmeldstatus kon niet worden afgerond.', passwordSetupFailed: 'Het wachtwoord kon server-side niet worden opgeslagen. Controleer het EOS-systeemlogboek.' },
|
|
121
124
|
securityTitle: 'Toegang wordt gecontroleerd', securityIntro: 'De veilige aanmelding wordt gecontroleerd. De interface blijft vergrendeld totdat de rechten eenduidig zijn geladen.',
|
|
122
125
|
securityRetry: 'Nu opnieuw controleren', securityLogout: 'Terug naar aanmelden', securityAuto: seconds => `Automatisch opnieuw proberen over ${seconds} seconden …`,
|
|
123
126
|
claimLauncher: 'Eerste aanmelding', claimTitle: 'Account voor het eerst activeren',
|
|
@@ -192,13 +195,13 @@
|
|
|
192
195
|
submit.disabled = true; submit.textContent = t.saving; setStatus('', '');
|
|
193
196
|
try {
|
|
194
197
|
const response = await fetch(endpoint, {
|
|
195
|
-
method: 'POST', credentials: '
|
|
198
|
+
method: 'POST', credentials: 'same-origin', cache: 'no-store',
|
|
196
199
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-NexoWatt-EOS-First-Login': '1' },
|
|
197
200
|
body: JSON.stringify({ password: password.value, passwordRepeat: repeat.value }),
|
|
198
201
|
});
|
|
199
202
|
const data = await response.json().catch(() => ({}));
|
|
200
203
|
if (!response.ok || data.error) {
|
|
201
|
-
const messages = { passwordRequired: t.required, passwordMismatch: t.mismatch, passwordLength: t.length(minLength), passwordComplexity: t.complexity, passwordTooEasy: t.easy,
|
|
204
|
+
const messages = { passwordRequired: t.required, passwordMismatch: t.mismatch, passwordLength: t.length(minLength), passwordComplexity: t.complexity, passwordTooEasy: t.easy, ...(t.backendErrors || {}) };
|
|
202
205
|
throw new Error(messages[data.error] || t.generic);
|
|
203
206
|
}
|
|
204
207
|
setStatus(t.success, 'success');
|
|
@@ -265,13 +268,13 @@
|
|
|
265
268
|
submit.disabled = true; submit.textContent = t.saving; setStatus('', '');
|
|
266
269
|
try {
|
|
267
270
|
const response = await fetch(endpoint, {
|
|
268
|
-
method: 'POST', credentials: '
|
|
271
|
+
method: 'POST', credentials: 'same-origin', cache: 'no-store',
|
|
269
272
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-NexoWatt-EOS-Passwordless-Password': '1' },
|
|
270
273
|
body: JSON.stringify({ password: password.value, passwordRepeat: repeat.value }),
|
|
271
274
|
});
|
|
272
275
|
const data = await response.json().catch(() => ({}));
|
|
273
276
|
if (!response.ok || data.error) {
|
|
274
|
-
const messages = { passwordRequired: t.required, passwordMismatch: t.mismatch, passwordLength: t.length(minLength), passwordComplexity: t.complexity, passwordTooEasy: t.easy, claimExpired: t.claimExpired };
|
|
277
|
+
const messages = { passwordRequired: t.required, passwordMismatch: t.mismatch, passwordLength: t.length(minLength), passwordComplexity: t.complexity, passwordTooEasy: t.easy, claimExpired: t.claimExpired, ...(t.backendErrors || {}) };
|
|
275
278
|
throw new Error(messages[data.error] || t.generic);
|
|
276
279
|
}
|
|
277
280
|
overlay.querySelector('.eos-activation-steps span:nth-of-type(2)')?.classList.add('done');
|
|
@@ -473,7 +476,7 @@
|
|
|
473
476
|
setStatus(card, t.claimChecking, '');
|
|
474
477
|
try {
|
|
475
478
|
const response = await fetch(new URL('nexowatt/account/passwordless-claim', base).href, {
|
|
476
|
-
method: 'POST', credentials: '
|
|
479
|
+
method: 'POST', credentials: 'same-origin', cache: 'no-store',
|
|
477
480
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-NexoWatt-EOS-Passwordless-Claim': '1' },
|
|
478
481
|
body: JSON.stringify({ user: account }),
|
|
479
482
|
});
|
|
@@ -500,7 +503,7 @@
|
|
|
500
503
|
const { username, password, card, submit } = loginElements();
|
|
501
504
|
if (!username || !password || !card) return;
|
|
502
505
|
card.classList.add('eos-login-card-modern');
|
|
503
|
-
//
|
|
506
|
+
// v100 normal-login first activation: do not add role buttons or a second panel.
|
|
504
507
|
// The account is entered in the existing Loginname field; a blank password is accepted only
|
|
505
508
|
// after the backend confirms that this exact managed account is eligible.
|
|
506
509
|
card.querySelectorAll('.eos-login-role-selector').forEach(element => element.remove());
|
|
@@ -634,7 +637,7 @@
|
|
|
634
637
|
const timeout = window.setTimeout(() => controller.abort(), 8000);
|
|
635
638
|
|
|
636
639
|
window.NEXOWATT_EOS_BOOTSTRAP_READY = fetch(contextUrl, {
|
|
637
|
-
credentials: '
|
|
640
|
+
credentials: 'same-origin', cache: 'no-store', headers: { Accept: 'application/json' }, signal: controller.signal,
|
|
638
641
|
})
|
|
639
642
|
.then(response => { if (!response.ok) throw new Error(`HTTP ${response.status}`); return response.json(); })
|
|
640
643
|
.then(policy => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const VERSION = '
|
|
4
|
+
const VERSION = 'v100-native-overview-ems-live-reserve-filter';
|
|
5
5
|
window.NEXOWATT_EOS_ROLE_UI_VERSION = VERSION;
|
|
6
6
|
|
|
7
7
|
const state = {
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
});
|
|
279
279
|
};
|
|
280
280
|
const ensureSafeOverview = () => safe(() => {
|
|
281
|
-
// 7.9.
|
|
281
|
+
// 7.9.100: never cover the real Admin Intro with a second tile surface.
|
|
282
282
|
// Installer and end-user use the native card component; security remains
|
|
283
283
|
// enforced by route/instance filters and backend permissions.
|
|
284
284
|
removeSafeOverview();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const VERSION = '
|
|
4
|
+
const VERSION = 'v100-nexowatt-native-shell-native-overview';
|
|
5
5
|
const previous = window.NEXOWATT_NATIVE_SHELL;
|
|
6
6
|
if (previous?.version === VERSION) return;
|
|
7
7
|
previous?.destroy?.();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* NexoWatt EOS stable runtime
|
|
1
|
+
/* NexoWatt EOS stable runtime v100 */
|
|
2
2
|
(() => {
|
|
3
3
|
'use strict';
|
|
4
4
|
const MANAGED_USERS = new Set(['installer', 'guest', 'user']);
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
const findSubmit = () => [...document.querySelectorAll('button,input[type="submit"]')].find(element => visible(element) && (/anmelden|login|sign in/i.test((element.textContent || element.value || '').trim()) || element.type === 'submit'));
|
|
15
15
|
const sync = () => {
|
|
16
16
|
if (!isLogin()) return;
|
|
17
|
-
document.documentElement.classList.add('nw-eos-login-
|
|
18
|
-
document.body?.classList.add('nw-eos-login-
|
|
17
|
+
document.documentElement.classList.add('nw-eos-login-v100');
|
|
18
|
+
document.body?.classList.add('nw-eos-login-v100');
|
|
19
19
|
const username = findInput('user');
|
|
20
20
|
const password = findInput('password');
|
|
21
21
|
const submit = findSubmit();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
'use strict';
|
|
3
|
-
const VERSION = '
|
|
3
|
+
const VERSION = 'v100-compact-login-ems-connection';
|
|
4
4
|
const MANAGED_USERS = new Set(['installer', 'guest', 'user']);
|
|
5
5
|
const normalizeUser = value => String(value || '').trim().toLowerCase().replace(/^system\.user\./, '');
|
|
6
6
|
const apply = () => {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
document.addEventListener('change', schedule, true);
|
|
30
30
|
};
|
|
31
31
|
document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', start, { once: true }) : start();
|
|
32
|
-
window.
|
|
32
|
+
window.NEXOWATT_EOS_STABLE_V100 = Object.freeze({ version: VERSION, refresh: apply });
|
|
33
33
|
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NexoWattStableUpdateManager = void 0;
|
|
4
|
+
exports.isNexoWattRepositoryEntry = isNexoWattRepositoryEntry;
|
|
5
|
+
const ADMIN_USER = 'system.user.admin';
|
|
6
|
+
const POLICY = 'major';
|
|
7
|
+
const RECONCILE_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
8
|
+
const REPOSITORY_REFRESH_DELAY_MS = 2500;
|
|
9
|
+
const clone = value => JSON.parse(JSON.stringify(value));
|
|
10
|
+
const normalizedName = value => String(value || '').trim().replace(/^system\.adapter\./, '').replace(/\.\d+$/, '');
|
|
11
|
+
const stableVersion = value => /^\d+\.\d+\.\d+$/.test(String(value || '').trim());
|
|
12
|
+
function isNexoWattRepositoryEntry(name, entry) {
|
|
13
|
+
const adapterName = normalizedName(entry?.name || name).toLowerCase();
|
|
14
|
+
if (adapterName === 'eos-admin' || adapterName.startsWith('nexowatt-') || adapterName.startsWith('eos-'))
|
|
15
|
+
return true;
|
|
16
|
+
const evidence = JSON.stringify({ name, adapterName, title: entry?.title, desc: entry?.desc, author: entry?.author, authors: entry?.authors, publisher: entry?.publisher, url: entry?.url, meta: entry?.meta, readme: entry?.readme, extIcon: entry?.extIcon, licenseInformation: entry?.licenseInformation }).toLowerCase();
|
|
17
|
+
return evidence.includes('nexowatt') || evidence.includes('github.com/nexowatt/');
|
|
18
|
+
}
|
|
19
|
+
class NexoWattStableUpdateManager {
|
|
20
|
+
adapter;
|
|
21
|
+
timer;
|
|
22
|
+
reconcilePromise;
|
|
23
|
+
refreshTimer;
|
|
24
|
+
retryTimer;
|
|
25
|
+
constructor(adapter) { this.adapter = adapter; }
|
|
26
|
+
get instanceId() { return `system.adapter.${this.adapter.namespace}`; }
|
|
27
|
+
async start() { const status = await this.reconcile('startup'); if (!this.timer) { this.timer = setInterval(() => void this.reconcile('interval'), RECONCILE_INTERVAL_MS); this.timer.unref?.(); } return status; }
|
|
28
|
+
stop() { if (this.timer) clearInterval(this.timer); if (this.refreshTimer) clearTimeout(this.refreshTimer); if (this.retryTimer) clearTimeout(this.retryTimer); this.timer = undefined; this.refreshTimer = undefined; this.retryTimer = undefined; }
|
|
29
|
+
async getStatus(refresh = false) { if (refresh) return this.reconcile('status'); const instance = await this.adapter.getForeignObjectAsync(this.instanceId); return this.statusFromNative(instance?.native || {}); }
|
|
30
|
+
async setEnabled(enabled) { await this.adapter.extendForeignObjectAsync(this.instanceId, { native: { eosNexoWattAutoUpdate: enabled } }, { user: ADMIN_USER }); return this.reconcile(enabled ? 'enabled' : 'disabled'); }
|
|
31
|
+
async reconcile(reason = 'manual') { if (this.reconcilePromise) return this.reconcilePromise; this.reconcilePromise = this.reconcileInternal(reason).finally(() => { this.reconcilePromise = undefined; }); return this.reconcilePromise; }
|
|
32
|
+
statusFromNative(native) { const state = native.eosNexoWattAutoUpdateState || {}; return { enabled: native.eosNexoWattAutoUpdate !== false, repository: String(state.selectedRepository || ''), managedAdapters: Array.isArray(state.managedAdapters) ? state.managedAdapters.map(String).sort() : [], availableStableAdapters: Array.isArray(state.availableStableAdapters) ? state.availableStableAdapters.map(String).sort() : [], lastSync: Number(state.lastSync || 0), lastRepositoryRefresh: Number(state.lastRepositoryRefresh || 0), error: String(state.error || ''), policy: POLICY, source: 'ioBroker-native-auto-upgrade' }; }
|
|
33
|
+
async reconcileInternal(reason) { const instance = await this.adapter.getForeignObjectAsync(this.instanceId); const native = instance?.native || {}; const enabled = native.eosNexoWattAutoUpdate !== false; const state = clone(native.eosNexoWattAutoUpdateState || {}); try { if (!enabled) return await this.disable(state, reason); return await this.enable(state, reason); } catch (error) { const message = error instanceof Error ? error.message : String(error || 'unknownError'); state.error = message; state.lastSync = Date.now(); await this.persist(false, state); this.adapter.log.warn(`[NexoWatt stable updates] ${message}`); return this.statusFromNative({ eosNexoWattAutoUpdate: enabled, eosNexoWattAutoUpdateState: state }); } }
|
|
34
|
+
async readInstalledAdapters() { const view = await this.adapter.getObjectViewAsync('system', 'adapter', { startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' }, { user: ADMIN_USER }); const result = new Map(); for (const row of view?.rows || []) { const object = row?.value || row?.doc; const name = normalizedName(object?.common?.name || row?.id || object?._id); if (name && object?.common?.version) result.set(name, object); } return result; }
|
|
35
|
+
async readRepositorySelection(systemConfig) { const repositories = await this.adapter.getForeignObjectAsync('system.repositories'); const rows = repositories?.native?.repositories || {}; const active = Array.isArray(systemConfig?.common?.activeRepo) ? systemConfig.common.activeRepo.map(String) : []; const candidates = Object.entries(rows).map(([name, repo]) => { const entries = repo?.json && typeof repo.json === 'object' ? repo.json : {}; const stableNames = Object.entries(entries).filter(([entryName, entry]) => stableVersion(entry?.version) && isNexoWattRepositoryEntry(entryName, entry)).map(([entryName, entry]) => normalizedName(entry?.name || entryName)).filter(Boolean); return { name, entries, stableNames: [...new Set(stableNames)].sort(), activeIndex: active.indexOf(name) }; }).filter(row => row.stableNames.length > 0); if (!candidates.length) throw new Error('nexowattStableRepositoryNotFound'); candidates.sort((a, b) => { const aa = a.activeIndex < 0 ? Number.MAX_SAFE_INTEGER : a.activeIndex; const bb = b.activeIndex < 0 ? Number.MAX_SAFE_INTEGER : b.activeIndex; return aa - bb || b.stableNames.length - a.stableNames.length || a.name.localeCompare(b.name); }); return candidates[0]; }
|
|
36
|
+
async enable(state, reason) { const systemConfig = await this.adapter.getForeignObjectAsync('system.config'); if (!systemConfig?.common) throw new Error('systemConfigUnavailable'); const selected = await this.readRepositorySelection(systemConfig); const installed = await this.readInstalledAdapters(); const managedNames = selected.stableNames.filter(name => installed.has(name)).sort(); if (!managedNames.length) throw new Error('noInstalledNexoWattStableAdapters'); state.previousPolicies ||= {}; for (const name of managedNames) { if (!(name in state.previousPolicies)) { const current = installed.get(name)?.common?.automaticUpgrade; state.previousPolicies[name] = current == null ? null : current; } await this.writeAdapterPolicy(name, POLICY); } const common = systemConfig.common; const activeRepo = Array.isArray(common.activeRepo) ? [...common.activeRepo] : []; const auto = common.adapterAutoUpgrade && typeof common.adapterAutoUpgrade === 'object' ? clone(common.adapterAutoUpgrade) : { repositories: {}, defaultPolicy: 'none' }; auto.repositories = auto.repositories && typeof auto.repositories === 'object' ? { ...auto.repositories } : {}; if (state.previousRepositoryEnabled === undefined) state.previousRepositoryEnabled = Object.prototype.hasOwnProperty.call(auto.repositories, selected.name) ? Boolean(auto.repositories[selected.name]) : null; auto.repositories[selected.name] = true; if (!auto.defaultPolicy) auto.defaultPolicy = 'none'; common.adapterAutoUpgrade = auto; if (activeRepo[0] !== selected.name) { if (!state.previousActiveRepo) state.previousActiveRepo = [...activeRepo]; state.ownsActiveRepoOrder = true; common.activeRepo = [selected.name, ...activeRepo.filter(name => name !== selected.name)]; } await this.adapter.setForeignObjectAsync('system.config', systemConfig, { user: ADMIN_USER }); state.selectedRepository = selected.name; state.availableStableAdapters = selected.stableNames; state.managedAdapters = managedNames; state.lastSync = Date.now(); state.error = ''; await this.persist(true, state); this.scheduleRepositoryRefresh(selected.name, state); this.adapter.log.info(`[NexoWatt stable updates] Enabled for ${managedNames.join(', ')} from repository "${selected.name}" (${reason})`); return this.statusFromNative({ eosNexoWattAutoUpdate: true, eosNexoWattAutoUpdateState: state }); }
|
|
37
|
+
async disable(state, reason) { for (const [name, previous] of Object.entries(state.previousPolicies || {})) { const current = await this.adapter.getForeignObjectAsync(`system.adapter.${normalizedName(name)}`); if (current?.common?.automaticUpgrade === POLICY) await this.writeAdapterPolicy(name, previous); } const systemConfig = await this.adapter.getForeignObjectAsync('system.config'); if (systemConfig?.common) { const auto = systemConfig.common.adapterAutoUpgrade && typeof systemConfig.common.adapterAutoUpgrade === 'object' ? clone(systemConfig.common.adapterAutoUpgrade) : null; if (auto && state.selectedRepository) { auto.repositories = auto.repositories && typeof auto.repositories === 'object' ? { ...auto.repositories } : {}; if (auto.repositories[state.selectedRepository] === true) { if (state.previousRepositoryEnabled === null || state.previousRepositoryEnabled === undefined) delete auto.repositories[state.selectedRepository]; else auto.repositories[state.selectedRepository] = state.previousRepositoryEnabled; } systemConfig.common.adapterAutoUpgrade = auto; } if (state.ownsActiveRepoOrder && Array.isArray(state.previousActiveRepo) && Array.isArray(systemConfig.common.activeRepo) && systemConfig.common.activeRepo[0] === state.selectedRepository) systemConfig.common.activeRepo = [...state.previousActiveRepo]; await this.adapter.setForeignObjectAsync('system.config', systemConfig, { user: ADMIN_USER }); } state.previousPolicies = {}; state.previousRepositoryEnabled = undefined; state.previousActiveRepo = undefined; state.ownsActiveRepoOrder = false; state.managedAdapters = []; state.lastSync = Date.now(); state.error = ''; await this.persist(false, state); this.adapter.log.info(`[NexoWatt stable updates] Disabled and previous policies restored (${reason})`); return this.statusFromNative({ eosNexoWattAutoUpdate: false, eosNexoWattAutoUpdateState: state }); }
|
|
38
|
+
async writeAdapterPolicy(name, policy) { const id = `system.adapter.${normalizedName(name)}`; const object = await this.adapter.getForeignObjectAsync(id); if (!object?.common) return; if (policy === null) delete object.common.automaticUpgrade; else object.common.automaticUpgrade = policy; await this.adapter.setForeignObjectAsync(id, object, { user: ADMIN_USER }); }
|
|
39
|
+
async persist(enabled, state) { await this.adapter.extendForeignObjectAsync(this.instanceId, { native: { eosNexoWattAutoUpdate: enabled, eosNexoWattAutoUpdateState: state } }, { user: ADMIN_USER }); }
|
|
40
|
+
scheduleRetry() { if (this.retryTimer) clearTimeout(this.retryTimer); this.retryTimer = setTimeout(() => void this.reconcile('retry'), 60000); this.retryTimer.unref?.(); }
|
|
41
|
+
scheduleRepositoryRefresh(repository, state) { if (!this.adapter.sendToHostAsync || !this.adapter.host) return; if (this.refreshTimer) clearTimeout(this.refreshTimer); this.refreshTimer = setTimeout(() => { void this.adapter.sendToHostAsync?.(this.adapter.host, 'getRepository', { repo: repository, update: true }).then(async () => { const current = await this.adapter.getForeignObjectAsync(this.instanceId); if (current?.native?.eosNexoWattAutoUpdate === false) return; state.lastRepositoryRefresh = Date.now(); await this.persist(true, state); }).catch(error => this.adapter.log.warn(`[NexoWatt stable updates] Repository refresh failed: ${error instanceof Error ? error.message : error}`)); }, REPOSITORY_REFRESH_DELAY_MS); this.refreshTimer.unref?.(); }
|
|
42
|
+
}
|
|
43
|
+
exports.NexoWattStableUpdateManager = NexoWattStableUpdateManager;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeEosPasswordTarget = normalizeEosPasswordTarget;
|
|
4
|
+
exports.setEosUserPasswordWithVerification = setEosUserPasswordWithVerification;
|
|
5
|
+
function normalizeEosPasswordTarget(value) {
|
|
6
|
+
const raw = String(value || '').trim();
|
|
7
|
+
const userId = raw.startsWith('system.user.') ? raw : `system.user.${raw}`;
|
|
8
|
+
const userName = userId.replace(/^system\.user\./, '').trim();
|
|
9
|
+
if (!userName || userName.includes('.') || !/^system\.user\.[^.]+$/.test(userId)) {
|
|
10
|
+
throw new Error('invalidPasswordTarget');
|
|
11
|
+
}
|
|
12
|
+
return { userId, userName };
|
|
13
|
+
}
|
|
14
|
+
async function callPasswordApi(adapter, userName, password, serviceUser) {
|
|
15
|
+
const options = { user: serviceUser };
|
|
16
|
+
if (typeof adapter.setPasswordAsync === 'function') {
|
|
17
|
+
await adapter.setPasswordAsync(userName, password, options);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (typeof adapter.setPassword === 'function') {
|
|
21
|
+
await new Promise((resolve, reject) => {
|
|
22
|
+
adapter.setPassword?.(userName, password, options, error => (error ? reject(error) : resolve()));
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
throw new Error('passwordApiUnavailable');
|
|
27
|
+
}
|
|
28
|
+
async function waitForPasswordHash(adapter, userId) {
|
|
29
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
30
|
+
const user = await adapter.getForeignObjectAsync(userId);
|
|
31
|
+
if (typeof user?.common?.password === 'string' && user.common.password.length > 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (attempt < 5) {
|
|
35
|
+
await new Promise(resolve => setTimeout(resolve, 40 * (attempt + 1)));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw new Error('passwordNotPersisted');
|
|
39
|
+
}
|
|
40
|
+
async function verifyCredential(adapter, userName, password, serviceUser) {
|
|
41
|
+
if (typeof adapter.checkPasswordAsync !== 'function') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
45
|
+
const result = await adapter.checkPasswordAsync(userName, password, { user: serviceUser });
|
|
46
|
+
const accepted = result === true || (Array.isArray(result) && result[0] === true);
|
|
47
|
+
if (accepted) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (attempt < 4) {
|
|
51
|
+
await new Promise(resolve => setTimeout(resolve, 50 * (attempt + 1)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new Error('passwordVerificationFailed');
|
|
55
|
+
}
|
|
56
|
+
async function setEosUserPasswordWithVerification(adapter, target, password, serviceUser = 'system.user.admin') {
|
|
57
|
+
const normalized = normalizeEosPasswordTarget(target);
|
|
58
|
+
await callPasswordApi(adapter, normalized.userName, password, serviceUser);
|
|
59
|
+
await waitForPasswordHash(adapter, normalized.userId);
|
|
60
|
+
await verifyCredential(adapter, normalized.userName, password, serviceUser);
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEosSameOriginRequest = isEosSameOriginRequest;
|
|
4
|
+
function isEosSameOriginRequest(headers) {
|
|
5
|
+
const origin = String(headers.origin || '').trim();
|
|
6
|
+
if (!origin) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(origin);
|
|
11
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const allowedHosts = new Set();
|
|
15
|
+
const addHost = value => {
|
|
16
|
+
const host = String(value || '').split(',')[0].trim().toLowerCase();
|
|
17
|
+
if (host)
|
|
18
|
+
allowedHosts.add(host);
|
|
19
|
+
};
|
|
20
|
+
addHost(headers.host);
|
|
21
|
+
addHost(headers['x-forwarded-host']);
|
|
22
|
+
if (!allowedHosts.size || !allowedHosts.has(parsed.host.toLowerCase())) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const fetchSite = String(headers['sec-fetch-site'] || '').trim().toLowerCase();
|
|
26
|
+
return !fetchSite || fetchSite === 'same-origin' || fetchSite === 'same-site' || fetchSite === 'none';
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|