1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-21 17:09:59 +00:00

config: add anonymous upload/registration limiting (#537)

This commit is contained in:
Anna-Maria Meriniemi 2019-01-02 13:40:56 +02:00 committed by Arylide
parent e4780aa47d
commit 8365894268
3 changed files with 26 additions and 2 deletions

View file

@ -14,6 +14,16 @@ MAINTENANCE_MODE_MESSAGE = 'Site is currently in read-only maintenance mode.'
# Allow logging in during maintenance (without updating last login date)
MAINTENANCE_MODE_LOGINS = True
# Block *anonymous* uploads completely
RAID_MODE_LIMIT_UPLOADS = False
# Message prepended to the full error message (account.py)
RAID_MODE_UPLOADS_MESSAGE = 'Anonymous uploads are currently disabled.'
# Require manual activation for newly registered accounts
RAID_MODE_LIMIT_REGISTER = False
# Message prepended to the full error message (account.py)
RAID_MODE_REGISTER_MESSAGE = 'Registration is currently being limited.'
#############
## General ##
#############

View file

@ -172,7 +172,11 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False):
raise TorrentExtraValidationException()
if not uploading_user:
if models.RangeBan.is_rangebanned(ip_address(flask.request.remote_addr).packed):
if app.config['RAID_MODE_LIMIT_UPLOADS']:
# XXX TODO: rename rangebanned to something more generic
upload_form.rangebanned.errors = [app.config['RAID_MODE_UPLOADS_MESSAGE']]
raise TorrentExtraValidationException()
elif models.RangeBan.is_rangebanned(ip_address(flask.request.remote_addr).packed):
upload_form.rangebanned.errors = ["Your IP is banned from "
"uploading anonymously."]
raise TorrentExtraValidationException()

View file

@ -90,7 +90,17 @@ def register():
user.last_login_ip = user.registration_ip
db.session.add(user)
db.session.commit()
if models.RangeBan.is_rangebanned(user.registration_ip):
if app.config['RAID_MODE_LIMIT_REGISTER']:
flask.flash(flask.Markup(app.config['RAID_MODE_REGISTER_MESSAGE'] + ' '
'Please <a href="{}">ask a moderator</a> to manually '
'activate your account <a href="{}">\'{}\'</a>.'
.format(flask.url_for('site.help') + '#irchelp',
flask.url_for('users.view_user',
user_name=user.username),
user.username)), 'warning')
elif models.RangeBan.is_rangebanned(user.registration_ip):
flask.flash(flask.Markup('Your IP is blocked from creating new accounts. '
'Please <a href="{}">ask a moderator</a> to manually '
'activate your account <a href="{}">\'{}\'</a>.'