From 12f90728eb4ddcd07d622cc24bbcb3df68fa872f Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:18:23 +0200 Subject: [PATCH] modified: app.py modified: templates/index.html new file: templates/user.html --- app.py | 31 ++++++++++++++++++++++++++ templates/index.html | 2 +- templates/user.html | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 templates/user.html diff --git a/app.py b/app.py index 9e1cb7b..dff764f 100644 --- a/app.py +++ b/app.py @@ -2,10 +2,18 @@ from flask import Flask, render_template, redirect, url_for, request, session import os import subprocess import psutil +import mysql.connector app = Flask(__name__) app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key") +# Verwende Umgebungsvariablen aus Coolify für die Datenbankverbindung +DB_HOST = os.getenv("DB_HOST") +DB_PORT = os.getenv("DB_PORT") +DB_USER = os.getenv("DB_USER") +DB_PASS = os.getenv("DB_PASS") +DB_NAME = os.getenv("DB_NAME") + # Globale Variablen für die Intros INTRO_FILE = "introduction.txt" ASKNOTES_INTRO_FILE = "asknotesintro.txt" @@ -50,6 +58,16 @@ def save_text_file(file_path, content): with open(file_path, 'w', encoding='utf-8') as file: file.write(content) +def get_db_connection(): + """Stellt eine Verbindung zur MySQL-Datenbank her.""" + return mysql.connector.connect( + host=DB_HOST, + port=DB_PORT, + user=DB_USER, + password=DB_PASS, + database=DB_NAME + ) + @app.route("/") def index(): if "username" in session: @@ -107,5 +125,18 @@ def settings(): return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction) return redirect(url_for("login")) +@app.route("/users") +def users(): + """Zeigt eine Liste aller Benutzer aus der Datenbank an.""" + if "username" in session: + connection = get_db_connection() + cursor = connection.cursor(dictionary=True) + cursor.execute("SELECT * FROM user_data") + users = cursor.fetchall() + cursor.close() + connection.close() + return render_template("users.html", users=users) + return redirect(url_for("login")) + if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/templates/index.html b/templates/index.html index b89b708..2f7e584 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,3 @@ -
@@ -21,6 +20,7 @@ Start Bot Stop Bot Settings + User Management Logout diff --git a/templates/user.html b/templates/user.html new file mode 100644 index 0000000..d6cb24b --- /dev/null +++ b/templates/user.html @@ -0,0 +1,53 @@ + + + + + +| User ID | +Permission Level | +Points | +Ban Status | +AskMultus Usage | +Filter Value | +Rank | +
|---|---|---|---|---|---|---|
| {{ user.user_id }} | +{{ user.permission }} | +{{ user.points }} | +{{ 'Banned' if user.ban else 'Active' }} | +{{ user.askmultus }} | +{{ user.filter_value }} | ++ {% if user.permission == 10 %} + Owner + {% elif user.permission == 8 %} + Admin + {% elif user.permission == 5 %} + Mod + {% else %} + User + {% endif %} + | +