modified: app.py
modified: requirements.txt
This commit is contained in:
39
app.py
39
app.py
@@ -1,20 +1,12 @@
|
|||||||
from flask import Flask, render_template, redirect, url_for, request, session, send_file
|
from flask import Flask, render_template, redirect, url_for, request, session
|
||||||
from flask_socketio import SocketIO, emit
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import psutil
|
import psutil
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import threading
|
|
||||||
import tailer
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
||||||
|
|
||||||
socketio = SocketIO(app)
|
|
||||||
|
|
||||||
# Logs Directory
|
|
||||||
LOGS_DIR = "logs"
|
|
||||||
|
|
||||||
# Verwende Umgebungsvariablen aus Coolify für die Datenbankverbindung
|
# Verwende Umgebungsvariablen aus Coolify für die Datenbankverbindung
|
||||||
DB_HOST = os.getenv("DB_HOST")
|
DB_HOST = os.getenv("DB_HOST")
|
||||||
DB_PORT = os.getenv("DB_PORT")
|
DB_PORT = os.getenv("DB_PORT")
|
||||||
@@ -146,34 +138,5 @@ def users():
|
|||||||
return render_template("users.html", users=users)
|
return render_template("users.html", users=users)
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/logs")
|
|
||||||
def logs():
|
|
||||||
if "username" in session:
|
|
||||||
log_files = sorted(os.listdir(LOGS_DIR), reverse=True)
|
|
||||||
return render_template("logs.html", log_files=log_files)
|
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
@app.route("/logs/<log_file>")
|
|
||||||
def view_log(log_file):
|
|
||||||
if "username" in session:
|
|
||||||
log_path = os.path.join(LOGS_DIR, log_file)
|
|
||||||
if os.path.exists(log_path):
|
|
||||||
return send_file(log_path)
|
|
||||||
else:
|
|
||||||
return "Log file not found", 404
|
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
@socketio.on('connect')
|
|
||||||
def handle_connect():
|
|
||||||
"""Streamt Echtzeit-Logs an den Client."""
|
|
||||||
def tail_log():
|
|
||||||
if bot_status():
|
|
||||||
log_file = os.path.join(LOGS_DIR, f"{datetime.now().strftime('%Y-%m-%d')}.log")
|
|
||||||
for line in tailer.follow(open(log_file)):
|
|
||||||
socketio.emit('log', {'data': line})
|
|
||||||
|
|
||||||
thread = threading.Thread(target=tail_log)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|||||||
@@ -13,4 +13,3 @@ pdfplumber
|
|||||||
python-dotenv
|
python-dotenv
|
||||||
flask
|
flask
|
||||||
psutil
|
psutil
|
||||||
flask-socketio
|
|
||||||
Reference in New Issue
Block a user