Easier way to block domains

merge-requests/8/head
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'
if not blockNickname.startswith('#'):
blockHandle = blockNickname + '@' + blockDomain
# is the handle already blocked?
blockHandle = blockNickname + '@' + blockDomain
if os.path.isfile(blockingFilename):
if blockHandle in open(blockingFilename).read():
return False
# block an account handle or domain
blockFile = open(blockingFilename, "a+")
blockFile.write(blockHandle + '\n')
blockFile.close()
else:
blockHashtag = blockNickname
# is the hashtag already blocked?
if os.path.isfile(blockingFilename):
if blockHashtag + '\n' in open(blockingFilename).read():
return False
# block a hashtag
blockFile = open(blockingFilename, "a+")
blockFile.write(blockHashtag + '\n')
blockFile.close()

View File

@ -1407,6 +1407,7 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = None
if moderationText.startswith('http') or \
moderationText.startswith('dat'):
# https://domain
blockDomain, blockPort = \
getDomainFromActor(moderationText)
fullBlockDomain = blockDomain
@ -1416,13 +1417,20 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = \
blockDomain + ':' + str(blockPort)
if '@' in moderationText:
# nick@domain or *@domain
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('#'):
addGlobalBlock(baseDir, nickname, fullBlockDomain)
if moderationButton == 'unblock':
fullBlockDomain = None
if moderationText.startswith('http') or \
moderationText.startswith('dat'):
# https://domain
blockDomain, blockPort = \
getDomainFromActor(moderationText)
fullBlockDomain = blockDomain
@ -1432,7 +1440,13 @@ class PubServer(BaseHTTPRequestHandler):
fullBlockDomain = \
blockDomain + ':' + str(blockPort)
if '@' in moderationText:
# nick@domain or *@domain
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('#'):
removeGlobalBlock(baseDir, nickname, fullBlockDomain)
if moderationButton == 'remove':