Additional ise of blocked domains cache

merge-requests/30/head
Bob Mottram 2021-06-21 15:32:17 +01:00
parent 1576db8ae3
commit 7d6b6d95fb
3 changed files with 39 additions and 15 deletions

View File

@ -243,19 +243,33 @@ def isBlockedDomain(baseDir: str, domain: str,
def isBlocked(baseDir: str, nickname: str, domain: str,
blockNickname: str, blockDomain: str) -> bool:
blockNickname: str, blockDomain: str,
blockedCache: [] = None) -> bool:
"""Is the given nickname blocked?
"""
if isEvil(blockDomain):
return True
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename):
if '*@' + blockDomain in open(globalBlockingFilename).read():
return True
if blockNickname:
blockHandle = blockNickname + '@' + blockDomain
if blockHandle in open(globalBlockingFilename).read():
blockHandle = None
if blockNickname and blockDomain:
blockHandle = blockNickname + '@' + blockDomain
if blockedCache:
for blockedStr in blockedCache:
if '*@' + domain in blockedStr:
return True
if blockHandle:
if blockHandle in blockedStr:
return True
else:
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename):
if '*@' + blockDomain in open(globalBlockingFilename).read():
return True
if blockHandle:
if blockHandle in open(globalBlockingFilename).read():
return True
allowFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/allowedinstances.txt'
if os.path.isfile(allowFilename):
@ -266,8 +280,7 @@ def isBlocked(baseDir: str, nickname: str, domain: str,
if os.path.isfile(blockingFilename):
if '*@' + blockDomain in open(blockingFilename).read():
return True
if blockNickname:
blockHandle = blockNickname + '@' + blockDomain
if blockHandle:
if blockHandle in open(blockingFilename).read():
return True
return False

View File

@ -1277,6 +1277,13 @@ class PubServer(BaseHTTPRequestHandler):
beginSaveTime = time.time()
# save the json for later queue processing
messageBytesDecoded = messageBytes.decode('utf-8')
self.server.blockedCacheLastUpdated = \
updateBlockedCache(self.server.baseDir,
self.server.blockedCache,
self.server.blockedCacheLastUpdated,
self.server.blockedCacheUpdateSecs)
queueFilename = \
savePostToInboxQueue(self.server.baseDir,
self.server.httpPrefix,
@ -1286,7 +1293,8 @@ class PubServer(BaseHTTPRequestHandler):
messageBytesDecoded,
headersDict,
self.path,
self.server.debug)
self.server.debug,
self.server.blockedCache)
if queueFilename:
# add json to the queue
if queueFilename not in self.server.inboxQueue:

View File

@ -353,7 +353,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
originalPostJsonObject: {},
messageBytes: str,
httpHeaders: {},
postPath: str, debug: bool) -> str:
postPath: str, debug: bool,
blockedCache: []) -> str:
"""Saves the give json to the inbox queue for the person
keyId specifies the actor sending the post
"""
@ -384,7 +385,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
pprint(postJsonObject)
print('No post Domain in actor')
return None
if isBlocked(baseDir, nickname, domain, postNickname, postDomain):
if isBlocked(baseDir, nickname, domain,
postNickname, postDomain, blockedCache):
if debug:
print('DEBUG: post from ' + postNickname + ' blocked')
return None
@ -398,7 +400,7 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
postJsonObject['object']['inReplyTo']
replyDomain, replyPort = \
getDomainFromActor(inReplyTo)
if isBlockedDomain(baseDir, replyDomain):
if isBlockedDomain(baseDir, replyDomain, blockedCache):
if debug:
print('WARN: post contains reply from ' +
str(actor) +
@ -409,7 +411,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
getNicknameFromActor(inReplyTo)
if replyNickname and replyDomain:
if isBlocked(baseDir, nickname, domain,
replyNickname, replyDomain):
replyNickname, replyDomain,
blockedCache):
if debug:
print('WARN: post contains reply from ' +
str(actor) +