mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
block conspiracy sites
This commit is contained in:
parent
56d09b264a
commit
ec3511eb17
2 changed files with 19 additions and 3 deletions
10
app/cli.py
10
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'))
|
||||
|
|
10
app/utils.py
10
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
|
||||
|
@ -182,3 +183,12 @@ def user_access(permission: str, user_id: int) -> bool:
|
|||
'WHERE ur.user_id = :user_id AND rp.permission = :permission'),
|
||||
{'user_id': user_id, 'permission': permission}).first()
|
||||
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
|
Loading…
Reference in a new issue