From 925e2ac4c38d919f579779aea63115d606e6389b Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 1 Feb 2024 01:27:01 +0200 Subject: [PATCH] fix /admin in localhost --- files/routes/admin.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 681a7a814..3f0b0d7dd 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -362,8 +362,9 @@ def reported_comments(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['ADMIN_HOME_VISIBLE']) def admin_home(v): - under_attack = (requests.get(f"{CLOUDFLARE_API_URL}/zones/{CF_ZONE}/settings/security_level", headers=CF_HEADERS, timeout=CLOUDFLARE_REQUEST_TIMEOUT_SECS).json()['result']['value'] == "under_attack") - set_setting('under_attack', under_attack) + if CLOUDFLARE_AVAILABLE: + under_attack = (requests.get(f"{CLOUDFLARE_API_URL}/zones/{CF_ZONE}/settings/security_level", headers=CF_HEADERS, timeout=CLOUDFLARE_REQUEST_TIMEOUT_SECS).json()['result']['value'] == "under_attack") + set_setting('under_attack', under_attack) return render_template("admin/admin_home.html", v=v) @app.post("/admin/site_settings/") @@ -2107,3 +2108,27 @@ def insert_transaction_post(v): claim_rewards_all_users() return {"message": "Transaction inserted successfully!"} + +@app.get("/admin/under_siege") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@admin_level_required(PERMS['CHANGE_UNDER_SIEGE']) +def change_under_siege(v): + thresholds = cache.get("under_siege_thresholds") + if not thresholds: + thresholds = DEFAULT_UNDER_SIEGE_THRESHOLDS + cache.set("under_siege_thresholds", thresholds) + + return render_template('admin/under_siege.html', v=v, thresholds=thresholds) + +@app.post("/admin/under_siege") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@admin_level_required(PERMS['CHANGE_UNDER_SIEGE']) +def change_under_siege_post(v): + thresholds = {} + for key in DEFAULT_UNDER_SIEGE_THRESHOLDS.keys(): + thresholds[key] = int(request.values.get(key)) + + cache.set("under_siege_thresholds", thresholds) + return {"message": "Thresholds changed successfully!"}