bv
This commit is contained in:
parent
e049e87248
commit
d4a33c06ce
5 changed files with 44 additions and 35 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,3 +10,4 @@ venv/
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
flask_session/
|
flask_session/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
disable_signups
|
|
@ -17,9 +17,9 @@ from sys import stdout
|
||||||
import faulthandler
|
import faulthandler
|
||||||
from json import loads
|
from json import loads
|
||||||
|
|
||||||
f = 'files/templates/sidebar_' + environ.get("SITE_NAME").strip() + '.html'
|
for f in (f'files/templates/sidebar_{environ.get("SITE_NAME").strip()}.html', 'disable_signups'):
|
||||||
if not path.exists(f):
|
if not path.exists(f):
|
||||||
with open(f, 'w', encoding="utf-8"): pass
|
with open(f, 'w', encoding="utf-8"): pass
|
||||||
|
|
||||||
app = Flask(__name__, template_folder='templates')
|
app = Flask(__name__, template_folder='templates')
|
||||||
app.url_map.strict_slashes = False
|
app.url_map.strict_slashes = False
|
||||||
|
|
|
@ -451,29 +451,37 @@ 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()
|
||||||
|
|
||||||
|
response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS).json()['result']['value']
|
||||||
|
x2 = response == 'under_attack'
|
||||||
|
|
||||||
|
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):
|
||||||
if environ.get('disable_signups'):
|
with open('disable_signups', 'r') as f: content = f.read()
|
||||||
environ["disable_signups"] = ""
|
|
||||||
ma = ModAction(
|
with open('disable_signups', 'w') as f:
|
||||||
kind="enable_signups",
|
if content == "yes":
|
||||||
user_id=v.id,
|
f.write("no")
|
||||||
)
|
ma = ModAction(
|
||||||
g.db.add(ma)
|
kind="enable_signups",
|
||||||
g.db.commit()
|
user_id=v.id,
|
||||||
return {"message": "Signups enabled!"}
|
)
|
||||||
else:
|
g.db.add(ma)
|
||||||
environ["disable_signups"] = "1"
|
g.db.commit()
|
||||||
ma = ModAction(
|
return {"message": "Signups enabled!"}
|
||||||
kind="disable_signups",
|
else:
|
||||||
user_id=v.id,
|
f.write("yes")
|
||||||
)
|
ma = ModAction(
|
||||||
g.db.add(ma)
|
kind="disable_signups",
|
||||||
g.db.commit()
|
user_id=v.id,
|
||||||
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")
|
||||||
|
@ -495,8 +503,9 @@ def purge_cache(v):
|
||||||
@app.post("/admin/under_attack")
|
@app.post("/admin/under_attack")
|
||||||
@admin_level_required(3)
|
@admin_level_required(3)
|
||||||
def under_attack(v):
|
def under_attack(v):
|
||||||
if environ.get('under_attack'):
|
response = requests.get(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS).json()['result']['value']
|
||||||
environ["under_attack"] = ""
|
|
||||||
|
if response == 'under_attack':
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
kind="disable_under_attack",
|
kind="disable_under_attack",
|
||||||
user_id=v.id,
|
user_id=v.id,
|
||||||
|
@ -508,7 +517,6 @@ def under_attack(v):
|
||||||
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
|
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
|
||||||
return {"error": "Failed to disable under attack mode."}
|
return {"error": "Failed to disable under attack mode."}
|
||||||
else:
|
else:
|
||||||
environ["under_attack"] = "1"
|
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
kind="enable_under_attack",
|
kind="enable_under_attack",
|
||||||
user_id=v.id,
|
user_id=v.id,
|
||||||
|
|
|
@ -174,8 +174,9 @@ def logout(v):
|
||||||
@app.get("/signup")
|
@app.get("/signup")
|
||||||
@auth_desired
|
@auth_desired
|
||||||
def sign_up_get(v):
|
def sign_up_get(v):
|
||||||
if environ.get('disable_signups'):
|
with open('disable_signups', 'r') as f:
|
||||||
return {"error": "New account registration is currently closed. Please come back later."}, 403
|
if f.read() == "yes":
|
||||||
|
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}/")
|
||||||
|
|
||||||
|
@ -218,8 +219,9 @@ 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):
|
||||||
if environ.get('disable_signups'):
|
with open('disable_signups', 'r') as f:
|
||||||
return {"error": "New account registration is currently closed. Please come back later."}, 403
|
if f.read() == "yes":
|
||||||
|
return {"error": "New account registration is currently closed. Please come back later."}, 403
|
||||||
|
|
||||||
if v: abort(403)
|
if v: abort(403)
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,12 @@
|
||||||
|
|
||||||
{% 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 environ.get('disable_signups') %}checked{% endif %} onchange="post_toast('/admin/disable_signups');">
|
<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');">
|
||||||
<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 %}
|
|
||||||
|
|
||||||
{% if v.admin_level == 3 %}
|
<div class="custom-control custom-switch">
|
||||||
<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 %}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>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue