remotes/1693045480750635534/spooky-22
Aevann1 2022-01-28 05:22:31 +02:00
parent 3c321b908e
commit cb5c37cc77
5 changed files with 49 additions and 63 deletions

2
.gitignore vendored
View File

@ -3,8 +3,6 @@ video.mp4
video.webm video.webm
cache/ cache/
__pycache__/ __pycache__/
disable_signups
under_attack
.idea/ .idea/
**/.pytest_cache/ **/.pytest_cache/
venv/ venv/

View File

@ -342,36 +342,29 @@ def reported_comments(v):
@app.get("/admin") @app.get("/admin")
@admin_level_required(2) @admin_level_required(2)
def admin_home(v): def admin_home(v):
return render_template("admin/admin_home.html", v=v)
with open('disable_signups', 'r') as f: x = f.read()
with open('under_attack', 'r') as f: x2 = f.read()
return render_template("admin/admin_home.html", v=v, x=x, x2=x2)
@app.post("/admin/disable_signups") @app.post("/admin/disable_signups")
@admin_level_required(3) @admin_level_required(3)
def disable_signups(v): def disable_signups(v):
with open('disable_signups', 'r') as f: content = f.read() if environ.get('disable_signups'):
environ["disable_signups"] = ""
with open('disable_signups', 'w') as f: ma = ModAction(
if content == "yes": kind="enable_signups",
f.write("no") user_id=v.id,
ma = ModAction( )
kind="enable_signups", g.db.add(ma)
user_id=v.id, g.db.commit()
) return {"message": "Signups enabled!"}
g.db.add(ma) else:
g.db.commit() environ["disable_signups"] = "1"
return {"message": "Signups enabled!"} ma = ModAction(
else: kind="disable_signups",
f.write("yes") user_id=v.id,
ma = ModAction( )
kind="disable_signups", g.db.add(ma)
user_id=v.id, g.db.commit()
) return {"message": "Signups disabled!"}
g.db.add(ma)
g.db.commit()
return {"message": "Signups disabled!"}
@app.post("/admin/purge_cache") @app.post("/admin/purge_cache")
@ -386,33 +379,30 @@ def purge_cache(v):
@app.post("/admin/under_attack") @app.post("/admin/under_attack")
@admin_level_required(2) @admin_level_required(2)
def under_attack(v): def under_attack(v):
with open('under_attack', 'r') as f: content = f.read() if environ.get('under_attack'):
environ["under_attack"] = ""
ma = ModAction(
kind="disable_under_attack",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
with open('under_attack', 'w') as f: response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"medium"}'))
if content == "yes": if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
f.write("no") return {"error": "Failed to disable under attack mode."}
ma = ModAction( else:
kind="disable_under_attack", environ["under_attack"] = "1"
user_id=v.id, ma = ModAction(
) kind="enable_under_attack",
g.db.add(ma) user_id=v.id,
g.db.commit() )
g.db.add(ma)
g.db.commit()
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"medium"}')) response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}'))
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"} if response == "<Response [200]>": return {"message": "Under attack mode enabled!"}
return {"error": "Failed to disable under attack mode."} return {"error": "Failed to enable under attack mode."}
else:
f.write("yes")
ma = ModAction(
kind="enable_under_attack",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}'))
if response == "<Response [200]>": return {"message": "Under attack mode enabled!"}
return {"error": "Failed to enable under attack mode."}
@app.get("/admin/badge_grant") @app.get("/admin/badge_grant")
@admin_level_required(2) @admin_level_required(2)

View File

