forked from indymedia/epicyon
create wrapping
parent
086ddbb004
commit
fde8fd4dd9
42
daemon.py
42
daemon.py
|
@ -230,25 +230,34 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# remove any trailing slashes from the path
|
||||||
|
self.path=self.path.replace('/outbox/','/outbox').replace('/inbox/','/inbox')
|
||||||
|
|
||||||
|
# if this is a POST to teh outbox then check authentication
|
||||||
|
self.outboxAuthenticated=False
|
||||||
|
self.postToNickname=None
|
||||||
if self.path.endswith('/outbox'):
|
if self.path.endswith('/outbox'):
|
||||||
if '/users/' in self.path:
|
if '/users/' in self.path:
|
||||||
if self.headers.get('Authorization'):
|
if self.headers.get('Authorization'):
|
||||||
nickname=self.path.split('/users/')[1].replace('/inbox','')
|
nickname=self.path.split('/users/')[1].replace('/inbox','')
|
||||||
if nickname==nicknameFromBasicAuth(self.headers['Authorization']):
|
if nickname==nicknameFromBasicAuth(self.headers['Authorization']):
|
||||||
if authorize(self.server.baseDir,self.headers['Authorization']):
|
if authorize(self.server.baseDir,self.headers['Authorization']):
|
||||||
|
self.outboxAuthenticated=True
|
||||||
|
self.postToNickname=nickname
|
||||||
# TODO
|
# TODO
|
||||||
print('c2s posts not supported yet')
|
print('c2s posts not supported yet')
|
||||||
self.send_response(405)
|
self.send_response(405)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
self.send_response(405)
|
if not self.outboxAuthenticated:
|
||||||
self.end_headers()
|
self.send_response(405)
|
||||||
self.server.POSTbusy=False
|
self.end_headers()
|
||||||
return
|
self.server.POSTbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
# check that the post is to an expected path
|
# check that the post is to an expected path
|
||||||
if not (self.path=='/outbox' or self.path.endswith('/inbox')):
|
if not (self.path.endswith('/outbox') or self.path.endswith('/inbox')):
|
||||||
print('Attempt to POST to invalid path '+self.path)
|
print('Attempt to POST to invalid path '+self.path)
|
||||||
self.send_response(400)
|
self.send_response(400)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -271,15 +280,28 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
messageBytes=self.rfile.read(length)
|
messageBytes=self.rfile.read(length)
|
||||||
messageJson = json.loads(messageBytes)
|
messageJson = json.loads(messageBytes)
|
||||||
|
|
||||||
|
# https://www.w3.org/TR/activitypub/#object-without-create
|
||||||
|
if self.outboxAuthenticated:
|
||||||
|
if not messageJson.get('object'):
|
||||||
|
if messageJson.get('type'):
|
||||||
|
if messageJson['type']!='Create':
|
||||||
|
messageJson=outboxMessageCreateWrap(self.server.httpPrefix,self.postToNickname,self.server.domain,messageJson)
|
||||||
|
else:
|
||||||
|
self.send_response(403)
|
||||||
|
self.end_headers()
|
||||||
|
self.server.POSTbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
# check the necessary properties are available
|
# check the necessary properties are available
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: Check message has params')
|
print('DEBUG: Check message has params')
|
||||||
|
|
||||||
if not inboxMessageHasParams(messageJson):
|
if self.path.endswith('/inbox'):
|
||||||
self.send_response(403)
|
if not inboxMessageHasParams(messageJson):
|
||||||
self.end_headers()
|
self.send_response(403)
|
||||||
self.server.POSTbusy=False
|
self.end_headers()
|
||||||
return
|
self.server.POSTbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList):
|
if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList):
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
|
|
24
posts.py
24
posts.py
|
@ -347,6 +347,30 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
commentjson.dump(newPost, fp, indent=4, sort_keys=False)
|
commentjson.dump(newPost, fp, indent=4, sort_keys=False)
|
||||||
return newPost
|
return newPost
|
||||||
|
|
||||||
|
def outboxMessageCreateWrap(httpPrefix str,nickname: str,domain: str,messageJson: {}) -> {}:
|
||||||
|
"""Wraps a received message in a Create
|
||||||
|
https://www.w3.org/TR/activitypub/#object-without-create
|
||||||
|
"""
|
||||||
|
|
||||||
|
statusNumber,published = getStatusNumber()
|
||||||
|
if messageJson.get('published'):
|
||||||
|
published = messageJson['published']
|
||||||
|
newPostId=httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber
|
||||||
|
cc=[]
|
||||||
|
if messageJson.get('cc'):
|
||||||
|
cc=messageJson['cc']
|
||||||
|
newPost = {
|
||||||
|
'id': newPostId+'/activity',
|
||||||
|
'type': 'Create',
|
||||||
|
'actor': httpPrefix+'://'+domain+'/users/'+nickname,
|
||||||
|
'published': published,
|
||||||
|
'to': messageJson['to'],
|
||||||
|
'cc': cc,
|
||||||
|
'object': messageJson
|
||||||
|
}
|
||||||
|
newPost['object']['id']=newPost['id']
|
||||||
|
return newPost
|
||||||
|
|
||||||
def createPublicPost(baseDir: str,
|
def createPublicPost(baseDir: str,
|
||||||
nickname: str, domain: str, port: int,httpPrefix: str, \
|
nickname: str, domain: str, port: int,httpPrefix: str, \
|
||||||
content: str, followersOnly: bool, saveToFile: bool,
|
content: str, followersOnly: bool, saveToFile: bool,
|
||||||
|
|
Loading…
Reference in New Issue