From ec3511eb176665ed56e6dc6d2b730506ea3fbeff Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:20:13 +1300 Subject: [PATCH] block conspiracy sites --- app/cli.py | 10 ++++++++-- app/utils.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/cli.py b/app/cli.py index 5902eee5..8c88d5ed 100644 --- a/app/cli.py +++ b/app/cli.py @@ -8,8 +8,8 @@ import os from app.auth.email import send_verification_email from app.auth.util import random_token -from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission -from app.utils import file_get_contents +from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain +from app.utils import file_get_contents, retrieve_block_list def register(app): @@ -76,6 +76,12 @@ def register(app): db.session.add(Interest(name='🖥️ Tech', communities=parse_communities(interests, 'tech'))) db.session.add(Interest(name='🤗 Mental Health', communities=parse_communities(interests, 'mental health'))) + # Load initial domain block list + block_list = retrieve_block_list() + if block_list: + for domain in block_list.split(): + db.session.add(Domain(name=domain.strip(), banned=True)) + # Initial roles anon_role = Role(name='Anonymous user', weight=0) anon_role.permissions.append(RolePermission(permission='register')) diff --git a/app/utils.py b/app/utils.py index 9f605b51..b50077b1 100644 --- a/app/utils.py +++ b/app/utils.py @@ -2,6 +2,7 @@ import random import markdown2 import math from urllib.parse import urlparse +import requests import flask from bs4 import BeautifulSoup @@ -181,4 +182,13 @@ def user_access(permission: str, user_id: int) -> bool: 'INNER JOIN user_role ur on rp.role_id = ur.role_id ' + 'WHERE ur.user_id = :user_id AND rp.permission = :permission'), {'user_id': user_id, 'permission': permission}).first() - return has_access is not None \ No newline at end of file + return has_access is not None + + +def retrieve_block_list(): + try: + response = requests.get('https://github.com/rimu/no-qanon/blob/master/domains.txt', timeout=1) + except: + return None + if response and response.status_code == 200: + return response.text \ No newline at end of file