# đ Admin Dashboard Integration â 4 Optionen
## Ăbersicht
Hier sind die Best Practices fĂźr die Integration eines Admin-Panels in die Flask-App:
---
## Option 1: Embedded Admin-Route (Empfohlen fĂźr Beta)
**Am schnellsten & sichersten fĂźr Beta-Phase**
### Wie es funktioniert:
- Admin-HTML wird direkt als Template serviert
- Nur fßr Admin-Benutzer zugänglich (/admin)
- Integriertes Logging-Dashboard
- Keine separate App nĂśtig
### Implementierung:
**In `app.py` (nach den Error Handlers hinzufĂźgen):**
```python
@app.route("/admin", methods=["GET"])
@auth.login_required
def admin_dashboard():
"""Admin Dashboard - nur fĂźr Admins"""
user = auth.current_user()
if user not in ADMIN_USERS:
log_access(user, "/admin", "GET", 403)
return jsonify({"error": "Unauthorized"}), 403
log_access(user, "/admin", "GET")
return render_template("admin.html", username=user)
@app.route("/api/admin/logs", methods=["GET"])
@auth.login_required
def get_admin_logs():
"""Logs als JSON fĂźr Dashboard"""
user = auth.current_user()
if user not in ADMIN_USERS:
return jsonify({"error": "Unauthorized"}), 403
logs = []
if os.path.exists(LOG_FILE):
with open(LOG_FILE, "r") as f:
logs = json.load(f)
# Optional: Letzte 100 Logs
return jsonify({"logs": logs[-100:]}), 200
@app.route("/api/admin/stats", methods=["GET"])
@auth.login_required
def get_admin_stats():
"""Statistiken fĂźr Dashboard"""
user = auth.current_user()
if user not in ADMIN_USERS:
return jsonify({"error": "Unauthorized"}), 403
logs = []
if os.path.exists(LOG_FILE):
with open(LOG_FILE, "r") as f:
logs = json.load(f)
# Statistiken berechnen
total_requests = len(logs)
unique_users = len(set(log["username"] for log in logs))
failed_logins = len([l for l in logs if l["status"] == 401])
return jsonify({
"total_requests": total_requests,
"unique_users": unique_users,
"failed_logins": failed_logins,
"last_update": datetime.now().isoformat()
}), 200
```
**Neue Template-Datei: `templates/admin.html`**
```html