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
cache/
__pycache__/
disable_signups
under_attack
.idea/
**/.pytest_cache/
venv/

View File

@ -342,36 +342,29 @@ def reported_comments(v):
@app.get("/admin")
@admin_level_required(2)
def admin_home(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)
return render_template("admin/admin_home.html", v=v)
@app.post("/admin/disable_signups")
@admin_level_required(3)
def disable_signups(v):
with open('disable_signups', 'r') as f: content = f.read()
with open('disable_signups', 'w') as f:
if content == "yes":
f.write("no")
ma = ModAction(
kind="enable_signups",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Signups enabled!"}
else:
f.write("yes")
ma = ModAction(
kind="disable_signups",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Signups disabled!"}
if environ.get('disable_signups'):
environ["disable_signups"] = ""
ma = ModAction(
kind="enable_signups",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Signups enabled!"}
else:
environ["disable_signups"] = "1"
ma = ModAction(
kind="disable_signups",
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Signups disabled!"}
@app.post("/admin/purge_cache")
@ -386,33 +379,30 @@ def purge_cache(v):
@app.post("/admin/under_attack")
@admin_level_required(2)
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:
if content == "yes":
f.write("no")
ma = ModAction(
kind="disable_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":"medium"}'))
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
return {"error": "Failed to disable under attack mode."}
else:
environ["under_attack"] = "1"
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":"medium"}'))
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
return {"error": "Failed to disable 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."}
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")
@admin_level_required(2)

View File

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

View File

@ -59,14 +59,14 @@
{% if v.admin_level > 2 %}
<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>
</div>
{% endif %}
{% if v.admin_level == 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>
</div>

View File

@ -288,11 +288,9 @@
{% 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 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>
<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>
{% endif %}
{% if v.id==p.author_id or v.admin_level > 1 %}