modified: web/blueprints/group_admin.py
modified: web/blueprints/site_admin.py modified: web/config.py new file: web/mailer.py modified: web/panel_db.py modified: web/templates/admin/base.html modified: web/templates/admin/dashboard.html new file: web/templates/admin/mail_settings.html
This commit is contained in:
@@ -4,6 +4,7 @@ Verwaltet alle Gruppen und Nutzer global.
|
||||
"""
|
||||
from functools import wraps
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, session, flash
|
||||
from mailer import send_mail
|
||||
import panel_db as db
|
||||
|
||||
site_admin = Blueprint("site_admin", __name__, url_prefix="/admin")
|
||||
@@ -28,22 +29,101 @@ def dashboard():
|
||||
try:
|
||||
groups = db.list_all_groups() or []
|
||||
users = db.list_all_users() or []
|
||||
has_mail = db.has_site_mail_settings()
|
||||
for g in groups:
|
||||
try:
|
||||
g["has_db"] = db.has_db_configured(g["id"])
|
||||
except Exception:
|
||||
g["has_db"] = False
|
||||
except Exception:
|
||||
groups, users = [], []
|
||||
groups, users, has_mail = [], [], False
|
||||
stats = {
|
||||
"group_count": len(groups),
|
||||
"user_count": len(users),
|
||||
"db_configured": sum(1 for g in groups if g.get("has_db")),
|
||||
"admin_count": sum(1 for u in users if u.get("is_site_admin")),
|
||||
"mail_configured": int(has_mail),
|
||||
}
|
||||
return render_template("admin/dashboard.html", groups=groups, users=users, stats=stats)
|
||||
|
||||
|
||||
@site_admin.route("/mail", methods=["GET", "POST"])
|
||||
@admin_required
|
||||
def mail_settings():
|
||||
settings = db.get_site_mail_settings()
|
||||
error = None
|
||||
|
||||
if request.method == "POST":
|
||||
host = request.form.get("host", "").strip()
|
||||
port = request.form.get("port", type=int) or 0
|
||||
username = request.form.get("username", "").strip()
|
||||
password = request.form.get("password", "")
|
||||
from_email = request.form.get("from_email", "").strip()
|
||||
from_name = request.form.get("from_name", "").strip()
|
||||
use_tls = request.form.get("use_tls") == "1"
|
||||
action = request.form.get("action", "save")
|
||||
test_recipient = request.form.get("test_recipient", "").strip()
|
||||
|
||||
if settings and not password:
|
||||
password = settings["password"]
|
||||
|
||||
if not all([host, port, username, password, from_email]):
|
||||
error = "Host, port, username, password and from email are required."
|
||||
elif "@" not in from_email:
|
||||
error = "Please provide a valid from email address."
|
||||
else:
|
||||
candidate = {
|
||||
"host": host,
|
||||
"port": port,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"from_email": from_email,
|
||||
"from_name": from_name,
|
||||
"use_tls": use_tls,
|
||||
}
|
||||
try:
|
||||
if action == "test":
|
||||
send_mail(
|
||||
candidate,
|
||||
test_recipient or from_email,
|
||||
"MCLogger SMTP Test",
|
||||
"This is a test email from your MCLogger admin panel.",
|
||||
)
|
||||
flash("Test email sent successfully.", "success")
|
||||
else:
|
||||
send_mail(
|
||||
candidate,
|
||||
test_recipient or from_email,
|
||||
"MCLogger SMTP Verification",
|
||||
"Your SMTP settings were verified successfully and have been saved.",
|
||||
)
|
||||
db.set_site_mail_settings(host, port, username, password, from_email, from_name, use_tls)
|
||||
flash("Mail settings saved and verified.", "success")
|
||||
return redirect(url_for("site_admin.mail_settings"))
|
||||
except Exception as exc:
|
||||
error = f"SMTP connection failed: {exc}"
|
||||
|
||||
settings = {
|
||||
"host": host,
|
||||
"port": port,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"from_email": from_email,
|
||||
"from_name": from_name,
|
||||
"use_tls": use_tls,
|
||||
}
|
||||
|
||||
return render_template("admin/mail_settings.html", settings=settings, error=error)
|
||||
|
||||
|
||||
@site_admin.route("/mail/delete", methods=["POST"])
|
||||
@admin_required
|
||||
def mail_settings_delete():
|
||||
db.delete_site_mail_settings()
|
||||
flash("Mail settings removed.", "success")
|
||||
return redirect(url_for("site_admin.mail_settings"))
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────
|
||||
# Gruppen verwalten
|
||||
# ──────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user