modified: app.py
modified: requirements.txt new file: templates/logs.html
This commit is contained in:
39
app.py
39
app.py
@@ -1,12 +1,20 @@
|
||||
from flask import Flask, render_template, redirect, url_for, request, session
|
||||
from flask import Flask, render_template, redirect, url_for, request, session, send_file
|
||||
from flask_socketio import SocketIO, emit
|
||||
import os
|
||||
import subprocess
|
||||
import psutil
|
||||
import mysql.connector
|
||||
import threading
|
||||
import tailer
|
||||
|
||||
app = Flask(__name__)
|
||||
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
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
@@ -138,5 +146,34 @@ def users():
|
||||
return render_template("users.html", users=users)
|
||||
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__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
Reference in New Issue
Block a user