From ac67db1679fd8f43da6d1e9b8f75e8ba898a3ae8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 5 Sep 2020 10:41:09 +0100 Subject: [PATCH] Easier way to block domains --- blocking.py | 6 +++++- daemon.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/blocking.py b/blocking.py index 8d6436f3..b59cc7f9 100644 --- a/blocking.py +++ b/blocking.py @@ -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() diff --git a/daemon.py b/daemon.py index c4c929ca..1c285256 100644 --- a/daemon.py +++ b/daemon.py @@ -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':