block conspiracy sites

This commit is contained in:
rimu 2023-10-21 16:20:13 +13:00
parent 56d09b264a
commit ec3511eb17
2 changed files with 19 additions and 3 deletions

View file

@ -8,8 +8,8 @@ import os
from app.auth.email import send_verification_email from app.auth.email import send_verification_email
from app.auth.util import random_token from app.auth.util import random_token
from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain
from app.utils import file_get_contents from app.utils import file_get_contents, retrieve_block_list
def register(app): 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='🖥️ Tech', communities=parse_communities(interests, 'tech')))
db.session.add(Interest(name='🤗 Mental Health', communities=parse_communities(interests, 'mental health'))) 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 # Initial roles
anon_role = Role(name='Anonymous user', weight=0) anon_role = Role(name='Anonymous user', weight=0)
anon_role.permissions.append(RolePermission(permission='register')) anon_role.permissions.append(RolePermission(permission='register'))

View file

@ -2,6 +2,7 @@ import random
import markdown2 import markdown2
import math import math
from urllib.parse import urlparse from urllib.parse import urlparse
import requests
import flask import flask
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -182,3 +183,12 @@ def user_access(permission: str, user_id: int) -> bool:
'WHERE ur.user_id = :user_id AND rp.permission = :permission'), 'WHERE ur.user_id = :user_id AND rp.permission = :permission'),
{'user_id': user_id, 'permission': permission}).first() {'user_id': user_id, 'permission': permission}).first()
return has_access is not None 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