Parsing outbox for hubzilla channel

main2
Bob Mottram 2019-10-17 23:26:47 +01:00
parent 385a0ee31d
commit 92214ef5ed
11 changed files with 122 additions and 42 deletions

View File

@ -185,7 +185,9 @@ def receiveAcceptReject(session,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no actor') print('DEBUG: '+messageJson['type']+' has no actor')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type'])
return False return False

View File

@ -269,7 +269,9 @@ def createAnnounce(session,baseDir: str,federationList: [], \
announceNickname=None announceNickname=None
announceDomain=None announceDomain=None
announcePort=None announcePort=None
if '/users/' in objectUrl or '/profile/' in objectUrl: if '/users/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
announceNickname=getNicknameFromActor(objectUrl) announceNickname=getNicknameFromActor(objectUrl)
announceDomain,announcePort=getDomainFromActor(objectUrl) announceDomain,announcePort=getDomainFromActor(objectUrl)
@ -380,7 +382,9 @@ def undoAnnounce(session,baseDir: str,federationList: [], \
announceNickname=None announceNickname=None
announceDomain=None announceDomain=None
announcePort=None announcePort=None
if '/users/' in objectUrl or '/profile/' in objectUrl: if '/users/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
announceNickname=getNicknameFromActor(objectUrl) announceNickname=getNicknameFromActor(objectUrl)
announceDomain,announcePort=getDomainFromActor(objectUrl) announceDomain,announcePort=getDomainFromActor(objectUrl)

View File

@ -46,7 +46,9 @@ def authorizeBasic(baseDir: str,path: str,authHeader: str,debug: bool) -> bool:
if debug: if debug:
print('DEBUG: Authorixation header does not contain a space character') print('DEBUG: Authorixation header does not contain a space character')
return False return False
if '/users/' not in path and '/profile/' not in path: if '/users/' not in path and \
'/channel/' not in path and \
'/profile/' not in path:
if debug: if debug:
print('DEBUG: Path for Authorization does not contain a user') print('DEBUG: Path for Authorization does not contain a user')
return False return False

View File

@ -333,7 +333,9 @@ def outboxBlock(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: c2s block object is not a status') print('DEBUG: c2s block object is not a status')
return return
if '/users/' not in messageId and '/profile/' not in messageId: if '/users/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s block object has no nickname') print('DEBUG: c2s block object has no nickname')
return return
@ -408,7 +410,9 @@ def outboxUndoBlock(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: c2s undo block object is not a status') print('DEBUG: c2s undo block object is not a status')
return return
if '/users/' not in messageId and '/profile/' not in messageId: if '/users/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s undo block object has no nickname') print('DEBUG: c2s undo block object has no nickname')
return return

View File

@ -68,7 +68,9 @@ def createDelete(session,baseDir: str,federationList: [], \
deleteNickname=None deleteNickname=None
deleteDomain=None deleteDomain=None
deletePort=None deletePort=None
if '/users/' in objectUrl or '/profile/' in objectUrl: if '/users/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
deleteNickname=getNicknameFromActor(objectUrl) deleteNickname=getNicknameFromActor(objectUrl)
deleteDomain,deletePort=getDomainFromActor(objectUrl) deleteDomain,deletePort=getDomainFromActor(objectUrl)
@ -242,7 +244,9 @@ def outboxDelete(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: c2s delete object is not a status') print('DEBUG: c2s delete object is not a status')
return return
if '/users/' not in messageId and '/profile/' not in messageId: if '/users/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s delete object has no nickname') print('DEBUG: c2s delete object has no nickname')
return return

View File

@ -846,15 +846,20 @@ if args.actor:
if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'): if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'):
# format: https://domain/@nick # format: https://domain/@nick
args.actor=args.actor.replace('https://','').replace('http://','').replace('dat://','').replace('/@','/users/') args.actor=args.actor.replace('https://','').replace('http://','').replace('dat://','').replace('/@','/users/')
if '/users/' not in args.actor and '/profile/' not in args.actor: if '/users/' not in args.actor and \
'/channel/' not in args.actor and \
'/profile/' not in args.actor:
print('Expected actor format: https://domain/@nick or https://domain/users/nick') print('Expected actor format: https://domain/@nick or https://domain/users/nick')
sys.exit() sys.exit()
if '/users/' in args.actor: if '/users/' in args.actor:
nickname=args.actor.split('/users/')[1].replace('\n','') nickname=args.actor.split('/users/')[1].replace('\n','')
domain=args.actor.split('/users/')[0] domain=args.actor.split('/users/')[0]
else: elif '/profile/' in args.actor:
nickname=args.actor.split('/profile/')[1].replace('\n','') nickname=args.actor.split('/profile/')[1].replace('\n','')
domain=args.actor.split('/profile/')[0] domain=args.actor.split('/profile/')[0]
else:
nickname=args.actor.split('/channel/')[1].replace('\n','')
domain=args.actor.split('/channel/')[0]
else: else:
# format: @nick@domain # format: @nick@domain
if '@' not in args.actor: if '@' not in args.actor:
@ -884,10 +889,14 @@ if args.actor:
print('Unable to webfinger '+nickname+'@'+domain) print('Unable to webfinger '+nickname+'@'+domain)
sys.exit() sys.exit()
pprint(wfRequest)
personUrl=None personUrl=None
if wfRequest.get('errors'): if wfRequest.get('errors'):
print('wfRequest error: '+str(wfRequest['errors'])) print('wfRequest error: '+str(wfRequest['errors']))
if '/users/' in args.actor: if '/users/' in args.actor or \
'/profile/' in args.actor or \
'/channel/' in args.actor:
personUrl=originalActor personUrl=originalActor
else: else:
sys.exit() sys.exit()
@ -896,8 +905,10 @@ if args.actor:
if not personUrl: if not personUrl:
personUrl = getUserUrl(wfRequest) personUrl = getUserUrl(wfRequest)
if nickname==domain: if nickname==domain:
personUrl=personUrl.replace('/users/','/actor/') personUrl=personUrl.replace('/users/','/actor/').replace('/channel/','/actor/').replace('/profile/','/actor/')
#print('personUrl: '+personUrl) #print('personUrl: '+personUrl)
if '/channel/' in personUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None) personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None)
if personJson: if personJson:
pprint(personJson) pprint(personJson)

