feat: Implement SSL support and kiosk mode enhancements
- Added SSL configuration to the backend, including self-signed certificate generation and management. - Updated `setup_myp.sh` to create SSL certificates during installation. - Enhanced `app.py` to support SSL context for secure communication. - Introduced a new SSL management menu in the setup script for easier certificate handling. - Updated frontend API calls to use HTTPS for secure data transmission. - Implemented kiosk mode features, including automatic browser launch with SSL support. - Improved documentation in `SUMMARY.md` to reflect new features and network topology changes.
This commit is contained in:
@@ -18,7 +18,7 @@ from flask_wtf.csrf import CSRFProtect
|
||||
from config.settings import (
|
||||
SECRET_KEY, TAPO_USERNAME, TAPO_PASSWORD, PRINTERS,
|
||||
FLASK_HOST, FLASK_PORT, FLASK_DEBUG, SESSION_LIFETIME,
|
||||
SCHEDULER_INTERVAL, SCHEDULER_ENABLED
|
||||
SCHEDULER_INTERVAL, SCHEDULER_ENABLED, get_ssl_context
|
||||
)
|
||||
from utils.logging_config import setup_logging, get_logger, log_startup_info
|
||||
from models import User, Printer, Job, Stats, get_db_session, init_database, create_initial_admin
|
||||
@@ -1265,16 +1265,19 @@ def tailwind_watch():
|
||||
|
||||
# Auto-Kompilierung beim Serverstart im Debug-Modus
|
||||
def compile_tailwind_if_debug():
|
||||
if app.debug:
|
||||
"""Kompiliert Tailwind CSS im Debug-Modus, falls notwendig."""
|
||||
if FLASK_DEBUG:
|
||||
try:
|
||||
subprocess.run(["npx", "tailwindcss", "-i", "./static/css/input.css",
|
||||
"-o", "./static/css/tailwind-dark-consolidated.min.css"],
|
||||
check=True, capture_output=True)
|
||||
print("Tailwind CSS für Debug-Modus kompiliert.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Warnung: Konnte Tailwind CSS nicht kompilieren: {e}")
|
||||
except FileNotFoundError:
|
||||
print("Warnung: Node.js/npm nicht gefunden. Tailwind CSS wurde nicht kompiliert.")
|
||||
app_logger.info("Kompiliere Tailwind CSS...")
|
||||
subprocess.run([
|
||||
"npx", "tailwindcss", "-i", "static/css/input.css",
|
||||
"-o", "static/css/tailwind.min.css", "--minify"
|
||||
], check=True)
|
||||
app_logger.info("Tailwind CSS erfolgreich kompiliert.")
|
||||
except subprocess.CalledProcessError:
|
||||
app_logger.warning("Tailwind konnte nicht kompiliert werden. Möglicherweise ist npx/Node.js nicht installiert.")
|
||||
except Exception as e:
|
||||
app_logger.error(f"Fehler beim Kompilieren von Tailwind CSS: {str(e)}")
|
||||
|
||||
# Tailwind CSS kompilieren, wenn im Debug-Modus
|
||||
if FLASK_DEBUG:
|
||||
@@ -1282,34 +1285,65 @@ if FLASK_DEBUG:
|
||||
|
||||
# Initialisierung der Datenbank beim Start
|
||||
def init_app():
|
||||
"""Initialisiert die App-Komponenten und startet den Scheduler."""
|
||||
# Datenbank initialisieren
|
||||
try:
|
||||
# Datenbank initialisieren
|
||||
init_database()
|
||||
# Admin-Benutzer erstellen oder zurücksetzen
|
||||
create_initial_admin()
|
||||
|
||||
# Template-Helper registrieren
|
||||
register_template_helpers(app)
|
||||
app_logger.info("Template-Helper registriert")
|
||||
|
||||
# Scheduler starten, wenn aktiviert
|
||||
if SCHEDULER_ENABLED:
|
||||
scheduler.start()
|
||||
app_logger.info("Job-Scheduler gestartet")
|
||||
except Exception as e:
|
||||
app_logger.error(f"Fehler bei der Initialisierung: {str(e)}")
|
||||
app_logger.error(f"Fehler bei der Datenbank-Initialisierung: {str(e)}")
|
||||
|
||||
# Jinja2-Helfer registrieren
|
||||
register_template_helpers(app)
|
||||
|
||||
# Tailwind im Debug-Modus kompilieren
|
||||
compile_tailwind_if_debug()
|
||||
|
||||
# Scheduler starten, wenn aktiviert
|
||||
if SCHEDULER_ENABLED:
|
||||
try:
|
||||
# Scheduler-Task für Druckauftrags-Prüfung registrieren
|
||||
scheduler.register_task(
|
||||
"check_jobs",
|
||||
check_jobs,
|
||||
interval=SCHEDULER_INTERVAL
|
||||
)
|
||||
|
||||
# Scheduler starten
|
||||
scheduler.start()
|
||||
app_logger.info(f"Scheduler gestartet mit Intervall {SCHEDULER_INTERVAL} Sekunden.")
|
||||
except Exception as e:
|
||||
app_logger.error(f"Fehler beim Starten des Schedulers: {str(e)}")
|
||||
|
||||
# SSL-Kontext protokollieren
|
||||
ssl_context = get_ssl_context()
|
||||
if ssl_context:
|
||||
app_logger.info(f"SSL aktiviert mit Zertifikat {ssl_context[0]}")
|
||||
else:
|
||||
app_logger.warning("SSL ist deaktiviert. Die Verbindung ist unverschlüsselt!")
|
||||
|
||||
# App starten
|
||||
if __name__ == "__main__":
|
||||
# Initialisierung ausführen
|
||||
init_app()
|
||||
|
||||
# Flask-Server starten
|
||||
app.run(
|
||||
host=FLASK_HOST,
|
||||
port=FLASK_PORT,
|
||||
debug=FLASK_DEBUG
|
||||
)
|
||||
try:
|
||||
# App initialisieren
|
||||
init_app()
|
||||
|
||||
# SSL-Kontext ermitteln
|
||||
ssl_context = get_ssl_context()
|
||||
|
||||
# Konsolen-Ausgabe für HTTPS
|
||||
protocol = "HTTPS" if ssl_context else "HTTP"
|
||||
app_logger.info(f"MYP startet auf {protocol}://{FLASK_HOST}:{FLASK_PORT} (Debug: {FLASK_DEBUG})")
|
||||
|
||||
# App starten
|
||||
app.run(
|
||||
host=FLASK_HOST,
|
||||
port=FLASK_PORT,
|
||||
debug=FLASK_DEBUG,
|
||||
ssl_context=ssl_context
|
||||
)
|
||||
except Exception as e:
|
||||
app_logger.critical(f"Kritischer Fehler beim Starten der Anwendung: {str(e)}")
|
||||
|
||||
# Content Security Policy anpassen
|
||||
@app.after_request
|
||||
|
Reference in New Issue
Block a user