mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
automatically block new user registrations based on referrer
This commit is contained in:
parent
081108a7c6
commit
ef43e78ae5
5 changed files with 20 additions and 3 deletions
|
@ -31,6 +31,7 @@ class SiteMiscForm(FlaskForm):
|
|||
types = [('Open', _l('Open')), ('RequireApplication', _l('Require application')), ('Closed', _l('Closed'))]
|
||||
registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str)
|
||||
application_question = TextAreaField(_l('Question to ask people applying for an account'))
|
||||
auto_decline_referrers = TextAreaField(_l('Block registrations from these referrers (one per line)'))
|
||||
log_activitypub_json = BooleanField(_l('Log ActivityPub JSON for debugging'))
|
||||
default_theme = SelectField(_l('Default theme'), coerce=str)
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
|
|
@ -18,7 +18,7 @@ from app.community.util import save_icon_file, save_banner_file
|
|||
from app.models import AllowedInstances, BannedInstances, ActivityPubLog, utcnow, Site, Community, CommunityMember, \
|
||||
User, Instance, File, Report, Topic, UserRegistration, Role, Post
|
||||
from app.utils import render_template, permission_required, set_setting, get_setting, gibberish, markdown_to_html, \
|
||||
moderating_communities, joined_communities, finalize_user_setup, theme_list, blocked_phrases
|
||||
moderating_communities, joined_communities, finalize_user_setup, theme_list, blocked_phrases, blocked_referrers
|
||||
from app.admin import bp
|
||||
|
||||
|
||||
|
@ -80,12 +80,14 @@ def admin_misc():
|
|||
site.reports_email_admins = form.reports_email_admins.data
|
||||
site.registration_mode = form.registration_mode.data
|
||||
site.application_question = form.application_question.data
|
||||
site.auto_decline_referrers = form.auto_decline_referrers.data
|
||||
site.log_activitypub_json = form.log_activitypub_json.data
|
||||
site.updated = utcnow()
|
||||
site.default_theme = form.default_theme.data
|
||||
if site.id is None:
|
||||
db.session.add(site)
|
||||
db.session.commit()
|
||||
cache.delete_memoized(blocked_referrers)
|
||||
flash('Settings saved.')
|
||||
elif request.method == 'GET':
|
||||
form.enable_downvotes.data = site.enable_downvotes
|
||||
|
@ -97,6 +99,7 @@ def admin_misc():
|
|||
form.reports_email_admins.data = site.reports_email_admins
|
||||
form.registration_mode.data = site.registration_mode
|
||||
form.application_question.data = site.application_question
|
||||
form.auto_decline_referrers.data = site.auto_decline_referrers
|
||||
form.log_activitypub_json.data = site.log_activitypub_json
|
||||
form.default_theme.data = site.default_theme if site.default_theme is not None else ''
|
||||
return render_template('admin/misc.html', title=_('Misc settings'), form=form,
|
||||
|
|
|
@ -12,7 +12,7 @@ from app.auth.util import random_token, normalize_utf
|
|||
from app.email import send_verification_email, send_password_reset_email
|
||||
from app.models import User, utcnow, IpBan, UserRegistration, Notification, Site
|
||||
from app.utils import render_template, ip_address, user_ip_banned, user_cookie_banned, banned_ip_addresses, \
|
||||
finalize_user_setup
|
||||
finalize_user_setup, blocked_referrers
|
||||
|
||||
|
||||
@bp.route('/login', methods=['GET', 'POST'])
|
||||
|
@ -98,6 +98,11 @@ def register():
|
|||
if form.user_name.data in disallowed_usernames:
|
||||
flash(_('Sorry, you cannot use that user name'), 'error')
|
||||
else:
|
||||
for referrer in blocked_referrers():
|
||||
if referrer in session.get('Referer'):
|
||||
resp = make_response(redirect(url_for('auth.please_wait')))
|
||||
resp.set_cookie('sesion', '17489047567495', expires=datetime(year=2099, month=12, day=30))
|
||||
return resp
|
||||
verification_token = random_token(16)
|
||||
form.user_name.data = form.user_name.data.strip()
|
||||
before_normalize = form.user_name.data
|
||||
|
|
|
@ -1171,7 +1171,7 @@ class Site(db.Model):
|
|||
allowlist = db.Column(db.Text, default='')
|
||||
blocklist = db.Column(db.Text, default='')
|
||||
blocked_phrases = db.Column(db.Text, default='') # discard incoming content with these phrases
|
||||
auto_decline_referrers = db.Column(db.Text, default='rdrama.net') # automatically decline registration requests if the referrer is one of these
|
||||
auto_decline_referrers = db.Column(db.Text, default='rdrama.net\nahrefs.com') # automatically decline registration requests if the referrer is one of these
|
||||
created_at = db.Column(db.DateTime, default=utcnow)
|
||||
updated = db.Column(db.DateTime, default=utcnow)
|
||||
last_active = db.Column(db.DateTime, default=utcnow)
|
||||
|
|
|
@ -339,6 +339,14 @@ def blocked_phrases() -> List[str]:
|
|||
return []
|
||||
|
||||
|
||||
@cache.memoize(timeout=86400)
|
||||
def blocked_referrers() -> List[str]:
|
||||
site = Site.query.get(1)
|
||||
if site.auto_decline_referrers:
|
||||
return [referrer for referrer in site.auto_decline_referrers.split('\n') if referrer != '']
|
||||
else:
|
||||
return []
|
||||
|
||||
def retrieve_block_list():
|
||||
try:
|
||||
response = requests.get('https://raw.githubusercontent.com/rimu/no-qanon/master/domains.txt', timeout=1)
|
||||
|
|
Loading…
Reference in a new issue