2021-08-04 15:35:10 +00:00
from files . mail import *
from files . __main__ import app , limiter
from files . helpers . alerts import *
2021-07-21 01:12:26 +00:00
2021-08-05 14:41:32 +00:00
site = environ . get ( " DOMAIN " ) . strip ( )
2021-08-19 05:40:23 +00:00
site_name = environ . get ( " SITE_NAME " ) . strip ( )
2021-07-25 21:59:20 +00:00
2021-08-07 12:20:00 +00:00
@app.get ( " /stats " )
@auth_desired
def participation_stats ( v ) :
now = int ( time . time ( ) )
day = now - 86400
data = { " valid_users " : g . db . query ( User ) . count ( ) ,
" private_users " : g . db . query ( User ) . filter_by ( is_private = True ) . count ( ) ,
" banned_users " : g . db . query ( User ) . filter ( User . is_banned > 0 ) . count ( ) ,
" verified_email_users " : g . db . query ( User ) . filter_by ( is_activated = True ) . count ( ) ,
" signups_last_24h " : g . db . query ( User ) . filter ( User . created_utc > day ) . count ( ) ,
" total_posts " : g . db . query ( Submission ) . count ( ) ,
" posting_users " : g . db . query ( Submission . author_id ) . distinct ( ) . count ( ) ,
" listed_posts " : g . db . query ( Submission ) . filter_by ( is_banned = False ) . filter ( Submission . deleted_utc == 0 ) . count ( ) ,
" removed_posts " : g . db . query ( Submission ) . filter_by ( is_banned = True ) . count ( ) ,
" deleted_posts " : g . db . query ( Submission ) . filter ( Submission . deleted_utc > 0 ) . count ( ) ,
" posts_last_24h " : g . db . query ( Submission ) . filter ( Submission . created_utc > day ) . count ( ) ,
" total_comments " : g . db . query ( Comment ) . count ( ) ,
" commenting_users " : g . db . query ( Comment . author_id ) . distinct ( ) . count ( ) ,
" removed_comments " : g . db . query ( Comment ) . filter_by ( is_banned = True ) . count ( ) ,
" deleted_comments " : g . db . query ( Comment ) . filter ( Comment . deleted_utc > 0 ) . count ( ) ,
" comments_last_24h " : g . db . query ( Comment ) . filter ( Comment . created_utc > day ) . count ( ) ,
" post_votes " : g . db . query ( Vote ) . count ( ) ,
" post_voting_users " : g . db . query ( Vote . user_id ) . distinct ( ) . count ( ) ,
" comment_votes " : g . db . query ( CommentVote ) . count ( ) ,
" comment_voting_users " : g . db . query ( CommentVote . user_id ) . distinct ( ) . count ( ) ,
" total_awards " : g . db . query ( AwardRelationship ) . count ( ) ,
" awards_given " : g . db . query ( AwardRelationship ) . filter ( or_ ( AwardRelationship . submission_id != None , AwardRelationship . comment_id != None ) ) . count ( )
}
return render_template ( " admin/content_stats.html " , v = v , title = " Content Statistics " , data = data )
2021-08-22 16:33:18 +00:00
@app.get ( " /paypigs " )
2021-07-30 15:14:41 +00:00
@auth_desired
def patrons ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
2021-08-22 19:13:08 +00:00
users = g . db . query ( User ) . options ( lazyload ( ' * ' ) ) . filter ( User . patron > 0 ) . order_by ( User . patron . desc ( ) ) . all ( )
2021-07-30 15:14:41 +00:00
return render_template ( " patrons.html " , v = v , users = users )
2021-08-18 15:32:27 +00:00
@app.get ( " /admins " )
2021-07-25 21:59:20 +00:00
@auth_desired
2021-08-18 15:32:27 +00:00
def admins ( v ) :
admins = g . db . query ( User ) . filter_by ( admin_level = 6 ) . order_by ( User . coins . desc ( ) ) . all ( )
return render_template ( " admins.html " , v = v , admins = admins )
2021-07-25 21:59:20 +00:00
2021-07-27 22:31:28 +00:00
@app.get ( " /log " )
2021-07-25 21:59:20 +00:00
@auth_desired
def log ( v ) :
page = int ( request . args . get ( " page " , 1 ) )
if v and v . admin_level == 6 : actions = g . db . query ( ModAction ) . order_by ( ModAction . id . desc ( ) ) . offset ( 25 * ( page - 1 ) ) . limit ( 26 ) . all ( )
else : actions = g . db . query ( ModAction ) . filter ( ModAction . kind != " shadowban " , ModAction . kind != " unshadowban " ) . order_by ( ModAction . id . desc ( ) ) . offset ( 25 * ( page - 1 ) ) . limit ( 26 ) . all ( )
next_exists = len ( actions ) == 26
2021-07-26 00:45:52 +00:00
actions = actions [ : 25 ]
2021-07-25 21:59:20 +00:00
2021-07-31 05:59:25 +00:00
return render_template ( " log.html " , v = v , actions = actions , next_exists = next_exists , page = page )
2021-07-25 21:59:20 +00:00
2021-07-30 08:28:18 +00:00
@app.get ( " /log/<id> " )
2021-07-25 21:59:20 +00:00
@auth_desired
2021-07-30 08:28:18 +00:00
def log_item ( id , v ) :
2021-07-25 21:59:20 +00:00
2021-07-30 08:28:18 +00:00
try : id = int ( id )
2021-07-31 06:59:18 +00:00
except :
try : id = int ( id , 36 )
except : abort ( 404 )
2021-07-30 08:28:18 +00:00
action = g . db . query ( ModAction ) . filter_by ( id = id ) . first ( )
2021-07-25 21:59:20 +00:00
if not action :
abort ( 404 )
if request . path != action . permalink :
return redirect ( action . permalink )
2021-07-31 05:59:25 +00:00
return render_template ( " log.html " ,
2021-07-25 21:59:20 +00:00
v = v ,
actions = [ action ] ,
next_exists = False ,
page = 1 ,
action = action
)
2021-07-21 01:12:26 +00:00
@app.route ( " /sex " )
def index ( ) :
return render_template ( " index.html " , * * { " greeting " : " Hello from Flask! " } )
2021-07-27 22:31:28 +00:00
@app.get ( " /assets/favicon.ico " )
2021-07-21 01:12:26 +00:00
def favicon ( ) :
2021-08-22 17:55:18 +00:00
return send_file ( f " ./assets/images/ { site_name } /icon.gif " )
2021-07-21 01:12:26 +00:00
2021-07-31 04:32:42 +00:00
@app.get ( " /api " )
2021-07-21 01:12:26 +00:00
@auth_desired
2021-07-31 04:32:42 +00:00
def api ( v ) :
return render_template ( " api.html " , v = v )
2021-07-21 01:12:26 +00:00
2021-07-27 22:31:28 +00:00
@app.get ( " /contact " )
2021-07-21 01:12:26 +00:00
@auth_desired
def contact ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
return render_template ( " contact.html " , v = v )
2021-07-27 22:31:28 +00:00
@app.post ( " /contact " )
2021-07-21 01:12:26 +00:00
@auth_desired
def submit_contact ( v ) :
2021-08-02 15:05:46 +00:00
message = f ' This message has been sent automatically to all admins via https:// { site } /contact, user email is " { v . email } " \n \n Message: \n \n ' + request . form . get ( " message " , " " )
2021-07-21 01:12:26 +00:00
send_admin ( v . id , message )
return render_template ( " contact.html " , v = v , msg = " Your message has been sent. " )
@app.route ( ' /archives ' )
@limiter.exempt
def archivesindex ( ) :
return redirect ( " /archives/index.html " )
@app.route ( ' /archives/<path:path> ' )
@limiter.exempt
def archives ( path ) :
resp = make_response ( send_from_directory ( ' /archives ' , path ) )
if request . path . endswith ( ' .css ' ) : resp . headers . add ( " Content-Type " , " text/css " )
return resp
@app.route ( ' /assets/<path:path> ' )
@limiter.exempt
def static_service ( path ) :
resp = make_response ( send_from_directory ( ' ./assets ' , path ) )
2021-07-30 13:44:03 +00:00
if request . path . endswith ( ' .css ' ) : resp . headers . add ( " Content-Type " , " text/css " )
2021-07-21 01:12:26 +00:00
return resp
2021-07-27 22:31:28 +00:00
@app.get ( " /robots.txt " )
2021-07-21 01:12:26 +00:00
def robots_txt ( ) :
return send_file ( " ./assets/robots.txt " )
2021-07-27 22:31:28 +00:00
@app.get ( " /settings " )
2021-07-21 01:12:26 +00:00
@auth_required
def settings ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
return redirect ( " /settings/profile " )
2021-07-27 22:31:28 +00:00
@app.get ( " /settings/profile " )
2021-07-21 01:12:26 +00:00
@auth_required
def settings_profile ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
return render_template ( " settings_profile.html " ,
v = v )
2021-07-27 22:31:28 +00:00
@app.get ( " /titles " )
2021-07-21 01:12:26 +00:00
@auth_desired
def titles ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
titles = [ x for x in g . db . query ( Title ) . order_by ( text ( " id asc " ) ) . all ( ) ]
return render_template ( " /titles.html " ,
v = v ,
titles = titles )
2021-07-27 22:31:28 +00:00
@app.get ( " /badges " )
2021-07-21 01:12:26 +00:00
@auth_desired
def badges ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
2021-08-20 05:55:53 +00:00
badges = g . db . query ( BadgeDef ) . all ( )
return render_template ( " badges.html " , v = v , badges = badges )
2021-07-21 01:12:26 +00:00
2021-07-27 22:31:28 +00:00
@app.get ( " /blocks " )
2021-07-21 01:12:26 +00:00
@auth_desired
def blocks ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
blocks = g . db . query ( UserBlock ) . all ( )
users = [ ]
targets = [ ]
for x in blocks :
users . append ( get_account ( x . user_id ) )
targets . append ( get_account ( x . target_id ) )
return render_template ( " blocks.html " , v = v , users = users , targets = targets )
2021-07-27 22:31:28 +00:00
@app.get ( " /banned " )
2021-07-21 01:12:26 +00:00
@auth_desired
def banned ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
2021-07-26 18:05:46 +00:00
users = [ x for x in g . db . query ( User ) . filter ( User . is_banned > 0 , User . unban_utc == 0 ) . all ( ) ]
2021-07-21 01:12:26 +00:00
return render_template ( " banned.html " , v = v , users = users )
2021-07-27 22:31:28 +00:00
@app.get ( " /formatting " )
2021-07-21 01:12:26 +00:00
@auth_desired
def formatting ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
return render_template ( " formatting.html " , v = v )
2021-07-27 22:31:28 +00:00
@app.get ( " /.well-known/brave-rewards-verification.txt " )
2021-07-21 01:12:26 +00:00
def brave ( ) :
with open ( " .well-known/brave-rewards-verification.txt " , " r " ) as f : return Response ( f . read ( ) , mimetype = ' text/plain ' )
2021-07-27 22:31:28 +00:00
@app.get ( " /.well-known/assetlinks.json " )
2021-07-21 01:12:26 +00:00
def googleplayapp ( ) :
with open ( " .well-known/assetlinks.json " , " r " ) as f : return Response ( f . read ( ) , mimetype = ' application/json ' )
@app.route ( " /service-worker.js " )
def serviceworker ( ) :
with open ( " .well-known/service-worker.js " , " r " ) as f : return Response ( f . read ( ) , mimetype = ' application/javascript ' )
2021-07-27 22:31:28 +00:00
@app.get ( " /settings/security " )
2021-07-21 01:12:26 +00:00
@auth_required
def settings_security ( v ) :
if v and v . is_banned and not v . unban_utc : return render_template ( " seized.html " )
return render_template ( " settings_security.html " ,
v = v ,
mfa_secret = pyotp . random_base32 ( ) if not v . mfa_secret else None ,
error = request . args . get ( " error " ) or None ,
msg = request . args . get ( " msg " ) or None
)
2021-07-27 22:31:28 +00:00
@app.post ( " /dismiss_mobile_tip " )
2021-07-21 01:12:26 +00:00
def dismiss_mobile_tip ( ) :
session [ " tooltip_last_dismissed " ] = int ( time . time ( ) )
session . modified = True
return " " , 204