AP manageur V1.2 (Bêta)
This commit is contained in:
1 parent
c48d5beae0
commit
188497ae79
7 files changed
+604
-75
No files matched your search
@@ -8858,6 +8858,29 @@ def fetch_iconify_svg(clean_name, color=None):
|
||||
short_label = (name.split('-')[0] if '-' in name else name)[:6].upper()
|
||||
return f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1.15em" height="1.15em" fill="none" stroke="{fallback_color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="2" width="20" height="20" rx="4"/><text x="12" y="16" font-size="9" text-anchor="middle" fill="{fallback_color}" stroke="none" font-weight="bold">{short_label}</text></svg>'
|
||||
|
||||
_restore_data_lock = threading.Lock()
|
||||
_restore_data_state = {
|
||||
'running': False,
|
||||
'step': 0,
|
||||
'total_steps': 5,
|
||||
'percent': 0,
|
||||
'message': '',
|
||||
'details': '',
|
||||
'done': False,
|
||||
'error': None
|
||||
}
|
||||
|
||||
def _set_restore_progress(step, total_steps, percent, message, details='', done=False, error=None):
|
||||
with _restore_data_lock:
|
||||
_restore_data_state['running'] = not done and error is None
|
||||
_restore_data_state['step'] = step
|
||||
_restore_data_state['total_steps'] = total_steps
|
||||
_restore_data_state['percent'] = percent
|
||||
_restore_data_state['message'] = message
|
||||
_restore_data_state['details'] = details
|
||||
_restore_data_state['done'] = done
|
||||
_restore_data_state['error'] = error
|
||||
|
||||
|
||||
def export_backup_data():
|
||||
c = db()
|
||||
@@ -8998,6 +9021,9 @@ def import_backup_data(payload, options=None):
|
||||
ensure_vpn_dirs()
|
||||
c = db()
|
||||
try:
|
||||
_set_restore_progress(2, 5, 40, "Restauration des réglages & préférences...", "Application des réglages système et des catégories...")
|
||||
time.sleep(0.35)
|
||||
|
||||
# 1. Catégories d'appareils
|
||||
if restore_categories and 'custom_device_types' in backup and isinstance(backup['custom_device_types'], list):
|
||||
for dt in backup['custom_device_types']:
|
||||
@@ -9019,6 +9045,9 @@ def import_backup_data(payload, options=None):
|
||||
''', (dt_id, label, icon, desc, order))
|
||||
stats['custom_device_types'] += 1
|
||||
|
||||
_set_restore_progress(3, 5, 65, "Restauration des équipements & quotas...", "Enregistrement des appareils et quotas réseau...")
|
||||
time.sleep(0.35)
|
||||
|
||||
# 2. Noms d'appareils & types
|
||||
if restore_devices and 'client_names' in backup and isinstance(backup['client_names'], list):
|
||||
for cn in backup['client_names']:
|
||||
@@ -9081,6 +9110,9 @@ def import_backup_data(payload, options=None):
|
||||
c.execute("INSERT INTO preferences(key, value) VALUES(?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value", (str(k), str(v)))
|
||||
stats['preferences'] += 1
|
||||
|
||||
_set_restore_progress(4, 5, 85, "Restauration des profils VPN & routages...", "Configuration des tunnels et assignation du trafic...")
|
||||
time.sleep(0.35)
|
||||
|
||||
# 5. Profils VPN et routage
|
||||
if restore_vpn and 'vpn_profiles' in backup and isinstance(backup['vpn_profiles'], list):
|
||||
profile_id_map = {}
|
||||
@@ -9234,6 +9266,8 @@ def import_backup_data(payload, options=None):
|
||||
stats['api_keys'] = stats.get('api_keys', 0) + 1
|
||||
|
||||
c.commit()
|
||||
_set_restore_progress(5, 5, 95, "Reconfiguration Wi-Fi & synchronisation...", "Finalisation de la configuration réseau...")
|
||||
time.sleep(0.35)
|
||||
finally:
|
||||
c.close()
|
||||
return stats
|
||||
@@ -10646,6 +10680,7 @@ def _download_sftp(cfg, remote_filename, dest_path):
|
||||
password = str(cfg.get('password', ''))
|
||||
key_text = str(cfg.get('key', '')).strip()
|
||||
import paramiko
|
||||
import io
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
pkey = None
|
||||
@@ -10655,13 +10690,20 @@ def _download_sftp(cfg, remote_filename, dest_path):
|
||||
pkey = pkey_class.from_private_key(io.StringIO(key_text))
|
||||
break
|
||||
except Exception: pass
|
||||
sftp = None
|
||||
try:
|
||||
connect_kwargs = {'hostname': host, 'port': port, 'username': user, 'timeout': 20}
|
||||
if pkey: connect_kwargs['pkey'] = pkey
|
||||
elif password: connect_kwargs['password'] = password
|
||||
ssh.connect(**connect_kwargs)
|
||||
sftp = ssh.open_sftp()
|
||||
_, target_file = _normalize_sftp_target(sftp, cfg.get('path', ''), remote_filename)
|
||||
sftp.get(target_file, dest_path)
|
||||
return True
|
||||
finally:
|
||||
try: sftp.close()
|
||||
except Exception: pass
|
||||
if sftp:
|
||||
try: sftp.close()
|
||||
except Exception: pass
|
||||
try: ssh.close()
|
||||
except Exception: pass
|
||||
|
||||
@@ -11287,7 +11329,21 @@ API_MSG_I18N = {
|
||||
'Toutes les données ont été réinitialisées avec succès.': {'en-us': 'All data has been reset successfully.', 'en-gb': 'All data has been reset successfully.'},
|
||||
'Démarrage de la réinitialisation...': {'en-us': 'Starting reset process...', 'en-gb': 'Starting reset process...'},
|
||||
'Réinitialisation déjà en cours': {'en-us': 'Reset already in progress', 'en-gb': 'Reset already in progress'},
|
||||
'Réinitialisation en cours': {'en-us': 'Reset in progress', 'en-gb': 'Reset in progress'}
|
||||
'Réinitialisation en cours': {'en-us': 'Reset in progress', 'en-gb': 'Reset in progress'},
|
||||
'Analyse et vérification de la sauvegarde...': {'en-us': 'Analyzing and verifying backup...', 'en-gb': 'Analyzing and verifying backup...'},
|
||||
'Inspection du fichier et validation du format...': {'en-us': 'Inspecting file and validating format...', 'en-gb': 'Inspecting file and validating format...'},
|
||||
'Restauration des réglages & préférences...': {'en-us': 'Restoring settings & preferences...', 'en-gb': 'Restoring settings & preferences...'},
|
||||
'Application des réglages système et des catégories...': {'en-us': 'Applying system settings and categories...', 'en-gb': 'Applying system settings and categories...'},
|
||||
'Restauration des équipements & quotas...': {'en-us': 'Restoring devices & quotas...', 'en-gb': 'Restoring devices & quotas...'},
|
||||
'Enregistrement des appareils et quotas réseau...': {'en-us': 'Registering devices and network quotas...', 'en-gb': 'Registering devices and network quotas...'},
|
||||
'Restauration des profils VPN & routages...': {'en-us': 'Restoring VPN profiles & routing...', 'en-gb': 'Restoring VPN profiles & routing...'},
|
||||
'Configuration des tunnels et assignation du trafic...': {'en-us': 'Configuring tunnels and assigning traffic...', 'en-gb': 'Configuring tunnels and assigning traffic...'},
|
||||
'Reconfiguration Wi-Fi & synchronisation...': {'en-us': 'Wi-Fi reconfiguration & synchronization...', 'en-gb': 'Wi-Fi reconfiguration & synchronization...'},
|
||||
'Finalisation de la configuration réseau...': {'en-us': 'Finalizing network configuration...', 'en-gb': 'Finalizing network configuration...'},
|
||||
'Sauvegarde restaurée avec succès !': {'en-us': 'Backup restored successfully!', 'en-gb': 'Backup restored successfully!'},
|
||||
'Redirection et synchronisation finale...': {'en-us': 'Redirecting and final synchronization...', 'en-gb': 'Redirecting and final synchronization...'},
|
||||
'Restauration déjà en cours': {'en-us': 'Restoration already in progress', 'en-gb': 'Restoration already in progress'},
|
||||
'Restauration en cours': {'en-us': 'Restoration in progress', 'en-gb': 'Restoration in progress'}
|
||||
}
|
||||
|
||||
def translate_api_text(text, lang='fr'):
|
||||
@@ -11543,6 +11599,10 @@ class Handler(BaseHTTPRequestHandler):
|
||||
with _clear_data_lock:
|
||||
self.send_json(dict(_clear_data_state))
|
||||
return
|
||||
if self.path == '/api/backup/restore/progress':
|
||||
with _restore_data_lock:
|
||||
self.send_json(dict(_restore_data_state))
|
||||
return
|
||||
if self.path == '/api/device-types':
|
||||
c = db()
|
||||
rows = c.execute('SELECT id, label, icon, desc, sort_order FROM custom_device_types ORDER BY sort_order ASC, id ASC').fetchall()
|
||||
@@ -12436,6 +12496,10 @@ class Handler(BaseHTTPRequestHandler):
|
||||
was_active = False
|
||||
try: was_active = bool(status(force_refresh=True).get('active'))
|
||||
except Exception: pass
|
||||
|
||||
_set_restore_progress(1, 5, 20, "Analyse et vérification de la sauvegarde...", "Inspection du fichier et validation du format...")
|
||||
time.sleep(0.35)
|
||||
|
||||
if 'data_base64' in data and data['data_base64']:
|
||||
raw_bytes = base64.b64decode(data['data_base64'])
|
||||
backup = inspect_backup_bytes(raw_bytes, data.get('filename', ''))
|
||||
@@ -12443,6 +12507,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif 'filename' in data and data['filename'] and not data.get('backup'):
|
||||
full_path, clean_name = safe_backup_filepath(data['filename'])
|
||||
if not os.path.isfile(full_path):
|
||||
_set_restore_progress(1, 5, 20, "Fichier introuvable", error="Fichier de sauvegarde introuvable", done=True)
|
||||
self.send_json({'error': 'Fichier de sauvegarde introuvable'}, 404); return
|
||||
with open(full_path, 'rb') as f_read:
|
||||
raw_bytes = f_read.read()
|
||||
@@ -12454,12 +12519,14 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if not was_active and stats.get('preferences', 0) > 0 and get_pref('ap_ssid', '') and get_pref('ap_password', ''):
|
||||
threading.Thread(target=restore_ap_from_db, daemon=True).start()
|
||||
log('import_configuration_complete', username(self) or 'Administrateur', request_ip(self), 'BACKUP')
|
||||
_set_restore_progress(5, 5, 100, "Sauvegarde restaurée avec succès !", "Redirection et synchronisation finale...", done=True)
|
||||
self.send_json({
|
||||
'ok': True,
|
||||
'message': f"Sauvegarde restaurée avec succès ({stats.get('vpn_profiles',0)} profils VPN, {stats.get('client_names',0)} appareils, {stats.get('preferences',0)} réglages restaurés).",
|
||||
'stats': stats
|
||||
})
|
||||
except Exception as e:
|
||||
_set_restore_progress(5, 5, 100, f"Erreur : {e}", error=str(e), done=True)
|
||||
self.send_json({'error': f'Erreur lors de la restauration: {e}'}, 400)
|
||||
return
|
||||
if self.path == '/api/backups/remote/test':
|
||||
@@ -12920,17 +12987,25 @@ class Handler(BaseHTTPRequestHandler):
|
||||
fname = str(data.get('filename', '')).strip()
|
||||
full_path, clean_name = safe_backup_filepath(fname)
|
||||
if not os.path.isfile(full_path):
|
||||
_set_restore_progress(1, 5, 20, "Fichier introuvable", error="Fichier de sauvegarde introuvable", done=True)
|
||||
self.send_json({'error': 'Fichier de sauvegarde introuvable'}, 404); return
|
||||
raw_bytes = open(full_path, 'rb').read()
|
||||
backup = inspect_backup_bytes(raw_bytes, clean_name)
|
||||
stats = import_backup_data(backup, data.get('options', {}))
|
||||
invalidate_status_cache()
|
||||
log('import_configuration_complete', f"{username(self) or 'Administrateur'} ({clean_name})", request_ip(self), 'BACKUP')
|
||||
self.send_json({
|
||||
'ok': True,
|
||||
'message': f"Sauvegarde « {clean_name} » restaurée avec succès ({stats.get('vpn_profiles',0)} profils VPN, {stats.get('client_names',0)} appareils, {stats.get('preferences',0)} réglages).",
|
||||
'stats': stats
|
||||
}); return
|
||||
try:
|
||||
_set_restore_progress(1, 5, 20, "Analyse et vérification de la sauvegarde...", f"Chargement de {clean_name}...")
|
||||
time.sleep(0.35)
|
||||
raw_bytes = open(full_path, 'rb').read()
|
||||
backup = inspect_backup_bytes(raw_bytes, clean_name)
|
||||
stats = import_backup_data(backup, data.get('options', {}))
|
||||
invalidate_status_cache()
|
||||
log('import_configuration_complete', f"{username(self) or 'Administrateur'} ({clean_name})", request_ip(self), 'BACKUP')
|
||||
_set_restore_progress(5, 5, 100, "Sauvegarde restaurée avec succès !", "Redirection et synchronisation finale...", done=True)
|
||||
self.send_json({
|
||||
'ok': True,
|
||||
'message': f"Sauvegarde « {clean_name} » restaurée avec succès ({stats.get('vpn_profiles',0)} profils VPN, {stats.get('client_names',0)} appareils, {stats.get('preferences',0)} réglages).",
|
||||
'stats': stats
|
||||
}); return
|
||||
except Exception as e:
|
||||
_set_restore_progress(5, 5, 100, f"Erreur : {e}", error=str(e), done=True)
|
||||
self.send_json({'error': f'Erreur lors de la restauration: {e}'}, 400); return
|
||||
if self.path == '/api/backups/remote':
|
||||
rcfg = save_backup_remote_config(data)
|
||||
log('configuration_stockage_distant', f"{username(self) or 'Administrateur'} ({rcfg.get('provider', '')})", request_ip(self), 'BACKUP')
|
||||
|
||||
+220
-34
@@ -7295,6 +7295,81 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 12. Modal Progression Restauration des données -->
|
||||
<div id="modalRestoreProgress" class="modal-overlay" style="z-index:999999;backdrop-filter:blur(6px);background:rgba(0,0,0,0.85)">
|
||||
<div class="modal-card" style="max-width:480px;width:92%;padding:28px 24px;border:1px solid rgba(56,189,248,0.4);box-shadow:0 16px 40px rgba(0,0,0,0.6), 0 0 30px rgba(56,189,248,0.2);border-radius:18px;display:flex;flex-direction:column;align-items:center;gap:18px">
|
||||
|
||||
<!-- Icône animée -->
|
||||
<div style="position:relative;width:68px;height:68px;display:flex;align-items:center;justify-content:center">
|
||||
<div style="position:absolute;inset:0;border-radius:50%;border:2px solid rgba(56,189,248,0.35);animation:radarPulse 2s ease-out infinite"></div>
|
||||
<div id="restoreProgressIcon" style="font-size:34px;z-index:1;animation:iconFloat 2s ease-in-out infinite">📦</div>
|
||||
</div>
|
||||
|
||||
<!-- Titre et sous-titre -->
|
||||
<div style="text-align:center">
|
||||
<h2 style="margin:0;font-size:18px;letter-spacing:-0.3px;color:var(--text)" data-i18n="restore_progress_title">Restauration des données</h2>
|
||||
<div style="margin-top:6px;display:inline-flex;align-items:center;gap:6px;background:rgba(56,189,248,0.12);border:1px solid rgba(56,189,248,0.3);color:var(--blue);padding:3px 12px;border-radius:20px;font-size:12px;font-weight:600">
|
||||
<span id="restoreProgressBadgeIcon" style="display:inline-flex;align-items:center;justify-content:center;animation:spin 1.5s linear infinite">⚙️</span>
|
||||
<span id="restoreProgressBadgeText" data-i18n="restore_progress_badge">Restauration en cours…</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Barre de progression -->
|
||||
<div class="loader-progress-box" style="width:100%;margin-top:4px">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;font-size:12px">
|
||||
<span id="restoreProgressStepLabel" style="font-weight:600;color:var(--text)" data-i18n="restore_step_label">Étape 1 / 5</span>
|
||||
<span id="restoreProgressPercent" style="font-weight:700;color:var(--blue);font-family:monospace">0%</span>
|
||||
</div>
|
||||
<div class="loader-bar-bg" style="height:10px;border-radius:8px;background:var(--panel2);border:1px solid var(--line);overflow:hidden">
|
||||
<div id="restoreProgressBar" class="loader-bar-fill" style="width:0%;height:100%;background:linear-gradient(90deg, #0284c7, #38bdf8);box-shadow:0 0 12px rgba(56,189,248,0.5);border-radius:8px;transition:width .35s ease"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Libellés d'état dynamique -->
|
||||
<div style="text-align:center;min-height:44px;width:100%">
|
||||
<div id="restoreProgressStatusText" style="font-weight:700;font-size:14px;color:var(--text)" data-i18n="restore_starting">Démarrage de la restauration…</div>
|
||||
<div id="restoreProgressDetails" class="muted" style="font-size:12px;margin-top:3px" data-i18n="restore_preparing">Inspection du fichier et validation du format…</div>
|
||||
</div>
|
||||
|
||||
<!-- Checklist visuelle des étapes -->
|
||||
<div class="loader-checklist" style="display:grid;grid-template-columns:1fr;gap:7px;width:100%;margin-top:4px;border-top:1px solid var(--line);padding-top:12px">
|
||||
<div id="restoreStepCheck" class="loader-step active" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid rgba(56,189,248,0.4);font-size:12.5px">
|
||||
<span class="step-icon">📦</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step1_check">Analyse & vérification de l'archive</span>
|
||||
<span class="step-state" id="restoreStepCheckState" style="font-weight:700;color:var(--blue)">↻</span>
|
||||
</div>
|
||||
<div id="restoreStepPrefs" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">⚙️</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step2_prefs">Restauration des réglages & préférences</span>
|
||||
<span class="step-state" id="restoreStepPrefsState">⏳</span>
|
||||
</div>
|
||||
<div id="restoreStepDevices" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">📱</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step3_dev">Restauration des équipements & quotas</span>
|
||||
<span class="step-state" id="restoreStepDevicesState">⏳</span>
|
||||
</div>
|
||||
<div id="restoreStepVpn" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">🛡️</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step4_vpn">Restauration des profils VPN & routages</span>
|
||||
<span class="step-state" id="restoreStepVpnState">⏳</span>
|
||||
</div>
|
||||
<div id="restoreStepSync" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">📶</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step5_sync">Reconfiguration Wi-Fi & synchronisation finale</span>
|
||||
<span class="step-state" id="restoreStepSyncState">⏳</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="restoreProgressErrorBox" style="display:none;width:100%;margin-top:8px;padding:10px;background:rgba(239,68,68,0.15);border:1px solid var(--red);border-radius:8px;color:var(--red);font-size:12px;text-align:center">
|
||||
<span id="restoreProgressErrorText"></span>
|
||||
<div style="margin-top:8px">
|
||||
<button type="button" class="secondary" style="padding:4px 10px;font-size:12px" onclick="closeRestoreProgressModal()">Fermer</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js" defer></script>
|
||||
@@ -12319,9 +12394,6 @@ ${vpnBadgeTopo}
|
||||
alert(t('backup_no_pending', "Aucune donnée de sauvegarde en attente."));
|
||||
return;
|
||||
}
|
||||
const btn = $('btnConfirmImportAction');
|
||||
const msg = $('importModalMsg');
|
||||
const mainMsg = $('backupActionMsg');
|
||||
|
||||
const options = {
|
||||
restore_vpn: $('chkRestoreVpn') ? $('chkRestoreVpn').checked : true,
|
||||
@@ -12341,52 +12413,161 @@ ${vpnBadgeTopo}
|
||||
return;
|
||||
}
|
||||
|
||||
if (btn) { btn.disabled = true; btn.textContent = t('backup_restoring', 'Restauration en cours…'); }
|
||||
if (msg) {
|
||||
msg.style.display = 'block';
|
||||
msg.style.background = 'rgba(56,189,248,0.12)';
|
||||
msg.style.color = 'var(--blue)';
|
||||
msg.textContent = t('backup_applying_to_db', 'Application de la sauvegarde dans la base de données…');
|
||||
}
|
||||
const backupPayload = pendingBackupData;
|
||||
const modal = $('modalImportBackup');
|
||||
if (modal) modal.style.display = 'none';
|
||||
pendingBackupData = null;
|
||||
|
||||
const progressModal = $('modalRestoreProgress');
|
||||
if (progressModal) progressModal.classList.add('active');
|
||||
|
||||
$('restoreProgressBar').style.width = '20%';
|
||||
$('restoreProgressPercent').textContent = '20%';
|
||||
$('restoreProgressStepLabel').textContent = (t('restore_step_label', 'Étape {step} / {total}') || 'Étape {step} / {total}').replace('{step}', '1').replace('{total}', '5');
|
||||
$('restoreProgressBadgeText').textContent = t('restore_progress_badge', 'Restauration en cours…');
|
||||
$('restoreProgressBadgeIcon').textContent = '⚙️';
|
||||
$('restoreProgressBadgeIcon').style.animation = 'spin 1.5s linear infinite';
|
||||
$('restoreProgressIcon').textContent = '📦';
|
||||
$('restoreProgressStatusText').textContent = t('restore_step1_check', 'Analyse & vérification de l\'archive…');
|
||||
$('restoreProgressDetails').textContent = t('restore_preparing', 'Inspection du fichier et validation du format…');
|
||||
if ($('restoreProgressErrorBox')) $('restoreProgressErrorBox').style.display = 'none';
|
||||
|
||||
const restoreStepPills = [
|
||||
{ id: 'restoreStepCheck', stateId: 'restoreStepCheckState' },
|
||||
{ id: 'restoreStepPrefs', stateId: 'restoreStepPrefsState' },
|
||||
{ id: 'restoreStepDevices', stateId: 'restoreStepDevicesState' },
|
||||
{ id: 'restoreStepVpn', stateId: 'restoreStepVpnState' },
|
||||
{ id: 'restoreStepSync', stateId: 'restoreStepSyncState' }
|
||||
];
|
||||
|
||||
restoreStepPills.forEach((s, idx) => {
|
||||
const el = $(s.id);
|
||||
const st = $(s.stateId);
|
||||
if (!el || !st) return;
|
||||
if (idx === 0) {
|
||||
el.className = 'loader-step active';
|
||||
el.style.borderColor = 'rgba(56,189,248,0.4)';
|
||||
st.textContent = '↻';
|
||||
st.style.color = 'var(--blue)';
|
||||
} else {
|
||||
el.className = 'loader-step';
|
||||
el.style.borderColor = 'transparent';
|
||||
st.textContent = '⏳';
|
||||
st.style.color = 'inherit';
|
||||
}
|
||||
});
|
||||
|
||||
let restorePollInterval = null;
|
||||
let isDone = false;
|
||||
|
||||
const doPollRestore = async () => {
|
||||
if (isDone) return;
|
||||
try {
|
||||
const res = await fetch(API_URL + '/api/backup/restore/progress', { cache: 'no-store' });
|
||||
if (!res.ok) return;
|
||||
const p = await res.json();
|
||||
if (!p) return;
|
||||
|
||||
const pct = Math.min(100, Math.max(0, p.percent || 0));
|
||||
$('restoreProgressBar').style.width = pct + '%';
|
||||
$('restoreProgressPercent').textContent = pct + '%';
|
||||
|
||||
if (p.step) {
|
||||
$('restoreProgressStepLabel').textContent = (t('restore_step_label', 'Étape {step} / {total}') || 'Étape {step} / {total}')
|
||||
.replace('{step}', p.step).replace('{total}', p.total_steps || 5);
|
||||
}
|
||||
if (p.message) {
|
||||
$('restoreProgressStatusText').textContent = tMsg(p.message);
|
||||
}
|
||||
if (p.details) {
|
||||
$('restoreProgressDetails').textContent = tMsg(p.details);
|
||||
}
|
||||
|
||||
const curStep = p.step || 1;
|
||||
restoreStepPills.forEach((s, idx) => {
|
||||
const stepNum = idx + 1;
|
||||
const el = $(s.id);
|
||||
const st = $(s.stateId);
|
||||
if (!el || !st) return;
|
||||
if (curStep > stepNum || (p.done && curStep >= stepNum && !p.error)) {
|
||||
el.className = 'loader-step done';
|
||||
el.style.borderColor = 'rgba(34,197,94,0.3)';
|
||||
st.textContent = '✓';
|
||||
st.style.color = 'var(--green)';
|
||||
} else if (curStep === stepNum && !p.done) {
|
||||
el.className = 'loader-step active';
|
||||
el.style.borderColor = 'rgba(56,189,248,0.4)';
|
||||
st.textContent = '↻';
|
||||
st.style.color = 'var(--blue)';
|
||||
} else {
|
||||
el.className = 'loader-step';
|
||||
el.style.borderColor = 'transparent';
|
||||
st.textContent = '⏳';
|
||||
st.style.color = 'inherit';
|
||||
}
|
||||
});
|
||||
|
||||
if (p.error) {
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
if ($('restoreProgressErrorBox')) {
|
||||
$('restoreProgressErrorBox').style.display = 'block';
|
||||
$('restoreProgressErrorText').textContent = tErr(p.error);
|
||||
}
|
||||
$('restoreProgressBadgeText').textContent = t('error', 'Erreur');
|
||||
$('restoreProgressBadgeIcon').textContent = '⚠️';
|
||||
$('restoreProgressBadgeIcon').style.animation = 'none';
|
||||
$('restoreProgressIcon').textContent = '⚠️';
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.done && !isDone) {
|
||||
isDone = true;
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
$('restoreProgressBar').style.width = '100%';
|
||||
$('restoreProgressPercent').textContent = '100%';
|
||||
$('restoreProgressBadgeText').textContent = t('done', 'Terminé !');
|
||||
$('restoreProgressBadgeIcon').textContent = '✅';
|
||||
$('restoreProgressBadgeIcon').style.animation = 'none';
|
||||
$('restoreProgressIcon').textContent = '✅';
|
||||
$('restoreProgressStatusText').textContent = t('restore_complete_title', 'Sauvegarde restaurée avec succès !');
|
||||
$('restoreProgressDetails').textContent = t('restore_reloading', 'Rechargement de l’interface en cours…');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1200);
|
||||
}
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
restorePollInterval = setInterval(doPollRestore, 200);
|
||||
|
||||
try {
|
||||
const res = await apiFetch('/api/backup/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
backup: pendingBackupData,
|
||||
backup: backupPayload,
|
||||
options: options
|
||||
})
|
||||
});
|
||||
const d = await res.json();
|
||||
if (!res.ok) throw new Error(d.error || 'Erreur lors de la restauration');
|
||||
|
||||
closeImportBackupModal();
|
||||
|
||||
if (mainMsg) {
|
||||
mainMsg.style.display = 'block';
|
||||
mainMsg.style.background = 'rgba(50,213,131,0.15)';
|
||||
mainMsg.style.color = 'var(--green)';
|
||||
mainMsg.textContent = '✓ ' + tMsg(d.message || 'Sauvegarde restaurée avec succès !');
|
||||
setTimeout(() => { if (mainMsg) mainMsg.style.display = 'none'; }, 8000);
|
||||
if (!isDone) {
|
||||
await doPollRestore();
|
||||
}
|
||||
|
||||
// Rafraîchir les données
|
||||
try { await load(); } catch (_) { }
|
||||
try { if (typeof loadVpnProfiles === 'function') await loadVpnProfiles(); } catch (_) { }
|
||||
try { if (typeof loadDevices === 'function') await loadDevices(); } catch (_) { }
|
||||
try { if (typeof loadDeviceTypesList === 'function') await loadDeviceTypesList(); } catch (_) { }
|
||||
try { if (typeof loadBlocked === 'function') await loadBlocked(); } catch (_) { }
|
||||
|
||||
} catch (e) {
|
||||
if (msg) {
|
||||
msg.style.display = 'block';
|
||||
msg.style.background = 'rgba(239,68,68,0.15)';
|
||||
msg.style.color = 'var(--red)';
|
||||
msg.textContent = tErr(e.message);
|
||||
if (!isDone) {
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
if ($('restoreProgressErrorBox')) {
|
||||
$('restoreProgressErrorBox').style.display = 'block';
|
||||
$('restoreProgressErrorText').textContent = tErr(e.message);
|
||||
}
|
||||
$('restoreProgressBadgeText').textContent = t('error', 'Erreur');
|
||||
$('restoreProgressBadgeIcon').textContent = '⚠️';
|
||||
$('restoreProgressBadgeIcon').style.animation = 'none';
|
||||
$('restoreProgressIcon').textContent = '⚠️';
|
||||
}
|
||||
} finally {
|
||||
if (btn) { btn.disabled = false; btn.textContent = 'Confirmer et restaurer'; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13331,6 +13512,11 @@ ${vpnBadgeTopo}
|
||||
if (modal) modal.classList.remove('active');
|
||||
};
|
||||
|
||||
window.closeRestoreProgressModal = function() {
|
||||
const modal = $('modalRestoreProgress');
|
||||
if (modal) modal.classList.remove('active');
|
||||
};
|
||||
|
||||
$('clearAllData').onclick = () => runAction(async () => {
|
||||
if (!confirm(t('confirm_delete_all_data', '⚠️ ATTENTION : Voulez-vous vraiment supprimer toutes les données de l’application ?'))) return;
|
||||
const modal = $('modalClearAllProgress');
|
||||
|
||||
@@ -170,6 +170,19 @@ window.I18N['en-gb'] = {
|
||||
"reset_step5_db": "Purging database and sessions",
|
||||
"reset_complete_title": "Reset completed successfully!",
|
||||
"reset_redirecting": "Redirecting to initial setup…",
|
||||
"restore_progress_title": "Data Restoration",
|
||||
"restore_progress_badge": "Restoration in progress…",
|
||||
"restore_step_label": "Step {step} / {total}",
|
||||
"restore_starting": "Starting restoration…",
|
||||
"restore_preparing": "Inspecting archive and preparing database…",
|
||||
"restore_step1_check": "Archive analysis & verification",
|
||||
"restore_step2_prefs": "Restoring settings & preferences",
|
||||
"restore_step3_dev": "Restoring devices & quotas",
|
||||
"restore_step4_vpn": "Restoring VPN profiles & routing",
|
||||
"restore_step5_sync": "Wi-Fi reconfiguration & final synchronization",
|
||||
"restore_complete_title": "Backup restored successfully!",
|
||||
"restore_redirecting_dash": "Redirecting to dashboard…",
|
||||
"restore_reloading": "Reloading interface…",
|
||||
"dash_card_clients": "Connected Clients",
|
||||
"dash_card_ssid": "SSID",
|
||||
"dash_card_status": "AP Status",
|
||||
|
||||
@@ -170,6 +170,19 @@ window.I18N['en-us'] = {
|
||||
"reset_step5_db": "Purging database and sessions",
|
||||
"reset_complete_title": "Reset completed successfully!",
|
||||
"reset_redirecting": "Redirecting to initial setup…",
|
||||
"restore_progress_title": "Data Restoration",
|
||||
"restore_progress_badge": "Restoration in progress…",
|
||||
"restore_step_label": "Step {step} / {total}",
|
||||
"restore_starting": "Starting restoration…",
|
||||
"restore_preparing": "Inspecting archive and preparing database…",
|
||||
"restore_step1_check": "Archive analysis & verification",
|
||||
"restore_step2_prefs": "Restoring settings & preferences",
|
||||
"restore_step3_dev": "Restoring devices & quotas",
|
||||
"restore_step4_vpn": "Restoring VPN profiles & routing",
|
||||
"restore_step5_sync": "Wi-Fi reconfiguration & final synchronization",
|
||||
"restore_complete_title": "Backup restored successfully!",
|
||||
"restore_redirecting_dash": "Redirecting to dashboard…",
|
||||
"restore_reloading": "Reloading interface…",
|
||||
"dash_card_clients": "Connected Clients",
|
||||
"dash_card_ssid": "SSID",
|
||||
"dash_card_status": "AP Status",
|
||||
|
||||
+13
@@ -170,6 +170,19 @@ window.I18N['fr'] = {
|
||||
"reset_step5_db": "Purge de la base et des sessions",
|
||||
"reset_complete_title": "Réinitialisation terminée avec succès !",
|
||||
"reset_redirecting": "Redirection vers l’assistant d’installation (Setup)…",
|
||||
"restore_progress_title": "Restauration des données",
|
||||
"restore_progress_badge": "Restauration en cours…",
|
||||
"restore_step_label": "Étape {step} / {total}",
|
||||
"restore_starting": "Démarrage de la restauration…",
|
||||
"restore_preparing": "Inspection de l'archive et préparation des tables…",
|
||||
"restore_step1_check": "Analyse & vérification de l'archive",
|
||||
"restore_step2_prefs": "Restauration des réglages & préférences",
|
||||
"restore_step3_dev": "Restauration des équipements & quotas",
|
||||
"restore_step4_vpn": "Restauration des profils VPN & routages",
|
||||
"restore_step5_sync": "Reconfiguration Wi-Fi & synchronisation finale",
|
||||
"restore_complete_title": "Sauvegarde restaurée avec succès !",
|
||||
"restore_redirecting_dash": "Redirection vers le tableau de bord…",
|
||||
"restore_reloading": "Rechargement de l'interface en cours…",
|
||||
"dash_card_clients": "Clients connectés",
|
||||
"dash_card_ssid": "SSID",
|
||||
"dash_card_status": "État de l’AP",
|
||||
|
||||
+255
-26
@@ -1036,6 +1036,37 @@
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
}
|
||||
|
||||
@keyframes radarPulse {
|
||||
0% { transform: scale(0.9); opacity: 0.8; }
|
||||
50% { transform: scale(1.4); opacity: 0.2; }
|
||||
100% { transform: scale(1.8); opacity: 0; }
|
||||
}
|
||||
@keyframes iconFloat {
|
||||
0%, 100% { transform: translateY(0); }
|
||||
50% { transform: translateY(-4px); }
|
||||
}
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
.loader-step {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 7px 12px;
|
||||
background: var(--panel2);
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
font-size: 12.5px;
|
||||
transition: all .25s ease;
|
||||
}
|
||||
.loader-step.active {
|
||||
border-color: rgba(56, 189, 248, 0.4);
|
||||
}
|
||||
.loader-step.done {
|
||||
border-color: rgba(34, 197, 94, 0.3);
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/themes/dark.css">
|
||||
<link rel="stylesheet" href="/themes/light.css">
|
||||
@@ -2720,6 +2751,83 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Progression Restauration de Sauvegarde (Setup) -->
|
||||
<div id="modalSetupRestoreProgress"
|
||||
style="display:none;position:fixed;inset:0;background:rgba(0,0,0,0.85);backdrop-filter:blur(6px);z-index:999999;align-items:center;justify-content:center;padding:16px">
|
||||
<div class="card"
|
||||
style="max-width:480px;width:92%;padding:28px 24px;border:1px solid rgba(56,189,248,0.4);box-shadow:0 16px 40px rgba(0,0,0,0.6), 0 0 30px rgba(56,189,248,0.2);border-radius:18px;display:flex;flex-direction:column;align-items:center;gap:18px;background:var(--panel)">
|
||||
|
||||
<!-- Icône animée -->
|
||||
<div style="position:relative;width:68px;height:68px;display:flex;align-items:center;justify-content:center">
|
||||
<div style="position:absolute;inset:0;border-radius:50%;border:2px solid rgba(56,189,248,0.35);animation:radarPulse 2s ease-out infinite"></div>
|
||||
<div id="setupRestoreIcon" style="font-size:34px;z-index:1;animation:iconFloat 2s ease-in-out infinite">📦</div>
|
||||
</div>
|
||||
|
||||
<!-- Titre et badge -->
|
||||
<div style="text-align:center">
|
||||
<h2 style="margin:0;font-size:18px;letter-spacing:-0.3px;color:var(--text)" data-i18n="restore_progress_title">Restauration des données</h2>
|
||||
<div style="margin-top:6px;display:inline-flex;align-items:center;gap:6px;background:rgba(56,189,248,0.12);border:1px solid rgba(56,189,248,0.3);color:var(--blue);padding:3px 12px;border-radius:20px;font-size:12px;font-weight:600">
|
||||
<span id="setupRestoreBadgeIcon" style="display:inline-flex;align-items:center;justify-content:center;animation:spin 1.5s linear infinite">⚙️</span>
|
||||
<span id="setupRestoreBadgeText" data-i18n="restore_progress_badge">Restauration en cours…</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Barre de progression -->
|
||||
<div style="width:100%;margin-top:4px">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;font-size:12px">
|
||||
<span id="setupRestoreStepLabel" style="font-weight:600;color:var(--text)" data-i18n="restore_step_label">Étape 1 / 5</span>
|
||||
<span id="setupRestorePercent" style="font-weight:700;color:var(--blue);font-family:monospace">0%</span>
|
||||
</div>
|
||||
<div style="height:10px;border-radius:8px;background:var(--panel2);border:1px solid var(--line);overflow:hidden">
|
||||
<div id="setupRestoreProgressBar" style="width:0%;height:100%;background:linear-gradient(90deg, #0284c7, #38bdf8);box-shadow:0 0 12px rgba(56,189,248,0.5);border-radius:8px;transition:width .35s ease"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Libellés d'état dynamique -->
|
||||
<div style="text-align:center;min-height:44px;width:100%">
|
||||
<div id="setupRestoreStatusText" style="font-weight:700;font-size:14px;color:var(--text)" data-i18n="restore_starting">Démarrage de la restauration…</div>
|
||||
<div id="setupRestoreDetails" class="muted" style="font-size:12px;margin-top:3px" data-i18n="restore_preparing">Inspection du fichier et validation du format…</div>
|
||||
</div>
|
||||
|
||||
<!-- Checklist visuelle des étapes -->
|
||||
<div style="display:grid;grid-template-columns:1fr;gap:7px;width:100%;margin-top:4px;border-top:1px solid var(--line);padding-top:12px">
|
||||
<div id="setupRestoreStepCheck" class="loader-step active" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid rgba(56,189,248,0.4);font-size:12.5px">
|
||||
<span class="step-icon">📦</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step1_check">Analyse & vérification de l'archive</span>
|
||||
<span class="step-state" id="setupRestoreStepCheckState" style="font-weight:700;color:var(--blue)">↻</span>
|
||||
</div>
|
||||
<div id="setupRestoreStepPrefs" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">⚙️</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step2_prefs">Restauration des réglages & préférences</span>
|
||||
<span class="step-state" id="setupRestoreStepPrefsState">⏳</span>
|
||||
</div>
|
||||
<div id="setupRestoreStepDevices" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">📱</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step3_dev">Restauration des équipements & quotas</span>
|
||||
<span class="step-state" id="setupRestoreStepDevicesState">⏳</span>
|
||||
</div>
|
||||
<div id="setupRestoreStepVpn" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">🛡️</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step4_vpn">Restauration des profils VPN & routages</span>
|
||||
<span class="step-state" id="setupRestoreStepVpnState">⏳</span>
|
||||
</div>
|
||||
<div id="setupRestoreStepSync" class="loader-step" style="display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--panel2);border-radius:8px;border:1px solid transparent;font-size:12.5px">
|
||||
<span class="step-icon">📶</span>
|
||||
<span class="step-name" style="flex:1" data-i18n="restore_step5_sync">Reconfiguration Wi-Fi & synchronisation finale</span>
|
||||
<span class="step-state" id="setupRestoreStepSyncState">⏳</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="setupRestoreErrorBox" style="display:none;width:100%;margin-top:8px;padding:10px;background:rgba(239,68,68,0.15);border:1px solid var(--red);border-radius:8px;color:var(--red);font-size:12px;text-align:center">
|
||||
<span id="setupRestoreErrorText"></span>
|
||||
<div style="margin-top:8px">
|
||||
<button type="button" class="secondary" style="padding:4px 10px;font-size:12px" onclick="closeSetupRestoreProgressModal()">Fermer</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Ajout de Profil VPN en Étape 5 -->
|
||||
<div id="modalSetupVpn"
|
||||
style="display:none;position:fixed;inset:0;background:rgba(0,0,0,0.72);backdrop-filter:blur(4px);z-index:9999;align-items:center;justify-content:center;padding:16px">
|
||||
@@ -4827,11 +4935,15 @@
|
||||
modal.style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeSetupRestoreProgressModal() {
|
||||
const modal = $('modalSetupRestoreProgress');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
window.closeSetupRestoreProgressModal = closeSetupRestoreProgressModal;
|
||||
|
||||
async function submitSetupBackup() {
|
||||
if (!pendingBackupData) return;
|
||||
|
||||
const btn = $('btnConfirmSetupBackup');
|
||||
const msg = $('backupModalMsg');
|
||||
const isEn = currentLanguage.startsWith('en');
|
||||
|
||||
const options = {
|
||||
@@ -4848,41 +4960,158 @@
|
||||
return;
|
||||
}
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = isEn ? 'Restoring…' : 'Restauration en cours…';
|
||||
if (msg) {
|
||||
msg.style.display = 'block';
|
||||
msg.style.background = 'rgba(92,167,255,0.15)';
|
||||
msg.style.color = 'var(--blue)';
|
||||
msg.textContent = isEn ? 'Applying backup to database…' : 'Application de la sauvegarde dans la base de données…';
|
||||
}
|
||||
const backupPayload = pendingBackupData;
|
||||
const backupModal = $('modalSetupBackup');
|
||||
if (backupModal) backupModal.style.display = 'none';
|
||||
closeSetupBackupPickerModal();
|
||||
pendingBackupData = null;
|
||||
|
||||
const progressModal = $('modalSetupRestoreProgress');
|
||||
if (progressModal) progressModal.style.display = 'flex';
|
||||
|
||||
$('setupRestoreProgressBar').style.width = '20%';
|
||||
$('setupRestorePercent').textContent = '20%';
|
||||
$('setupRestoreStepLabel').textContent = (t('restore_step_label', 'Étape {step} / {total}') || 'Étape {step} / {total}').replace('{step}', '1').replace('{total}', '5');
|
||||
$('setupRestoreBadgeText').textContent = t('restore_progress_badge', 'Restauration en cours…');
|
||||
$('setupRestoreBadgeIcon').textContent = '⚙️';
|
||||
$('setupRestoreBadgeIcon').style.animation = 'spin 1.5s linear infinite';
|
||||
$('setupRestoreIcon').textContent = '📦';
|
||||
$('setupRestoreStatusText').textContent = t('restore_step1_check', 'Analyse & vérification de l\'archive…');
|
||||
$('setupRestoreDetails').textContent = t('restore_preparing', 'Inspection du fichier et validation du format…');
|
||||
if ($('setupRestoreErrorBox')) $('setupRestoreErrorBox').style.display = 'none';
|
||||
|
||||
const restoreStepPills = [
|
||||
{ id: 'setupRestoreStepCheck', stateId: 'setupRestoreStepCheckState' },
|
||||
{ id: 'setupRestoreStepPrefs', stateId: 'setupRestoreStepPrefsState' },
|
||||
{ id: 'setupRestoreStepDevices', stateId: 'setupRestoreStepDevicesState' },
|
||||
{ id: 'setupRestoreStepVpn', stateId: 'setupRestoreStepVpnState' },
|
||||
{ id: 'setupRestoreStepSync', stateId: 'setupRestoreStepSyncState' }
|
||||
];
|
||||
|
||||
restoreStepPills.forEach((s, idx) => {
|
||||
const el = $(s.id);
|
||||
const st = $(s.stateId);
|
||||
if (!el || !st) return;
|
||||
if (idx === 0) {
|
||||
el.className = 'loader-step active';
|
||||
el.style.borderColor = 'rgba(56,189,248,0.4)';
|
||||
st.textContent = '↻';
|
||||
st.style.color = 'var(--blue)';
|
||||
} else {
|
||||
el.className = 'loader-step';
|
||||
el.style.borderColor = 'transparent';
|
||||
st.textContent = '⏳';
|
||||
st.style.color = 'inherit';
|
||||
}
|
||||
});
|
||||
|
||||
let restorePollInterval = null;
|
||||
let isDone = false;
|
||||
|
||||
const doPollSetupRestore = async () => {
|
||||
if (isDone) return;
|
||||
try {
|
||||
const res = await fetch(API_URL + '/api/backup/restore/progress', { cache: 'no-store' });
|
||||
if (!res.ok) return;
|
||||
const p = await res.json();
|
||||
if (!p) return;
|
||||
|
||||
const pct = Math.min(100, Math.max(0, p.percent || 0));
|
||||
$('setupRestoreProgressBar').style.width = pct + '%';
|
||||
$('setupRestorePercent').textContent = pct + '%';
|
||||
|
||||
if (p.step) {
|
||||
$('setupRestoreStepLabel').textContent = (t('restore_step_label', 'Étape {step} / {total}') || 'Étape {step} / {total}')
|
||||
.replace('{step}', p.step).replace('{total}', p.total_steps || 5);
|
||||
}
|
||||
if (p.message) {
|
||||
$('setupRestoreStatusText').textContent = p.message;
|
||||
}
|
||||
if (p.details) {
|
||||
$('setupRestoreDetails').textContent = p.details;
|
||||
}
|
||||
|
||||
const curStep = p.step || 1;
|
||||
restoreStepPills.forEach((s, idx) => {
|
||||
const stepNum = idx + 1;
|
||||
const el = $(s.id);
|
||||
const st = $(s.stateId);
|
||||
if (!el || !st) return;
|
||||
if (curStep > stepNum || (p.done && curStep >= stepNum && !p.error)) {
|
||||
el.className = 'loader-step done';
|
||||
el.style.borderColor = 'rgba(34,197,94,0.3)';
|
||||
st.textContent = '✓';
|
||||
st.style.color = 'var(--green)';
|
||||
} else if (curStep === stepNum && !p.done) {
|
||||
el.className = 'loader-step active';
|
||||
el.style.borderColor = 'rgba(56,189,248,0.4)';
|
||||
st.textContent = '↻';
|
||||
st.style.color = 'var(--blue)';
|
||||
} else {
|
||||
el.className = 'loader-step';
|
||||
el.style.borderColor = 'transparent';
|
||||
st.textContent = '⏳';
|
||||
st.style.color = 'inherit';
|
||||
}
|
||||
});
|
||||
|
||||
if (p.error) {
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
if ($('setupRestoreErrorBox')) {
|
||||
$('setupRestoreErrorBox').style.display = 'block';
|
||||
$('setupRestoreErrorText').textContent = p.error;
|
||||
}
|
||||
$('setupRestoreBadgeText').textContent = isEn ? 'Error' : 'Erreur';
|
||||
$('setupRestoreBadgeIcon').textContent = '⚠️';
|
||||
$('setupRestoreBadgeIcon').style.animation = 'none';
|
||||
$('setupRestoreIcon').textContent = '⚠️';
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.done && !isDone) {
|
||||
isDone = true;
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
$('setupRestoreProgressBar').style.width = '100%';
|
||||
$('setupRestorePercent').textContent = '100%';
|
||||
$('setupRestoreBadgeText').textContent = isEn ? 'Done!' : 'Terminé !';
|
||||
$('setupRestoreBadgeIcon').textContent = '✅';
|
||||
$('setupRestoreBadgeIcon').style.animation = 'none';
|
||||
$('setupRestoreIcon').textContent = '✅';
|
||||
$('setupRestoreStatusText').textContent = t('restore_complete_title', 'Sauvegarde restaurée avec succès !');
|
||||
$('setupRestoreDetails').textContent = t('restore_redirecting_dash', 'Redirection vers le tableau de bord…');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.replace('/');
|
||||
}, 1200);
|
||||
}
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
restorePollInterval = setInterval(doPollSetupRestore, 200);
|
||||
|
||||
try {
|
||||
const res = await fetch(API_URL + '/api/backup/import', {
|
||||
method: 'POST',
|
||||
headers: getSetupAuthHeaders(),
|
||||
body: JSON.stringify({ backup: pendingBackupData, options: options })
|
||||
body: JSON.stringify({ backup: backupPayload, options: options })
|
||||
});
|
||||
const d = await res.json();
|
||||
if (!res.ok) throw new Error(d.error || 'Erreur lors de la restauration');
|
||||
|
||||
if (msg) {
|
||||
msg.style.background = 'rgba(50,213,131,0.15)';
|
||||
msg.style.color = 'var(--green)';
|
||||
msg.textContent = isEn ? '✅ Backup restored successfully! Redirecting to dashboard…' : '✅ Sauvegarde restaurée avec succès ! Redirection vers le tableau de bord…';
|
||||
if (!isDone) {
|
||||
await doPollSetupRestore();
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
location.href = '/';
|
||||
}, 1500);
|
||||
|
||||
} catch (err) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = isEn ? '🚀 Restore This Backup' : '🚀 Restaurer cette sauvegarde';
|
||||
if (msg) {
|
||||
msg.style.background = 'rgba(255,107,107,0.15)';
|
||||
msg.style.color = 'var(--red)';
|
||||
msg.textContent = '❌ ' + (err.message || 'Erreur de restauration');
|
||||
if (!isDone) {
|
||||
if (restorePollInterval) clearInterval(restorePollInterval);
|
||||
if ($('setupRestoreErrorBox')) {
|
||||
$('setupRestoreErrorBox').style.display = 'block';
|
||||
$('setupRestoreErrorText').textContent = err.message || 'Erreur de restauration';
|
||||
}
|
||||
$('setupRestoreBadgeText').textContent = isEn ? 'Error' : 'Erreur';
|
||||
$('setupRestoreBadgeIcon').textContent = '⚠️';
|
||||
$('setupRestoreBadgeIcon').style.animation = 'none';
|
||||
$('setupRestoreIcon').textContent = '⚠️';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "V1.2 (Bêta)",
|
||||
"commit": "9b86c11a24a29494d9ab541d856e66573c572469",
|
||||
"build_date": "2026-11-23T01:52:05Z"
|
||||
"commit": "c48d5beae0e652401c931205cfda03345d58fb96",
|
||||
"build_date": "2026-11-23T02:06:11Z"
|
||||
}
|
||||
Reference in new issue
Block a user