mirror of https://gitlab.com/bashrc2/epicyon
c2s blocking
parent
2782a4b8cf
commit
e52dde8027
20
blocking.py
20
blocking.py
|
@ -328,25 +328,25 @@ def isBlocked(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
def outboxBlock(baseDir: str, httpPrefix: str,
|
def outboxBlock(baseDir: str, httpPrefix: str,
|
||||||
nickname: str, domain: str, port: int,
|
nickname: str, domain: str, port: int,
|
||||||
messageJson: {}, debug: bool) -> None:
|
messageJson: {}, debug: bool) -> bool:
|
||||||
""" When a block request is received by the outbox from c2s
|
""" When a block request is received by the outbox from c2s
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('type'):
|
if not messageJson.get('type'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: block - no type')
|
print('DEBUG: block - no type')
|
||||||
return
|
return False
|
||||||
if not messageJson['type'] == 'Block':
|
if not messageJson['type'] == 'Block':
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: not a block')
|
print('DEBUG: not a block')
|
||||||
return
|
return False
|
||||||
if not messageJson.get('object'):
|
if not messageJson.get('object'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: no object in block')
|
print('DEBUG: no object in block')
|
||||||
return
|
return False
|
||||||
if not isinstance(messageJson['object'], str):
|
if not isinstance(messageJson['object'], str):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: block object is not string')
|
print('DEBUG: block object is not string')
|
||||||
return
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block request arrived in outbox')
|
print('DEBUG: c2s block request arrived in outbox')
|
||||||
|
|
||||||
|
@ -354,31 +354,31 @@ def outboxBlock(baseDir: str, httpPrefix: str,
|
||||||
if '/statuses/' not in messageId:
|
if '/statuses/' not in messageId:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block object is not a status')
|
print('DEBUG: c2s block object is not a status')
|
||||||
return
|
return False
|
||||||
if not hasUsersPath(messageId):
|
if not hasUsersPath(messageId):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block object has no nickname')
|
print('DEBUG: c2s block object has no nickname')
|
||||||
return
|
return False
|
||||||
domain = removeDomainPort(domain)
|
domain = removeDomainPort(domain)
|
||||||
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
||||||
if not postFilename:
|
if not postFilename:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block post not found in inbox or outbox')
|
print('DEBUG: c2s block post not found in inbox or outbox')
|
||||||
print(messageId)
|
print(messageId)
|
||||||
return
|
return False
|
||||||
nicknameBlocked = getNicknameFromActor(messageJson['object'])
|
nicknameBlocked = getNicknameFromActor(messageJson['object'])
|
||||||
if not nicknameBlocked:
|
if not nicknameBlocked:
|
||||||
print('WARN: unable to find nickname in ' + messageJson['object'])
|
print('WARN: unable to find nickname in ' + messageJson['object'])
|
||||||
return
|
return False
|
||||||
domainBlocked, portBlocked = getDomainFromActor(messageJson['object'])
|
domainBlocked, portBlocked = getDomainFromActor(messageJson['object'])
|
||||||
domainBlockedFull = getFullDomain(domainBlocked, portBlocked)
|
domainBlockedFull = getFullDomain(domainBlocked, portBlocked)
|
||||||
|
|
||||||
addBlock(baseDir, nickname, domain,
|
addBlock(baseDir, nickname, domain,
|
||||||
nicknameBlocked, domainBlockedFull)
|
nicknameBlocked, domainBlockedFull)
|
||||||
# TODO send block activity
|
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post blocked via c2s - ' + postFilename)
|
print('DEBUG: post blocked via c2s - ' + postFilename)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def outboxUndoBlock(baseDir: str, httpPrefix: str,
|
def outboxUndoBlock(baseDir: str, httpPrefix: str,
|
||||||
|
|
Loading…
Reference in New Issue