modified: app.py

modified:   templates/index.html
	new file:   templates/user.html
This commit is contained in:
SimolZimol
2024-09-03 10:18:23 +02:00
parent 8a2245a61b
commit 12f90728eb
3 changed files with 85 additions and 1 deletions

31
app.py
View File

@@ -2,10 +2,18 @@ from flask import Flask, render_template, redirect, url_for, request, session
import os import os
import subprocess import subprocess
import psutil import psutil
import mysql.connector
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")
# 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 # Globale Variablen für die Intros
INTRO_FILE = "introduction.txt" INTRO_FILE = "introduction.txt"
ASKNOTES_INTRO_FILE = "asknotesintro.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: with open(file_path, 'w', encoding='utf-8') as file:
file.write(content) 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("/") @app.route("/")
def index(): def index():
if "username" in session: if "username" in session:
@@ -107,5 +125,18 @@ def settings():
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction) return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction)
return redirect(url_for("login")) 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__": 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)

View File

@@ -1,4 +1,3 @@
<!-- web_panel/templates/index.html -->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -21,6 +20,7 @@
<a href="{{ url_for('start') }}" class="btn btn-primary btn-block {{ 'disabled' if bot_running else '' }}">Start Bot</a> <a href="{{ url_for('start') }}" class="btn btn-primary btn-block {{ 'disabled' if bot_running else '' }}">Start Bot</a>
<a href="{{ url_for('stop') }}" class="btn btn-danger btn-block {{ 'disabled' if not bot_running else '' }}">Stop Bot</a> <a href="{{ url_for('stop') }}" class="btn btn-danger btn-block {{ 'disabled' if not bot_running else '' }}">Stop Bot</a>
<a href="{{ url_for('settings') }}" class="btn btn-secondary btn-block">Settings</a> <a href="{{ url_for('settings') }}" class="btn btn-secondary btn-block">Settings</a>
<a href="{{ url_for('users') }}" class="btn btn-info btn-block">User Management</a>
<a href="{{ url_for('logout') }}" class="btn btn-outline-secondary btn-block">Logout</a> <a href="{{ url_for('logout') }}" class="btn btn-outline-secondary btn-block">Logout</a>
</div> </div>
</div> </div>

53
templates/user.html Normal file
View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">User Management</h1>
<table class="table table-striped mt-4">
<thead>
<tr>
<th>User ID</th>
<th>Permission Level</th>
<th>Points</th>
<th>Ban Status</th>
<th>AskMultus Usage</th>
<th>Filter Value</th>
<th>Rank</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.user_id }}</td>
<td>{{ user.permission }}</td>
<td>{{ user.points }}</td>
<td>{{ 'Banned' if user.ban else 'Active' }}</td>
<td>{{ user.askmultus }}</td>
<td>{{ user.filter_value }}</td>
<td>
{% if user.permission == 10 %}
Owner
{% elif user.permission == 8 %}
Admin
{% elif user.permission == 5 %}
Mod
{% else %}
User
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ url_for('index') }}" class="btn btn-secondary btn-block mt-3">Back to Dashboard</a>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>