Receiving follow requests

master
Bob Mottram 2019-07-02 19:17:04 +01:00
parent f52fea680d
commit 534cea06f8
2 changed files with 30 additions and 0 deletions

View File

@ -249,6 +249,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
return return
print('**************** POST valid') print('**************** POST valid')
if receiveFollowRequest(self.server.baseDir,messageJson,self.server.federationList):
self.send_response(200)
self.end_headers()
self.server.POSTbusy=False
return
pprint(messageJson) pprint(messageJson)
# add a property to the object, just to mess with data # add a property to the object, just to mess with data
#message['received'] = 'ok' #message['received'] = 'ok'

View File

@ -198,3 +198,27 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str,https: bool,fo
if nextPageNumber>lastPage: if nextPageNumber>lastPage:
following['next']=prefix+'://'+domain+'/users/'+username+'/'+followFile+'?page='+str(lastPage) following['next']=prefix+'://'+domain+'/users/'+username+'/'+followFile+'?page='+str(lastPage)
return following return following
def receiveFollowRequest(baseDir: str,messageJson: {},federationList: []) -> bool:
if not messageJson['type'].startswith('Follow'):
return False
if '/users/' not in messageJson['actor']:
return False
domain=messageJson['actor'].split('/users/')[0].replace('https://','').replace('http://','')
if not domainPermitted(domain,federationList):
return False
username=messageJson['actor'].split('/users/')[1].replace('@','')
handle=username.lower()+'@'+domain.lower()
if not os.path.isdir(baseDir+'/accounts/'+handle):
return False
if '/users/' not in messageJson['object']:
return False
domainToFollow=messageJson['object'].split('/users/')[0].replace('https://','').replace('http://','')
if not domainPermitted(domainToFollow,federationList):
return False
usernameToFollow=messageJson['object'].split('/users/')[1].replace('@','')
handleToFollow=usernameToFollow.lower()+'@'+domainToFollow.lower()
if domainToFollow==domain:
if not os.path.isdir(baseDir+'/accounts/'+handleToFollow):
return False
return followerOfPerson(baseDir,username,domain,usernameToFollow,domainToFollow,federationList)