Easier way to block domains

main
Bob Mottram 2020-09-05 10:41:09 +01:00
parent 0e15d936b3
commit ac67db1679
2 changed files with 19 additions and 1 deletions

View File

@ -21,18 +21,22 @@ def addGlobalBlock(baseDir: str,
""" """
blockingFilename = baseDir + '/accounts/blocking.txt' blockingFilename = baseDir + '/accounts/blocking.txt'
if not blockNickname.startswith('#'): if not blockNickname.startswith('#'):
blockHandle = blockNickname + '@' + blockDomain # is the handle already blocked?
blockHandle = blockNickname + '@' + blockDomain
if os.path.isfile(blockingFilename): if os.path.isfile(blockingFilename):
if blockHandle in open(blockingFilename).read(): if blockHandle in open(blockingFilename).read():
return False return False
# block an account handle or domain
blockFile = open(blockingFilename, "a+") blockFile = open(blockingFilename, "a+")
blockFile.write(blockHandle + '\n') blockFile.write(blockHandle + '\n')
blockFile.close() blockFile.close()
else: else:
blockHashtag = blockNickname blockHashtag = blockNickname
# is the hashtag already blocked?
if os.path.isfile(blockingFilename): if os.path.isfile(blockingFilename):
if blockHashtag + '\n' in open(blockingFilename).read(): if blockHashtag + '\n' in open(blockingFilename).read():
return False return False
# block a hashtag
blockFile = open(blockingFilename, "a+") blockFile = open(blockingFilename, "a+")
blockFile.write(blockHashtag + '\n') blockFile.write(blockHashtag + '\n')
blockFile.close() blockFile.close()

View File

@ -1407,6 +1407,7 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = None fullBlockDomain = None
if moderationText.startswith('http') or \ if moderationText.startswith('http') or \
moderationText.startswith('dat'): moderationText.startswith('dat'):
# https://domain
blockDomain, blockPort = \ blockDomain, blockPort = \
getDomainFromActor(moderationText) getDomainFromActor(moderationText)
fullBlockDomain = blockDomain fullBlockDomain = blockDomain
@ -1416,13 +1417,20 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = \ fullBlockDomain = \
blockDomain + ':' + str(blockPort) blockDomain + ':' + str(blockPort)
if '@' in moderationText: if '@' in moderationText:
# nick@domain or *@domain
fullBlockDomain = moderationText.split('@')[1] fullBlockDomain = moderationText.split('@')[1]
else:
# assume the text is a domain name
if not fullBlockDomain and '.' in moderationText:
nickname = '*'
fullBlockDomain = moderationText.strip()
if fullBlockDomain or nickname.startswith('#'): if fullBlockDomain or nickname.startswith('#'):
addGlobalBlock(baseDir, nickname, fullBlockDomain) addGlobalBlock(baseDir, nickname, fullBlockDomain)
if moderationButton == 'unblock': if moderationButton == 'unblock':
fullBlockDomain = None fullBlockDomain = None
if moderationText.startswith('http') or \ if moderationText.startswith('http') or \
moderationText.startswith('dat'): moderationText.startswith('dat'):
# https://domain
blockDomain, blockPort = \ blockDomain, blockPort = \
getDomainFromActor(moderationText) getDomainFromActor(moderationText)
fullBlockDomain = blockDomain fullBlockDomain = blockDomain
@ -1432,7 +1440,13 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = \ fullBlockDomain = \
blockDomain + ':' + str(blockPort) blockDomain + ':' + str(blockPort)
if '@' in moderationText: if '@' in moderationText:
# nick@domain or *@domain
fullBlockDomain = moderationText.split('@')[1] fullBlockDomain = moderationText.split('@')[1]
else:
# assume the text is a domain name
if not fullBlockDomain and '.' in moderationText:
nickname = '*'
fullBlockDomain = moderationText.strip()
if fullBlockDomain or nickname.startswith('#'): if fullBlockDomain or nickname.startswith('#'):
removeGlobalBlock(baseDir, nickname, fullBlockDomain) removeGlobalBlock(baseDir, nickname, fullBlockDomain)
if moderationButton == 'remove': if moderationButton == 'remove':