forked from indymedia/epicyon
Receive follow accept
parent
29fba53e9b
commit
e3be2f4328
|
@ -11,6 +11,9 @@ import commentjson
|
||||||
from utils import getStatusNumber
|
from utils import getStatusNumber
|
||||||
from utils import createOutboxDir
|
from utils import createOutboxDir
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
|
from utils import getDomainFromActor
|
||||||
|
from utils import getNicknameFromActor
|
||||||
|
from utils import domainPermitted
|
||||||
|
|
||||||
def createAcceptReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str,acceptType: str) -> {}:
|
def createAcceptReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str,acceptType: str) -> {}:
|
||||||
"""Accepts or rejects something (eg. a follow request)
|
"""Accepts or rejects something (eg. a follow request)
|
||||||
|
@ -41,3 +44,35 @@ def createAccept(baseDir: str,federationList: [],capsList: [],nickname: str,doma
|
||||||
|
|
||||||
def createReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str) -> {}:
|
def createReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str) -> {}:
|
||||||
return createAcceptReject(baseDir,federationList,capsList,nickname,domain,port,toUrl,ccUrl,httpPrefix,objectUrl,'Reject')
|
return createAcceptReject(baseDir,federationList,capsList,nickname,domain,port,toUrl,ccUrl,httpPrefix,objectUrl,'Reject')
|
||||||
|
|
||||||
|
def receiveAcceptReject(session,baseDir: str,httpPrefix: str,port: int,sendThreads: [],postLog: [],cachedWebfingers: {},personCache: {},messageJson: {},federationList: [],capsList: [],debug : bool) -> bool:
|
||||||
|
"""Receives an Accept or Reject within the POST section of HTTPServer
|
||||||
|
"""
|
||||||
|
if messageJson['type']!='Accept' and messageJson['type']!='Reject':
|
||||||
|
return False
|
||||||
|
if not messageJson.get('actor'):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' has no actor')
|
||||||
|
return False
|
||||||
|
if '/users/' not in messageJson['actor']:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: "users" missing from actor in '+messageJson['type'])
|
||||||
|
return False
|
||||||
|
domain,tempPort=getDomainFromActor(messageJson['actor'])
|
||||||
|
if not domainPermitted(domain,federationList):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' from domain not permitted - '+domain)
|
||||||
|
return False
|
||||||
|
nickname=getNicknameFromActor(messageJson['actor'])
|
||||||
|
if not nickname:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' does not contain a nickname')
|
||||||
|
return False
|
||||||
|
handle=nickname.lower()+'@'+domain.lower()
|
||||||
|
if '/users/' not in messageJson['object']:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: "users" not found within object of '+messageJson['type'])
|
||||||
|
return False
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Uh, '+messageJson['type']+', I guess')
|
||||||
|
return True
|
||||||
|
|
40
follow.py
40
follow.py
|
@ -12,6 +12,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from person import validNickname
|
from person import validNickname
|
||||||
from utils import domainPermitted
|
from utils import domainPermitted
|
||||||
|
from utils import getDomainFromActor
|
||||||
|
from utils import getNicknameFromActor
|
||||||
from posts import sendSignedJson
|
from posts import sendSignedJson
|
||||||
from capabilities import isCapable
|
from capabilities import isCapable
|
||||||
from acceptreject import createAccept
|
from acceptreject import createAccept
|
||||||
|
@ -244,29 +246,34 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str,port: int,sendThre
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: "users" missing from actor')
|
print('DEBUG: "users" missing from actor')
|
||||||
return False
|
return False
|
||||||
domain=messageJson['actor'].split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','')
|
domain,tempPort=getDomainFromActor(messageJson['actor'])
|
||||||
if ':' in domain:
|
fromPort=port
|
||||||
domain=domain.split(':')[0]
|
if tempPort:
|
||||||
|
fromPort=tempPort
|
||||||
if not domainPermitted(domain,federationList):
|
if not domainPermitted(domain,federationList):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: follower from domain not permitted - '+domain)
|
print('DEBUG: follower from domain not permitted - '+domain)
|
||||||
return False
|
return False
|
||||||
nickname=messageJson['actor'].split('/users/')[1].replace('@','')
|
nickname=getNicknameFromActor(messageJson['actor'])
|
||||||
|
if not nickname:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: follow request does not contain a nickname')
|
||||||
|
return False
|
||||||
handle=nickname.lower()+'@'+domain.lower()
|
handle=nickname.lower()+'@'+domain.lower()
|
||||||
if '/users/' not in messageJson['object']:
|
if '/users/' not in messageJson['object']:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: "users" not found within object')
|
print('DEBUG: "users" not found within object')
|
||||||
return False
|
return False
|
||||||
domainToFollow=messageJson['object'].split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','')
|
domainToFollow,tempPort=getDomainFromActor(messageJson['object'])
|
||||||
toPort=port
|
|
||||||
if ':' in domainToFollow:
|
|
||||||
toPort=domainToFollow.split(':')[1]
|
|
||||||
domainToFollow=domainToFollow.split(':')[0]
|
|
||||||
if not domainPermitted(domainToFollow,federationList):
|
if not domainPermitted(domainToFollow,federationList):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: follow domain not permitted '+domainToFollow)
|
print('DEBUG: follow domain not permitted '+domainToFollow)
|
||||||
return False
|
return False
|
||||||
nicknameToFollow=messageJson['object'].split('/users/')[1].replace('@','')
|
nicknameToFollow=getNicknameFromActor(messageJson['object'])
|
||||||
|
if not nicknameToFollow:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: follow request does not contain a nickname for the account followed')
|
||||||
|
return False
|
||||||
handleToFollow=nicknameToFollow.lower()+'@'+domainToFollow.lower()
|
handleToFollow=nicknameToFollow.lower()+'@'+domainToFollow.lower()
|
||||||
if domainToFollow==domain:
|
if domainToFollow==domain:
|
||||||
if not os.path.isdir(baseDir+'/accounts/'+handleToFollow):
|
if not os.path.isdir(baseDir+'/accounts/'+handleToFollow):
|
||||||
|
@ -283,12 +290,15 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str,port: int,sendThre
|
||||||
personUrl=messageJson['actor']
|
personUrl=messageJson['actor']
|
||||||
acceptJson=createAccept(baseDir,federationList,capsList,nickname,domain,port, \
|
acceptJson=createAccept(baseDir,federationList,capsList,nickname,domain,port, \
|
||||||
personUrl,'',httpPrefix,messageJson['object'])
|
personUrl,'',httpPrefix,messageJson['object'])
|
||||||
|
if debug:
|
||||||
|
pprint(acceptJson)
|
||||||
|
print('DEBUG: sending follow Accept from '+nicknameToFollow+'@'+domainToFollow+' port '+str(port)+' to '+nickname+'@'+domain+' port '+ str(fromPort))
|
||||||
clientToServer=False
|
clientToServer=False
|
||||||
sendSignedJson(acceptJson,session,baseDir,nickname,domain,port, \
|
return sendSignedJson(acceptJson,session,baseDir,nicknameToFollow,domainToFollow,port, \
|
||||||
nicknameToFollow,domainToFollow,port, '', \
|
nickname,domain,fromPort, '', \
|
||||||
httpPrefix,True,clientToServer, \
|
httpPrefix,True,clientToServer, \
|
||||||
federationList, capsList, \
|
federationList, capsList, \
|
||||||
sendThreads,postLog,cachedWebfingers,personCache,debug)
|
sendThreads,postLog,cachedWebfingers,personCache,debug)
|
||||||
|
|
||||||
def sendFollowRequest(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
|
def sendFollowRequest(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
|
||||||
followNickname: str,followDomain: str,followPort: bool,followHttpPrefix: str, \
|
followNickname: str,followDomain: str,followPort: bool,followHttpPrefix: str, \
|
||||||
|
|
17
inbox.py
17
inbox.py
|
@ -23,6 +23,7 @@ from follow import receiveFollowRequest
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
|
from acceptreject import receiveAcceptReject
|
||||||
|
|
||||||
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
||||||
if not personUrl:
|
if not personUrl:
|
||||||
|
@ -238,7 +239,21 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
||||||
os.remove(queueFilename)
|
os.remove(queueFilename)
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if receiveAcceptReject(session, \
|
||||||
|
baseDir,httpPrefix,port, \
|
||||||
|
sendThreads,postLog, \
|
||||||
|
cachedWebfingers,
|
||||||
|
personCache,
|
||||||
|
queueJson['post'], \
|
||||||
|
federationList,capsList, \
|
||||||
|
debug):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Accept/Reject received from '+keyId)
|
||||||
|
os.remove(queueFilename)
|
||||||
|
queue.pop(0)
|
||||||
|
continue
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Queue post accepted')
|
print('DEBUG: Queue post accepted')
|
||||||
|
|
||||||
|
|
22
utils.py
22
utils.py
|
@ -59,3 +59,25 @@ def urlPermitted(url: str, federationList: [],capsList: [],capability: str):
|
||||||
if domain in url:
|
if domain in url:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def getNicknameFromActor(actor: str) -> str:
|
||||||
|
"""Returns the nickname from an actor url
|
||||||
|
"""
|
||||||
|
if '/users/' not in actor:
|
||||||
|
return None
|
||||||
|
return actor.split('/users/')[1].replace('@','')
|
||||||
|
|
||||||
|
def getDomainFromActor(actor: str) -> (str,int):
|
||||||
|
"""Returns the domain name from an actor url
|
||||||
|
"""
|
||||||
|
port=None
|
||||||
|
if '/users/' not in actor:
|
||||||
|
domain = actor.replace('https://','').replace('http://','').replace('dat://','')
|
||||||
|
else:
|
||||||
|
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','')
|
||||||
|
if ':' in domain:
|
||||||
|
port=int(domain.split(':')[1])
|
||||||
|
domain=domain.split(':')[0]
|
||||||
|
return domain,port
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue