2021-10-15 14:08:27 +00:00
|
|
|
from files.mail import *
|
2022-01-12 02:42:26 +00:00
|
|
|
from files.__main__ import app, limiter, mail
|
2021-10-15 14:08:27 +00:00
|
|
|
from files.helpers.alerts import *
|
2021-12-20 12:48:02 +00:00
|
|
|
from files.helpers.const import *
|
2021-10-15 14:08:27 +00:00
|
|
|
from files.classes.award import AWARDS
|
|
|
|
from sqlalchemy import func
|
|
|
|
from os import path
|
|
|
|
import calendar
|
|
|
|
import matplotlib.pyplot as plt
|
2021-11-23 22:54:48 +00:00
|
|
|
from files.classes.mod_logs import ACTIONTYPES, ACTIONTYPES2
|
2022-01-23 19:51:56 +00:00
|
|
|
from files.classes.badges import BadgeDef
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-04-10 14:56:38 +00:00
|
|
|
@app.get("/r/drama/comments/<id>/<title>")
|
|
|
|
@app.get("/r/Drama/comments/<id>/<title>")
|
|
|
|
def rdrama(id, title):
|
|
|
|
id = ''.join(f'{x}/' for x in id)
|
|
|
|
return redirect(f'/archives/drama/comments/{id}{title}.html')
|
|
|
|
|
2022-04-19 20:22:24 +00:00
|
|
|
@app.get('/logged_out/')
|
|
|
|
@app.get('/logged_out/<path:old>')
|
|
|
|
def logged_out(old = ""):
|
|
|
|
# Remove trailing question mark from request.full_path which flask adds if there are no query parameters
|
|
|
|
redirect_url = request.full_path.replace("/logged_out", "", 1)
|
|
|
|
if redirect_url.endswith("?"):
|
|
|
|
redirect_url = redirect_url[:-1]
|
|
|
|
|
|
|
|
# Handle cases like /logged_out?asdf by adding a slash to the beginning
|
|
|
|
if not redirect_url.startswith('/'):
|
|
|
|
redirect_url = f"/{redirect_url}"
|
|
|
|
|
|
|
|
# Prevent redirect loop caused by visiting /logged_out/logged_out/logged_out/etc...
|
|
|
|
if redirect_url.startswith('/logged_out'):
|
|
|
|
abort(400)
|
|
|
|
|
|
|
|
return redirect(redirect_url)
|
|
|
|
|
|
|
|
|
2022-01-02 20:20:13 +00:00
|
|
|
@app.get("/marseys")
|
2022-01-12 02:42:26 +00:00
|
|
|
@auth_required
|
2022-01-22 14:08:14 +00:00
|
|
|
def marseys(v):
|
2022-04-02 16:54:27 +00:00
|
|
|
if SITE_NAME == 'rDrama':
|
2022-03-05 22:09:06 +00:00
|
|
|
marseys = g.db.query(Marsey, User).join(User, User.id==Marsey.author_id)
|
2022-03-05 22:09:46 +00:00
|
|
|
sort = request.values.get("sort", "usage")
|
2022-03-06 00:31:19 +00:00
|
|
|
if sort == "usage": marseys = marseys.order_by(Marsey.count.desc(), User.username)
|
|
|
|
else: marseys = marseys.order_by(User.username, Marsey.count.desc())
|
2022-01-28 01:49:32 +00:00
|
|
|
else:
|
|
|
|
marseys = g.db.query(Marsey).order_by(Marsey.count.desc())
|
2022-01-23 23:06:34 +00:00
|
|
|
return render_template("marseys.html", v=v, marseys=marseys)
|
|
|
|
|
|
|
|
@app.get("/marsey_list")
|
|
|
|
@cache.memoize(timeout=600)
|
|
|
|
def marsey_list():
|
2022-04-02 16:54:27 +00:00
|
|
|
if SITE_NAME == 'rDrama':
|
2022-01-28 01:49:09 +00:00
|
|
|
marseys = [f"{x.name} : {y} {x.tags}" for x, y in g.db.query(Marsey, User.username).join(User, User.id==Marsey.author_id).order_by(Marsey.count.desc())]
|
|
|
|
else:
|
|
|
|
marseys = [f"{x.name} : {x.tags}" for x in g.db.query(Marsey).order_by(Marsey.count.desc())]
|
|
|
|
|
2022-01-24 19:06:41 +00:00
|
|
|
return str(marseys).replace("'",'"')
|
2021-12-14 21:32:58 +00:00
|
|
|
|
2022-04-24 17:30:05 +00:00
|
|
|
@app.get('/rules')
|
2021-12-30 05:27:22 +00:00
|
|
|
@app.get('/sidebar')
|
2022-01-14 04:15:41 +00:00
|
|
|
@auth_desired
|
2021-12-30 05:27:22 +00:00
|
|
|
def sidebar(v):
|
2022-01-14 00:14:55 +00:00
|
|
|
return render_template('sidebar.html', v=v)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/stats")
|
|
|
|
@auth_required
|
|
|
|
def participation_stats(v):
|
|
|
|
|
2022-04-29 00:02:00 +00:00
|
|
|
return render_template("admin/content_stats.html", v=v, title="Content Statistics", data=stats(site=SITE))
|
2022-01-24 16:21:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cache.memoize(timeout=86400)
|
2022-04-29 00:02:00 +00:00
|
|
|
def stats(site=None):
|
2022-01-24 21:04:35 +00:00
|
|
|
day = int(time.time()) - 86400
|
2022-01-24 21:04:16 +00:00
|
|
|
|
2022-02-14 21:00:59 +00:00
|
|
|
week = int(time.time()) - 604800
|
|
|
|
posters = g.db.query(Submission.author_id).distinct(Submission.author_id).filter(Submission.created_utc > week).all()
|
|
|
|
commenters = g.db.query(Comment.author_id).distinct(Comment.author_id).filter(Comment.created_utc > week).all()
|
2022-02-22 04:47:19 +00:00
|
|
|
voters = g.db.query(Vote.user_id).distinct(Vote.user_id).filter(Vote.created_utc > week).all()
|
|
|
|
commentvoters = g.db.query(CommentVote.user_id).distinct(CommentVote.user_id).filter(CommentVote.created_utc > week).all()
|
2022-02-22 04:46:44 +00:00
|
|
|
|
2022-02-22 04:48:21 +00:00
|
|
|
active_users = set(posters) | set(commenters) | set(voters) | set(commentvoters)
|
2022-02-14 21:00:59 +00:00
|
|
|
|
2022-04-25 21:16:32 +00:00
|
|
|
stats = {"marseys": g.db.query(Marsey.name).count(),
|
2022-01-03 11:26:30 +00:00
|
|
|
"users": g.db.query(User.id).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"private users": g.db.query(User.id).filter_by(is_private=True).count(),
|
|
|
|
"banned users": g.db.query(User.id).filter(User.is_banned > 0).count(),
|
|
|
|
"verified email users": g.db.query(User.id).filter_by(is_activated=True).count(),
|
|
|
|
"coins in circulation": g.db.query(func.sum(User.coins)).scalar(),
|
|
|
|
"total shop sales": g.db.query(func.sum(User.coins_spent)).scalar(),
|
|
|
|
"signups last 24h": g.db.query(User.id).filter(User.created_utc > day).count(),
|
|
|
|
"total posts": g.db.query(Submission.id).count(),
|
|
|
|
"posting users": g.db.query(Submission.author_id).distinct().count(),
|
|
|
|
"listed posts": g.db.query(Submission.id).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
|
2022-02-14 23:14:59 +00:00
|
|
|
"removed posts (by admins)": g.db.query(Submission.id).filter_by(is_banned=True).count(),
|
|
|
|
"deleted posts (by author)": g.db.query(Submission.id).filter(Submission.deleted_utc > 0).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"posts last 24h": g.db.query(Submission.id).filter(Submission.created_utc > day).count(),
|
|
|
|
"total comments": g.db.query(Comment.id).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
|
|
|
"commenting users": g.db.query(Comment.author_id).distinct().count(),
|
2022-02-14 23:14:59 +00:00
|
|
|
"removed comments (by admins)": g.db.query(Comment.id).filter_by(is_banned=True).count(),
|
|
|
|
"deleted comments (by author)": g.db.query(Comment.id).filter(Comment.deleted_utc > 0).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"comments last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
2022-02-16 01:42:11 +00:00
|
|
|
"post votes": g.db.query(Vote.submission_id).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"post voting users": g.db.query(Vote.user_id).distinct().count(),
|
2022-02-16 01:16:01 +00:00
|
|
|
"comment votes": g.db.query(CommentVote.comment_id).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"comment voting users": g.db.query(CommentVote.user_id).distinct().count(),
|
2022-02-16 01:42:11 +00:00
|
|
|
"total upvotes": g.db.query(Vote.submission_id).filter_by(vote_type=1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=1).count(),
|
|
|
|
"total downvotes": g.db.query(Vote.submission_id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=-1).count(),
|
2022-02-14 21:00:59 +00:00
|
|
|
"total awards": g.db.query(AwardRelationship.id).count(),
|
|
|
|
"awards given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
|
2022-04-22 15:45:26 +00:00
|
|
|
"users who posted, commented, or voted in the past 7 days": len(active_users),
|
2022-04-25 21:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if SITE_NAME == 'rDrama':
|
2022-05-02 02:00:14 +00:00
|
|
|
furries1 = g.db.query(User.id).filter(User.house.like('Furry%')).count()
|
|
|
|
femboys1 = g.db.query(User.id).filter(User.house.like('Femboy%')).count()
|
|
|
|
vampires1 = g.db.query(User.id).filter(User.house.like('Vampire%')).count()
|
|
|
|
racists1 = g.db.query(User.id).filter(User.house.like('Racist%')).count()
|
|
|
|
|
|
|
|
furries2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Furry%')).scalar()
|
|
|
|
femboys2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Femboy%')).scalar()
|
|
|
|
vampires2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Vampire%')).scalar()
|
|
|
|
racists2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Racist%')).scalar()
|
|
|
|
|
|
|
|
stats2 = {"House furry members": furries1,
|
|
|
|
"House femboy members": femboys1,
|
|
|
|
"House vampire members": vampires1,
|
|
|
|
"House racist members": racists1,
|
|
|
|
"House furry total truescore": furries2,
|
|
|
|
"House femboy total truescore": femboys2,
|
|
|
|
"House vampire total truescore": vampires2,
|
|
|
|
"House racist total truescore": racists2,
|
|
|
|
}
|
2022-04-25 21:16:32 +00:00
|
|
|
|
2022-04-26 12:59:28 +00:00
|
|
|
stats.update(stats2)
|
2022-04-25 21:16:32 +00:00
|
|
|
|
2022-05-02 01:54:07 +00:00
|
|
|
ids = (NOTIFICATIONS_ID, AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID)
|
2022-05-02 02:11:01 +00:00
|
|
|
bots = g.db.query(User).filter(User.id.in_(ids))
|
2022-05-02 01:54:07 +00:00
|
|
|
|
2022-05-02 02:11:01 +00:00
|
|
|
for u in bots:
|
2022-05-02 01:54:07 +00:00
|
|
|
g.db.add(u)
|
|
|
|
|
|
|
|
if u.patron_utc and u.patron_utc < time.time():
|
|
|
|
u.patron = 0
|
|
|
|
u.patron_utc = 0
|
|
|
|
send_repeatable_notification(u.id, "Your paypig status has expired!")
|
|
|
|
if u.discord_id: remove_role(v, "1")
|
|
|
|
|
|
|
|
if u.unban_utc and u.unban_utc < time.time():
|
|
|
|
u.is_banned = 0
|
|
|
|
u.unban_utc = 0
|
|
|
|
u.ban_evade = 0
|
|
|
|
send_repeatable_notification(u.id, "You have been unbanned!")
|
|
|
|
|
|
|
|
if u.agendaposter and u.agendaposter < time.time():
|
|
|
|
u.agendaposter = 0
|
|
|
|
send_repeatable_notification(u.id, "Your chud theme has expired!")
|
|
|
|
badge = u.has_badge(28)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.flairchanged and u.flairchanged < time.time():
|
|
|
|
u.flairchanged = None
|
|
|
|
send_repeatable_notification(u.id, "Your flair lock has expired. You can now change your flair!")
|
|
|
|
badge = u.has_badge(96)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.marseyawarded and u.marseyawarded < time.time():
|
|
|
|
u.marseyawarded = None
|
|
|
|
send_repeatable_notification(u.id, "Your marsey award has expired!")
|
|
|
|
badge = u.has_badge(98)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.longpost and u.longpost < time.time():
|
|
|
|
u.longpost = None
|
|
|
|
send_repeatable_notification(u.id, "Your pizzashill award has expired!")
|
|
|
|
badge = u.has_badge(97)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.bird and u.bird < time.time():
|
|
|
|
u.bird = None
|
|
|
|
send_repeatable_notification(u.id, "Your bird site award has expired!")
|
|
|
|
badge = u.has_badge(95)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.progressivestack and u.progressivestack < time.time():
|
|
|
|
u.progressivestack = None
|
|
|
|
send_repeatable_notification(u.id, "Your progressive stack has expired!")
|
|
|
|
badge = u.has_badge(94)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.rehab and u.rehab < time.time():
|
|
|
|
u.rehab = None
|
|
|
|
send_repeatable_notification(u.id, "Your rehab has finished!")
|
|
|
|
badge = u.has_badge(109)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
|
|
|
if u.deflector and u.deflector < time.time():
|
|
|
|
u.deflector = None
|
|
|
|
send_repeatable_notification(u.id, "Your deflector has expired!")
|
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
2022-04-25 21:16:32 +00:00
|
|
|
return stats
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/chart")
|
2022-04-23 22:09:25 +00:00
|
|
|
def chart():
|
2022-04-21 16:10:15 +00:00
|
|
|
return redirect('/weekly_chart')
|
2022-01-24 21:49:12 +00:00
|
|
|
|
|
|
|
|
2022-04-19 18:19:12 +00:00
|
|
|
@app.get("/weekly_chart")
|
|
|
|
@auth_required
|
|
|
|
def weekly_chart(v):
|
2022-04-29 00:02:00 +00:00
|
|
|
file = cached_chart(kind="weekly", site=SITE)
|
2022-04-19 18:19:12 +00:00
|
|
|
f = send_file(file)
|
|
|
|
return f
|
|
|
|
|
|
|
|
@app.get("/daily_chart")
|
|
|
|
@auth_required
|
|
|
|
def daily_chart(v):
|
2022-04-29 00:02:00 +00:00
|
|
|
file = cached_chart(kind="daily", site=SITE)
|
2022-04-19 18:19:12 +00:00
|
|
|
f = send_file(file)
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2022-01-24 21:49:12 +00:00
|
|
|
@cache.memoize(timeout=86400)
|
2022-04-29 00:02:00 +00:00
|
|
|
def cached_chart(kind, site):
|
2021-10-15 14:08:27 +00:00
|
|
|
now = time.gmtime()
|
|
|
|
midnight_this_morning = time.struct_time((now.tm_year,
|
|
|
|
now.tm_mon,
|
|
|
|
now.tm_mday,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
now.tm_wday,
|
|
|
|
now.tm_yday,
|
|
|
|
0)
|
|
|
|
)
|
|
|
|
today_cutoff = calendar.timegm(midnight_this_morning)
|
|
|
|
|
2022-04-25 21:16:32 +00:00
|
|
|
if kind == "daily": day_cutoffs = [today_cutoff - 86400 * i for i in range(47)][1:]
|
|
|
|
else: day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(47)][1:]
|
2021-12-15 22:32:22 +00:00
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
day_cutoffs.insert(0, calendar.timegm(now))
|
|
|
|
|
2021-12-15 22:53:29 +00:00
|
|
|
daily_times = [time.strftime("%d/%m", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][::-1]
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-15 22:53:29 +00:00
|
|
|
daily_signups = [g.db.query(User.id).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][::-1]
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-15 22:53:29 +00:00
|
|
|
post_stats = [g.db.query(Submission.id).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][::-1]
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-20 12:48:02 +00:00
|
|
|
comment_stats = [g.db.query(Comment.id).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() for i in range(len(day_cutoffs) - 1)][::-1]
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-03-26 18:13:49 +00:00
|
|
|
plt.rcParams["figure.figsize"] = (30, 20)
|
2021-11-18 16:59:05 +00:00
|
|
|
|
2022-03-26 18:13:49 +00:00
|
|
|
signup_chart = plt.subplot2grid((30, 20), (0, 0), rowspan=6, colspan=30)
|
|
|
|
posts_chart = plt.subplot2grid((30, 20), (10, 0), rowspan=6, colspan=30)
|
|
|
|
comments_chart = plt.subplot2grid((30, 20), (20, 0), rowspan=6, colspan=30)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
signup_chart.grid(), posts_chart.grid(), comments_chart.grid()
|
|
|
|
|
|
|
|
signup_chart.plot(
|
|
|
|
daily_times,
|
|
|
|
daily_signups,
|
|
|
|
color='red')
|
|
|
|
posts_chart.plot(
|
|
|
|
daily_times,
|
|
|
|
post_stats,
|
2022-02-25 13:33:32 +00:00
|
|
|
color='blue')
|
2021-10-15 14:08:27 +00:00
|
|
|
comments_chart.plot(
|
|
|
|
daily_times,
|
|
|
|
comment_stats,
|
2022-02-25 13:33:32 +00:00
|
|
|
color='purple')
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-01-02 00:05:22 +00:00
|
|
|
signup_chart.set_ylim(ymin=0)
|
|
|
|
posts_chart.set_ylim(ymin=0)
|
|
|
|
comments_chart.set_ylim(ymin=0)
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
signup_chart.set_ylabel("Signups")
|
|
|
|
posts_chart.set_ylabel("Posts")
|
|
|
|
comments_chart.set_ylabel("Comments")
|
|
|
|
comments_chart.set_xlabel("Time (UTC)")
|
|
|
|
|
|
|
|
signup_chart.legend(loc='upper left', frameon=True)
|
|
|
|
posts_chart.legend(loc='upper left', frameon=True)
|
|
|
|
comments_chart.legend(loc='upper left', frameon=True)
|
|
|
|
|
2022-04-25 21:16:32 +00:00
|
|
|
file = f"/{SITE}_{kind}.png"
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
plt.savefig(file)
|
|
|
|
plt.clf()
|
2022-01-24 21:49:12 +00:00
|
|
|
return file
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/patrons")
|
|
|
|
@app.get("/paypigs")
|
2021-11-21 18:54:36 +00:00
|
|
|
@admin_level_required(3)
|
2021-10-15 14:08:27 +00:00
|
|
|
def patrons(v):
|
2022-01-12 04:22:00 +00:00
|
|
|
users = g.db.query(User).filter(User.patron > 0).order_by(User.patron.desc(), User.id).all()
|
2021-11-24 12:20:52 +00:00
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("patrons.html", v=v, users=users)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/admins")
|
2021-10-19 15:42:58 +00:00
|
|
|
@app.get("/badmins")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def admins(v):
|
2021-12-26 01:03:21 +00:00
|
|
|
if v and v.admin_level > 2:
|
|
|
|
admins = g.db.query(User).filter(User.admin_level>1).order_by(User.truecoins.desc()).all()
|
|
|
|
admins += g.db.query(User).filter(User.admin_level==1).order_by(User.truecoins.desc()).all()
|
|
|
|
else: admins = g.db.query(User).filter(User.admin_level>0).order_by(User.truecoins.desc()).all()
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("admins.html", v=v, admins=admins)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/log")
|
2021-10-19 15:42:58 +00:00
|
|
|
@app.get("/modlog")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def log(v):
|
|
|
|
|
2022-05-01 00:53:24 +00:00
|
|
|
try: page = max(int(request.values.get("page", 1)), 1)
|
|
|
|
except: page = 1
|
|
|
|
|
2021-12-20 15:17:43 +00:00
|
|
|
admin = request.values.get("admin")
|
2021-11-23 00:04:13 +00:00
|
|
|
if admin: admin_id = get_id(admin)
|
|
|
|
else: admin_id = 0
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-20 15:17:43 +00:00
|
|
|
kind = request.values.get("kind")
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-11-23 21:58:46 +00:00
|
|
|
if v and v.admin_level > 1: types = ACTIONTYPES
|
|
|
|
else: types = ACTIONTYPES2
|
|
|
|
|
|
|
|
if kind not in types: kind = None
|
2021-11-22 23:25:33 +00:00
|
|
|
|
2021-11-23 21:58:46 +00:00
|
|
|
actions = g.db.query(ModAction)
|
2021-11-23 21:54:07 +00:00
|
|
|
if not (v and v.admin_level > 1):
|
2022-03-19 19:15:13 +00:00
|
|
|
actions = actions.filter(ModAction.kind.notin_(["shadowban","unshadowban","flair_post","edit_post"]))
|
2021-11-23 21:58:46 +00:00
|
|
|
|
2022-03-19 18:12:14 +00:00
|
|
|
if admin_id:
|
|
|
|
actions = actions.filter_by(user_id=admin_id)
|
|
|
|
kinds = set([x.kind for x in actions])
|
|
|
|
types2 = {}
|
|
|
|
for k,val in types.items():
|
|
|
|
if k in kinds: types2[k] = val
|
|
|
|
types = types2
|
2021-11-23 23:01:50 +00:00
|
|
|
if kind: actions = actions.filter_by(kind=kind)
|
2021-11-23 21:54:07 +00:00
|
|
|
|
2021-11-22 23:25:33 +00:00
|
|
|
actions = actions.order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all()
|
2021-10-15 14:08:27 +00:00
|
|
|
next_exists=len(actions)>25
|
|
|
|
actions=actions[:25]
|
|
|
|
|
2022-03-19 18:15:12 +00:00
|
|
|
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level > 1).order_by(User.username).all()]
|
2021-11-23 00:09:11 +00:00
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, next_exists=next_exists, page=page)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/log/<id>")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def log_item(id, v):
|
|
|
|
|
|
|
|
try: id = int(id)
|
2022-02-04 08:59:12 +00:00
|
|
|
except: abort(404)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-01-02 00:06:46 +00:00
|
|
|
action=g.db.query(ModAction).filter_by(id=id).one_or_none()
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-02-04 08:59:12 +00:00
|
|
|
if not action: abort(404)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-11-23 21:54:07 +00:00
|
|
|
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level > 1).all()]
|
|
|
|
|
2021-11-23 21:58:46 +00:00
|
|
|
if v and v.admin_level > 1: types = ACTIONTYPES
|
|
|
|
else: types = ACTIONTYPES2
|
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, admins=admins, types=types)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/api")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def api(v):
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("api.html", v=v)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/contact")
|
2021-10-19 15:42:58 +00:00
|
|
|
@app.get("/press")
|
|
|
|
@app.get("/media")
|
2021-10-15 14:08:27 +00:00
|
|
|
@auth_required
|
|
|
|
def contact(v):
|
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("contact.html", v=v)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-01-06 21:38:54 +00:00
|
|
|
@app.post("/send_admin")
|
2022-01-15 06:31:17 +00:00
|
|
|
@limiter.limit("1/second;2/minute;6/hour;10/day")
|
2021-10-15 14:08:27 +00:00
|
|
|
@auth_required
|
|
|
|
def submit_contact(v):
|
2022-01-14 06:40:30 +00:00
|
|
|
body = request.values.get("message")
|
|
|
|
if not body: abort(400)
|
|
|
|
|
2022-02-11 15:02:27 +00:00
|
|
|
body = f'This message has been sent automatically to all admins via [/contact](/contact)\n\nMessage:\n\n' + body
|
2022-04-17 20:20:40 +00:00
|
|
|
body_html = sanitize(body)
|
2022-01-14 06:40:30 +00:00
|
|
|
|
|
|
|
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
|
|
|
file=request.files["file"]
|
|
|
|
if file.content_type.startswith('image/'):
|
2022-03-25 22:30:15 +00:00
|
|
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
2022-01-24 23:40:34 +00:00
|
|
|
file.save(name)
|
|
|
|
url = process_image(name)
|
2022-03-21 21:31:16 +00:00
|
|
|
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
|
2022-01-14 06:40:30 +00:00
|
|
|
elif file.content_type.startswith('video/'):
|
|
|
|
file.save("video.mp4")
|
|
|
|
with open("video.mp4", 'rb') as f:
|
2022-03-22 03:45:30 +00:00
|
|
|
try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
|
|
|
|
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
2022-03-19 14:59:56 +00:00
|
|
|
try: url = req['link']
|
2022-05-01 21:44:38 +00:00
|
|
|
except:
|
|
|
|
error = req['error']
|
|
|
|
if error == 'File exceeds max duration': error += ' (60 seconds)'
|
|
|
|
return {"error": error}, 400
|
2022-01-14 06:40:30 +00:00
|
|
|
if url.endswith('.'): url += 'mp4'
|
|
|
|
body_html += f"<p>{url}</p>"
|
|
|
|
else: return {"error": "Image/Video files only"}, 400
|
|
|
|
|
2022-02-21 01:58:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
new_comment = Comment(author_id=v.id,
|
|
|
|
parent_submission=None,
|
|
|
|
level=1,
|
|
|
|
body_html=body_html,
|
|
|
|
sentto=2
|
|
|
|
)
|
|
|
|
g.db.add(new_comment)
|
|
|
|
g.db.flush()
|
2022-04-04 01:41:20 +00:00
|
|
|
new_comment.top_comment_id = new_comment.id
|
|
|
|
|
2022-04-11 11:25:58 +00:00
|
|
|
for admin in g.db.query(User).filter(User.admin_level > 2).all():
|
2022-02-21 01:58:12 +00:00
|
|
|
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
|
|
|
|
g.db.add(notif)
|
|
|
|
|
|
|
|
|
2022-01-14 06:40:30 +00:00
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
g.db.commit()
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("contact.html", v=v, msg="Your message has been sent.")
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get('/archives')
|
2022-01-24 16:21:54 +00:00
|
|
|
def archivesindex():
|
2022-04-02 17:11:35 +00:00
|
|
|
return redirect("/archives/index.html")
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get('/archives/<path:path>')
|
2022-01-24 16:21:54 +00:00
|
|
|
def archives(path):
|
2021-10-15 14:08:27 +00:00
|
|
|
resp = make_response(send_from_directory('/archives', path))
|
|
|
|
if request.path.endswith('.css'): resp.headers.add("Content-Type", "text/css")
|
|
|
|
return resp
|
|
|
|
|
2022-02-24 18:31:28 +00:00
|
|
|
@app.get('/e/<emoji>')
|
|
|
|
@limiter.exempt
|
|
|
|
def emoji(emoji):
|
2022-03-29 17:32:36 +00:00
|
|
|
if not emoji.endswith('.webp'): abort(404)
|
2022-02-25 12:43:25 +00:00
|
|
|
resp = make_response(send_from_directory('assets/images/emojis', emoji))
|
2022-02-24 18:31:28 +00:00
|
|
|
resp.headers.remove("Cache-Control")
|
|
|
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
|
|
|
resp.headers.remove("Content-Type")
|
|
|
|
resp.headers.add("Content-Type", "image/webp")
|
|
|
|
return resp
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
@app.get('/assets/<path:path>')
|
2021-12-23 13:32:17 +00:00
|
|
|
@app.get('/static/assets/<path:path>')
|
2021-10-15 14:08:27 +00:00
|
|
|
@limiter.exempt
|
2022-01-11 23:00:10 +00:00
|
|
|
def static_service(path):
|
2021-12-14 21:32:58 +00:00
|
|
|
resp = make_response(send_from_directory('assets', path))
|
2022-03-31 17:16:13 +00:00
|
|
|
if request.path.endswith('.webp') or request.path.endswith('.gif') or request.path.endswith('.ttf') or request.path.endswith('.woff2'):
|
2021-10-15 14:08:27 +00:00
|
|
|
resp.headers.remove("Cache-Control")
|
2022-02-22 09:15:45 +00:00
|
|
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-11-11 18:58:09 +00:00
|
|
|
if request.path.endswith('.webp'):
|
|
|
|
resp.headers.remove("Content-Type")
|
|
|
|
resp.headers.add("Content-Type", "image/webp")
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
return resp
|
|
|
|
|
2021-12-23 13:32:17 +00:00
|
|
|
@app.get('/images/<path>')
|
|
|
|
@app.get('/hostedimages/<path>')
|
|
|
|
@app.get("/static/images/<path>")
|
2021-10-15 14:08:27 +00:00
|
|
|
@limiter.exempt
|
2022-01-11 23:00:10 +00:00
|
|
|
def images(path):
|
2021-12-13 01:00:08 +00:00
|
|
|
resp = make_response(send_from_directory('/images', path.replace('.WEBP','.webp')))
|
2021-10-15 14:08:27 +00:00
|
|
|
resp.headers.remove("Cache-Control")
|
2022-02-22 09:15:45 +00:00
|
|
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
2021-11-11 18:58:09 +00:00
|
|
|
if request.path.endswith('.webp'):
|
|
|
|
resp.headers.remove("Content-Type")
|
|
|
|
resp.headers.add("Content-Type", "image/webp")
|
2021-10-15 14:08:27 +00:00
|
|
|
return resp
|
|
|
|
|
|
|
|
@app.get("/robots.txt")
|
|
|
|
def robots_txt():
|
2022-02-03 06:39:02 +00:00
|
|
|
try: f = send_file("assets/robots.txt")
|
|
|
|
except:
|
|
|
|
print('/robots.txt', flush=True)
|
|
|
|
abort(404)
|
|
|
|
return f
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/badges")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2022-05-02 18:14:06 +00:00
|
|
|
@cache.memoize(timeout=3600)
|
2021-10-15 14:08:27 +00:00
|
|
|
def badges(v):
|
2022-05-02 18:14:06 +00:00
|
|
|
nonlurk_truecoins = 100
|
|
|
|
|
2022-02-21 01:35:01 +00:00
|
|
|
badges = g.db.query(BadgeDef).order_by(BadgeDef.id).all()
|
2022-05-02 18:14:06 +00:00
|
|
|
counts_raw = g.db.query(Badge.badge_id, func.count()).group_by(Badge.badge_id).all()
|
|
|
|
users_nonlurk = g.db.query(User.id).filter(User.truecoins >= nonlurk_truecoins).count()
|
|
|
|
|
|
|
|
counts = {}
|
|
|
|
for c in counts_raw:
|
|
|
|
counts[c[0]] = (c[1], float(c[1]) * 100 / max(users_nonlurk, 1))
|
2022-01-22 10:43:06 +00:00
|
|
|
|
2022-05-02 18:14:06 +00:00
|
|
|
return render_template("badges.html", v=v, badges=badges, counts=counts, nonlurk=users_nonlurk, nonlurk_tc=nonlurk_truecoins)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/blocks")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def blocks(v):
|
|
|
|
|
|
|
|
|
2021-11-06 15:52:48 +00:00
|
|
|
blocks=g.db.query(UserBlock).all()
|
2021-10-15 14:08:27 +00:00
|
|
|
users = []
|
|
|
|
targets = []
|
|
|
|
for x in blocks:
|
|
|
|
users.append(get_account(x.user_id))
|
|
|
|
targets.append(get_account(x.target_id))
|
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("blocks.html", v=v, users=users, targets=targets)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/banned")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def banned(v):
|
|
|
|
|
2022-01-12 04:22:00 +00:00
|
|
|
users = [x for x in g.db.query(User).filter(User.is_banned > 0, User.unban_utc == 0).all()]
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("banned.html", v=v, users=users)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/formatting")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def formatting(v):
|
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("formatting.html", v=v)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/service-worker.js")
|
2022-01-24 16:21:54 +00:00
|
|
|
def serviceworker():
|
2022-02-06 10:54:05 +00:00
|
|
|
with open("files/assets/js/service-worker.js", "r", encoding="utf-8") as f: return Response(f.read(), mimetype='application/javascript')
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.get("/settings/security")
|
|
|
|
@auth_required
|
|
|
|
def settings_security(v):
|
|
|
|
|
2022-01-14 12:04:34 +00:00
|
|
|
return render_template("settings_security.html",
|
2021-10-15 14:08:27 +00:00
|
|
|
v=v,
|
2021-12-28 14:11:50 +00:00
|
|
|
mfa_secret=pyotp.random_base32() if not v.mfa_secret else None
|
2022-02-18 10:24:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@app.get("/.well-known/assetlinks.json")
|
|
|
|
def googleplayapp():
|
|
|
|
with open("files/assets/assetlinks.json", "r") as f:
|
2022-04-07 01:18:46 +00:00
|
|
|
return Response(f.read(), mimetype='application/json')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/dismiss_mobile_tip")
|
|
|
|
def dismiss_mobile_tip():
|
|
|
|
session["tooltip_last_dismissed"] = int(time.time())
|
2022-04-13 22:54:32 +00:00
|
|
|
return "", 204
|