forked from indymedia/epicyon
Posting via web interface
parent
d640cd2934
commit
fcf8399b5a
57
daemon.py
57
daemon.py
|
@ -320,7 +320,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
messageJson,self.server.debug)
|
messageJson,self.server.debug)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _updateInboxQueue(self,nickname: str,messageJson: {}) -> int:
|
def _updateInboxQueue(self,nickname: str,messageJson: {},postFromWebInterface: bool) -> int:
|
||||||
"""Update the inbox queue
|
"""Update the inbox queue
|
||||||
"""
|
"""
|
||||||
# Check if the queue is full
|
# Check if the queue is full
|
||||||
|
@ -341,6 +341,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.headers['host'],
|
self.headers['host'],
|
||||||
self.headers['signature'],
|
self.headers['signature'],
|
||||||
'/'+self.path.split('/')[-1],
|
'/'+self.path.split('/')[-1],
|
||||||
|
postFromWebInterface,
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
if queueFilename:
|
if queueFilename:
|
||||||
# add json to the queue
|
# add json to the queue
|
||||||
|
@ -396,7 +397,18 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if '/media/' not in self.path and \
|
if '/media/' not in self.path and \
|
||||||
'/sharefiles/' not in self.path and \
|
'/sharefiles/' not in self.path and \
|
||||||
'/icons/' not in self.path:
|
'/icons/' not in self.path:
|
||||||
if not authorized:
|
divertToLoginScreen=True
|
||||||
|
if self.path.startswith('/users/'):
|
||||||
|
if '/' not in self.path.split('/users/')[1]:
|
||||||
|
divertToLoginScreen=False
|
||||||
|
else:
|
||||||
|
if self.path.endswith('/following') or \
|
||||||
|
self.path.endswith('/followers') or \
|
||||||
|
self.path.endswith('/skills') or \
|
||||||
|
self.path.endswith('/roles') or \
|
||||||
|
self.path.endswith('/shares'):
|
||||||
|
divertToLoginScreen=False
|
||||||
|
if divertToLoginScreen and not authorized:
|
||||||
self.send_response(303)
|
self.send_response(303)
|
||||||
self.send_header('Location', '/login')
|
self.send_header('Location', '/login')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -1075,6 +1087,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields={}
|
fields={}
|
||||||
filename=None
|
filename=None
|
||||||
for f in messageFields:
|
for f in messageFields:
|
||||||
|
if f=='--':
|
||||||
|
continue
|
||||||
if ' name="' in f:
|
if ' name="' in f:
|
||||||
postStr=f.split(' name="',1)[1]
|
postStr=f.split(' name="',1)[1]
|
||||||
if '"' in postStr:
|
if '"' in postStr:
|
||||||
|
@ -1096,19 +1110,19 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
searchStr=b'Content-Type: image/png'
|
searchStr=b'Content-Type: image/png'
|
||||||
imageLocation=postBytes.find(searchStr)
|
imageLocation=postBytes.find(searchStr)
|
||||||
filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload'
|
filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload'
|
||||||
if imageLocation:
|
if imageLocation>-1:
|
||||||
filename=filenameBase+'.png'
|
filename=filenameBase+'.png'
|
||||||
else:
|
else:
|
||||||
searchStr=b'Content-Type: image/jpeg'
|
searchStr=b'Content-Type: image/jpeg'
|
||||||
imageLocation=postBytes.find(searchStr)
|
imageLocation=postBytes.find(searchStr)
|
||||||
if imageLocation:
|
if imageLocation>-1:
|
||||||
filename=filenameBase+'.jpg'
|
filename=filenameBase+'.jpg'
|
||||||
else:
|
else:
|
||||||
searchStr=b'Content-Type: image/gif'
|
searchStr=b'Content-Type: image/gif'
|
||||||
imageLocation=postBytes.find(searchStr)
|
imageLocation=postBytes.find(searchStr)
|
||||||
if imageLocation:
|
if imageLocation>-1:
|
||||||
filename=filenameBase+'.gif'
|
filename=filenameBase+'.gif'
|
||||||
if filename and imageLocation:
|
if filename and imageLocation>-1:
|
||||||
# locate the beginning of the image, after any
|
# locate the beginning of the image, after any
|
||||||
# carriage returns
|
# carriage returns
|
||||||
startPos=imageLocation+len(searchStr)
|
startPos=imageLocation+len(searchStr)
|
||||||
|
@ -1144,9 +1158,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
filename,fields['imageDescription'],True, \
|
filename,fields['imageDescription'],True, \
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
queueStatus=self._updateInboxQueue(nickname,messageJson)
|
self.postToNickname=nickname
|
||||||
if queueStatus==0:
|
return self._postToOutbox(messageJson)
|
||||||
return True
|
|
||||||
|
|
||||||
if postType=='newunlisted':
|
if postType=='newunlisted':
|
||||||
messageJson= \
|
messageJson= \
|
||||||
|
@ -1158,9 +1171,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
filename,fields['imageDescription'],True, \
|
filename,fields['imageDescription'],True, \
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
queueStatus=self._updateInboxQueue(nickname,messageJson)
|
self.postToNickname=nickname
|
||||||
if queueStatus==0:
|
return self._postToOutbox(messageJson)
|
||||||
return True
|
|
||||||
|
|
||||||
if postType=='newfollowers':
|
if postType=='newfollowers':
|
||||||
messageJson= \
|
messageJson= \
|
||||||
|
@ -1172,9 +1184,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
filename,fields['imageDescription'],True, \
|
filename,fields['imageDescription'],True, \
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
queueStatus=self._updateInboxQueue(nickname,messageJson)
|
self.postToNickname=nickname
|
||||||
if queueStatus==0:
|
return self._postToOutbox(messageJson)
|
||||||
return True
|
|
||||||
|
|
||||||
if postType=='newdm':
|
if postType=='newdm':
|
||||||
messageJson= \
|
messageJson= \
|
||||||
|
@ -1184,11 +1195,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
fields['message'],True,False,False, \
|
fields['message'],True,False,False, \
|
||||||
filename,fields['imageDescription'],True, \
|
filename,fields['imageDescription'],True, \
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'],fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
queueStatus=self._updateInboxQueue(nickname,messageJson)
|
self.postToNickname=nickname
|
||||||
if queueStatus==0:
|
return self._postToOutbox(messageJson)
|
||||||
return True
|
|
||||||
|
|
||||||
if postType=='newshare':
|
if postType=='newshare':
|
||||||
if not fields.get('itemType'):
|
if not fields.get('itemType'):
|
||||||
|
@ -1211,11 +1221,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields['location'], \
|
fields['location'], \
|
||||||
fields['duration'],
|
fields['duration'],
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
# TODO distribute shares to followers
|
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
return True
|
self.postToNickname=nickname
|
||||||
|
return self._postToOutbox(messageJson)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
@ -1493,7 +1502,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
self.postToNickname=pathUsersSection.split('/')[0]
|
self.postToNickname=pathUsersSection.split('/')[0]
|
||||||
if self.postToNickname:
|
if self.postToNickname:
|
||||||
queueStatus=self._updateInboxQueue(self.postToNickname,messageJson)
|
queueStatus=self._updateInboxQueue(self.postToNickname,messageJson,False)
|
||||||
if queueStatus==0:
|
if queueStatus==0:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -1511,7 +1520,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
if self.path == '/sharedInbox' or self.path == '/inbox':
|
if self.path == '/sharedInbox' or self.path == '/inbox':
|
||||||
print('DEBUG: POST to shared inbox')
|
print('DEBUG: POST to shared inbox')
|
||||||
queueStatus=_updateInboxQueue('inbox',messageJson)
|
queueStatus=_updateInboxQueue('inbox',messageJson,False)
|
||||||
if queueStatus==0:
|
if queueStatus==0:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
52
inbox.py
52
inbox.py
|
@ -157,7 +157,7 @@ def validPublishedDate(published) -> bool:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJsonObject: {},host: str,headers: str,postPath: str,debug: bool) -> str:
|
def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJsonObject: {},host: str,headers: str,postPath: str,postFromWebInterface: bool,debug: bool) -> str:
|
||||||
"""Saves the give json to the inbox queue for the person
|
"""Saves the give json to the inbox queue for the person
|
||||||
keyId specifies the actor sending the post
|
keyId specifies the actor sending the post
|
||||||
"""
|
"""
|
||||||
|
@ -221,7 +221,8 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
|
||||||
'path': postPath,
|
'path': postPath,
|
||||||
'post': postJsonObject,
|
'post': postJsonObject,
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
'destination': destination
|
'destination': destination,
|
||||||
|
'postFromWebInterface': postFromWebInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -1048,6 +1049,8 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
|
||||||
pubKey=None
|
pubKey=None
|
||||||
keyId=None
|
keyId=None
|
||||||
for tries in range(8):
|
for tries in range(8):
|
||||||
|
if queueJson['postFromWebInterface']:
|
||||||
|
break
|
||||||
keyId=None
|
keyId=None
|
||||||
signatureParams=queueJson['headers'].split(',')
|
signatureParams=queueJson['headers'].split(',')
|
||||||
for signatureItem in signatureParams:
|
for signatureItem in signatureParams:
|
||||||
|
@ -1071,30 +1074,31 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
|
||||||
print('DEBUG: Retry '+str(tries+1)+' obtaining public key for '+keyId)
|
print('DEBUG: Retry '+str(tries+1)+' obtaining public key for '+keyId)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
if not pubKey:
|
if not queueJson['postFromWebInterface']:
|
||||||
if debug:
|
if not pubKey:
|
||||||
print('DEBUG: public key could not be obtained from '+keyId)
|
if debug:
|
||||||
os.remove(queueFilename)
|
print('DEBUG: public key could not be obtained from '+keyId)
|
||||||
queue.pop(0)
|
os.remove(queueFilename)
|
||||||
continue
|
queue.pop(0)
|
||||||
|
continue
|
||||||
|
|
||||||
# check the signature
|
# check the signature
|
||||||
verifyHeaders={
|
verifyHeaders={
|
||||||
'host': queueJson['host'],
|
'host': queueJson['host'],
|
||||||
'signature': queueJson['headers']
|
'signature': queueJson['headers']
|
||||||
}
|
}
|
||||||
if not verifyPostHeaders(httpPrefix, \
|
if not verifyPostHeaders(httpPrefix, \
|
||||||
pubKey, verifyHeaders, \
|
pubKey, verifyHeaders, \
|
||||||
queueJson['path'], False, \
|
queueJson['path'], False, \
|
||||||
json.dumps(queueJson['post'])):
|
json.dumps(queueJson['post'])):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Header signature check failed')
|
print('DEBUG: Header signature check failed')
|
||||||
os.remove(queueFilename)
|
os.remove(queueFilename)
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Signature check success')
|
print('DEBUG: Signature check success')
|
||||||
|
|
||||||
if receiveUndo(session, \
|
if receiveUndo(session, \
|
||||||
baseDir,httpPrefix,port, \
|
baseDir,httpPrefix,port, \
|
||||||
|
|
2
utils.py
2
utils.py
|
@ -24,7 +24,7 @@ def getStatusNumber() -> (str,str):
|
||||||
def createPersonDir(nickname: str,domain: str,baseDir: str,dirname: str) -> str:
|
def createPersonDir(nickname: str,domain: str,baseDir: str,dirname: str) -> str:
|
||||||
"""Create a directory for a person
|
"""Create a directory for a person
|
||||||
"""
|
"""
|
||||||
handle=nickname.lower()+'@'+domain.lower()
|
handle=nickname+'@'+domain
|
||||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||||
os.mkdir(baseDir+'/accounts/'+handle)
|
os.mkdir(baseDir+'/accounts/'+handle)
|
||||||
boxDir=baseDir+'/accounts/'+handle+'/'+dirname
|
boxDir=baseDir+'/accounts/'+handle+'/'+dirname
|
||||||
|
|
Loading…
Reference in New Issue