mirror of https://gitlab.com/bashrc2/epicyon
Additional ise of blocked domains cache
parent
1576db8ae3
commit
7d6b6d95fb
33
blocking.py
33
blocking.py
|
@ -243,19 +243,33 @@ def isBlockedDomain(baseDir: str, domain: str,
|
||||||
|
|
||||||
|
|
||||||
def isBlocked(baseDir: str, nickname: 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?
|
"""Is the given nickname blocked?
|
||||||
"""
|
"""
|
||||||
if isEvil(blockDomain):
|
if isEvil(blockDomain):
|
||||||
return True
|
return True
|
||||||
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
|
|
||||||
if os.path.isfile(globalBlockingFilename):
|
blockHandle = None
|
||||||
if '*@' + blockDomain in open(globalBlockingFilename).read():
|
if blockNickname and blockDomain:
|
||||||
return True
|
blockHandle = blockNickname + '@' + blockDomain
|
||||||
if blockNickname:
|
|
||||||
blockHandle = blockNickname + '@' + blockDomain
|
if blockedCache:
|
||||||
if blockHandle in open(globalBlockingFilename).read():
|
for blockedStr in blockedCache:
|
||||||
|
if '*@' + domain in blockedStr:
|
||||||
return True
|
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/' + \
|
allowFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/allowedinstances.txt'
|
nickname + '@' + domain + '/allowedinstances.txt'
|
||||||
if os.path.isfile(allowFilename):
|
if os.path.isfile(allowFilename):
|
||||||
|
@ -266,8 +280,7 @@ def isBlocked(baseDir: str, nickname: str, domain: str,
|
||||||
if os.path.isfile(blockingFilename):
|
if os.path.isfile(blockingFilename):
|
||||||
if '*@' + blockDomain in open(blockingFilename).read():
|
if '*@' + blockDomain in open(blockingFilename).read():
|
||||||
return True
|
return True
|
||||||
if blockNickname:
|
if blockHandle:
|
||||||
blockHandle = blockNickname + '@' + blockDomain
|
|
||||||
if blockHandle in open(blockingFilename).read():
|
if blockHandle in open(blockingFilename).read():
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
10
daemon.py
10
daemon.py
|
@ -1277,6 +1277,13 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
beginSaveTime = time.time()
|
beginSaveTime = time.time()
|
||||||
# save the json for later queue processing
|
# save the json for later queue processing
|
||||||
messageBytesDecoded = messageBytes.decode('utf-8')
|
messageBytesDecoded = messageBytes.decode('utf-8')
|
||||||
|
|
||||||
|
self.server.blockedCacheLastUpdated = \
|
||||||
|
updateBlockedCache(self.server.baseDir,
|
||||||
|
self.server.blockedCache,
|
||||||
|
self.server.blockedCacheLastUpdated,
|
||||||
|
self.server.blockedCacheUpdateSecs)
|
||||||
|
|
||||||
queueFilename = \
|
queueFilename = \
|
||||||
savePostToInboxQueue(self.server.baseDir,
|
savePostToInboxQueue(self.server.baseDir,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
|
@ -1286,7 +1293,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
messageBytesDecoded,
|
messageBytesDecoded,
|
||||||
headersDict,
|
headersDict,
|
||||||
self.path,
|
self.path,
|
||||||
self.server.debug)
|
self.server.debug,
|
||||||
|
self.server.blockedCache)
|
||||||
if queueFilename:
|
if queueFilename:
|
||||||
# add json to the queue
|
# add json to the queue
|
||||||
if queueFilename not in self.server.inboxQueue:
|
if queueFilename not in self.server.inboxQueue:
|
||||||
|
|
11
inbox.py
11
inbox.py
|
@ -353,7 +353,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
|
||||||
originalPostJsonObject: {},
|
originalPostJsonObject: {},
|
||||||
messageBytes: str,
|
messageBytes: str,
|
||||||
httpHeaders: {},
|
httpHeaders: {},
|
||||||
postPath: str, debug: bool) -> str:
|
postPath: str, debug: bool,
|
||||||
|
blockedCache: []) -> str:
|
||||||
"""Saves the give json to the inbox queue for the person
|
"""Saves the give json to the inbox queue for the person
|
||||||
keyId specifies the actor sending the post
|
keyId specifies the actor sending the post
|
||||||
"""
|
"""
|
||||||
|
@ -384,7 +385,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
print('No post Domain in actor')
|
print('No post Domain in actor')
|
||||||
return None
|
return None
|
||||||
if isBlocked(baseDir, nickname, domain, postNickname, postDomain):
|
if isBlocked(baseDir, nickname, domain,
|
||||||
|
postNickname, postDomain, blockedCache):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post from ' + postNickname + ' blocked')
|
print('DEBUG: post from ' + postNickname + ' blocked')
|
||||||
return None
|
return None
|
||||||
|
@ -398,7 +400,7 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
|
||||||
postJsonObject['object']['inReplyTo']
|
postJsonObject['object']['inReplyTo']
|
||||||
replyDomain, replyPort = \
|
replyDomain, replyPort = \
|
||||||
getDomainFromActor(inReplyTo)
|
getDomainFromActor(inReplyTo)
|
||||||
if isBlockedDomain(baseDir, replyDomain):
|
if isBlockedDomain(baseDir, replyDomain, blockedCache):
|
||||||
if debug:
|
if debug:
|
||||||
print('WARN: post contains reply from ' +
|
print('WARN: post contains reply from ' +
|
||||||
str(actor) +
|
str(actor) +
|
||||||
|
@ -409,7 +411,8 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
|
||||||
getNicknameFromActor(inReplyTo)
|
getNicknameFromActor(inReplyTo)
|
||||||
if replyNickname and replyDomain:
|
if replyNickname and replyDomain:
|
||||||
if isBlocked(baseDir, nickname, domain,
|
if isBlocked(baseDir, nickname, domain,
|
||||||
replyNickname, replyDomain):
|
replyNickname, replyDomain,
|
||||||
|
blockedCache):
|
||||||
if debug:
|
if debug:
|
||||||
print('WARN: post contains reply from ' +
|
print('WARN: post contains reply from ' +
|
||||||
str(actor) +
|
str(actor) +
|
||||||
|
|
Loading…
Reference in New Issue