diff --git a/backend/.claude/settings.local.json b/backend/.claude/settings.local.json index 52aac0259..8dbf45f04 100644 --- a/backend/.claude/settings.local.json +++ b/backend/.claude/settings.local.json @@ -36,7 +36,11 @@ "Bash(rg:*)", "Bash(grep:*)", "Bash(grep:*)", - "Bash(chmod:*)" + "Bash(chmod:*)", + "Bash(node --version)", + "Bash(npm --version)", + "Bash(python:*)", + "Bash(pip3 install:*)" ], "deny": [] } diff --git a/backend/__pycache__/app.cpython-313.pyc b/backend/__pycache__/app.cpython-313.pyc index eaf45ac76..b3f6ee4e8 100644 Binary files a/backend/__pycache__/app.cpython-313.pyc and b/backend/__pycache__/app.cpython-313.pyc differ diff --git a/backend/app.py b/backend/app.py index d01390be1..05df15de1 100644 --- a/backend/app.py +++ b/backend/app.py @@ -420,13 +420,8 @@ 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") +# Konfiguration anwenden basierend auf Environment wird später gemacht +# (nach Definition der apply_*_config Funktionen) # Session-Manager initialisieren session_manager.init_app(app) @@ -520,41 +515,7 @@ 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""" @@ -663,10 +624,6 @@ def apply_development_config(app): app_logger.info(f"[DEVELOPMENT] ✅ Debug Mode: {DevelopmentConfig.DEBUG}") app_logger.info(f"[DEVELOPMENT] ✅ SQL Echo: {DevelopmentConfig.SQLALCHEMY_ENGINE_OPTIONS.get('echo', False)}") -# Flask-App initialisieren -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() @@ -678,13 +635,12 @@ app_logger.info(f"[CONFIG] Production-Modus: {USE_PRODUCTION_CONFIG}") if USE_PRODUCTION_CONFIG: apply_production_config(app) - else: # Development-Konfiguration (konsolidiert default/fallback) app_logger.info("[CONFIG] Verwende Development-Konfiguration") apply_development_config(app) -# Umgebungs-spezifische Einstellungen werden bereits oben gesetzt +# Umgebungs-spezifische Einstellungen if OFFLINE_MODE: app_logger.info("[CONFIG] ✅ Air-Gapped/Offline-Modus aktiviert") app.config['DISABLE_EXTERNAL_REQUESTS'] = True diff --git a/backend/database/myp.db-shm b/backend/database/myp.db-shm index 6dbad0fe7..f47442a76 100644 Binary files a/backend/database/myp.db-shm and b/backend/database/myp.db-shm differ diff --git a/backend/logs/app/app.log b/backend/logs/app/app.log index 44c5787c8..25cee056a 100644 --- a/backend/logs/app/app.log +++ b/backend/logs/app/app.log @@ -41547,3 +41547,6 @@ WHERE users.id = ? 2025-06-16 17:45:06 - [app] app - [INFO] INFO - [SHUTDOWN] 🧹 Cleanup wird ausgeführt... 2025-06-16 17:45:06 - [app] app - [INFO] INFO - [SHUTDOWN] ✅ Queue Manager gestoppt 2025-06-16 17:45:06 - [app] app - [ERROR] ERROR - [SHUTDOWN] ❌ Cleanup-Fehler: 'BackgroundTaskScheduler' object has no attribute 'shutdown' +2025-06-16 18:04:07 - [app] app - [INFO] INFO - Optimierte SQLite-Engine erstellt: ./database/myp.db +2025-06-16 18:04:07 - [app] app - [INFO] INFO - SQLite für Raspberry Pi optimiert (reduzierte Cache-Größe, SD-Karten I/O) +2025-06-16 18:04:07 - [app] app - [INFO] INFO - Datenbank mit Optimierungen initialisiert diff --git a/backend/logs/core_system/core_system.log b/backend/logs/core_system/core_system.log index 702609b81..b894b3b9c 100644 --- a/backend/logs/core_system/core_system.log +++ b/backend/logs/core_system/core_system.log @@ -254,3 +254,5 @@ 2025-06-16 17:44:29 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion) 2025-06-16 17:44:56 - [core_system] core_system - [INFO] INFO - ✅ Core System Management Module erfolgreich initialisiert 2025-06-16 17:44:56 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion) +2025-06-16 18:04:07 - [core_system] core_system - [INFO] INFO - ✅ Core System Management Module erfolgreich initialisiert +2025-06-16 18:04:07 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion) diff --git a/backend/logs/data_management/data_management.log b/backend/logs/data_management/data_management.log index b4d511baf..f524b6be3 100644 --- a/backend/logs/data_management/data_management.log +++ b/backend/logs/data_management/data_management.log @@ -599,3 +599,5 @@ 2025-06-16 17:44:29 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) 2025-06-16 17:44:56 - [data_management] data_management - [INFO] INFO - ✅ Data Management Module initialisiert 2025-06-16 17:44:56 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) +2025-06-16 18:04:07 - [data_management] data_management - [INFO] INFO - ✅ Data Management Module initialisiert +2025-06-16 18:04:07 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) diff --git a/backend/logs/hardware_integration/hardware_integration.log b/backend/logs/hardware_integration/hardware_integration.log index 1800328df..738d19af5 100644 --- a/backend/logs/hardware_integration/hardware_integration.log +++ b/backend/logs/hardware_integration/hardware_integration.log @@ -2476,3 +2476,7 @@ 2025-06-16 17:44:56 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor initialisiert 2025-06-16 17:44:56 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert 2025-06-16 17:44:56 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion) +2025-06-16 18:04:07 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ PyP100 (TP-Link Tapo) verfügbar +2025-06-16 18:04:07 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor initialisiert +2025-06-16 18:04:07 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert +2025-06-16 18:04:07 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion) diff --git a/backend/logs/job_queue_system/job_queue_system.log b/backend/logs/job_queue_system/job_queue_system.log index 1ac98d9e9..9a08f2ea2 100644 --- a/backend/logs/job_queue_system/job_queue_system.log +++ b/backend/logs/job_queue_system/job_queue_system.log @@ -1179,3 +1179,5 @@ 2025-06-16 17:44:57 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestartet (Legacy-Kompatibilität) 2025-06-16 17:45:05 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestoppt (Legacy-Kompatibilität) 2025-06-16 17:45:06 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestoppt (Legacy-Kompatibilität) +2025-06-16 18:04:07 - [job_queue_system] job_queue_system - [INFO] INFO - ✅ Job & Queue System Module initialisiert +2025-06-16 18:04:07 - [job_queue_system] job_queue_system - [INFO] INFO - 📊 MASSIVE Konsolidierung: 4 Dateien → 1 Datei (75% Reduktion) diff --git a/backend/logs/monitoring_analytics/monitoring_analytics.log b/backend/logs/monitoring_analytics/monitoring_analytics.log index 4ecf0f3b0..aae3e03a3 100644 --- a/backend/logs/monitoring_analytics/monitoring_analytics.log +++ b/backend/logs/monitoring_analytics/monitoring_analytics.log @@ -599,3 +599,5 @@ 2025-06-16 17:44:30 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) 2025-06-16 17:44:57 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert 2025-06-16 17:44:57 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) +2025-06-16 18:04:10 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert +2025-06-16 18:04:10 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) diff --git a/backend/logs/scheduler/scheduler.log b/backend/logs/scheduler/scheduler.log index 582d7b9d0..9f43e5443 100644 --- a/backend/logs/scheduler/scheduler.log +++ b/backend/logs/scheduler/scheduler.log @@ -2106,3 +2106,4 @@ 2025-06-16 17:44:56 - [scheduler] scheduler - [INFO] INFO - Task check_jobs registriert: Intervall 30s, Enabled: True 2025-06-16 17:44:57 - [scheduler] scheduler - [INFO] INFO - Scheduler-Thread gestartet 2025-06-16 17:44:57 - [scheduler] scheduler - [INFO] INFO - Scheduler gestartet +2025-06-16 18:04:07 - [scheduler] scheduler - [INFO] INFO - Task check_jobs registriert: Intervall 30s, Enabled: True diff --git a/backend/logs/security_suite/security_suite.log b/backend/logs/security_suite/security_suite.log index 7d87768fa..28bf0dd4d 100644 --- a/backend/logs/security_suite/security_suite.log +++ b/backend/logs/security_suite/security_suite.log @@ -899,3 +899,5 @@ 2025-06-16 17:44:56 - [security_suite] security_suite - [INFO] INFO - ✅ Security Suite Module initialisiert 2025-06-16 17:44:56 - [security_suite] security_suite - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) 2025-06-16 17:44:57 - [security_suite] security_suite - [INFO] INFO - 🔒 Security Suite initialisiert +2025-06-16 18:04:07 - [security_suite] security_suite - [INFO] INFO - ✅ Security Suite Module initialisiert +2025-06-16 18:04:07 - [security_suite] security_suite - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion) diff --git a/backend/logs/startup/startup.log b/backend/logs/startup/startup.log index c1432cbee..f69230ae8 100644 --- a/backend/logs/startup/startup.log +++ b/backend/logs/startup/startup.log @@ -2364,3 +2364,12 @@ 2025-06-16 17:44:57 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert 2025-06-16 17:44:57 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert 2025-06-16 17:44:57 - [startup] startup - [INFO] INFO - ================================================== +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - ================================================== +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - [START] MYP Platform Backend wird gestartet... +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - 🐍 Python Version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - 💻 Betriebssystem: nt (win32) +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - 📁 Arbeitsverzeichnis: C:\Users\TTOMCZA.EMEA\Dev\Projektarbeit-MYP\backend +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - ⏰ Startzeit: 2025-06-16T18:04:10.535096 +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert +2025-06-16 18:04:10 - [startup] startup - [INFO] INFO - ================================================== diff --git a/backend/logs/tapo_controller/tapo_controller.log b/backend/logs/tapo_controller/tapo_controller.log index 2e6aa9ff1..b18bb90c4 100644 --- a/backend/logs/tapo_controller/tapo_controller.log +++ b/backend/logs/tapo_controller/tapo_controller.log @@ -2888,3 +2888,4 @@ 2025-06-16 17:44:25 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert 2025-06-16 17:44:29 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert 2025-06-16 17:44:56 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert +2025-06-16 18:04:07 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert diff --git a/backend/logs/tapo_status_manager/tapo_status_manager.log b/backend/logs/tapo_status_manager/tapo_status_manager.log index b0fe671f7..7e172db7c 100644 --- a/backend/logs/tapo_status_manager/tapo_status_manager.log +++ b/backend/logs/tapo_status_manager/tapo_status_manager.log @@ -266,3 +266,4 @@ 2025-06-16 17:44:25 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager mit Session-Caching initialisiert 2025-06-16 17:44:29 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager mit Session-Caching initialisiert 2025-06-16 17:44:56 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager mit Session-Caching initialisiert +2025-06-16 18:04:07 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager mit Session-Caching initialisiert diff --git a/backend/logs/utilities_collection/utilities_collection.log b/backend/logs/utilities_collection/utilities_collection.log index b5e864453..c465781e9 100644 --- a/backend/logs/utilities_collection/utilities_collection.log +++ b/backend/logs/utilities_collection/utilities_collection.log @@ -769,3 +769,5 @@ 2025-06-16 17:44:29 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) 2025-06-16 17:44:56 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert 2025-06-16 17:44:56 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) +2025-06-16 18:04:07 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert +2025-06-16 18:04:07 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) diff --git a/backend/logs/windows_fixes/windows_fixes.log b/backend/logs/windows_fixes/windows_fixes.log index b0425f146..a139effc7 100644 --- a/backend/logs/windows_fixes/windows_fixes.log +++ b/backend/logs/windows_fixes/windows_fixes.log @@ -257,3 +257,5 @@ 2025-06-16 17:44:29 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet 2025-06-16 17:44:56 - [windows_fixes] windows_fixes - [INFO] INFO - 🔧 Wende Windows-spezifische Fixes an... 2025-06-16 17:44:56 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet +2025-06-16 18:04:07 - [windows_fixes] windows_fixes - [INFO] INFO - 🔧 Wende Windows-spezifische Fixes an... +2025-06-16 18:04:07 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet diff --git a/backend/utils/settings.py b/backend/utils/settings.py new file mode 100644 index 000000000..f40356490 --- /dev/null +++ b/backend/utils/settings.py @@ -0,0 +1,192 @@ +import os +import json +from datetime import timedelta + +def get_env_variable(name: str, default: str = None) -> str: + """ + Holt eine Umgebungsvariable oder gibt den Standardwert zurück. + + Args: + name: Name der Umgebungsvariable + default: Standardwert, falls die Variable nicht gesetzt ist + + Returns: + str: Wert der Umgebungsvariable oder Standardwert + """ + return os.environ.get(name, default) + +# Hardcodierte Konfiguration +SECRET_KEY = "7445630171969DFAC92C53CEC92E67A9CB2E00B3CB2F" + +# Dynamische Pfade basierend auf dem aktuellen Arbeitsverzeichnis +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # backend/app +PROJECT_ROOT = os.path.dirname(BASE_DIR) # Projektroot +DATABASE_PATH = os.path.join(PROJECT_ROOT, "database", "myp.db") # ./database/myp.db + +# ===== SMART PLUG KONFIGURATION ===== +# TP-Link Tapo P110 Standardkonfiguration +TAPO_USERNAME = "till.tomczak@mercedes-benz.com" +TAPO_PASSWORD = "744563017196A" + +# Automatische Steckdosen-Erkennung aktivieren +TAPO_AUTO_DISCOVERY = True + +# Standard-Steckdosen-IPs (Mercedes-Benz TBA Marienfelde - 6 feste Arbeitsplätze) +DEFAULT_TAPO_IPS = [ + "192.168.0.100", # 3D-Drucker 1 - TBA Marienfelde + "192.168.0.101", # 3D-Drucker 2 - TBA Marienfelde + "192.168.0.102", # 3D-Drucker 3 - TBA Marienfelde + "192.168.0.103", # 3D-Drucker 4 - TBA Marienfelde + "192.168.0.104", # 3D-Drucker 5 - TBA Marienfelde + "192.168.0.106" # 3D-Drucker 6 - TBA Marienfelde +] + +# Timeout-Konfiguration für Tapo-Verbindungen +TAPO_TIMEOUT = 10 # Sekunden +TAPO_RETRY_COUNT = 3 # Anzahl Wiederholungsversuche + +# Drucker-Konfiguration mit korrekten IPs +PRINTERS = { + "3D-Drucker 1 - Halle A": {"ip": "192.168.1.101", "plug_ip": "192.168.1.201"}, + "3D-Drucker 2 - Halle A": {"ip": "192.168.1.102", "plug_ip": "192.168.1.202"}, + "3D-Drucker 3 - Halle B": {"ip": "192.168.1.103", "plug_ip": "192.168.1.203"}, + "3D-Drucker 4 - Halle B": {"ip": "192.168.1.104", "plug_ip": "192.168.1.204"}, + "3D-Drucker 5 - Labor": {"ip": "192.168.1.105", "plug_ip": "192.168.1.205"}, + "3D-Drucker 6 - Werkstatt": {"ip": "192.168.1.106", "plug_ip": "192.168.1.206"} +} + +# Logging-Konfiguration +LOG_DIR = os.path.join(BASE_DIR, "logs") +LOG_SUBDIRS = ["app", "scheduler", "auth", "jobs", "printers", "errors"] +LOG_LEVEL = "INFO" +LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" +LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" + +# Flask-Konfiguration +FLASK_HOST = "0.0.0.0" +FLASK_PORT = 443 # Geändert von 443 auf 8443 (nicht-privilegierter Port) +FLASK_FALLBACK_PORT = 8080 # Geändert von 80 auf 8080 (nicht-privilegierter Port) +FLASK_DEBUG = True +SESSION_LIFETIME = timedelta(hours=2) # Reduziert von 7 Tagen auf 2 Stunden für bessere Sicherheit + +# Upload-Konfiguration +UPLOAD_FOLDER = os.path.join(PROJECT_ROOT, "uploads") # ./uploads im Projektroot +ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'gcode', '3mf', 'stl'} +MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB Maximum-Dateigröße +MAX_FILE_SIZE = 16 * 1024 * 1024 # 16MB Maximum-Dateigröße für Drag & Drop System + +# Umgebungskonfiguration +ENVIRONMENT = get_env_variable("MYP_ENVIRONMENT", "development") + +# SSL-Konfiguration +SSL_ENABLED = get_env_variable("MYP_SSL_ENABLED", "True").lower() in ("true", "1", "yes") +SSL_CERT_PATH = os.path.join(BASE_DIR, "certs", "myp.crt") +SSL_KEY_PATH = os.path.join(BASE_DIR, "certs", "myp.key") +SSL_HOSTNAME = get_env_variable("MYP_SSL_HOSTNAME", "localhost") + +# Scheduler-Konfiguration +SCHEDULER_INTERVAL = 60 # Sekunden +SCHEDULER_ENABLED = True + +# Datenbank-Konfiguration +DB_ENGINE = f"sqlite:///{DATABASE_PATH}" + +# Mercedes-Benz TBA spezifische Konfiguration +FIXED_PRINTER_COUNT = 6 # Immer 6 feste Arbeitsplätze anzeigen +ALWAYS_SHOW_ALL_SOCKETS = True # Alle 6 Steckdosen immer anzeigen, auch wenn offline + +def get_log_file(category: str) -> str: + """ + Gibt den Pfad zur Log-Datei für eine bestimmte Kategorie zurück. + + Args: + category: Log-Kategorie (app, scheduler, auth, jobs, printers, errors) + + Returns: + str: Pfad zur Log-Datei + """ + if category not in LOG_SUBDIRS: + category = "app" + + return os.path.join(LOG_DIR, category, f"{category}.log") + +def ensure_log_directories(): + """Erstellt alle erforderlichen Log-Verzeichnisse.""" + os.makedirs(LOG_DIR, exist_ok=True) + for subdir in LOG_SUBDIRS: + os.makedirs(os.path.join(LOG_DIR, subdir), exist_ok=True) + +def ensure_database_directory(): + """Erstellt das Datenbank-Verzeichnis.""" + db_dir = os.path.dirname(DATABASE_PATH) + if db_dir: + os.makedirs(db_dir, exist_ok=True) + +def ensure_ssl_directory(): + """Erstellt das SSL-Verzeichnis, falls es nicht existiert.""" + ssl_dir = os.path.dirname(SSL_CERT_PATH) + if ssl_dir and not os.path.exists(ssl_dir): + os.makedirs(ssl_dir, exist_ok=True) + +def ensure_upload_directory(): + """Erstellt das Upload-Verzeichnis, falls es nicht existiert.""" + if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER, exist_ok=True) + +def get_ssl_context(): + """ + Gibt den SSL-Kontext für Flask zurück, wenn SSL aktiviert ist. + + Returns: + tuple oder None: Tuple mit Zertifikat- und Schlüsselpfad, wenn SSL aktiviert ist, sonst None + """ + if not SSL_ENABLED: + return None + + # Wenn Zertifikate nicht existieren, diese automatisch erstellen + if not os.path.exists(SSL_CERT_PATH) or not os.path.exists(SSL_KEY_PATH): + ensure_ssl_directory() + + # Im Entwicklungsmodus versuchen wir, einfache Zertifikate zu erstellen + if FLASK_DEBUG: + print("SSL-Zertifikate nicht gefunden. Erstelle einfache selbstsignierte Zertifikate...") + try: + # Einfache Zertifikate mit Python erstellen + create_simple_ssl_cert() + + # Prüfen, ob die Zertifikate erfolgreich erstellt wurden + if not os.path.exists(SSL_CERT_PATH) or not os.path.exists(SSL_KEY_PATH): + print("Konnte keine SSL-Zertifikate erstellen.") + return None + + except Exception as e: + print(f"Fehler beim Erstellen der SSL-Zertifikate: {e}") + return None + else: + print("WARNUNG: SSL-Zertifikate nicht gefunden und Nicht-Debug-Modus. SSL wird deaktiviert.") + return None + + return (SSL_CERT_PATH, SSL_KEY_PATH) + +def create_simple_ssl_cert(): + """ + Erstellt ein Mercedes-Benz SSL-Zertifikat mit dem neuen SSL-Manager. + """ + try: + # Verwende den neuen SSL-Manager + from utils.ssl_manager import ssl_manager + success = ssl_manager.generate_mercedes_certificate() + + if success: + print(f"Mercedes-Benz SSL-Zertifikat erfolgreich erstellt: {SSL_CERT_PATH}") + return True + else: + print("Fehler beim Erstellen des Mercedes-Benz SSL-Zertifikats") + return None + + except ImportError as e: + print(f"SSL-Manager nicht verfügbar: {e}") + return None + except Exception as e: + print(f"Fehler beim Erstellen der SSL-Zertifikate: {e}") + return None \ No newline at end of file