Improve user agent blocking

main
Bob Mottram 2022-03-31 17:33:21 +01:00
parent c395688c18
commit 92f3bbb763
1 changed files with 8 additions and 7 deletions

View File

@ -379,7 +379,7 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
if '*@' + domain in blocked_str: if '*@' + domain in blocked_str:
return True return True
if block_handle: if block_handle:
if block_handle in blocked_str: if blocked_str == block_handle:
return True return True
else: else:
global_blocks_filename = base_dir + '/accounts/blocking.txt' global_blocks_filename = base_dir + '/accounts/blocking.txt'
@ -387,33 +387,34 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
if '*@' + block_domain in open(global_blocks_filename).read(): if '*@' + block_domain in open(global_blocks_filename).read():
return True return True
if block_handle: if block_handle:
if block_handle in open(global_blocks_filename).read(): block_str = block_handle + '\n'
if block_str in open(global_blocks_filename).read():
return True return True
else: else:
# instance allow list # instance allow list
allow_filename = base_dir + '/accounts/allowedinstances.txt' allow_filename = base_dir + '/accounts/allowedinstances.txt'
short_domain = _get_short_domain(block_domain) short_domain = _get_short_domain(block_domain)
if not short_domain: if not short_domain:
if block_domain not in open(allow_filename).read(): if block_domain + '\n' not in open(allow_filename).read():
return True return True
else: else:
if short_domain not in open(allow_filename).read(): if short_domain + '\n' not in open(allow_filename).read():
return True return True
# account level allow list # account level allow list
account_dir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
allow_filename = account_dir + '/allowedinstances.txt' allow_filename = account_dir + '/allowedinstances.txt'
if os.path.isfile(allow_filename): if os.path.isfile(allow_filename):
if block_domain not in open(allow_filename).read(): if block_domain + '\n' not in open(allow_filename).read():
return True return True
# account level block list # account level block list
blocking_filename = account_dir + '/blocking.txt' blocking_filename = account_dir + '/blocking.txt'
if os.path.isfile(blocking_filename): if os.path.isfile(blocking_filename):
if '*@' + block_domain in open(blocking_filename).read(): if '*@' + block_domain + '\n' in open(blocking_filename).read():
return True return True
if block_handle: if block_handle:
if block_handle in open(blocking_filename).read(): if block_handle + '\n' in open(blocking_filename).read():
return True return True
return False return False