Actions critiques de maintenance et réinitialisation complète du système.
⚠️
Suppression irréversible
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 = '';
+ for (let i = 0; i < 24; i++) {
+ const v = String(i).padStart(2, '0');
+ hHtml += ``;
+ }
+ 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 += ``;
+ }
+ 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 = `
| ${escapeHtml(t('backup_list_empty', 'Aucune sauvegarde dans le dossier pour le moment.'))} |
`;
+ return;
+ }
+ tbody.innerHTML = serverBackupsCache.map(bk => {
+ const fname = bk.filename || '';
+ const safeArg = escapeHtml(fname).replace(/'/g, ''');
+ const typePill = bk.trigger === 'auto'
+ ? `
🤖 ${escapeHtml(t('backup_type_auto', 'Auto (Cron)'))}`
+ : (bk.trigger === 'manual'
+ ? `
👤 ${escapeHtml(t('backup_type_manual', 'Manuel'))}`
+ : `
📄 ${escapeHtml(t('backup_type_external', 'Externe'))}`);
+ return `
+ | ${escapeHtml(fname)} |
+ ${typePill} |
+ ${escapeHtml(bk.created_at || '—')} |
+ ${escapeHtml(bk.size_str || '—')} |
+
+
+
+
+
+
+ |
+
`;
+ }).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 = `
| ${escapeHtml(tErr(e.message))} |
`;
+ }
+ }
+
+ 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 = '
';
const EYE_OFF = '
';
const REGISTERED_PASSWORD_TOGGLES = [];
diff --git a/lang/en-gb.js b/lang/en-gb.js
index 80446f4..aa97017 100644
--- a/lang/en-gb.js
+++ b/lang/en-gb.js
@@ -1160,4 +1160,42 @@ window.I18N['en-gb'] = {
"tip_switch_to_ap": "Switch instantly to AP Mode (Router/NAT)",
"tip_switch_to_bridge": "Switch instantly to Bridge Mode (Router DHCP)",
"mode_switching": "Switching…",
+ "settings_tab_backup": "Backups",
+ "backup_tab_title": "Backups & Restore",
+ "backup_tab_subtitle": "Create, schedule (Cron), export, restore, or delete backups stored in the Docker volume.",
+ "backup_create_now_btn": "💾 Create Backup Now",
+ "backup_cron_title": "⏱️ Automated Backups (Cron)",
+ "backup_cron_desc": "Schedule automatic backups saved into the directory configured via Docker Compose.",
+ "backup_cron_enable": "Enable Schedule",
+ "backup_cron_day_label": "Frequency / Day",
+ "backup_cron_hour_label": "Hour",
+ "backup_cron_min_label": "Minute",
+ "backup_cron_retention_label": "Retention (0 = unlimited)",
+ "backup_cron_expr_label": "Cron Expression (minute hour day month weekday)",
+ "backup_cron_save_btn": "💾 Save",
+ "backup_cron_invalid": "Invalid Cron expression (5 fields required)",
+ "backup_preset_daily": "Every night 03:00",
+ "backup_preset_weekly": "Sunday 04:00",
+ "backup_preset_6h": "Every 6h",
+ "backup_list_title": "📂 Saved Backups",
+ "backup_list_summary": "{count} backup(s) • Disk usage: {size}",
+ "backup_list_empty": "No backups in the directory yet.",
+ "backup_th_file": "FILE",
+ "backup_th_type": "TYPE",
+ "backup_th_date": "DATE",
+ "backup_th_size": "SIZE",
+ "backup_th_actions": "ACTIONS",
+ "backup_type_auto": "Auto (Cron)",
+ "backup_type_manual": "Manual",
+ "backup_type_external": "External",
+ "backup_btn_export": "Export",
+ "backup_btn_restore": "Restore",
+ "backup_last_run": "Last run:",
+ "backup_never_run": "No run recorded yet",
+ "backup_schedule_saved": "Cron schedule saved successfully!",
+ "backup_creating_server": "Creating backup on server…",
+ "backup_created_success": "Backup created successfully!",
+ "backup_analyzing": "Inspecting backup file…",
+ "backup_confirm_delete": "Permanently delete backup \"{file}\"?",
+ "backup_deleted_success": "Backup deleted."
};
diff --git a/lang/en-us.js b/lang/en-us.js
index 05acb9f..3288c6b 100644
--- a/lang/en-us.js
+++ b/lang/en-us.js
@@ -1160,4 +1160,42 @@ window.I18N['en-us'] = {
"tip_switch_to_ap": "Switch instantly to AP Mode (Router/NAT)",
"tip_switch_to_bridge": "Switch instantly to Bridge Mode (Router DHCP)",
"mode_switching": "Switching…",
+ "settings_tab_backup": "Backups",
+ "backup_tab_title": "Backups & Restore",
+ "backup_tab_subtitle": "Create, schedule (Cron), export, restore, or delete backups stored in the Docker volume.",
+ "backup_create_now_btn": "💾 Create Backup Now",
+ "backup_cron_title": "⏱️ Automated Backups (Cron)",
+ "backup_cron_desc": "Schedule automatic backups saved into the directory configured via Docker Compose.",
+ "backup_cron_enable": "Enable Schedule",
+ "backup_cron_day_label": "Frequency / Day",
+ "backup_cron_hour_label": "Hour",
+ "backup_cron_min_label": "Minute",
+ "backup_cron_retention_label": "Retention (0 = unlimited)",
+ "backup_cron_expr_label": "Cron Expression (minute hour day month weekday)",
+ "backup_cron_save_btn": "💾 Save",
+ "backup_cron_invalid": "Invalid Cron expression (5 fields required)",
+ "backup_preset_daily": "Every night 03:00",
+ "backup_preset_weekly": "Sunday 04:00",
+ "backup_preset_6h": "Every 6h",
+ "backup_list_title": "📂 Saved Backups",
+ "backup_list_summary": "{count} backup(s) • Disk usage: {size}",
+ "backup_list_empty": "No backups in the directory yet.",
+ "backup_th_file": "FILE",
+ "backup_th_type": "TYPE",
+ "backup_th_date": "DATE",
+ "backup_th_size": "SIZE",
+ "backup_th_actions": "ACTIONS",
+ "backup_type_auto": "Auto (Cron)",
+ "backup_type_manual": "Manual",
+ "backup_type_external": "External",
+ "backup_btn_export": "Export",
+ "backup_btn_restore": "Restore",
+ "backup_last_run": "Last run:",
+ "backup_never_run": "No run recorded yet",
+ "backup_schedule_saved": "Cron schedule saved successfully!",
+ "backup_creating_server": "Creating backup on server…",
+ "backup_created_success": "Backup created successfully!",
+ "backup_analyzing": "Inspecting backup file…",
+ "backup_confirm_delete": "Permanently delete backup \"{file}\"?",
+ "backup_deleted_success": "Backup deleted."
};
diff --git a/lang/fr.js b/lang/fr.js
index 65b6d4b..8c0182c 100644
--- a/lang/fr.js
+++ b/lang/fr.js
@@ -1160,4 +1160,42 @@ window.I18N['fr'] = {
"tip_switch_to_ap": "Basculer instantanément en Mode AP (Routeur/NAT)",
"tip_switch_to_bridge": "Basculer instantanément en Mode Pont (DHCP Box)",
"mode_switching": "Bascule…",
+ "settings_tab_backup": "Sauvegardes",
+ "backup_tab_title": "Sauvegardes & Restauration",
+ "backup_tab_subtitle": "Créez, planifiez (Cron), exportez, restaurez ou supprimez vos sauvegardes stockées dans le volume Docker.",
+ "backup_create_now_btn": "💾 Créer une sauvegarde maintenant",
+ "backup_cron_title": "⏱️ Automatisation des sauvegardes (Cron)",
+ "backup_cron_desc": "Planifiez des sauvegardes automatiques enregistrées dans le dossier configuré via Docker Compose.",
+ "backup_cron_enable": "Activer la planification",
+ "backup_cron_day_label": "Fréquence / Jour",
+ "backup_cron_hour_label": "Heure",
+ "backup_cron_min_label": "Minute",
+ "backup_cron_retention_label": "Rétention (0 = illimité)",
+ "backup_cron_expr_label": "Expression Cron (minute heure jour mois jour_semaine)",
+ "backup_cron_save_btn": "💾 Enregistrer",
+ "backup_cron_invalid": "Expression Cron invalide (5 champs requis)",
+ "backup_preset_daily": "Chaque nuit 03:00",
+ "backup_preset_weekly": "Dimanche 04:00",
+ "backup_preset_6h": "Toutes les 6h",
+ "backup_list_title": "📂 Sauvegardes enregistrées",
+ "backup_list_summary": "{count} sauvegarde(s) • Espace utilisé : {size}",
+ "backup_list_empty": "Aucune sauvegarde dans le dossier pour le moment.",
+ "backup_th_file": "FICHIER",
+ "backup_th_type": "TYPE",
+ "backup_th_date": "DATE",
+ "backup_th_size": "TAILLE",
+ "backup_th_actions": "ACTIONS",
+ "backup_type_auto": "Auto (Cron)",
+ "backup_type_manual": "Manuel",
+ "backup_type_external": "Externe",
+ "backup_btn_export": "Exporter",
+ "backup_btn_restore": "Restaurer",
+ "backup_last_run": "Dernière exécution :",
+ "backup_never_run": "Aucune exécution enregistrée",
+ "backup_schedule_saved": "Planification Cron enregistrée avec succès !",
+ "backup_creating_server": "Création de la sauvegarde sur le serveur en cours…",
+ "backup_created_success": "Sauvegarde créée avec succès !",
+ "backup_analyzing": "Analyse de la sauvegarde en cours…",
+ "backup_confirm_delete": "Supprimer définitivement la sauvegarde « {file} » ?",
+ "backup_deleted_success": "Sauvegarde supprimée."
};