diff --git a/ap.py b/ap.py index 36c0669..dda5ac2 100644 --- a/ap.py +++ b/ap.py @@ -10755,7 +10755,7 @@ def download_remote_file(remote_filename, dest_path, custom_cfg=None): def list_remote_files_detailed(custom_cfg=None): cfg = custom_cfg or get_backup_remote_config() - if not cfg.get('enabled'): + if not cfg.get('enabled') and not custom_cfg: return None, "Stockage distant désactivé" provider = str(cfg.get('provider', 'ftp')).strip().lower() p_cfg = cfg.get(provider, {}) if isinstance(cfg.get(provider), dict) else {} @@ -11493,7 +11493,7 @@ class Handler(BaseHTTPRequestHandler): except Exception as e: self.send_json({'error': f'Erreur génération archive ZIP: {e}'}, 500); return if self.path.startswith('/api/backups/list'): - if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return parsed = urllib.parse.urlparse(self.path) qs = urllib.parse.parse_qs(parsed.query) if qs.get('sync_remote', ['0'])[0] in ('1', 'true'): @@ -11513,10 +11513,10 @@ class Handler(BaseHTTPRequestHandler): 'total_size_str': format_bytes(total_size) }); return if self.path == '/api/backups/remote': - if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return self.send_json({'ok': True, 'remote': get_backup_remote_config()}); return if self.path.startswith('/api/backups/remote/files'): - if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return rcfg = get_backup_remote_config() if not rcfg.get('enabled'): self.send_json({'ok': False, 'error': "Le stockage distant n'est pas activé. Activez-le dans les réglages de sauvegarde.", 'enabled': False}, 400); return @@ -12249,15 +12249,27 @@ class Handler(BaseHTTPRequestHandler): raw_json = data.get('backup') if raw_json and isinstance(raw_json, dict): self.send_json({'ok': True, 'filename': fname, 'backup': raw_json}); return - if not b64_content: - self.send_json({'error': 'Contenu du fichier manquant'}, 400); return - try: - raw_bytes = base64.b64decode(b64_content) - backup = inspect_backup_bytes(raw_bytes, fname) - self.send_json({'ok': True, 'filename': fname, 'backup': backup}) - except Exception as e: - self.send_json({'error': f'Impossible d’analyser le fichier : {e}'}, 400) - return + if b64_content: + try: + raw_bytes = base64.b64decode(b64_content) + backup = inspect_backup_bytes(raw_bytes, fname) + self.send_json({'ok': True, 'filename': fname, 'backup': backup}) + except Exception as e: + self.send_json({'error': f'Impossible d’analyser le fichier : {e}'}, 400) + return + if fname: + full_path, clean_name = safe_backup_filepath(fname) + if os.path.isfile(full_path): + try: + with open(full_path, 'rb') as f_read: + raw_bytes = f_read.read() + backup = inspect_backup_bytes(raw_bytes, clean_name) + sz = os.path.getsize(full_path) + self.send_json({'ok': True, 'filename': clean_name, 'size': sz, 'backup': backup}) + return + except Exception as e: + self.send_json({'error': f'Impossible d’analyser le fichier local : {e}'}, 400); return + self.send_json({'error': 'Contenu du fichier manquant ou fichier local introuvable'}, 400); return if self.path == '/api/backup/import': if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return try: @@ -12268,6 +12280,14 @@ class Handler(BaseHTTPRequestHandler): raw_bytes = base64.b64decode(data['data_base64']) backup = inspect_backup_bytes(raw_bytes, data.get('filename', '')) stats = import_backup_data(backup, data.get('options', {})) + 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): + self.send_json({'error': 'Fichier de sauvegarde introuvable'}, 404); return + with open(full_path, 'rb') as f_read: + raw_bytes = f_read.read() + backup = inspect_backup_bytes(raw_bytes, clean_name) + stats = import_backup_data(backup, data.get('options', {})) else: stats = import_backup_data(data) invalidate_status_cache() @@ -12282,6 +12302,75 @@ class Handler(BaseHTTPRequestHandler): except Exception as e: self.send_json({'error': f'Erreur lors de la restauration: {e}'}, 400) return + if self.path == '/api/backups/remote/test': + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return + custom_cfg = data.get('config') if isinstance(data, dict) and 'config' in data else None + try: + ok, msg = test_backup_remote(custom_cfg) + self.send_json({'ok': ok, 'message': msg}); return + except Exception as e: + self.send_json({'ok': False, 'error': str(e)}, 500); return + if self.path == '/api/backups/remote/files': + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return + custom_cfg = data.get('config') if (isinstance(data, dict) and data.get('config')) else None + rcfg = custom_cfg or get_backup_remote_config() + if not rcfg.get('enabled') and not custom_cfg: + self.send_json({'ok': False, 'error': "Le stockage distant n'est pas activé.", 'enabled': False}, 400); return + provider = str(rcfg.get('provider', 'ftp')).strip().lower() + try: + items, err = list_remote_files_detailed(rcfg) + if items is None: + self.send_json({'ok': False, 'error': err or f"Impossible de contacter le stockage distant ({provider.upper()})", 'provider': provider}, 500); return + prov_names = {'gdrive': 'Google Drive', 'dropbox': 'Dropbox', 'sftp': 'SFTP', 'ftp': 'FTP', 'webdav': 'WebDAV', 's3': 'S3', 'webhook': 'Webhook'} + self.send_json({ + 'ok': True, + 'enabled': True, + 'provider': provider, + 'provider_name': prov_names.get(provider, provider.upper()), + 'files': items, + 'count': len(items) + }); return + except Exception as e: + self.send_json({'ok': False, 'error': f"Erreur lors de la lecture des fichiers distants : {e}"}, 500); return + if self.path == '/api/backups/remote/file/pull': + if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return + fname = str(data.get('filename', '')).strip() + if not fname or not fname.lower().endswith(BACKUP_ALLOWED_EXTS): + self.send_json({'error': 'Nom de fichier invalide'}, 400); return + clean_name = os.path.basename(fname) + custom_cfg = data.get('config') if isinstance(data, dict) and 'config' in data else None + ensure_backup_dir() + full_path = os.path.join(BACKUP_DIR, clean_name) + tmp_dest = full_path + '.download.tmp' + try: + download_remote_file(clean_name, tmp_dest, custom_cfg=custom_cfg) + os.replace(tmp_dest, full_path) + try: + sync_remote_backups_presence(force=True) + except Exception: + pass + log('recuperation_sauvegarde_distante', f"{username(self) or 'Administrateur'} ({clean_name})", request_ip(self), 'BACKUP') + backup_data = None + try: + with open(full_path, 'rb') as f_read: + backup_data = inspect_backup_bytes(f_read.read(), clean_name) + except Exception as e_insp: + print(f"[ap-backup] Avertissement inspection pull : {e_insp}", flush=True) + file_size = os.path.getsize(full_path) if os.path.exists(full_path) else 0 + items, total_size = list_server_backups() + self.send_json({ + 'ok': True, + 'message': f"Sauvegarde « {clean_name} » importée avec succès !", + 'filename': clean_name, + 'size': file_size, + 'backup': backup_data, + 'backups': items + }); return + except Exception as e: + if os.path.exists(tmp_dest): + try: os.unlink(tmp_dest) + except OSError: pass + self.send_json({'error': f"Échec récupération sauvegarde : {e}"}, 500); return if self.path == '/api/vpn/profiles': if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return pid = create_or_update_vpn_profile(data) @@ -12729,10 +12818,6 @@ class Handler(BaseHTTPRequestHandler): rcfg = save_backup_remote_config(data) log('configuration_stockage_distant', f"{username(self) or 'Administrateur'} ({rcfg.get('provider', '')})", request_ip(self), 'BACKUP') self.send_json({'ok': True, 'message': 'Configuration du stockage distant enregistrée avec succès', 'remote': rcfg}); return - if self.path == '/api/backups/remote/test': - custom_cfg = data.get('config') if isinstance(data, dict) and 'config' in data else None - ok, msg = test_backup_remote(custom_cfg) - self.send_json({'ok': True, 'message': msg}); return if self.path == '/api/backups/remote/upload': fname = str(data.get('filename', '')).strip() full_path, clean_name = safe_backup_filepath(fname) @@ -12747,31 +12832,6 @@ class Handler(BaseHTTPRequestHandler): log('televersement_distant_manuel', f"{username(self) or 'Administrateur'} ({clean_name})", request_ip(self), 'BACKUP') items, total_size = list_server_backups() self.send_json({'ok': True, 'message': msg, 'remote': get_backup_remote_config(), 'backups': items}); return - if self.path == '/api/backups/remote/file/pull': - if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return - fname = str(data.get('filename', '')).strip() - if not fname or not fname.lower().endswith(BACKUP_ALLOWED_EXTS): - self.send_json({'error': 'Nom de fichier invalide'}, 400); return - clean_name = os.path.basename(fname) - ensure_backup_dir() - full_path = os.path.join(BACKUP_DIR, clean_name) - tmp_dest = full_path + '.download.tmp' - try: - download_remote_file(clean_name, tmp_dest) - os.replace(tmp_dest, full_path) - sync_remote_backups_presence(force=True) - log('recuperation_sauvegarde_distante', f"{username(self) or 'Administrateur'} ({clean_name})", request_ip(self), 'BACKUP') - items, total_size = list_server_backups() - self.send_json({ - 'ok': True, - 'message': f"Sauvegarde « {clean_name} » importée localement avec succès !", - 'backups': items - }); return - except Exception as e: - if os.path.exists(tmp_dest): - try: os.unlink(tmp_dest) - except OSError: pass - self.send_json({'error': f"Échec récupération sauvegarde : {e}"}, 500); return if self.path == '/api/backups/remote/file/delete': if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return fname = str(data.get('filename', '')).strip() diff --git a/lang/en-gb.js b/lang/en-gb.js index 17d486c..4b8c486 100644 --- a/lang/en-gb.js +++ b/lang/en-gb.js @@ -1368,5 +1368,25 @@ window.I18N['en-gb'] = { "apikey_delete_confirm": "Are you sure you want to permanently delete the API key « {name} » ?\\nAll services using it will lose access.", "log_cle_api_creee": "⚡ API Key created", "log_cle_api_modifiee": "⚡ API Key modified", - "log_cle_api_supprimee": "🗑️ API Key deleted" + "log_cle_api_supprimee": "🗑️ API Key deleted", + "setup_detected_backups_title": "Existing Backups Detected", + "setup_detected_backups_desc": "Backups were found on the server. You can restore your configuration right away.", + "btn_view_detected_backups": "View Backups", + "modal_picker_title": "Import Backup", + "modal_picker_sub": "Restore settings, VPN profiles and devices from the server, your PC or the Cloud", + "tab_server_backups": "Server Backups", + "tab_cloud_backups": "Cloud Services", + "tab_local_file": "Local File (PC)", + "server_backups_list_title": "Files found on server", + "server_backups_dir_hint": "Storage location: /app/backups/", + "server_backups_loading": "Searching for backups on the server…", + "server_backups_none": "No backups found on server.", + "cloud_setup_desc": "Connect directly to your remote storage (Google Drive, Dropbox, SFTP, FTP, WebDAV or S3) to browse and import your backups without your PC.", + "btn_test_cloud_connection": "Test Connection", + "btn_explore_cloud_backups": "Browse Cloud Backups", + "cloud_files_found_title": "Backups available on the Cloud:", + "local_file_upload_desc": "Select a backup archive (.zip) or configuration file (.json) previously exported from AP Manageur.", + "dropzone_title": "Click or drag and drop your file here", + "dropzone_hint": "Accepted formats: .zip, .json (max 100 MB)", + "btn_browse_pc": "Browse your files…" }; diff --git a/lang/en-us.js b/lang/en-us.js index 48f5dc2..f7b8849 100644 --- a/lang/en-us.js +++ b/lang/en-us.js @@ -1368,5 +1368,25 @@ window.I18N['en-us'] = { "apikey_delete_confirm": "Are you sure you want to permanently delete the API key « {name} » ?\\nAll services using it will lose access.", "log_cle_api_creee": "⚡ API Key created", "log_cle_api_modifiee": "⚡ API Key modified", - "log_cle_api_supprimee": "🗑️ API Key deleted" + "log_cle_api_supprimee": "🗑️ API Key deleted", + "setup_detected_backups_title": "Existing Backups Detected", + "setup_detected_backups_desc": "Backups were found on the server. You can restore your configuration right away.", + "btn_view_detected_backups": "View Backups", + "modal_picker_title": "Import Backup", + "modal_picker_sub": "Restore settings, VPN profiles and devices from the server, your PC or the Cloud", + "tab_server_backups": "Server Backups", + "tab_cloud_backups": "Cloud Services", + "tab_local_file": "Local File (PC)", + "server_backups_list_title": "Files found on server", + "server_backups_dir_hint": "Storage location: /app/backups/", + "server_backups_loading": "Searching for backups on the server…", + "server_backups_none": "No backups found on server.", + "cloud_setup_desc": "Connect directly to your remote storage (Google Drive, Dropbox, SFTP, FTP, WebDAV or S3) to browse and import your backups without your PC.", + "btn_test_cloud_connection": "Test Connection", + "btn_explore_cloud_backups": "Browse Cloud Backups", + "cloud_files_found_title": "Backups available on the Cloud:", + "local_file_upload_desc": "Select a backup archive (.zip) or configuration file (.json) previously exported from AP Manageur.", + "dropzone_title": "Click or drag and drop your file here", + "dropzone_hint": "Accepted formats: .zip, .json (max 100 MB)", + "btn_browse_pc": "Browse your files…" }; diff --git a/lang/fr.js b/lang/fr.js index 07d8b41..1fb7a44 100644 --- a/lang/fr.js +++ b/lang/fr.js @@ -1368,5 +1368,25 @@ window.I18N['fr'] = { "apikey_delete_confirm": "Êtes-vous sûr de vouloir supprimer définitivement la clé d’API « {name} » ?\\nTous les services l'utilisant perdront leur accès.", "log_cle_api_creee": "⚡ Clé API créée", "log_cle_api_modifiee": "⚡ Clé API modifiée", - "log_cle_api_supprimee": "🗑️ Clé API supprimée" + "log_cle_api_supprimee": "🗑️ Clé API supprimée", + "setup_detected_backups_title": "Sauvegardes existantes détectées", + "setup_detected_backups_desc": "Des sauvegardes ont été trouvées sur le serveur. Vous pouvez restaurer votre configuration immédiatement.", + "btn_view_detected_backups": "Voir les sauvegardes", + "modal_picker_title": "Importer une sauvegarde", + "modal_picker_sub": "Restaurez vos réglages, profils VPN et équipements depuis le serveur, votre PC ou le Cloud", + "tab_server_backups": "Sauvegardes serveur", + "tab_cloud_backups": "Services Cloud", + "tab_local_file": "Fichier local (PC)", + "server_backups_list_title": "Fichiers trouvés sur le serveur", + "server_backups_dir_hint": "Emplacement de stockage : /app/backups/", + "server_backups_loading": "Recherche des sauvegardes sur le serveur…", + "server_backups_none": "Aucune sauvegarde trouvée sur le serveur.", + "cloud_setup_desc": "Connectez-vous directement à votre stockage distant (Google Drive, Dropbox, SFTP, FTP, WebDAV ou S3) pour lister et importer vos sauvegardes sans passer par votre PC.", + "btn_test_cloud_connection": "Tester la connexion", + "btn_explore_cloud_backups": "Explorer les sauvegardes Cloud", + "cloud_files_found_title": "Sauvegardes disponibles sur le Cloud :", + "local_file_upload_desc": "Sélectionnez une archive de sauvegarde (.zip) ou un fichier de configuration (.json) exporté précédemment depuis AP Manageur.", + "dropzone_title": "Cliquez ou glissez-déposez votre fichier ici", + "dropzone_hint": "Formats acceptés : .zip, .json (max 100 Mo)", + "btn_browse_pc": "Parcourir vos fichiers…" }; diff --git a/setup.html b/setup.html index b7e2dbf..a9541a4 100644 --- a/setup.html +++ b/setup.html @@ -478,10 +478,31 @@ } #modalSetupVpn > div, - #modalSetupBackup > div { + #modalSetupBackup > div, + #modalSetupBackupPicker > div { animation: modalPop .24s cubic-bezier(0.22, 1, 0.36, 1); } + .setup-backup-tab.active { + border-bottom-color: var(--accent) !important; + color: var(--text) !important; + } + .setup-prov-btn { + transition: all .15s ease; + } + .setup-prov-btn:hover { + border-color: var(--accent) !important; + } + .setup-prov-btn.active { + border-color: var(--accent) !important; + background: var(--accent) !important; + color: #fff !important; + } + #setupDropZone:hover { + border-color: var(--accent) !important; + background: var(--panel3) !important; + } + @media (prefers-reduced-motion: reduce) { .step-panel, .step-panel.slide-prev, @@ -491,7 +512,8 @@ .field-reveal, .err-shake, #modalSetupVpn > div, - #modalSetupBackup > div { + #modalSetupBackup > div, + #modalSetupBackupPicker > div { animation: none !important; } @@ -1214,6 +1236,22 @@ + + + @@ -1222,7 +1260,7 @@
Étape 1 sur 6
- @@ -2388,6 +2426,227 @@
+ + +