modified: app.py
modified: templates/index.html modified: templates/login.html modified: templates/settings.html
This commit is contained in:
32
app.py
32
app.py
@@ -1,6 +1,7 @@
|
||||
from flask import Flask, render_template, redirect, url_for, request, session
|
||||
import os
|
||||
import subprocess
|
||||
import psutil
|
||||
import mysql.connector
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -10,13 +11,12 @@ app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
||||
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")
|
||||
DB_PASS = os.getenv("DB_PASSWORD")
|
||||
DB_NAME = os.getenv("DB_DATABASE")
|
||||
|
||||
# Globale Variablen für die Intros und Themes
|
||||
# Globale Variablen für die Intros
|
||||
INTRO_FILE = "introduction.txt"
|
||||
ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
||||
THEME_FILE = "theme.txt"
|
||||
|
||||
# Speichern der Prozess-ID
|
||||
bot_process = None
|
||||
@@ -68,19 +68,10 @@ def get_db_connection():
|
||||
database=DB_NAME
|
||||
)
|
||||
|
||||
def get_current_theme():
|
||||
"""Lädt das aktuelle Theme."""
|
||||
return load_text_file(THEME_FILE) or "light" # Standard-Theme ist 'light'
|
||||
|
||||
def set_current_theme(theme):
|
||||
"""Speichert das aktuelle Theme."""
|
||||
save_text_file(THEME_FILE, theme)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
if "username" in session:
|
||||
theme = get_current_theme()
|
||||
return render_template("index.html", bot_running=bot_status(), theme=theme)
|
||||
return render_template("index.html", bot_running=bot_status())
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
@@ -93,8 +84,7 @@ def login():
|
||||
return redirect(url_for("index"))
|
||||
else:
|
||||
return "Invalid credentials!"
|
||||
theme = get_current_theme()
|
||||
return render_template("login.html", theme=theme)
|
||||
return render_template("login.html")
|
||||
|
||||
@app.route("/logout")
|
||||
def logout():
|
||||
@@ -121,21 +111,18 @@ def settings():
|
||||
if request.method == "POST":
|
||||
introduction = request.form.get("introduction")
|
||||
asknotes_introduction = request.form.get("asknotes_introduction")
|
||||
theme = request.form.get("theme")
|
||||
|
||||
# Speichern der Intros und des Themes
|
||||
# Speichern der Intros
|
||||
save_text_file(INTRO_FILE, introduction)
|
||||
save_text_file(ASKNOTES_INTRO_FILE, asknotes_introduction)
|
||||
set_current_theme(theme)
|
||||
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
# Laden der aktuellen Inhalte aus den Textdateien
|
||||
introduction = load_text_file(INTRO_FILE)
|
||||
asknotes_introduction = load_text_file(ASKNOTES_INTRO_FILE)
|
||||
current_theme = get_current_theme()
|
||||
|
||||
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction, current_theme=current_theme)
|
||||
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/users")
|
||||
@@ -148,8 +135,7 @@ def users():
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
theme = get_current_theme()
|
||||
return render_template("users.html", users=users, theme=theme)
|
||||
return render_template("users.html", users=users)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<!-- web_panel/templates/index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Panel</title>
|
||||
<link href="{{ url_for('static', filename='css/' + theme + '.css') }}" rel="stylesheet">
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
@@ -20,7 +21,6 @@
|
||||
<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('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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="{{ url_for('static', filename='css/theme-' + theme + '.css') }}" rel="stylesheet">
|
||||
<title>Login</title>
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -20,14 +20,6 @@
|
||||
<label for="asknotes_introduction">Asknotes Introduction Text</label>
|
||||
<textarea id="asknotes_introduction" name="asknotes_introduction" class="form-control" rows="5">{{ asknotes_introduction }}</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="theme">Select Theme</label>
|
||||
<select id="theme" name="theme" class="form-control">
|
||||
<option value="light" {% if current_theme == "light" %}selected{% endif %}>Light</option>
|
||||
<option value="dark" {% if current_theme == "dark" %}selected{% endif %}>Dark</option>
|
||||
<option value="blue" {% if current_theme == "blue" %}selected{% endif %}>Blue</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-block">Save Settings</button>
|
||||
</form>
|
||||
<a href="{{ url_for('index') }}" class="btn btn-secondary btn-block mt-3">Back to Dashboard</a>
|
||||
|
||||
Reference in New Issue
Block a user