@ -170,8 +170,8 @@ def logout(v):
@app.get("/signup") @app.get("/signup")
@auth_desired @auth_desired
def sign_up_get(v): def sign_up_get(v):
with open('disable_signups', 'r') as f: if environ.get('disable_signups'):
if f.read() == "yes": return {"error": "New account registration is currently closed. Please come back later."}, 403 return {"error": "New account registration is currently closed. Please come back later."}, 403
if v: return redirect(f"{SITE_FULL}/") if v: return redirect(f"{SITE_FULL}/")
@ -214,8 +214,8 @@ def sign_up_get(v):
@limiter.limit("1/minute;5/day") @limiter.limit("1/minute;5/day")
@auth_desired @auth_desired
def sign_up_post(v): def sign_up_post(v):
with open('disable_signups', 'r') as f: if environ.get('disable_signups'):
if f.read() == "yes": return {"error": "New account registration is currently closed. Please come back later."}, 403 return {"error": "New account registration is currently closed. Please come back later."}, 403
if v: abort(403) if v: abort(403)

View File

@ -59,14 +59,14 @@
{% if v.admin_level > 2 %} {% if v.admin_level > 2 %}
<div class="custom-control custom-switch"> <div class="custom-control custom-switch">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="disable_signups" name="disable_signups" {% if x == "yes" %}checked{% endif %} onchange="post_toast('/admin/disable_signups');"> <input autocomplete="off" type="checkbox" class="custom-control-input" id="disable_signups" name="disable_signups" {% if environ.get('disable_signups') %}checked{% endif %} onchange="post_toast('/admin/disable_signups');">
<label class="custom-control-label" for="disable_signups">Disable signups</label> <label class="custom-control-label" for="disable_signups">Disable signups</label>
</div> </div>
{% endif %} {% endif %}
{% if v.admin_level == 3 %} {% if v.admin_level == 3 %}
<div class="custom-control custom-switch mt-3"> <div class="custom-control custom-switch mt-3">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="under_attack" name="under_attack" {% if x2 == "yes" %}checked{% endif %} onchange="post_toast('/admin/under_attack');"> <input autocomplete="off" type="checkbox" class="custom-control-input" id="under_attack" name="under_attack" {% if environ.get('under_attack') %}checked{% endif %} onchange="post_toast('/admin/under_attack');">
<label class="custom-control-label" for="under_attack">Under attack mode</label> <label class="custom-control-label" for="under_attack">Under attack mode</label>
</div> </div>

View File

@ -288,11 +288,9 @@
{% if v.id != p.author_id and not p.ghost %} {% if v.id != p.author_id and not p.ghost %}
<a id="unblock-{{p.id}}" class="text-success list-inline-item {% if not p.is_blocking %} d-none{% endif %}" role="button" onclick="post_toast2('/settings/unblock?username={{p.author_name}}','block-{{p.id}}','unblock-{{p.id}}')"><i class="fas fa-eye text-success"></i>Unblock user</a> <a id="unblock-{{p.id}}" class="dropdown-item text-success list-inline-item {% if not p.is_blocking %}d-none{% endif %}" role="button" onclick="post_toast2('/settings/unblock?username={{p.author_name}}','block-{{p.id}}','unblock-{{p.id}}')"><i class="fas fa-eye text-success"></i>Unblock user</a>
<a id="prompt-{{p.id}}" class="dropdown-item text-danger blockuser list-inline-item d-none" role="button" onclick="post_toast2('/settings/block?username={{p.author_name}}','prompt-{{p.id}}','unblock-{{p.id}}')"><i class="fas fa-eye-slash text-danger"></i>Are you sure?</a> <a id="block-{{p.id}}" class="dropdown-item list-inline-item text-danger {% if p.is_blocking %}d-none{% endif %}" role="button" onclick="post_toast2('/settings/block?username={{p.author_name}}','block-{{p.id}}','unblock-{{p.id}}')"><i class="fas fa-eye-slash text-danger"></i>Block user</a>
<a id="block-{{p.id}}" class="dropdown-item text-danger blockuser list-inline-item {% if p.is_blocking %} d-none{% endif %}" role="button" onclick="document.getElementById('block-{{p.id}}').classList.toggle('d-none');document.getElementById('prompt-{{p.id}}').classList.toggle('d-none');"><i class="fas fa-eye-slash text-danger"></i>Block user</a>
{% endif %} {% endif %}
{% if v.id==p.author_id or v.admin_level > 1 %} {% if v.id==p.author_id or v.admin_level > 1 %}