From 6653f3cf721387c7c4bba0e8e43d42ccfef4ebb6 Mon Sep 17 00:00:00 2001 From: olaf Date: Thu, 19 Jun 2025 19:46:46 +0000 Subject: [PATCH] Set all requests to ssl --- dashboard/app.py | 52 +++++++++++++++---- dashboard/callbacks/appointments_callbacks.py | 24 ++++++--- dashboard/callbacks/overview_callbacks.py | 8 ++- 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/dashboard/app.py b/dashboard/app.py index fa08372..70b5a3f 100644 --- a/dashboard/app.py +++ b/dashboard/app.py @@ -2,44 +2,78 @@ import sys sys.path.append('/workspace') -from dash import Dash, html, dcc, page_container, Output, Input, State, callback +from dash import Dash, html, dcc, page_container from flask import Flask import dash_bootstrap_components as dbc import dash_mantine_components as dmc from components.header import Header -# from components.sidebar import Sidebar -import callbacks.ui_callbacks # wichtig! -import dashboard.callbacks.overview_callbacks # <-- Das registriert die Callbacks +import callbacks.ui_callbacks +import dashboard.callbacks.overview_callbacks import dashboard.callbacks.appointments_callbacks import dashboard.callbacks.appointment_modal_callbacks from config import SECRET_KEY, ENV +import os +import threading +import logging + +# Logging konfigurieren +logging.basicConfig( + level=logging.DEBUG if ENV == "development" else logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' +) +logger = logging.getLogger(__name__) server = Flask(__name__) server.secret_key = SECRET_KEY +# Flask's eigene Logs aktivieren +if ENV == "development": + logging.getLogger('werkzeug').setLevel(logging.INFO) + app = Dash( __name__, server=server, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True, - serve_locally=True + serve_locally=True, + meta_tags=[ + {"name": "viewport", "content": "width=device-width, initial-scale=1"}, + {"charset": "utf-8"} + ] ) app.layout = dmc.MantineProvider([ Header(), html.Div([ - html.Div(id="sidebar"), # KEINE className="sidebar" hier! + html.Div(id="sidebar"), html.Div(page_container, className="page-content"), dcc.Store(id="sidebar-state", data={"collapsed": False}), ], style={"display": "flex"}), ]) +# def open_browser(): +# """Öffnet die HTTPS-URL im Standardbrowser.""" +# os.system('$BROWSER https://localhost:8050') # Entferne das "&", um sicherzustellen, dass der Browser korrekt geöffnet wird + +print("Testausgabe: Debug-Print funktioniert!") # Testausgabe if __name__ == "__main__": + debug_mode = ENV == "development" + + logger.info(f"Starting application in {'DEBUG' if debug_mode else 'PRODUCTION'} mode") + logger.info(f"Environment: {ENV}") + logger.info("🔧 Debug features: print(), logging, hot reload all active") + logger.info("🚀 Dashboard starting up...") + + # Browser nur einmal öffnen, nicht bei Reload-Prozessen + # if debug_mode and os.environ.get("WERKZEUG_RUN_MAIN") != "true": + # threading.Timer(1.0, open_browser).start() + app.run( host="0.0.0.0", port=8050, - debug=(ENV=="development"), - ssl_context=("/workspace/certs/dev.crt", "/workspace/certs/dev.key") - ) + debug=debug_mode, + ssl_context=("/workspace/certs/dev.crt", "/workspace/certs/dev.key"), + use_reloader=False # Verhindert doppeltes Öffnen durch Dash + ) \ No newline at end of file diff --git a/dashboard/callbacks/appointments_callbacks.py b/dashboard/callbacks/appointments_callbacks.py index 2948660..3bd8a12 100644 --- a/dashboard/callbacks/appointments_callbacks.py +++ b/dashboard/callbacks/appointments_callbacks.py @@ -1,3 +1,7 @@ +import logging +from math import fabs + +logger = logging.getLogger(__name__) # dashboard/callbacks/appointments_callbacks.py import requests import json @@ -7,6 +11,10 @@ import os import sys from datetime import datetime, timedelta +# This message will now appear in the terminal during startup +logger.debug("Registering appointments page...") + + # --- Modalbox öffnen: jetzt auch auf Kalenderklick reagieren --- sys.path.append('/workspace') @@ -14,6 +22,7 @@ sys.path.append('/workspace') print("appointments_callbacks.py geladen") API_BASE_URL = os.getenv("API_BASE_URL", "http://192.168.43.100") +ENV = os.getenv("ENV", "development") @callback( @@ -51,22 +60,23 @@ def display_select(select_info): dash.Input('calendar', 'lastNavClick'), ) def load_events(view_dates): - """ - Lädt Events aus der API für den angezeigten Zeitraum im Kalender. - """ - print("Lade Events für Zeitraum:", view_dates) + logger.info(f"Lade Events für Zeitraum: {view_dates}") if not view_dates or "start" not in view_dates or "end" not in view_dates: return [] start = view_dates["start"] end = view_dates["end"] try: - resp = requests.get(f"{API_BASE_URL}/api/events", - params={"start": start, "end": end}) + verify_ssl = True if ENV == "production" else False + resp = requests.get( + f"{API_BASE_URL}/api/events", + params={"start": start, "end": end}, + verify=verify_ssl + ) resp.raise_for_status() events = resp.json() return events except Exception as e: - print("Fehler beim Laden der Events:", e) + logger.info(f"Fehler beim Laden der Events: {e}") return [] # --- Modalbox öffnen --- diff --git a/dashboard/callbacks/overview_callbacks.py b/dashboard/callbacks/overview_callbacks.py index 0ebc052..c0b4b75 100644 --- a/dashboard/callbacks/overview_callbacks.py +++ b/dashboard/callbacks/overview_callbacks.py @@ -17,7 +17,7 @@ from datetime import datetime print("overview_callbacks.py geladen") -API_BASE_URL = os.getenv("API_BASE_URL", "http://192.168.43.100") +API_BASE_URL = os.getenv("API_BASE_URL", "https://192.168.43.100") mqtt_thread_started = False SCREENSHOT_DIR = "received-screenshots" @@ -40,7 +40,11 @@ def get_latest_screenshot(client_uuid): def fetch_clients(): try: - resp = requests.get(f"{API_BASE_URL}/api/clients") + verify_ssl = True if ENV == "production" else False + resp = requests.get( + f"{API_BASE_URL}/api/clients", + verify=verify_ssl + ) resp.raise_for_status() return resp.json() except Exception as e: