"feat: Integrate new API for user authentication in backend"
This commit is contained in:
parent
ebaef3a9b5
commit
3b53e78799
@ -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, get_ssl_context
|
||||
SCHEDULER_INTERVAL, SCHEDULER_ENABLED, get_ssl_context, FLASK_FALLBACK_PORT
|
||||
)
|
||||
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
|
||||
@ -1324,26 +1324,41 @@ def init_app():
|
||||
|
||||
# App starten
|
||||
if __name__ == "__main__":
|
||||
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)}")
|
||||
init_app()
|
||||
ssl_context = get_ssl_context()
|
||||
|
||||
# Starte den Haupt-Server mit SSL auf Port 443
|
||||
if ssl_context:
|
||||
print(f"Starte Flask-Server mit SSL auf {FLASK_HOST}:{FLASK_PORT}")
|
||||
app.run(host=FLASK_HOST, port=FLASK_PORT, debug=FLASK_DEBUG, ssl_context=ssl_context)
|
||||
else:
|
||||
print(f"Starte Flask-Server ohne SSL auf {FLASK_HOST}:{FLASK_PORT}")
|
||||
app.run(host=FLASK_HOST, port=FLASK_PORT, debug=FLASK_DEBUG)
|
||||
|
||||
# Starte einen zweiten Server auf Port 80 als Fallback
|
||||
# Dies wird in einem separaten Thread ausgeführt
|
||||
def run_fallback_server():
|
||||
try:
|
||||
from werkzeug.serving import make_server
|
||||
fallback_app = Flask("fallback_app")
|
||||
|
||||
@fallback_app.route('/', defaults={'path': ''})
|
||||
@fallback_app.route('/<path:path>')
|
||||
def catch_all(path):
|
||||
# Leite alle Anfragen an HTTPS weiter
|
||||
host = request.host.split(':')[0]
|
||||
return redirect(f"https://{host}:{FLASK_PORT}/{path}")
|
||||
|
||||
server = make_server(FLASK_HOST, FLASK_FALLBACK_PORT, fallback_app)
|
||||
print(f"Starte Fallback-Server auf {FLASK_HOST}:{FLASK_FALLBACK_PORT}")
|
||||
server.serve_forever()
|
||||
except Exception as e:
|
||||
print(f"Fehler beim Starten des Fallback-Servers: {str(e)}")
|
||||
|
||||
# Starte den Fallback-Server in einem separaten Thread
|
||||
fallback_thread = threading.Thread(target=run_fallback_server)
|
||||
fallback_thread.daemon = True
|
||||
fallback_thread.start()
|
||||
|
||||
# Content Security Policy anpassen
|
||||
@app.after_request
|
||||
|
@ -27,7 +27,8 @@ LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
# Flask-Konfiguration
|
||||
FLASK_HOST = "0.0.0.0"
|
||||
FLASK_PORT = 5000
|
||||
FLASK_PORT = 443
|
||||
FLASK_FALLBACK_PORT = 80
|
||||
FLASK_DEBUG = True
|
||||
SESSION_LIFETIME = timedelta(days=7)
|
||||
|
||||
@ -35,6 +36,7 @@ SESSION_LIFETIME = timedelta(days=7)
|
||||
SSL_ENABLED = True
|
||||
SSL_CERT_PATH = "/opt/myp/ssl/myp.crt"
|
||||
SSL_KEY_PATH = "/opt/myp/ssl/myp.key"
|
||||
SSL_HOSTNAME = "raaspberry"
|
||||
|
||||
# Scheduler-Konfiguration
|
||||
SCHEDULER_INTERVAL = 60 # Sekunden
|
||||
@ -102,8 +104,8 @@ def get_ssl_context():
|
||||
if os.path.exists(script_path):
|
||||
os.system(f"chmod +x {script_path}")
|
||||
|
||||
# Zertifikate erstellen
|
||||
os.system(f"{script_path} -c {SSL_CERT_PATH} -k {SSL_KEY_PATH}")
|
||||
# Zertifikate erstellen mit spezifischem Hostnamen
|
||||
os.system(f"{script_path} -c {SSL_CERT_PATH} -k {SSL_KEY_PATH} -h {SSL_HOSTNAME}")
|
||||
else:
|
||||
print(f"WARNUNG: SSL-Zertifikat-Generator nicht gefunden: {script_path}")
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user