APmanageur Wi-Fi V1.0
This commit is contained in:
1 parent
b261949b4f
commit
d4a81b766d
1 file changed
+63
-26
+63
-26
@@ -3233,15 +3233,24 @@
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setupNotifVerifiedSigs = {};
|
||||||
|
|
||||||
|
function getNotifChannelSignature(ch, cfg) {
|
||||||
|
const c = (cfg || getNotificationFormPayload())[ch];
|
||||||
|
if (!c) return '';
|
||||||
|
return JSON.stringify(c);
|
||||||
|
}
|
||||||
|
|
||||||
async function testSetupNotification(channel) {
|
async function testSetupNotification(channel) {
|
||||||
const detailsBox = $('setupNotifTestDetails');
|
const detailsBox = $('setupNotifTestDetails');
|
||||||
if (detailsBox) {
|
if (detailsBox) {
|
||||||
detailsBox.innerHTML = `<div style="font-size:13px;color:var(--blue);padding:10px 14px;background:var(--panel);border:1px solid var(--line);border-radius:8px;margin-bottom:12px;display:flex;align-items:center;gap:8px"><span>⏳</span> <span>${t('notif_testing_progress', 'Envoi de la notification de test en cours…')}</span></div>`;
|
detailsBox.innerHTML = `<div style="font-size:13px;color:var(--blue);padding:10px 14px;background:var(--panel);border:1px solid var(--line);border-radius:8px;margin-bottom:12px;display:flex;align-items:center;gap:8px"><span>⏳</span> <span>${t('notif_testing_progress', 'Envoi de la notification de test en cours…')}</span></div>`;
|
||||||
}
|
}
|
||||||
|
const testedConfig = getNotificationFormPayload();
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
channel: channel,
|
channel: channel,
|
||||||
config: getNotificationFormPayload()
|
config: testedConfig
|
||||||
};
|
};
|
||||||
const res = await fetch(API_URL + '/api/notifications/test', {
|
const res = await fetch(API_URL + '/api/notifications/test', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -3269,17 +3278,30 @@
|
|||||||
for (const [ch, info] of Object.entries(results)) {
|
for (const [ch, info] of Object.entries(results)) {
|
||||||
const chName = labels[ch] || ch;
|
const chName = labels[ch] || ch;
|
||||||
if (info.ok) {
|
if (info.ok) {
|
||||||
|
if (ch !== 'general') {
|
||||||
|
setupNotifVerifiedSigs[ch] = getNotifChannelSignature(ch, testedConfig);
|
||||||
|
}
|
||||||
html += `<div style="font-size:13px;color:var(--green);background:rgba(50,213,131,0.1);border:1px solid rgba(50,213,131,0.3);padding:9px 12px;border-radius:8px;display:flex;align-items:center;gap:8px"><span>✅</span> <strong>${chName} :</strong> <span>${info.message || 'Succès'}</span></div>`;
|
html += `<div style="font-size:13px;color:var(--green);background:rgba(50,213,131,0.1);border:1px solid rgba(50,213,131,0.3);padding:9px 12px;border-radius:8px;display:flex;align-items:center;gap:8px"><span>✅</span> <strong>${chName} :</strong> <span>${info.message || 'Succès'}</span></div>`;
|
||||||
} else {
|
} else {
|
||||||
|
if (ch !== 'general') {
|
||||||
|
delete setupNotifVerifiedSigs[ch];
|
||||||
|
}
|
||||||
html += `<div style="font-size:13px;color:var(--red);background:rgba(255,107,107,0.1);border:1px solid rgba(255,107,107,0.3);padding:9px 12px;border-radius:8px;display:flex;align-items:center;gap:8px"><span>❌</span> <strong>${chName} :</strong> <span>${info.error || 'Échec'}</span></div>`;
|
html += `<div style="font-size:13px;color:var(--red);background:rgba(255,107,107,0.1);border:1px solid rgba(255,107,107,0.3);padding:9px 12px;border-radius:8px;display:flex;align-items:center;gap:8px"><span>❌</span> <strong>${chName} :</strong> <span>${info.error || 'Échec'}</span></div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
if (detailsBox) detailsBox.innerHTML = html;
|
if (detailsBox) detailsBox.innerHTML = html;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (channel && channel !== 'all') {
|
||||||
|
delete setupNotifVerifiedSigs[channel];
|
||||||
|
} else {
|
||||||
|
Object.keys(setupNotifVerifiedSigs).forEach(k => delete setupNotifVerifiedSigs[k]);
|
||||||
|
}
|
||||||
if (detailsBox) {
|
if (detailsBox) {
|
||||||
detailsBox.innerHTML = `<div style="font-size:13px;color:var(--red);background:rgba(255,107,107,0.1);border:1px solid rgba(255,107,107,0.3);padding:9px 12px;border-radius:8px;margin-bottom:12px;display:flex;align-items:center;gap:8px"><span>❌</span> <strong>${t('notif_test_err', 'Erreur lors du test : ')}</strong> <span>${e.message}</span></div>`;
|
detailsBox.innerHTML = `<div style="font-size:13px;color:var(--red);background:rgba(255,107,107,0.1);border:1px solid rgba(255,107,107,0.3);padding:9px 12px;border-radius:8px;margin-bottom:12px;display:flex;align-items:center;gap:8px"><span>❌</span> <strong>${t('notif_test_err', 'Erreur lors du test : ')}</strong> <span>${e.message}</span></div>`;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
updateStep4ContinueState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3573,7 +3595,7 @@
|
|||||||
{ id: 'notifWebhookEnabled', name: 'Webhook' }
|
{ id: 'notifWebhookEnabled', name: 'Webhook' }
|
||||||
];
|
];
|
||||||
let activeChannels = [];
|
let activeChannels = [];
|
||||||
if (notifSt.anyConfigured) {
|
if (notifSt.ready) {
|
||||||
channels.forEach(c => {
|
channels.forEach(c => {
|
||||||
if ($(c.id) && $(c.id).checked) activeChannels.push(c.name);
|
if ($(c.id) && $(c.id).checked) activeChannels.push(c.name);
|
||||||
});
|
});
|
||||||
@@ -3625,7 +3647,7 @@
|
|||||||
if (stepNum < 1 || stepNum > 6) return;
|
if (stepNum < 1 || stepNum > 6) return;
|
||||||
if (currentStep === 4 && stepNum > 4) {
|
if (currentStep === 4 && stepNum > 4) {
|
||||||
const st = getStep4NotificationStatus();
|
const st = getStep4NotificationStatus();
|
||||||
if (st.anyChecked && !st.anyConfigured) {
|
if (st.anyChecked && !st.ready) {
|
||||||
updateStep4ContinueState();
|
updateStep4ContinueState();
|
||||||
selectSetupNotifSubTab('services');
|
selectSetupNotifSubTab('services');
|
||||||
return;
|
return;
|
||||||
@@ -3733,19 +3755,26 @@
|
|||||||
function getStep4NotificationStatus() {
|
function getStep4NotificationStatus() {
|
||||||
const p = getNotificationFormPayload();
|
const p = getNotificationFormPayload();
|
||||||
const checks = [
|
const checks = [
|
||||||
{ en: p.email.enabled, ok: !!(p.email.smtp_host && p.email.to_addr) },
|
{ key: 'email', en: p.email.enabled, ok: !!(p.email.smtp_host && p.email.to_addr) },
|
||||||
{ en: p.gotify.enabled, ok: !!(p.gotify.server_url && p.gotify.token) },
|
{ key: 'gotify', en: p.gotify.enabled, ok: !!(p.gotify.server_url && p.gotify.token) },
|
||||||
{ en: p.discord.enabled, ok: !!p.discord.webhook_url },
|
{ key: 'discord', en: p.discord.enabled, ok: !!p.discord.webhook_url },
|
||||||
{ en: p.ntfy.enabled, ok: !!(p.ntfy.server_url && p.ntfy.topic) },
|
{ key: 'ntfy', en: p.ntfy.enabled, ok: !!(p.ntfy.server_url && p.ntfy.topic) },
|
||||||
{ en: p.pushbullet.enabled, ok: !!p.pushbullet.api_token },
|
{ key: 'pushbullet', en: p.pushbullet.enabled, ok: !!p.pushbullet.api_token },
|
||||||
{ en: p.pushover.enabled, ok: !!(p.pushover.user_key && p.pushover.api_token) },
|
{ key: 'pushover', en: p.pushover.enabled, ok: !!(p.pushover.user_key && p.pushover.api_token) },
|
||||||
{ en: p.slack.enabled, ok: !!p.slack.webhook_url },
|
{ key: 'slack', en: p.slack.enabled, ok: !!p.slack.webhook_url },
|
||||||
{ en: p.telegram.enabled, ok: !!(p.telegram.bot_token && p.telegram.chat_id) },
|
{ key: 'telegram', en: p.telegram.enabled, ok: !!(p.telegram.bot_token && p.telegram.chat_id) },
|
||||||
{ en: p.webhook.enabled, ok: !!p.webhook.url }
|
{ key: 'webhook', en: p.webhook.enabled, ok: !!p.webhook.url }
|
||||||
];
|
];
|
||||||
|
const enabledList = checks.filter(c => c.en);
|
||||||
|
const anyChecked = enabledList.length > 0;
|
||||||
|
const allEnabledConfigured = anyChecked && enabledList.every(c => c.ok);
|
||||||
|
const allEnabledVerified = allEnabledConfigured && enabledList.every(c => setupNotifVerifiedSigs[c.key] === getNotifChannelSignature(c.key, p));
|
||||||
return {
|
return {
|
||||||
anyChecked: checks.some(c => c.en),
|
anyChecked,
|
||||||
anyConfigured: checks.some(c => c.en && c.ok)
|
anyConfigured: allEnabledConfigured,
|
||||||
|
allEnabledConfigured,
|
||||||
|
allEnabledVerified,
|
||||||
|
ready: allEnabledVerified
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3755,19 +3784,26 @@
|
|||||||
const st = getStep4NotificationStatus();
|
const st = getStep4NotificationStatus();
|
||||||
const isEn = currentLanguage.startsWith('en');
|
const isEn = currentLanguage.startsWith('en');
|
||||||
|
|
||||||
if (!st.anyConfigured) {
|
if (!st.ready) {
|
||||||
if (btn) {
|
if (btn) {
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
btn.style.opacity = '0.5';
|
btn.style.opacity = '0.5';
|
||||||
btn.style.cursor = 'not-allowed';
|
btn.style.cursor = 'not-allowed';
|
||||||
}
|
}
|
||||||
const msg = st.anyChecked
|
let msg;
|
||||||
? (isEn
|
if (!st.anyChecked) {
|
||||||
? '⚠️ Please fill in the required fields for the enabled notification service (URL, token, recipient...) to continue, or click "Skip".'
|
msg = isEn
|
||||||
: '⚠️ Veuillez compléter les champs obligatoires du service de notification activé (URL, jeton, destinataire...) pour continuer, ou cliquez sur « Ignorer ».')
|
? '⚠️ Please enable, configure, and test at least one notification service to continue, or click "Skip".'
|
||||||
: (isEn
|
: '⚠️ Veuillez activer, configurer et tester au moins un service de notification pour continuer, ou cliquez sur « Ignorer ».';
|
||||||
? '⚠️ Please enable and configure at least one notification service to continue, or click "Skip".'
|
} else if (!st.allEnabledConfigured) {
|
||||||
: '⚠️ Veuillez activer et configurer au moins un service de notification pour continuer, ou cliquez sur « Ignorer ».');
|
msg = isEn
|
||||||
|
? '⚠️ Please fill in the required fields for each enabled notification service (URL, token, recipient...) to continue, or click "Skip".'
|
||||||
|
: '⚠️ Veuillez compléter les champs obligatoires de chaque service de notification activé (URL, jeton, destinataire...) pour continuer, ou cliquez sur « Ignorer ».';
|
||||||
|
} else {
|
||||||
|
msg = isEn
|
||||||
|
? '🧪 Please click "Test" and make sure the test succeeds before continuing (or click "Skip").'
|
||||||
|
: '🧪 Veuillez lancer un test réussi sur chaque service activé avant de pouvoir continuer (ou cliquez sur « Ignorer »).';
|
||||||
|
}
|
||||||
showError(errEl, msg);
|
showError(errEl, msg);
|
||||||
} else {
|
} else {
|
||||||
if (btn) {
|
if (btn) {
|
||||||
@@ -3784,6 +3820,7 @@
|
|||||||
const chk = $('notif' + cap + 'Enabled');
|
const chk = $('notif' + cap + 'Enabled');
|
||||||
if (chk) chk.checked = false;
|
if (chk) chk.checked = false;
|
||||||
});
|
});
|
||||||
|
Object.keys(setupNotifVerifiedSigs).forEach(k => delete setupNotifVerifiedSigs[k]);
|
||||||
toggleNotifFields();
|
toggleNotifFields();
|
||||||
if ($('step4Error')) $('step4Error').style.display = 'none';
|
if ($('step4Error')) $('step4Error').style.display = 'none';
|
||||||
goToStep(5);
|
goToStep(5);
|
||||||
@@ -3792,7 +3829,7 @@
|
|||||||
function validateStep4() {
|
function validateStep4() {
|
||||||
updateStep4ContinueState();
|
updateStep4ContinueState();
|
||||||
const st = getStep4NotificationStatus();
|
const st = getStep4NotificationStatus();
|
||||||
if (!st.anyConfigured) {
|
if (!st.ready) {
|
||||||
selectSetupNotifSubTab('services');
|
selectSetupNotifSubTab('services');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4033,7 +4070,7 @@
|
|||||||
if (!password || password !== confirmation) { goToStep(2); return validateStep2(); }
|
if (!password || password !== confirmation) { goToStep(2); return validateStep2(); }
|
||||||
if (!adminUser || !adminPass) { goToStep(3); return validateStep3(); }
|
if (!adminUser || !adminPass) { goToStep(3); return validateStep3(); }
|
||||||
const notifSt = getStep4NotificationStatus();
|
const notifSt = getStep4NotificationStatus();
|
||||||
if (notifSt.anyChecked && !notifSt.anyConfigured) { goToStep(4); return validateStep4(); }
|
if (notifSt.anyChecked && !notifSt.ready) { goToStep(4); return validateStep4(); }
|
||||||
|
|
||||||
isConfiguring = true;
|
isConfiguring = true;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
@@ -4122,8 +4159,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// E. Enregistrement des notifications (si au moins un service configuré)
|
// E. Enregistrement des notifications (si au moins un service configuré et testé)
|
||||||
if (notifSt.anyConfigured) {
|
if (notifSt.ready) {
|
||||||
msg.textContent = isEn ? '4/5 Saving notification channels & alert events…' : '4/5 Enregistrement des alertes et notifications…';
|
msg.textContent = isEn ? '4/5 Saving notification channels & alert events…' : '4/5 Enregistrement des alertes et notifications…';
|
||||||
if (progBar) progBar.style.width = '80%';
|
if (progBar) progBar.style.width = '80%';
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user