remotes/1693045480750635534/spooky-22
Aevann1 2021-10-12 19:31:05 +02:00
parent 108a960474
commit bc9c2d6a5f
3 changed files with 0 additions and 95 deletions

View File

@ -648,58 +648,6 @@ def admin_removed(v):
@app.post("/admin/image_ban")
@limiter.limit("1/second")
@admin_level_required(4)
@validate_formkey
def admin_image_ban(v):
if request.content_length > 4 * 1024 * 1024: return "Max file size is 4 MB.", 413
i=request.files['file']
tempname = f"admin_image_ban_{v.username}_{int(time.time())}"
i.save(tempname)
h=imagehash.phash(IMAGE.open(tempname))
value = int(str(h), 16)
bindigits = []
digit = (value % 2)
value //= 2
bindigits.append(digit)
while value > 0:
digit = (value % 2)
value //= 2
bindigits.append(digit)
h = ''.join([str(d) for d in bindigits])
badpic = g.db.query(BadPic).options(lazyload('*')).filter_by(
phash=h
).first()
remove(tempname)
if badpic:
return render_template("admin/image_ban.html", v=v, existing=badpic)
new_bp=BadPic(
phash=h,
ban_reason=request.values.get("ban_reason"),
ban_time=int(request.values.get("ban_length",0))
)
g.db.add(new_bp)
g.db.commit()
return render_template("admin/image_ban.html", v=v, success=True)
@app.post("/agendaposter/<user_id>")
@admin_level_required(6)
@validate_formkey

View File

@ -28,7 +28,6 @@
<h4>Safety</h4>
<ul>
<li><a href="/admin/banned_domains">Banned Domains</a></li>
<li><a href="/admin/image_ban">Perceptive Hash Image Ban</a></li>
<li><a href="/admin/alt_votes">Multi Vote Analysis</a></li>
</ul>

View File

@ -1,42 +0,0 @@
{% extends "default.html" %}
{% block title %}
<title>Image Ban</title>
<meta name="description" content="Image Ban">
{% endblock %}
{% block content %}
{% if existing %}
<p class="text-danger">Image already banned for: {{existing.ban_reason}}</p>
{% elif success %}
<p class="text-success">Image banned.</p>
{% endif %}
<pre>
</pre>
<h5>Perceptive Hash Image Ban</h5>
<p>Upload an image to add its hash to the ban list.</p>
<form action="/admin/image_ban" method="post" class="mb-6" enctype="multipart/form-data">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<label for="img-input">Image Upload</label>
<input id="img-input" type="file" class="form-control-file mb-2" name="file">
<label for="img-input" class="mt-3">Ban Reason</label>
<select name="ban_reason" class="form-control" id="ban_reason">
<option disabled selected>Select Ban Reason</option>
<option value="Bestiality">Bestiality</option>
<option value="Child Sexual Abuse Material">CSAM</option>
<option value="Involuntary Pornography">Involuntary Pornography</option>
</select>
<label for="time-input" class="mt-3">Penalty</label>
<small>Enter the number of days to ban a user who attempts to upload this image</small>
<input id="time-input" class="form-control" type="text" name="ban_length" placeholder="Enter 0 for permanent ban" required>
<input type="submit" value="Ban Image" class="btn btn-primary mt-3">
</form>
{% endblock %}