72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
# app.py
|
|
|
|
from flask import Flask, render_template, redirect, url_for, request, session
|
|
import os
|
|
import subprocess
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
|
|
|
# Status-Anzeige des Bots
|
|
def bot_status():
|
|
result = subprocess.run(["pgrep", "-f", "bot.py"], stdout=subprocess.PIPE)
|
|
return result.returncode == 0 # 0 bedeutet, dass der Prozess läuft
|
|
|
|
# Startet den Bot
|
|
def start_bot():
|
|
subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# Stoppt den Bot
|
|
def stop_bot():
|
|
subprocess.run(["pkill", "-f", "bot.py"])
|
|
|
|
@app.route("/")
|
|
def index():
|
|
if "username" in session:
|
|
return render_template("index.html", bot_running=bot_status())
|
|
return redirect(url_for("login"))
|
|
|
|
@app.route("/login", methods=["GET", "POST"])
|
|
def login():
|
|
if request.method == "POST":
|
|
username = request.form["username"]
|
|
password = request.form["password"]
|
|
if username == os.getenv("ADMIN_USER") and password == os.getenv("ADMIN_PASS"):
|
|
session["username"] = username
|
|
return redirect(url_for("index"))
|
|
else:
|
|
return "Invalid credentials!"
|
|
return render_template("login.html")
|
|
|
|
@app.route("/logout")
|
|
def logout():
|
|
session.pop("username", None)
|
|
return redirect(url_for("login"))
|
|
|
|
@app.route("/start_bot")
|
|
def start():
|
|
if "username" in session:
|
|
start_bot()
|
|
return redirect(url_for("index"))
|
|
return redirect(url_for("login"))
|
|
|
|
@app.route("/stop_bot")
|
|
def stop():
|
|
if "username" in session:
|
|
stop_bot()
|
|
return redirect(url_for("index"))
|
|
return redirect(url_for("login"))
|
|
|
|
@app.route("/settings", methods=["GET", "POST"])
|
|
def settings():
|
|
if "username" in session:
|
|
if request.method == "POST":
|
|
# Hier kannst du Formulareingaben für Bot-Einstellungen verarbeiten
|
|
# Z.B. in die .env-Datei schreiben
|
|
pass
|
|
return render_template("settings.html")
|
|
return redirect(url_for("login"))
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=5000, debug=True)
|