APmanageur Wi-Fi V1.0
This commit is contained in:
1 parent
8770fe4f7a
commit
eb6659dad2
2 files changed
+88
-54
No files matched your search
@@ -750,6 +750,10 @@ def list_sessions(current_token='', lang='fr'):
|
||||
|
||||
def extract_token(h):
|
||||
token = h.headers.get('X-Session-Token', '') if hasattr(h, 'headers') else ''
|
||||
if not token and hasattr(h, 'headers'):
|
||||
auth_hdr = h.headers.get('Authorization', '')
|
||||
if auth_hdr.lower().startswith('bearer '):
|
||||
token = auth_hdr[7:].strip()
|
||||
if not token and hasattr(h, 'headers') and 'Cookie' in h.headers:
|
||||
for part in h.headers.get('Cookie', '').split(';'):
|
||||
part = part.strip()
|
||||
@@ -8468,6 +8472,60 @@ class Handler(BaseHTTPRequestHandler):
|
||||
log('modification_identifiants', f"Renommage machine -> {new_name}", request_ip(self), 'AUTH')
|
||||
self.send_json({'ok': True, 'message': 'Machine renommée avec succès', 'name': new_name})
|
||||
return
|
||||
if self.path == '/api/backup/inspect':
|
||||
if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return
|
||||
fname = str(data.get('filename', 'sauvegarde')).strip()
|
||||
b64_content = str(data.get('data_base64', '')).strip()
|
||||
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 self.path == '/api/backup/import':
|
||||
if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return
|
||||
try:
|
||||
was_active = False
|
||||
try: was_active = bool(status(force_refresh=True).get('active'))
|
||||
except Exception: pass
|
||||
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', ''))
|
||||
stats = import_backup_data(backup, data.get('options', {}))
|
||||
else:
|
||||
stats = import_backup_data(data)
|
||||
invalidate_status_cache()
|
||||
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), 'SYSTEM')
|
||||
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:
|
||||
self.send_json({'error': f'Erreur lors de la restauration: {e}'}, 400)
|
||||
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)
|
||||
self.send_json({'ok': True, 'message': 'Profil VPN enregistré avec succès', 'id': pid}); return
|
||||
if self.path == '/api/notifications/settings':
|
||||
if auth_state().get('configured') and not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
save_notifications_settings(data)
|
||||
self.send_json({'ok':True, 'message':'Réglages des notifications enregistrés avec succès'}); return
|
||||
if self.path == '/api/notifications/test':
|
||||
if auth_state().get('configured') and not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
channel = str(data.get('channel', 'all')).strip().lower()
|
||||
test_cfg = data.get('config')
|
||||
results = test_notifications(channel, test_config=test_cfg)
|
||||
self.send_json({'ok':True, 'results':results}); return
|
||||
if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
if self.path == '/api/clients/block': set_blocked(str(data.get('mac','')),bool(data.get('blocked',True))); self.send_json({'ok':True}); return
|
||||
if self.path == '/api/devices/limits':
|
||||
@@ -8696,10 +8754,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
c.commit(); c.close()
|
||||
log('configuration_proxy_inverse_modifiee', username(self) or 'Administrateur', request_ip(self), 'SETTINGS')
|
||||
self.send_json({'ok': True, 'message': 'Réglages du proxy inversé enregistrés avec succès !'}); 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)
|
||||
self.send_json({'ok': True, 'message': 'Profil VPN enregistré avec succès', 'id': pid}); return
|
||||
if self.path == '/api/vpn/profiles/delete':
|
||||
if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
pid = int(data.get('id', 0))
|
||||
@@ -8741,16 +8795,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
ks = 1 if data.get('kill_switch') else 0
|
||||
assign_client_vpn(mac, pid, ks)
|
||||
self.send_json({'ok': True, 'message': 'Assignation VPN du client mise à jour avec succès'}); return
|
||||
if self.path == '/api/notifications/settings':
|
||||
if auth_state().get('configured') and not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
save_notifications_settings(data)
|
||||
self.send_json({'ok':True, 'message':'Réglages des notifications enregistrés avec succès'}); return
|
||||
if self.path == '/api/notifications/test':
|
||||
if auth_state().get('configured') and not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
channel = str(data.get('channel', 'all')).strip().lower()
|
||||
test_cfg = data.get('config')
|
||||
results = test_notifications(channel, test_config=test_cfg)
|
||||
self.send_json({'ok':True, 'results':results}); return
|
||||
if self.path == '/api/notifications/stats-report/trigger':
|
||||
if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
|
||||
ok, msg = trigger_manual_stats_report()
|
||||
@@ -8800,40 +8844,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
with traffic_lock: station_traffic.clear()
|
||||
log('reinitialisation_donnees', 'Système', request_ip(self), 'SYSTEM')
|
||||
self.send_json({'ok':True,'message':'Toutes les données et le point d’accès ont été réinitialisés et supprimés'}); return
|
||||
if self.path == '/api/backup/inspect':
|
||||
if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return
|
||||
fname = str(data.get('filename', 'sauvegarde')).strip()
|
||||
b64_content = str(data.get('data_base64', '')).strip()
|
||||
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 self.path == '/api/backup/import':
|
||||
if not valid_session(self) and auth_state()['configured']: self.send_json({'error':'Authentification requise'},401); return
|
||||
try:
|
||||
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', ''))
|
||||
stats = import_backup_data(backup, data.get('options', {}))
|
||||
else:
|
||||
stats = import_backup_data(data)
|
||||
log('import_configuration_complete', username(self) or 'Administrateur', request_ip(self), 'SYSTEM')
|
||||
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:
|
||||
self.send_json({'error': f'Erreur lors de la restauration: {e}'}, 400)
|
||||
return
|
||||
if self.path == '/api/auth/2fa/status':
|
||||
self.send_json({'enabled':auth_state()['two_factor'],'recovery_remaining':recovery_remaining()}); return
|
||||
if self.path == '/api/auth/2fa/enable':
|
||||
|
||||
Reference in new issue
Block a user