Die Dateien wurden geändert und hinzugefügt:

This commit is contained in:
2025-06-16 17:58:27 +02:00
parent 19cb6d95b1
commit a1782ce6b5
140 changed files with 1610 additions and 10 deletions

1
COMMON_ERRORS.md Normal file
View File

@ -0,0 +1 @@

View File

@ -371,6 +371,9 @@ def get_environment_type():
else:
return 'development'
# ===== GLOBALE KONFIGURATIONSVARIABLEN =====
# Diese werden später nach den Funktionsdefinitionen gesetzt
# Windows-spezifische Fixes
if os.name == 'nt':
try:
@ -414,6 +417,30 @@ log_startup_info()
# Logger für verschiedene Komponenten
app_logger = get_logger("app")
# ===== FLASK-APP INITIALISIERUNG =====
app = Flask(__name__)
# Konfiguration anwenden basierend auf Environment
if USE_PRODUCTION_CONFIG:
apply_production_config(app)
app_logger.info(f"[INIT] ✅ Production-Konfiguration angewendet")
else:
apply_development_config(app)
app_logger.info(f"[INIT] ✅ Development-Konfiguration angewendet")
# Session-Manager initialisieren
session_manager.init_app(app)
# Login-Manager initialisieren
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'auth.login'
login_manager.login_message = 'Bitte melden Sie sich an, um auf diese Seite zuzugreifen.'
login_manager.login_message_category = 'info'
# CSRF-Schutz initialisieren
csrf = CSRFProtect(app)
# Thread-sichere Caches
_user_cache = {}
_user_cache_lock = threading.RLock()
@ -493,6 +520,42 @@ def register_aggressive_shutdown():
# Shutdown-Handler registrieren
register_aggressive_shutdown()
def apply_production_config(app):
"""Wendet die Production-Konfiguration auf die Flask-App an"""
app_logger.info("[PRODUCTION] Aktiviere Production-Konfiguration für Mercedes-Benz TBA")
# Dynamische Werte setzen
app.config.from_object(ProductionConfig)
app.config['SECRET_KEY'] = SECRET_KEY
app.config['PERMANENT_SESSION_LIFETIME'] = SESSION_LIFETIME
# SSL-Konfiguration
app.config['PREFERRED_URL_SCHEME'] = 'https'
# Security Headers setzen
@app.after_request
def set_security_headers(response):
"""Setzt Production-Security-Headers"""
for header, value in ProductionConfig.SECURITY_HEADERS.items():
response.headers[header] = value
return response
app_logger.info("[PRODUCTION] ✅ Production-Konfiguration aktiviert")
def apply_development_config(app):
"""Wendet die Development-Konfiguration auf die Flask-App an"""
app_logger.info("[DEVELOPMENT] Aktiviere Development-Konfiguration")
# Dynamische Werte setzen
app.config.from_object(DevelopmentConfig)
app.config['SECRET_KEY'] = SECRET_KEY
app.config['PERMANENT_SESSION_LIFETIME'] = SESSION_LIFETIME
# HTTP für Development
app.config['PREFERRED_URL_SCHEME'] = 'http'
app_logger.info("[DEVELOPMENT] ✅ Development-Konfiguration aktiviert")
def apply_production_config(app):
"""Wendet die Production-Konfiguration auf die Flask-App an"""
app_logger.info("[PRODUCTION] Aktiviere Production-Konfiguration für Mercedes-Benz TBA")
@ -605,8 +668,10 @@ app = Flask(__name__)
app.secret_key = SECRET_KEY
# ===== KONFIGURATION ANWENDEN =====
# Jetzt können wir die Funktionen aufrufen, da sie definiert sind
ENVIRONMENT_TYPE = get_environment_type()
USE_PRODUCTION_CONFIG = detect_production_environment()
OFFLINE_MODE = USE_PRODUCTION_CONFIG
app_logger.info(f"[CONFIG] Erkannte Umgebung: {ENVIRONMENT_TYPE}")
app_logger.info(f"[CONFIG] Production-Modus: {USE_PRODUCTION_CONFIG}")
@ -619,8 +684,7 @@ else:
app_logger.info("[CONFIG] Verwende Development-Konfiguration")
apply_development_config(app)
# Umgebungs-spezifische Einstellungen
OFFLINE_MODE = getattr(ProductionConfig, 'OFFLINE_MODE', False) if USE_PRODUCTION_CONFIG else getattr(DevelopmentConfig, 'OFFLINE_MODE', False)
# Umgebungs-spezifische Einstellungen werden bereits oben gesetzt
if OFFLINE_MODE:
app_logger.info("[CONFIG] ✅ Air-Gapped/Offline-Modus aktiviert")
app.config['DISABLE_EXTERNAL_REQUESTS'] = True
@ -1455,6 +1519,56 @@ def handle_exception(error):
app_logger.error(f"Template-Fehler im Exception-Handler: {str(template_error)}")
return f"<h1>500 - Unerwarteter Fehler</h1><p>Ein unerwarteter Fehler ist aufgetreten. Fehler-ID: {error_id}</p>", 500
# ===== APP-FACTORY =====
def create_app(config_name=None):
"""
Flask-App-Factory für Tests und modulare Initialisierung
Args:
config_name: 'production', 'development' oder None (auto-detect)
Returns:
Flask: Konfigurierte Flask-App-Instanz
"""
# Bestimme Konfiguration
if config_name is None:
config_name = get_environment_type()
# Setze Environment-Variablen basierend auf config_name
if config_name == 'production':
os.environ['FLASK_ENV'] = 'production'
os.environ['USE_PRODUCTION_CONFIG'] = 'true'
else:
os.environ['FLASK_ENV'] = 'development'
os.environ['USE_PRODUCTION_CONFIG'] = 'false'
# Globale Variablen neu setzen
global ENVIRONMENT_TYPE, USE_PRODUCTION_CONFIG, OFFLINE_MODE
ENVIRONMENT_TYPE = config_name
USE_PRODUCTION_CONFIG = (config_name == 'production')
OFFLINE_MODE = USE_PRODUCTION_CONFIG
# App-Konfiguration anwenden
if USE_PRODUCTION_CONFIG:
apply_production_config(app)
app_logger.info(f"[FACTORY] ✅ Production-Konfiguration angewendet")
else:
apply_development_config(app)
app_logger.info(f"[FACTORY] ✅ Development-Konfiguration angewendet")
# Session-Manager initialisieren
session_manager.init_app(app)
# Sicherheitssuite initialisieren
try:
init_security(app)
app_logger.info("[FACTORY] ✅ Sicherheitssuite initialisiert")
except Exception as e:
app_logger.warning(f"[FACTORY] ⚠️ Sicherheitssuite-Fehler: {e}")
app_logger.info(f"[FACTORY] 🏭 Flask-App erstellt ({config_name})")
return app
# ===== HAUPTFUNKTION =====
def main():
"""Hauptfunktion zum Starten der Anwendung"""

BIN
backend/database/myp.db-shm Normal file

Binary file not shown.

BIN
backend/database/myp.db-wal Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More