Refactoring - Part 1
1. Konfiguration extrahiert (config.py)
- Alle App-Einstellungen zentralisiert
- Flask-Konfiguration, Datenbank, Backup, Rate-Limiting
- 576 Zeilen Code reduziert
2. Datenbank-Layer (db.py)
- Connection Management mit Context Managers
- Helper-Funktionen für Queries
- Saubere Fehlerbehandlung
3. Auth-Module (auth/)
- decorators.py - Login-Required mit Session-Timeout
- password.py - Bcrypt Hashing
- two_factor.py - TOTP, QR-Codes, Backup-Codes
- rate_limiting.py - IP-Blocking, Login-Versuche
4. Utility-Module (utils/)
- audit.py - Audit-Logging
- backup.py - Verschlüsselte Backups
- license.py - Lizenzschlüssel-Generierung
- export.py - Excel-Export
- network.py - IP-Ermittlung
- recaptcha.py - reCAPTCHA-Verifikation
5. Models (models.py)
- User-Model-Funktionen
Dieser Commit ist enthalten in:
52
v2_adminpanel/remove_duplicate_routes.py
Normale Datei
52
v2_adminpanel/remove_duplicate_routes.py
Normale Datei
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Remove duplicate routes that have been moved to blueprints
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
# Read the current app.py
|
||||
with open('app.py', 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# List of function names that have been moved to blueprints
|
||||
moved_functions = [
|
||||
# Auth routes
|
||||
'login',
|
||||
'logout',
|
||||
'verify_2fa',
|
||||
'profile',
|
||||
'change_password',
|
||||
'setup_2fa',
|
||||
'enable_2fa',
|
||||
'disable_2fa',
|
||||
'heartbeat',
|
||||
# Admin routes
|
||||
'dashboard',
|
||||
'audit_log',
|
||||
'backups',
|
||||
'create_backup_route',
|
||||
'restore_backup_route',
|
||||
'download_backup',
|
||||
'delete_backup',
|
||||
'blocked_ips',
|
||||
'unblock_ip',
|
||||
'clear_attempts'
|
||||
]
|
||||
|
||||
# Create a pattern to match route decorators and their functions
|
||||
for func_name in moved_functions:
|
||||
# Pattern to match from @app.route to the end of the function
|
||||
pattern = rf'@app\.route\([^)]+\)\s*(?:@login_required\s*)?def {func_name}\([^)]*\):.*?(?=\n@app\.route|\n@[a-zA-Z]|\nif __name__|$)'
|
||||
|
||||
# Replace with a comment
|
||||
replacement = f'# Function {func_name} moved to blueprint'
|
||||
|
||||
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
|
||||
|
||||
# Write the modified content
|
||||
with open('app_no_duplicates.py', 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
print("Created app_no_duplicates.py with duplicate routes removed")
|
||||
print("Please review the file before using it")
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren