New files for stdev calculation for v0.2

This commit is contained in:
2026-07-02 13:08:22 +00:00
parent f621ba772b
commit c13e19dd13
17 changed files with 3187 additions and 3228 deletions
+11 -86
View File
@@ -19,17 +19,17 @@ auth = HTTPBasicAuth()
# Benutzer für Beta-Phase (in Produktion aus env-Variablen laden!)
BETA_USERS = {
"beta": "rollcalc_beta_2026", # Ändere das Passwort!
"naue": "naue_access_2026", # Zweiter User optional
"cniehues": "beta_test_2026", # Christian Niehues EDD
"lvollmert": "Geheim!", # Lars Vollmert EDD
"mtazl": "rollcalc", # Martin Tazl EDD
"controlling": "beta2026" # Lars Krückemeier und Lea-Marie
"beta": "rollcalc_beta_2026", # ⚠️ ÄNDERN!
"naue": "naue_access_2026", # ⚠️ ÄNDERN!
"cniehues": "beta_test_2026", # ⚠️ ÄNDERN!
"lvollmert": "Geheim!", # ⚠️ ÄNDERN!
"mtazl": "rollcalc", # ⚠️ ÄNDERN!
"controlling": "beta2026" # ⚠️ ÄNDERN!
}
# Optional: Admin-Features (z.B. Logs, Stats)
ADMIN_USERS = {
"admin": "admin_secure_pwd_2026"
"admin": "admin_secure_pwd_2026" # ⚠️ ÄNDERN!
}
# Logging für Auditing
@@ -89,7 +89,7 @@ def serve_static(filename):
@auth.login_required
def health_check():
"""Simple health check endpoint"""
return jsonify({"status": "ok", "version": "1.0.0-beta"}), 200
return jsonify({"status": "ok", "version": "14.1"}), 200
@app.route("/api/user", methods=["GET"])
@auth.login_required
@@ -104,7 +104,6 @@ def get_user():
"timestamp": datetime.now().isoformat()
}), 200
# Admin-only endpoint (optional)
@app.route("/admin/logs", methods=["GET"])
@auth.login_required
def get_logs():
@@ -140,102 +139,28 @@ def internal_error(e):
"""Handle 500 Internal Server Error"""
return jsonify({"error": "Internal server error"}), 500
# ============================================================================
# ADMIN ROUTES
# ============================================================================
@app.route("/admin", methods=["GET"])
@auth.login_required
def admin_dashboard():
"""Admin Dashboard - nur für Admin-Benutzer"""
user = auth.current_user()
if user not in ADMIN_USERS:
log_access(user, "/admin", "GET", 403)
return jsonify({"error": "Unauthorized - Admin access required"}), 403
log_access(user, "/admin", "GET")
return render_template("admin.html")
@app.route("/api/admin/stats", methods=["GET"])
@auth.login_required
def get_admin_stats():
"""Statistiken für Admin Dashboard"""
user = auth.current_user()
if user not in ADMIN_USERS:
log_access(user, "/api/admin/stats", "GET", 403)
return jsonify({"error": "Unauthorized"}), 403
log_access(user, "/api/admin/stats", "GET")
logs = []
if os.path.exists(LOG_FILE):
try:
with open(LOG_FILE, "r") as f:
logs = json.load(f)
except json.JSONDecodeError:
logs = []
total_requests = len(logs)
unique_users = len(set(log.get("username", "unknown") for log in logs))
failed_logins = len([l for l in logs if l.get("status") == 401])
return jsonify({
"total_requests": total_requests,
"unique_users": unique_users,
"failed_logins": failed_logins,
"timestamp": datetime.now().isoformat()
}), 200
@app.route("/api/admin/logs", methods=["GET"])
@auth.login_required
def get_admin_logs():
"""Access Logs für Admin Dashboard"""
user = auth.current_user()
if user not in ADMIN_USERS:
log_access(user, "/api/admin/logs", "GET", 403)
return jsonify({"error": "Unauthorized"}), 403
log_access(user, "/api/admin/logs", "GET")
logs = []
if os.path.exists(LOG_FILE):
try:
with open(LOG_FILE, "r") as f:
logs = json.load(f)
except json.JSONDecodeError:
logs = []
logs_sorted = sorted(logs, key=lambda x: x.get("timestamp", ""), reverse=True)
return jsonify({"logs": logs_sorted[-500:]}), 200
# ============================================================================
# STARTUP
# ============================================================================
if __name__ == "__main__":
# Erstelle templates-Verzeichnis falls nicht vorhanden
os.makedirs("templates", exist_ok=True)
os.makedirs("static", exist_ok=True)
print("""
╔═══════════════════════════════════════════════════════════╗
║ Naue Roll Calculator - Beta ║
║ Naue Roll Calculator - V14 + QoL Update ║
║ HTTP Basic Auth Enabled ║
║ ║
║ Test credentials: ║
║ User: beta / Password: rollcalc_beta_2026 ║
║ User: admin / Password: admin_secure_pwd_2026 ║
║ ⚠️ BEFORE PRODUCTION: Update passwords in app.py ║
║ ║
║ Starten auf: http://localhost:5000 ║
║ ⚠️ ÄNDERE DIE PASSWÖRTER VOR PRODUKTIVBEREITSTELLUNG! ║
╚═══════════════════════════════════════════════════════════╝
""")
app.run(
host="0.0.0.0",
port=5000,
debug=False, # In Produktion: False
debug=False,
use_reloader=True
)