Improve account based blocking

main
bashrc 2026-01-30 17:29:05 +00:00
parent 6f188dbdb7
commit 38c3d800de
3 changed files with 36 additions and 26 deletions

View File

@ -1232,26 +1232,30 @@ def daemon_http_post(self) -> None:
nickname = self.path.split('/users/')[1] nickname = self.path.split('/users/')[1]
if '/' in nickname: if '/' in nickname:
nickname = nickname.split('/')[0] nickname = nickname.split('/')[0]
if self.server.block_military.get(nickname): if nickname in self.server.block_military:
if contains_military_domain(decoded_message_bytes): if self.server.block_military[nickname] is True and \
contains_military_domain(decoded_message_bytes):
http_400(self) http_400(self)
print('BLOCK: blocked military domain') print('BLOCK: blocked military domain')
self.server.postreq_busy = False self.server.postreq_busy = False
return return
if self.server.block_government.get(nickname): if nickname in self.server.block_government:
if contains_government_domain(decoded_message_bytes): if self.server.block_government[nickname] is True and \
contains_government_domain(decoded_message_bytes):
http_400(self) http_400(self)
print('BLOCK: blocked government domain') print('BLOCK: blocked government domain')
self.server.postreq_busy = False self.server.postreq_busy = False
return return
if self.server.block_bluesky.get(nickname): if nickname in self.server.block_bluesky:
if contains_bluesky_domain(decoded_message_bytes): if self.server.block_bluesky[nickname] is True and \
contains_bluesky_domain(decoded_message_bytes):
http_400(self) http_400(self)
print('BLOCK: blocked bluesky domain') print('BLOCK: blocked bluesky domain')
self.server.postreq_busy = False self.server.postreq_busy = False
return return
if self.server.block_nostr.get(nickname): if nickname in self.server.block_nostr:
if contains_nostr_domain(decoded_message_bytes): if self.server.block_nostr[nickname] is True and \
contains_nostr_domain(decoded_message_bytes):
http_400(self) http_400(self)
print('BLOCK: blocked nostr domain') print('BLOCK: blocked nostr domain')
self.server.postreq_busy = False self.server.postreq_busy = False

View File

@ -1870,25 +1870,27 @@ def receive_announce(recent_posts_cache: {},
# Check that the domain of the announced post is not blocked # Check that the domain of the announced post is not blocked
handle_nickname = handle.split('@')[0] handle_nickname = handle.split('@')[0]
if block_military.get(handle_nickname): if handle_nickname in block_military:
if contains_military_domain(announce_url): if block_military[handle_nickname] is True and \
contains_military_domain(announce_url):
print('BLOCK: ' + handle_nickname + print('BLOCK: ' + handle_nickname +
' blocked military domain announce') ' blocked military domain announce')
return False return False
if block_government.get(handle_nickname): if handle_nickname in block_government:
if contains_government_domain(announce_url): if block_government[handle_nickname] is True and \
contains_government_domain(announce_url):
print('BLOCK: ' + handle_nickname + print('BLOCK: ' + handle_nickname +
' blocked government domain announce') ' blocked government domain announce')
return False return False
print('DEBUG: block_bluesky ' + str(block_bluesky) + ', ' + if handle_nickname in block_bluesky:
announce_url) if block_bluesky[handle_nickname] is True and \
if block_bluesky.get(handle_nickname): contains_bluesky_domain(announce_url):
if contains_bluesky_domain(announce_url):
print('BLOCK: ' + handle_nickname + print('BLOCK: ' + handle_nickname +
' blocked bluesky domain announce') ' blocked bluesky domain announce')
return False return False
if block_nostr.get(handle_nickname): if handle_nickname in block_nostr:
if contains_nostr_domain(announce_url): if block_nostr[handle_nickname] is True and \
contains_nostr_domain(announce_url):
print('BLOCK: ' + handle_nickname + print('BLOCK: ' + handle_nickname +
' blocked nostr domain announce') ' blocked nostr domain announce')
return False return False

View File

@ -6513,26 +6513,30 @@ def download_announce(session, base_dir: str, http_prefix: str,
return None return None
# check for blocked content # check for blocked content
if block_military.get(nickname): if nickname in block_military:
if contains_military_domain(announced_json_str): if block_military[nickname] is True and \
contains_military_domain(announced_json_str):
_reject_announce(announce_filename, _reject_announce(announce_filename,
base_dir, nickname, domain, post_id, base_dir, nickname, domain, post_id,
recent_posts_cache, debug) recent_posts_cache, debug)
return None return None
if block_government.get(nickname): if nickname in block_government:
if contains_government_domain(announced_json_str): if block_government[nickname] is True and \
contains_government_domain(announced_json_str):
_reject_announce(announce_filename, _reject_announce(announce_filename,
base_dir, nickname, domain, post_id, base_dir, nickname, domain, post_id,
recent_posts_cache, debug) recent_posts_cache, debug)
return None return None
if block_bluesky.get(nickname): if nickname in block_bluesky:
if contains_bluesky_domain(announced_json_str): if block_bluesky[nickname] is True and \
contains_bluesky_domain(announced_json_str):
_reject_announce(announce_filename, _reject_announce(announce_filename,
base_dir, nickname, domain, post_id, base_dir, nickname, domain, post_id,
recent_posts_cache, debug) recent_posts_cache, debug)
return None return None
if block_nostr.get(nickname): if nickname in block_nostr:
if contains_nostr_domain(announced_json_str): if block_nostr[nickname] is True and \
contains_nostr_domain(announced_json_str):
_reject_announce(announce_filename, _reject_announce(announce_filename,
base_dir, nickname, domain, post_id, base_dir, nickname, domain, post_id,
recent_posts_cache, debug) recent_posts_cache, debug)