forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-08-03 14:16:57 +02:00
parent 33cd357b86
commit 7d73977233
3 changed files with 17 additions and 45 deletions

View File

@ -1,34 +1,21 @@
from sqlalchemy import * from sqlalchemy import *
from drama.__main__ import Base from drama.__main__ import Base
reasons = {
1: "URL shorteners are not allowed.",
3: "Piracy is not allowed.",
4: "Sites hosting digitally malicious content are not allowed.",
5: "Spam",
6: "Doxxing is not allowed.",
7: "Sexualizing minors is strictly prohibited."
}
class BannedDomain(Base): class BannedDomain(Base):
__tablename__ = "banneddomains" __tablename__ = "banneddomains"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
domain = Column(String) domain = Column(String)
reason = Column(Integer, default=0) reason = Column(String)
@property
def reason_text(self): return reasons.get(self.reason)
class BadLink(Base): class BadLink(Base):
__tablename__ = "badlinks" __tablename__ = "badlinks"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
reason = Column(Integer)
link = Column(String(512)) link = Column(String(512))
reason = Column(String)
autoban = Column(Boolean, default=False) autoban = Column(Boolean, default=False)
@property ALTER TABLE banneddomains ALTER COLUMN TYPE text;
def reason_text(self): return reasons.get(self.reason) ALTER TABLE badlinks ALTER COLUMN TYPE text;

View File

@ -947,34 +947,26 @@ def admin_dump_cache(v):
@admin_level_required(4) @admin_level_required(4)
def admin_banned_domains(v): def admin_banned_domains(v):
domains = g.db.query(BannedDomain).all() banned_domains = g.db.query(BannedDomain).all()
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
return render_template(
"admin/banned_domains.html",
v=v,
domains=domains,
reasons=REASONS
)
@app.post("/admin/ban_domain") @app.post("/admin/ban_domain")
@admin_level_required(4) @admin_level_required(4)
@validate_formkey @validate_formkey
def admin_ban_domain(v): def admin_ban_domain(v):
domain=request.form.get("domain",'').strip() domain=request.form.get("domain").strip()
if not domain: abort(400) if not domain: abort(400)
reason=int(request.form.get("reason",0)) reason=request.form.get("reason").strip()
if not reason: abort(400) if not reason: abort(400)
d_query=domain.replace("_","\_") domain = g.db.query(BannedDomain).filter_by(domain=domain.replace("_","\_")).first()
d=g.db.query(BannedDomain).filter_by(domain=d_query).first() if domain: domain.reason=reason
if d: d.reason=reason else: domain=BannedDomain(domain=domain, reason=reason)
else: d=BannedDomain(domain=domain, reason=reason)
g.db.add(d) g.db.add(domain)
return redirect(d.permalink) return redirect("/admin/banned_domains/")
@app.post("/admin/nuke_user") @app.post("/admin/nuke_user")

View File

@ -18,26 +18,19 @@
</tr> </tr>
</thead> </thead>
{% for domain in domains %} {% for domain in banned_domains %}
<tr> <tr>
<td style="font-weight:bold;">{{domain}}</td> <td style="font-weight:bold;">{{domain}}</td>
<td>{{domain.reason_text}}</td> <td>{{domain.reason_text}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<form action="/admin/ban_domain" method="post"> <form action="/admin/ban_domain" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}"> <input type="hidden" name="formkey" value="{{v.formkey}}">
<input name="domain" placeholder="Enter domain here.." required> <input name="domain" placeholder="Enter domain here.." class="form-control" required>
<input name="reason" placeholder="Enter ban reason here.." class="form-control" required>
<select id="reason_select" class="form-control" name="reason" onchange="$('#ban-submit').prop('disabled', false)">
<option value="0">---Select Ban Reason---</option>
{% for i in reasons %}
<option value="{{i}}">{{reasons[i]}}</option>
{% endfor %}
</select>
<input id="ban-submit" type="submit" class="btn btn-primary" value="Ban domain" disabled> <input id="ban-submit" type="submit" class="btn btn-primary" value="Ban domain" disabled>
</form> </form>