APmanageur Wi-Fi V1.0

This commit is contained in:
yoannmultigaming committed 2026-11-18 18:38:33 +01:00
1 parent c46d60d262
commit ed08f9c8d4
8 files changed
+915 -26

No files matched your search

+457 -24
View File
@@ -2888,6 +2888,10 @@
onclick="selectSettingsTab('custom')">
<span>🎨</span> <span data-i18n="settings_tab_custom">Personnalisation</span>
</button>
<button id="tabSettingsBackup" class="settings-nav-btn" type="button" role="tab" aria-selected="false"
onclick="selectSettingsTab('backup')">
<span>📦</span> <span data-i18n="settings_tab_backup">Sauvegardes</span>
</button>
<button id="tabSettingsDanger" class="settings-nav-btn" type="button" role="tab" aria-selected="false"
onclick="selectSettingsTab('danger')">
<span>⚠️</span> <span data-i18n="settings_tab_danger">Zone dangereuse</span>
@@ -4752,30 +4756,24 @@
</div>
<!-- 5. Zone dangereuse -->
<div id="panelSettingsDanger" class="settings-panel card" style="display:none">
<h2 data-i18n="danger_title">Zone dangereuse &amp; Maintenance</h2>
<p class="muted" data-i18n="danger_subtitle">Gestion des sauvegardes, restauration de la configuration et
actions critiques de maintenance du système.</p>
<!-- Module de Sauvegarde & Restauration (Export / Import) -->
<div
style="background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:18px;margin-top:16px">
<div
style="display:flex;align-items:flex-start;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-bottom:12px">
<div>
<strong style="font-size:15px;display:flex;align-items:center;gap:8px" data-i18n="danger_backup_title">
📦 Sauvegarde &amp; Restauration globale
</strong>
<p class="muted" style="margin:6px 0 0;font-size:13px;line-height:1.5" data-i18n="danger_backup_desc">
Exportez l'intégralité de la configuration système (réglages Wi-Fi, profils VPN WireGuard &amp; OpenVPN,
routages des équipements, noms et logos des appareils, liste noire de blocage et base de données SQLite)
dans un fichier sécurisé, ou restaurez une configuration précédente en un clic.
</p>
</div>
<!-- 7. Sauvegardes & Automatisation Cron -->
<div id="panelSettingsBackup" class="settings-panel card" style="display:none;max-width:960px">
<div style="display:flex;align-items:flex-start;justify-content:space-between;flex-wrap:wrap;gap:10px">
<div>
<h2 style="margin:0 0 4px" data-i18n="backup_tab_title">Sauvegardes &amp; Restauration</h2>
<p class="muted" style="margin:0" data-i18n="backup_tab_subtitle">Créez, planifiez (Cron), exportez, restaurez ou supprimez vos sauvegardes stockées dans le volume Docker.</p>
</div>
<span id="backupDirBadge" class="pill pill-blue pill-no-dot" style="font-size:12px;font-family:monospace">📁 /backups</span>
</div>
<div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:14px">
<button id="btnExportBackup" type="button" onclick="exportBackup()"
<!-- Actions rapides : Créer / Exporter / Importer -->
<div style="background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:16px;margin-top:16px">
<div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap">
<button id="btnCreateServerBackup" type="button" onclick="createServerBackupNow()"
style="display:inline-flex;align-items:center;gap:8px" data-i18n="backup_create_now_btn">
💾 Créer une sauvegarde maintenant
</button>
<button id="btnExportBackup" type="button" class="secondary" onclick="exportBackup()"
style="display:inline-flex;align-items:center;gap:8px" data-i18n="danger_export_btn">
📥 Exporter la configuration &amp; base de données
</button>
@@ -4791,7 +4789,111 @@
style="margin-top:12px;font-size:12px;display:none;padding:8px 12px;border-radius:6px"></div>
</div>
<div class="notice" style="margin-top:20px;border-color:rgba(239,68,68,0.3)">
<!-- Automatisation Cron -->
<div style="background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:18px;margin-top:16px">
<div style="display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-bottom:12px">
<div>
<strong style="font-size:15px;display:flex;align-items:center;gap:8px" data-i18n="backup_cron_title">
⏱️ Automatisation des sauvegardes (Cron)
</strong>
<p class="muted" style="margin:4px 0 0;font-size:13px" data-i18n="backup_cron_desc">
Planifiez des sauvegardes automatiques enregistrées dans le dossier configuré via Docker Compose.
</p>
</div>
<label style="display:inline-flex;align-items:center;gap:8px;cursor:pointer;font-weight:600;user-select:none">
<input type="checkbox" id="backupCronEnabled" style="width:auto;margin:0" onchange="onBackupCronToggle()">
<span data-i18n="backup_cron_enable">Activer la planification</span>
</label>
</div>
<div id="backupCronFields" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px;margin-top:12px">
<div>
<label class="label" for="backupCronDay" data-i18n="backup_cron_day_label">Fréquence / Jour</label>
<select id="backupCronDay" onchange="syncBackupCronFromSelects()">
<option value="*" data-i18n="stats_cron_day_all_short">Tous les jours</option>
<option value="1-5" data-i18n="stats_cron_day_workdays_short">Jours ouvrés (Lun-Ven)</option>
<option value="6,7" data-i18n="stats_cron_day_weekend_short">Week-end (Sam-Dim)</option>
<option value="1" data-i18n="stats_cron_day_mon">Chaque Lundi</option>
<option value="2" data-i18n="stats_cron_day_tue">Chaque Mardi</option>
<option value="3" data-i18n="stats_cron_day_wed">Chaque Mercredi</option>
<option value="4" data-i18n="stats_cron_day_thu">Chaque Jeudi</option>
<option value="5" data-i18n="stats_cron_day_fri">Chaque Vendredi</option>
<option value="6" data-i18n="stats_cron_day_sat">Chaque Samedi</option>
<option value="0" data-i18n="stats_cron_day_sun">Chaque Dimanche</option>
</select>
</div>
<div>
<label class="label" for="backupCronHour" data-i18n="backup_cron_hour_label">Heure</label>
<select id="backupCronHour" onchange="syncBackupCronFromSelects()"></select>
</div>
<div>
<label class="label" for="backupCronMinute" data-i18n="backup_cron_min_label">Minute</label>
<select id="backupCronMinute" onchange="syncBackupCronFromSelects()"></select>
</div>
<div>
<label class="label" for="backupCronRetention" data-i18n="backup_cron_retention_label">Rétention (0 = illimité)</label>
<input id="backupCronRetention" type="number" min="0" max="365" value="7">
</div>
</div>
<div style="display:grid;grid-template-columns:1fr auto;gap:10px;align-items:end;margin-top:12px">
<div>
<label class="label" for="backupCronExpr" data-i18n="backup_cron_expr_label">Expression Cron (minute heure jour mois jour_semaine)</label>
<input id="backupCronExpr" type="text" value="0 3 * * *" placeholder="0 3 * * *" style="font-family:monospace;margin-bottom:0" oninput="updateBackupCronSummary()">
</div>
<button id="btnSaveBackupSchedule" type="button" onclick="saveBackupSchedule()" data-i18n="backup_cron_save_btn">
💾 Enregistrer
</button>
</div>
<div style="display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;margin-top:10px">
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
<span id="backupCronHuman" class="pill pill-blue pill-no-dot" style="font-size:12px">📅 Tous les jours à 03:00</span>
<button type="button" class="secondary" style="padding:3px 9px;font-size:11px" onclick="applyBackupCronPreset('0 3 * * *','*',3,0)" data-i18n="backup_preset_daily">Chaque nuit 03:00</button>
<button type="button" class="secondary" style="padding:3px 9px;font-size:11px" onclick="applyBackupCronPreset('0 4 * * 0','0',4,0)" data-i18n="backup_preset_weekly">Dimanche 04:00</button>
<button type="button" class="secondary" style="padding:3px 9px;font-size:11px" onclick="applyBackupCronPreset('0 */6 * * *','*','*',0)" data-i18n="backup_preset_6h">Toutes les 6h</button>
</div>
<span id="backupCronLastRun" class="muted" style="font-size:12px"></span>
</div>
<div id="backupScheduleMsg" style="margin-top:10px;font-size:12px;display:none;padding:8px 12px;border-radius:6px"></div>
</div>
<!-- Liste des sauvegardes enregistrées -->
<div style="margin-top:20px">
<div class="topline" style="flex-wrap:wrap;gap:10px;margin-bottom:12px">
<div>
<h3 style="margin:0;font-size:16px" data-i18n="backup_list_title">📂 Sauvegardes enregistrées</h3>
<div id="backupsListSummary" class="muted" style="font-size:12px;margin-top:3px">—</div>
</div>
<button type="button" class="secondary" onclick="loadBackupsTab()" style="display:inline-flex;align-items:center;gap:6px" data-i18n="btn_refresh">
🔄 Actualiser
</button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th data-i18n="backup_th_file">FICHIER</th>
<th data-i18n="backup_th_type">TYPE</th>
<th data-i18n="backup_th_date">DATE</th>
<th data-i18n="backup_th_size">TAILLE</th>
<th data-i18n="backup_th_actions" style="text-align:right">ACTIONS</th>
</tr>
</thead>
<tbody id="backupsTableBody">
<tr><td colspan="5" class="empty" data-i18n="loading">Chargement…</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- 8. Zone dangereuse -->
<div id="panelSettingsDanger" class="settings-panel card" style="display:none">
<h2 data-i18n="danger_title">Zone dangereuse &amp; Maintenance</h2>
<p class="muted" data-i18n="danger_subtitle">Actions critiques de maintenance et réinitialisation complète du système.</p>
<div class="notice" style="margin-top:16px;border-color:rgba(239,68,68,0.3)">
<strong style="color:var(--red);display:flex;align-items:center;gap:6px" data-i18n="danger_delete_title">⚠️
Suppression irréversible</strong>
<p style="margin:8px 0 14px" data-i18n="danger_delete_desc">Supprime l’historique des logs, les appareils
@@ -7620,7 +7722,7 @@ ${vpnBadgeTopo}
function selectSettingsTab(tabKey) {
if (tabKey === '2fa') tabKey = 'admin';
currentSettingsTab = tabKey;
const tabs = ['wifi', 'admin', 'vpn', 'proxy', 'notif', 'custom', 'danger'];
const tabs = ['wifi', 'admin', 'vpn', 'proxy', 'notif', 'custom', 'backup', 'danger'];
tabs.forEach(k => {
const btnId = 'tabSettings' + k.charAt(0).toUpperCase() + k.slice(1);
const panelId = 'panelSettings' + k.charAt(0).toUpperCase() + k.slice(1);
@@ -7650,6 +7752,9 @@ ${vpnBadgeTopo}
if (tabKey === 'custom') {
if (typeof loadDeviceTypes === 'function') loadDeviceTypes();
}
if (tabKey === 'backup') {
if (typeof loadBackupsTab === 'function') loadBackupsTab();
}
}
let vpnTabRefreshTimer = null;
@@ -10405,6 +10510,334 @@ ${vpnBadgeTopo}
}
}
/* ============================================================
Onglet Sauvegardes : Planification Cron & Gestion des fichiers
============================================================ */
let serverBackupsCache = [];
function initBackupCronSelects() {
const hSel = $('backupCronHour');
const mSel = $('backupCronMinute');
if (hSel && hSel.options.length <= 1) {
let hHtml = '<option value="*">' + t('stats_cron_day_all', 'Toutes les heures (*)') + '</option>';
for (let i = 0; i < 24; i++) {
const v = String(i).padStart(2, '0');
hHtml += `<option value="${i}"${i === 3 ? ' selected' : ''}>${v}h (${v}:00)</option>`;
}
hSel.innerHTML = hHtml;
}
if (mSel && mSel.options.length <= 1) {
let mHtml = '';
for (let i = 0; i < 60; i++) {
const v = String(i).padStart(2, '0');
mHtml += `<option value="${i}"${i === 0 ? ' selected' : ''}>${v} min (:${v})</option>`;
}
mSel.innerHTML = mHtml;
}
}
function onBackupCronToggle() {
const en = !!($('backupCronEnabled') && $('backupCronEnabled').checked);
const box = $('backupCronFields');
if (box) box.style.opacity = en ? '1' : '0.65';
updateBackupCronSummary();
}
function syncBackupCronFromSelects() {
const d = $('backupCronDay')?.value || '*';
const h = $('backupCronHour')?.value ?? '3';
const m = $('backupCronMinute')?.value ?? '0';
const expr = `${m} ${h} * * ${d}`;
if ($('backupCronExpr')) $('backupCronExpr').value = expr;
updateBackupCronSummary();
}
function applyBackupCronPreset(expr, day, hour, minute) {
initBackupCronSelects();
if ($('backupCronEnabled')) $('backupCronEnabled').checked = true;
if ($('backupCronDay')) $('backupCronDay').value = String(day);
if ($('backupCronHour')) $('backupCronHour').value = String(hour);
if ($('backupCronMinute')) $('backupCronMinute').value = String(minute);
if ($('backupCronExpr')) $('backupCronExpr').value = expr;
onBackupCronToggle();
}
function updateBackupCronSummary() {
const badge = $('backupCronHuman');
if (!badge) return;
const expr = ($('backupCronExpr')?.value || '').trim();
const parts = expr.split(/\s+/);
if (parts.length !== 5) {
badge.textContent = '⚠️ ' + t('backup_cron_invalid', 'Expression Cron invalide (5 champs requis)');
return;
}
const [minPart, hourPart, domPart, monthPart, dowPart] = parts;
if (domPart !== '*' || monthPart !== '*' || hourPart.includes('/') || minPart.includes('/')) {
badge.textContent = '⚙️ Cron : ' + expr;
return;
}
const daysMap = {
'*': t('stats_cron_day_all_short', 'Tous les jours'),
'1-5': t('stats_cron_day_workdays_short', 'Jours ouvrés (Lun-Ven)'),
'6,7': t('stats_cron_day_weekend_short', 'Week-end (Sam-Dim)'),
'1': t('stats_cron_day_mon', 'Chaque Lundi'),
'2': t('stats_cron_day_tue', 'Chaque Mardi'),
'3': t('stats_cron_day_wed', 'Chaque Mercredi'),
'4': t('stats_cron_day_thu', 'Chaque Jeudi'),
'5': t('stats_cron_day_fri', 'Chaque Vendredi'),
'6': t('stats_cron_day_sat', 'Chaque Samedi'),
'0': t('stats_cron_day_sun', 'Chaque Dimanche'),
'7': t('stats_cron_day_sun', 'Chaque Dimanche')
};
const dStr = daysMap[dowPart] || (t('stats_cron_day_prefix', 'Jour ') + dowPart);
let timeStr = '';
if (hourPart === '*') {
timeStr = t('stats_cron_hourly_at', 'toutes les heures à :{min}').replace('{min}', String(minPart).padStart(2, '0'));
} else {
timeStr = t('stats_cron_at_time', 'à {time}').replace('{time}', `${String(hourPart).padStart(2, '0')}:${String(minPart).padStart(2, '0')}`);
}
badge.textContent = `📅 ${dStr} ${timeStr}`;
}
function renderServerBackupsTable(backups, totalSizeStr) {
serverBackupsCache = Array.isArray(backups) ? backups : [];
const tbody = $('backupsTableBody');
const summary = $('backupsListSummary');
if (summary) {
summary.textContent = t('backup_list_summary', '{count} sauvegarde(s) • Espace utilisé : {size}')
.replace('{count}', String(serverBackupsCache.length))
.replace('{size}', totalSizeStr || '0 o');
}
if (!tbody) return;
if (!serverBackupsCache.length) {
tbody.innerHTML = `<tr><td colspan="5" class="empty">${escapeHtml(t('backup_list_empty', 'Aucune sauvegarde dans le dossier pour le moment.'))}</td></tr>`;
return;
}
tbody.innerHTML = serverBackupsCache.map(bk => {
const fname = bk.filename || '';
const safeArg = escapeHtml(fname).replace(/'/g, '&#39;');
const typePill = bk.trigger === 'auto'
? `<span class="pill pill-green pill-no-dot" style="font-size:11px;padding:2px 8px">🤖 ${escapeHtml(t('backup_type_auto', 'Auto (Cron)'))}</span>`
: (bk.trigger === 'manual'
? `<span class="pill pill-blue pill-no-dot" style="font-size:11px;padding:2px 8px">👤 ${escapeHtml(t('backup_type_manual', 'Manuel'))}</span>`
: `<span class="pill pill-no-dot" style="font-size:11px;padding:2px 8px">📄 ${escapeHtml(t('backup_type_external', 'Externe'))}</span>`);
return `<tr>
<td style="font-family:monospace;font-size:12px;word-break:break-all"><strong>${escapeHtml(fname)}</strong></td>
<td>${typePill}</td>
<td style="white-space:nowrap;font-size:12px" class="muted">${escapeHtml(bk.created_at || '—')}</td>
<td style="white-space:nowrap;font-size:12px">${escapeHtml(bk.size_str || '—')}</td>
<td style="text-align:right;white-space:nowrap">
<div style="display:inline-flex;gap:6px;flex-wrap:wrap;justify-content:flex-end">
<button type="button" class="secondary" style="padding:5px 10px;font-size:12px" onclick="downloadServerBackup('${safeArg}')" title="${escapeHtml(t('backup_btn_export', 'Exporter'))}">⬇️ ${escapeHtml(t('backup_btn_export', 'Exporter'))}</button>
<button type="button" class="secondary" style="padding:5px 10px;font-size:12px;border-color:var(--blue);color:var(--blue)" onclick="restoreServerBackup('${safeArg}')" title="${escapeHtml(t('backup_btn_restore', 'Restaurer'))}">♻️ ${escapeHtml(t('backup_btn_restore', 'Restaurer'))}</button>
<button type="button" class="secondary danger" style="padding:5px 10px;font-size:12px;border-color:rgba(239,68,68,0.45);color:var(--red)" onclick="deleteServerBackup('${safeArg}')" title="${escapeHtml(t('btn_delete', 'Supprimer'))}">🗑️</button>
</div>
</td>
</tr>`;
}).join('');
}
function applyBackupScheduleToUI(sched) {
if (!sched) return;
initBackupCronSelects();
if ($('backupCronEnabled')) $('backupCronEnabled').checked = !!sched.enabled;
if ($('backupCronDay') && sched.day !== undefined) $('backupCronDay').value = String(sched.day);
if ($('backupCronHour') && sched.hour !== undefined) $('backupCronHour').value = String(sched.hour);
if ($('backupCronMinute') && sched.minute !== undefined) $('backupCronMinute').value = String(sched.minute);
if ($('backupCronRetention') && sched.retention !== undefined) $('backupCronRetention').value = String(sched.retention);
if ($('backupCronExpr') && sched.cron_expr) $('backupCronExpr').value = sched.cron_expr;
if ($('backupCronLastRun')) {
$('backupCronLastRun').textContent = sched.last_run
? `${t('backup_last_run', 'Dernière exécution :')} ${sched.last_run}${sched.last_file ? ' (' + sched.last_file + ')' : ''}`
: t('backup_never_run', 'Aucune exécution enregistrée');
}
onBackupCronToggle();
}
async function loadBackupsTab() {
initBackupCronSelects();
try {
const res = await apiFetch('/api/backups/list', { cache: 'no-store' });
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Erreur chargement sauvegardes');
if ($('backupDirBadge') && d.backup_dir) $('backupDirBadge').textContent = '📁 ' + d.backup_dir;
applyBackupScheduleToUI(d.schedule);
renderServerBackupsTable(d.backups || [], d.total_size_str || '0 o');
} catch (e) {
const tbody = $('backupsTableBody');
if (tbody) tbody.innerHTML = `<tr><td colspan="5" class="empty">${escapeHtml(tErr(e.message))}</td></tr>`;
}
}
async function saveBackupSchedule() {
const msg = $('backupScheduleMsg');
const btn = $('btnSaveBackupSchedule');
const expr = ($('backupCronExpr')?.value || '').trim();
if (expr.split(/\s+/).length !== 5) {
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = t('backup_cron_invalid', 'Expression Cron invalide (5 champs requis)');
}
return;
}
if (btn) btn.disabled = true;
try {
const payload = {
enabled: !!($('backupCronEnabled') && $('backupCronEnabled').checked),
day: $('backupCronDay')?.value || '*',
hour: $('backupCronHour')?.value ?? '3',
minute: parseInt($('backupCronMinute')?.value || '0', 10) || 0,
retention: parseInt($('backupCronRetention')?.value || '7', 10) || 0,
cron_expr: expr
};
const res = await apiFetch('/api/backups/schedule', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Erreur enregistrement');
applyBackupScheduleToUI(d.schedule);
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(50,213,131,0.12)';
msg.style.color = 'var(--green)';
msg.textContent = '✓ ' + t('backup_schedule_saved', 'Planification Cron enregistrée avec succès !');
setTimeout(() => { if (msg) msg.style.display = 'none'; }, 5000);
}
} catch (e) {
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = '❌ ' + tErr(e.message);
}
} finally {
if (btn) btn.disabled = false;
}
}
async function createServerBackupNow() {
const msg = $('backupActionMsg');
const btn = $('btnCreateServerBackup');
if (btn) btn.disabled = true;
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(56,189,248,0.12)';
msg.style.color = 'var(--blue)';
msg.textContent = t('backup_creating_server', 'Création de la sauvegarde sur le serveur en cours…');
}
try {
const res = await apiFetch('/api/backups/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Erreur création sauvegarde');
if (d.schedule) applyBackupScheduleToUI(d.schedule);
renderServerBackupsTable(d.backups || [], d.total_size_str || '0 o');
if (msg) {
msg.style.background = 'rgba(50,213,131,0.12)';
msg.style.color = 'var(--green)';
msg.textContent = '✓ ' + (d.message || t('backup_created_success', 'Sauvegarde créée avec succès !'));
setTimeout(() => { if (msg) msg.style.display = 'none'; }, 6000);
}
} catch (e) {
if (msg) {
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = '❌ ' + tErr(e.message);
}
} finally {
if (btn) btn.disabled = false;
}
}
async function downloadServerBackup(filename) {
const msg = $('backupActionMsg');
try {
const res = await apiFetch('/api/backups/download?file=' + encodeURIComponent(filename));
if (!res.ok) {
let errText = 'Erreur téléchargement';
try { const d = await res.json(); if (d.error) errText = d.error; } catch (_) { }
throw new Error(errText);
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 2000);
} catch (e) {
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = '❌ ' + tErr(e.message);
}
}
}
async function restoreServerBackup(filename) {
const msg = $('backupActionMsg');
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(56,189,248,0.12)';
msg.style.color = 'var(--blue)';
msg.textContent = t('backup_analyzing', 'Analyse de la sauvegarde en cours…');
}
try {
const res = await apiFetch('/api/backups/inspect', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename })
});
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Fichier invalide');
if (msg) msg.style.display = 'none';
pendingBackupData = d.backup;
showImportBackupModal(filename, d.backup);
} catch (e) {
if (msg) {
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = '❌ ' + tErr(e.message);
}
}
}
async function deleteServerBackup(filename) {
const confirmTxt = t('backup_confirm_delete', 'Supprimer définitivement la sauvegarde « {file} » ?').replace('{file}', filename);
if (!confirm(confirmTxt)) return;
const msg = $('backupActionMsg');
try {
const res = await apiFetch('/api/backups/delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename })
});
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Erreur suppression');
renderServerBackupsTable(d.backups || [], d.total_size_str || '0 o');
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(50,213,131,0.12)';
msg.style.color = 'var(--green)';
msg.textContent = '✓ ' + (d.message || t('backup_deleted_success', 'Sauvegarde supprimée.'));
setTimeout(() => { if (msg) msg.style.display = 'none'; }, 5000);
}
} catch (e) {
if (msg) {
msg.style.display = 'block';
msg.style.background = 'rgba(239,68,68,0.12)';
msg.style.color = 'var(--red)';
msg.textContent = '❌ ' + tErr(e.message);
}
}
}
const EYE_OPEN = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-8 10-8 10 8 10 8-3.5 8-10 8S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>';
const EYE_OFF = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 4.2A10.7 10.7 0 0 1 12 4c5 0 8.5 4 10 8a16.7 16.7 0 0 1-3.1 4.8M6.6 6.6C4.7 7.8 3.5 9.7 2 12c1.5 4 5 8 10 8 1 0 2-.2 2.9-.5"/></svg>';
const REGISTERED_PASSWORD_TOGGLES = [];