View File

@ -439,7 +439,9 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: follow request has no actor') print('DEBUG: follow request has no actor')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor') print('DEBUG: "users" or "profile" missing from actor')
return False return False
@ -463,7 +465,9 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
if not messageJson.get('to'): if not messageJson.get('to'):
messageJson['to']=messageJson['object'] messageJson['to']=messageJson['object']
handle=nickname.lower()+'@'+domain.lower() handle=nickname.lower()+'@'+domain.lower()
if '/users/' not in messageJson['object'] and '/profile/' not in messageJson['object']: if '/users/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug: if debug:
print('DEBUG: "users" or "profile" not found within object') print('DEBUG: "users" or "profile" not found within object')
return False return False

View File

@ -553,7 +553,9 @@ def receiveUndoFollow(session,baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: follow request has no actor within object') print('DEBUG: follow request has no actor within object')
return False return False
if '/users/' not in messageJson['object']['actor'] and '/profile/' not in messageJson['object']['actor']: if '/users/' not in messageJson['object']['actor'] and \
'/channel/' not in messageJson['object']['actor'] and \
'/profile/' not in messageJson['object']['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor within object') print('DEBUG: "users" or "profile" missing from actor within object')
return False return False
@ -612,7 +614,9 @@ def receiveUndo(session,baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: follow request has no actor') print('DEBUG: follow request has no actor')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor') print('DEBUG: "users" or "profile" missing from actor')
return False return False
@ -663,11 +667,13 @@ def personReceiveUpdate(baseDir: str, \
if actor not in personJson['id']: if actor not in personJson['id']:
actor=updateDomainFull+'/profile/'+updateNickname actor=updateDomainFull+'/profile/'+updateNickname
if actor not in personJson['id']: if actor not in personJson['id']:
if debug: actor=updateDomainFull+'/channel/'+updateNickname
print('actor: '+actor) if actor not in personJson['id']:
print('id: '+personJson['id']) if debug:
print('DEBUG: Actor does not match id') print('actor: '+actor)
return False print('id: '+personJson['id'])
print('DEBUG: Actor does not match id')
return False
if updateDomainFull==domainFull: if updateDomainFull==domainFull:
if debug: if debug:
print('DEBUG: You can only receive actor updates for domains other than your own') print('DEBUG: You can only receive actor updates for domains other than your own')
@ -763,7 +769,9 @@ def receiveUpdate(session,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' object has no type') print('DEBUG: '+messageJson['type']+' object has no type')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type'])
return False return False
@ -827,7 +835,9 @@ def receiveLike(session,handle: str,isGroup: bool,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no "to" list') print('DEBUG: '+messageJson['type']+' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type'])
return False return False
@ -876,7 +886,9 @@ def receiveUndoLike(session,handle: str,isGroup: bool,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' like object is not a string') print('DEBUG: '+messageJson['type']+' like object is not a string')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']+' like') print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']+' like')
return False return False
@ -937,7 +949,9 @@ def receiveDelete(session,handle: str,isGroup: bool,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no "to" list') print('DEBUG: '+messageJson['type']+' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type'])
return False return False
@ -995,11 +1009,15 @@ def receiveAnnounce(session,handle: str,isGroup: bool,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no "to" list') print('DEBUG: '+messageJson['type']+' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type'])
return False return False
if '/users/' not in messageJson['object'] and '/profile/' not in messageJson['object']: if '/users/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing in '+messageJson['type']) print('DEBUG: "users" or "profile" missing in '+messageJson['type'])
return False return False
@ -1042,7 +1060,9 @@ def receiveAnnounce(session,handle: str,isGroup: bool,baseDir: str, \
if postJsonObject['object'].get('attributedTo'): if postJsonObject['object'].get('attributedTo'):
lookupActor=postJsonObject['object']['attributedTo'] lookupActor=postJsonObject['object']['attributedTo']
if lookupActor: if lookupActor:
if '/users/' in lookupActor or '/profile/' in lookupActor: if '/users/' in lookupActor or \
'/channel/' in lookupActor or \
'/profile/' in lookupActor:
if '/statuses/' in lookupActor: if '/statuses/' in lookupActor:
lookupActor=lookupActor.split('/statuses/')[0] lookupActor=lookupActor.split('/statuses/')[0]
@ -1086,7 +1106,9 @@ def receiveUndoAnnounce(session,handle: str,isGroup: bool,baseDir: str, \
return False return False
if messageJson['object']['type']!='Announce': if messageJson['object']['type']!='Announce':
return False return False
if '/users/' not in messageJson['actor'] and '/profile/' not in messageJson['actor']: if '/users/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']+' announce') print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']+' announce')
return False return False
@ -1249,7 +1271,9 @@ def obtainAvatarForReplyPost(session,baseDir: str,httpPrefix: str,domain: str,pe
lookupActor=postJsonObject['object']['inReplyTo'] lookupActor=postJsonObject['object']['inReplyTo']
if lookupActor: if lookupActor:
if '/users/' in lookupActor or '/profile/' in lookupActor: if '/users/' in lookupActor or \
'/channel/' in lookupActor or \
'/profile/' in lookupActor:
if '/statuses/' in lookupActor: if '/statuses/' in lookupActor:
lookupActor=lookupActor.split('/statuses/')[0] lookupActor=lookupActor.split('/statuses/')[0]

16
like.py
View File

@ -211,7 +211,9 @@ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port:
likedPostNickname=None likedPostNickname=None
likedPostDomain=None likedPostDomain=None
likedPostPort=None likedPostPort=None
if '/users/' in objectUrl or '/profile/' in objectUrl: if '/users/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
likedPostNickname=getNicknameFromActor(objectUrl) likedPostNickname=getNicknameFromActor(objectUrl)
likedPostDomain,likedPostPort=getDomainFromActor(objectUrl) likedPostDomain,likedPostPort=getDomainFromActor(objectUrl)
@ -308,7 +310,9 @@ def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,p
likedPostNickname=None likedPostNickname=None
likedPostDomain=None likedPostDomain=None
likedPostPort=None likedPostPort=None
if '/users/' in objectUrl or '/profile/' in objectUrl: if '/users/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
likedPostNickname=getNicknameFromActor(objectUrl) likedPostNickname=getNicknameFromActor(objectUrl)
likedPostDomain,likedPostPort=getDomainFromActor(objectUrl) likedPostDomain,likedPostPort=getDomainFromActor(objectUrl)
@ -544,7 +548,9 @@ def outboxLike(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: c2s like object is not a status') print('DEBUG: c2s like object is not a status')
return return
if '/users/' not in messageId and '/profile/' not in messageId: if '/users/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s like object has no nickname') print('DEBUG: c2s like object has no nickname')
return return
@ -599,7 +605,9 @@ def outboxUndoLike(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: c2s undo like object is not a status') print('DEBUG: c2s undo like object is not a status')
return return
if '/users/' not in messageId and '/profile/' not in messageId: if '/users/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s undo like object has no nickname') print('DEBUG: c2s undo like object has no nickname')
return return

View File

@ -119,7 +119,9 @@ def getUserUrl(wfRequest) -> str:
for link in wfRequest['links']: for link in wfRequest['links']:
if link.get('type') and link.get('href'): if link.get('type') and link.get('href'):
if link['type'] == 'application/activity+json': if link['type'] == 'application/activity+json':
if '/users/' in link['href'] or '/profile/' in link['href']: if '/users/' in link['href'] or \
'/profile/' in link['href'] or \
'/channel/' in link['href']:
return link['href'] return link['href']
else: else:
print('Webfinger activity+json does not contain a valid actor') print('Webfinger activity+json does not contain a valid actor')
@ -168,6 +170,8 @@ def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
return None,None,None,None,None,None,None,None return None,None,None,None,None,None,None,None
personJson = getPersonFromCache(baseDir,personUrl,personCache) personJson = getPersonFromCache(baseDir,personUrl,personCache)
if not personJson: if not personJson:
if '/channel/' in personUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personJson = getJson(session,personUrl,asHeader,None, \ personJson = getJson(session,personUrl,asHeader,None, \
projectVersion,httpPrefix,domain) projectVersion,httpPrefix,domain)
if not personJson: if not personJson:
@ -228,6 +232,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
if not outboxUrl: if not outboxUrl:
return personPosts return personPosts
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
if '/outbox/' in outboxUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
if raw: if raw:
result = [] result = []
i = 0 i = 0
@ -2410,7 +2416,9 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str,nickname: str,domain:
if '/statuses/' not in announcedJson['id']: if '/statuses/' not in announcedJson['id']:
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
return None return None
if '/users/' not in announcedJson['id'] and '/profile/' not in announcedJson['id']: if '/users/' not in announcedJson['id'] and \
'/channel/' not in announcedJson['id'] and \
'/profile/' not in announcedJson['id']:
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
return None return None
if not announcedJson.get('type'): if not announcedJson.get('type'):

View File

@ -115,6 +115,12 @@ def getNicknameFromActor(actor: str) -> str:
return nickStr return nickStr
else: else:
return nickStr.split('/')[0] return nickStr.split('/')[0]
if '/channel/' in actor:
nickStr=actor.split('/channel/')[1].replace('@','')
if '/' not in nickStr:
return nickStr
else:
return nickStr.split('/')[0]
# https://domain/@nick # https://domain/@nick
if '/@' in actor: if '/@' in actor:
nickStr=actor.split('/@')[1] nickStr=actor.split('/@')[1]
@ -135,12 +141,15 @@ def getDomainFromActor(actor: str) -> (str,int):
if '/profile/' in actor: if '/profile/' in actor:
domain = actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('dat://','') domain = actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('dat://','')
else: else:
if '/users/' not in actor: if '/channel/' in actor:
domain = actor.replace('https://','').replace('http://','').replace('dat://','') domain = actor.split('/channel/')[0].replace('https://','').replace('http://','').replace('dat://','')
if '/' in actor:
domain=domain.split('/')[0]
else: else:
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','') if '/users/' not in actor:
domain = actor.replace('https://','').replace('http://','').replace('dat://','')
if '/' in actor:
domain=domain.split('/')[0]
else:
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','')
if ':' in domain: if ':' in domain:
port=int(domain.split(':')[1]) port=int(domain.split(':')[1])
domain=domain.split(':')[0] domain=domain.split(':')[0]
@ -326,7 +335,7 @@ def validNickname(domain: str,nickname: str) -> bool:
return False return False
if nickname==domain: if nickname==domain:
return False return False
reservedNames=['inbox','dm','outbox','following','public','followers','capabilities','calendar','tlreplies','tlmedia','moderation'] reservedNames=['inbox','dm','outbox','following','public','followers','profile','channel','capabilities','calendar','tlreplies','tlmedia','moderation']
if nickname in reservedNames: if nickname in reservedNames:
return False return False
return True return True