Use federated block domains

merge-requests/30/head
Bob Mottram 2024-02-09 21:25:40 +00:00
parent 7abf819572
commit 2ba05bc7ae
4 changed files with 29 additions and 6 deletions

View File

@ -696,7 +696,8 @@ def _get_short_domain(domain: str) -> str:
def is_blocked_domain(base_dir: str, domain: str, def is_blocked_domain(base_dir: str, domain: str,
blocked_cache: [] = None) -> bool: blocked_cache: [] = None,
block_federated: [] = None) -> bool:
"""Is the given domain blocked? """Is the given domain blocked?
""" """
if '.' not in domain: if '.' not in domain:
@ -709,6 +710,10 @@ def is_blocked_domain(base_dir: str, domain: str,
search_str = '*@' + domain search_str = '*@' + domain
if not broch_mode_is_active(base_dir): if not broch_mode_is_active(base_dir):
if block_federated:
if domain in block_federated:
return True
if blocked_cache: if blocked_cache:
for blocked_str in blocked_cache: for blocked_str in blocked_cache:
if blocked_str == search_str: if blocked_str == search_str:
@ -778,7 +783,8 @@ def is_blocked_nickname(base_dir: str, nickname: str,
def is_blocked(base_dir: str, nickname: str, domain: str, def is_blocked(base_dir: str, nickname: str, domain: str,
block_nickname: str, block_domain: str, block_nickname: str, block_domain: str,
blocked_cache: [] = None) -> bool: blocked_cache: [] = None,
block_federated: [] = None) -> bool:
"""Is the given account blocked? """Is the given account blocked?
""" """
if is_evil(block_domain): if is_evil(block_domain):
@ -790,6 +796,15 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
if not broch_mode_is_active(base_dir): if not broch_mode_is_active(base_dir):
# instance level block list # instance level block list
if block_federated:
for blocked_str in block_federated:
if '@' in blocked_str:
if block_handle:
if blocked_str == block_handle:
return True
elif blocked_str == block_domain:
return True
if blocked_cache: if blocked_cache:
for blocked_str in blocked_cache: for blocked_str in blocked_cache:
if block_nickname: if block_nickname:

View File

@ -105,6 +105,7 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
blocked_cache_last_updated, blocked_cache_last_updated,
base_dir: str, base_dir: str,
blocked_cache: [], blocked_cache: [],
block_federated: [],
blocked_cache_update_secs: int, blocked_cache_update_secs: int,
crawlers_allowed: [], crawlers_allowed: [],
known_bots: [], path: str, known_bots: [], path: str,
@ -179,7 +180,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
blocked_cache_update_secs) blocked_cache_update_secs)
blocked_ua = \ blocked_ua = \
is_blocked_domain(base_dir, agent_domain, blocked_cache) is_blocked_domain(base_dir, agent_domain,
blocked_cache, block_federated)
# if self.server.debug: # if self.server.debug:
if blocked_ua: if blocked_ua:
print('BLOCK: Blocked User agent 2: ' + agent_domain) print('BLOCK: Blocked User agent 2: ' + agent_domain)

View File

@ -2100,7 +2100,8 @@ class PubServer(BaseHTTPRequestHandler):
if debug: if debug:
print('INBOX: checking for blocked domain ' + message_domain) print('INBOX: checking for blocked domain ' + message_domain)
if is_blocked_domain(self.server.base_dir, message_domain, if is_blocked_domain(self.server.base_dir, message_domain,
self.server.blocked_cache): self.server.blocked_cache,
self.server.block_federated):
print('INBOX: POST from blocked domain ' + message_domain) print('INBOX: POST from blocked domain ' + message_domain)
self._400() self._400()
self.server.postreq_busy = False self.server.postreq_busy = False
@ -2206,6 +2207,7 @@ class PubServer(BaseHTTPRequestHandler):
self.path, self.path,
self.server.debug, self.server.debug,
self.server.blocked_cache, self.server.blocked_cache,
self.server.block_federated,
self.server.system_language, self.server.system_language,
mitm) mitm)
if queue_filename: if queue_filename:
@ -17581,6 +17583,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.blocked_cache_last_updated, self.server.blocked_cache_last_updated,
self.server.base_dir, self.server.base_dir,
self.server.blocked_cache, self.server.blocked_cache,
self.server.block_federated,
self.server.blocked_cache_update_secs, self.server.blocked_cache_update_secs,
self.server.crawlers_allowed, self.server.crawlers_allowed,
self.server.known_bots, self.server.known_bots,
@ -23581,6 +23584,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.blocked_cache_last_updated, self.server.blocked_cache_last_updated,
self.server.base_dir, self.server.base_dir,
self.server.blocked_cache, self.server.blocked_cache,
self.server.block_federated,
self.server.blocked_cache_update_secs, self.server.blocked_cache_update_secs,
self.server.crawlers_allowed, self.server.crawlers_allowed,
self.server.known_bots, self.server.known_bots,

View File

@ -680,7 +680,9 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
message_bytes: str, message_bytes: str,
http_headers: {}, http_headers: {},
post_path: str, debug: bool, post_path: str, debug: bool,
blocked_cache: [], system_language: str, blocked_cache: [],
block_federated: [],
system_language: str,
mitm: bool) -> str: mitm: bool) -> str:
"""Saves the given json to the inbox queue for the person """Saves the given json to the inbox queue for the person
key_id specifies the actor sending the post key_id specifies the actor sending the post
@ -753,7 +755,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str,
get_domain_from_actor(in_reply_to) get_domain_from_actor(in_reply_to)
if reply_domain: if reply_domain:
if is_blocked_domain(base_dir, reply_domain, if is_blocked_domain(base_dir, reply_domain,
blocked_cache): blocked_cache, block_federated):
if debug: if debug:
print('WARN: post contains reply from ' + print('WARN: post contains reply from ' +
str(actor) + str(actor) +