more mail ui work
This commit is contained in:
parent
898085887c
commit
30604fa23c
@ -458,11 +458,35 @@ class API:
|
|||||||
|
|
||||||
@app.route('/insertblock', methods=['POST'])
|
@app.route('/insertblock', methods=['POST'])
|
||||||
def insertBlock():
|
def insertBlock():
|
||||||
|
encrypt = False
|
||||||
bData = request.get_json(force=True)
|
bData = request.get_json(force=True)
|
||||||
message = bData['message']
|
message = bData['message']
|
||||||
to = bData['to']
|
|
||||||
subject = 'temp'
|
subject = 'temp'
|
||||||
return Response(self._core.insertBlock(message, header='pm', encryptType='asym', sign=True, asymPeer=to, meta={'subject': subject}))
|
encryptType = ''
|
||||||
|
sign = True
|
||||||
|
meta = {}
|
||||||
|
to = ''
|
||||||
|
try:
|
||||||
|
if bData['encrypt']:
|
||||||
|
to = bData['to']
|
||||||
|
encrypt = True
|
||||||
|
encryptType = 'asym'
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
if not bData['sign']:
|
||||||
|
sign = False
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
bType = bData['type']
|
||||||
|
except KeyError:
|
||||||
|
bType = 'bin'
|
||||||
|
try:
|
||||||
|
meta = json.loads(bData['meta'])
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return Response(self._core.insertBlock(message, header=bType, encryptType=encryptType, sign=sign, asymPeer=to, meta=meta))
|
||||||
|
|
||||||
@app.route('/apipoints/<path:subpath>', methods=['POST', 'GET'])
|
@app.route('/apipoints/<path:subpath>', methods=['POST', 'GET'])
|
||||||
def pluginEndpoints(subpath=''):
|
def pluginEndpoints(subpath=''):
|
||||||
|
@ -603,7 +603,7 @@ class OnionrCommunicatorDaemon:
|
|||||||
def detectAPICrash(self):
|
def detectAPICrash(self):
|
||||||
'''exit if the api server crashes/stops'''
|
'''exit if the api server crashes/stops'''
|
||||||
if self._core._utils.localCommand('ping', silent=False) not in ('pong', 'pong!'):
|
if self._core._utils.localCommand('ping', silent=False) not in ('pong', 'pong!'):
|
||||||
for i in range(5):
|
for i in range(8):
|
||||||
if self._core._utils.localCommand('ping') in ('pong', 'pong!'):
|
if self._core._utils.localCommand('ping') in ('pong', 'pong!'):
|
||||||
break # break for loop
|
break # break for loop
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -731,6 +731,7 @@ class Core:
|
|||||||
logger.error(allocationReachedMessage)
|
logger.error(allocationReachedMessage)
|
||||||
return False
|
return False
|
||||||
retData = False
|
retData = False
|
||||||
|
|
||||||
# check nonce
|
# check nonce
|
||||||
dataNonce = self._utils.bytesToStr(self._crypto.sha3Hash(data))
|
dataNonce = self._utils.bytesToStr(self._crypto.sha3Hash(data))
|
||||||
try:
|
try:
|
||||||
@ -746,6 +747,11 @@ class Core:
|
|||||||
if type(data) is bytes:
|
if type(data) is bytes:
|
||||||
data = data.decode()
|
data = data.decode()
|
||||||
data = str(data)
|
data = str(data)
|
||||||
|
plaintext = data
|
||||||
|
|
||||||
|
# Convert asym peer human readable key to base32 if set
|
||||||
|
if ' ' in asymPeer.strip():
|
||||||
|
asymPeer = self._utils.convertHumanReadableID(asymPeer)
|
||||||
|
|
||||||
retData = ''
|
retData = ''
|
||||||
signature = ''
|
signature = ''
|
||||||
@ -839,7 +845,7 @@ class Core:
|
|||||||
self.daemonQueueAdd('uploadBlock', retData)
|
self.daemonQueueAdd('uploadBlock', retData)
|
||||||
|
|
||||||
if retData != False:
|
if retData != False:
|
||||||
events.event('insertBlock', onionr = None, threaded = False)
|
events.event('insertblock', {'content': plaintext, 'meta': jsonMeta, 'hash': retData, 'peer': self._utils.bytesToStr(asymPeer)}, onionr = self.onionrInst, threaded = False)
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def introduceNode(self):
|
def introduceNode(self):
|
||||||
|
@ -259,7 +259,7 @@ _words = [
|
|||||||
["wayside", "Wilmington"],
|
["wayside", "Wilmington"],
|
||||||
["willow", "Wyoming"],
|
["willow", "Wyoming"],
|
||||||
["woodlark", "yesteryear"],
|
["woodlark", "yesteryear"],
|
||||||
["Zulu", "Yucatán"]]
|
["Zulu", "Yucatan"]]
|
||||||
|
|
||||||
hexre = re.compile("[a-fA-F0-9]+")
|
hexre = re.compile("[a-fA-F0-9]+")
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ class DataPOW:
|
|||||||
if not self.hashing:
|
if not self.hashing:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
time.sleep(2)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
logger.warn('Got keyboard interrupt while waiting for POW result, stopping')
|
logger.warn('Got keyboard interrupt while waiting for POW result, stopping')
|
||||||
@ -299,7 +299,7 @@ class POW:
|
|||||||
if not self.hashing:
|
if not self.hashing:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
time.sleep(2)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
logger.warn('Got keyboard interrupt while waiting for POW result, stopping')
|
logger.warn('Got keyboard interrupt while waiting for POW result, stopping')
|
||||||
|
@ -163,7 +163,7 @@ class OnionrUtils:
|
|||||||
retData += '%s:%s' % (hostname, config.get('client.client.port'))
|
retData += '%s:%s' % (hostname, config.get('client.client.port'))
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def localCommand(self, command, data='', silent = True, post=False, postData = {}, maxWait=10):
|
def localCommand(self, command, data='', silent = True, post=False, postData = {}, maxWait=20):
|
||||||
'''
|
'''
|
||||||
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.
|
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.
|
||||||
'''
|
'''
|
||||||
@ -185,9 +185,9 @@ class OnionrUtils:
|
|||||||
payload = 'http://%s/%s%s' % (hostname, command, data)
|
payload = 'http://%s/%s%s' % (hostname, command, data)
|
||||||
try:
|
try:
|
||||||
if post:
|
if post:
|
||||||
retData = requests.post(payload, data=postData, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, 30)).text
|
retData = requests.post(payload, data=postData, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
||||||
else:
|
else:
|
||||||
retData = requests.get(payload, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, 30)).text
|
retData = requests.get(payload, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
if not silent:
|
if not silent:
|
||||||
logger.error('Failed to make local request (command: %s):%s' % (command, error))
|
logger.error('Failed to make local request (command: %s):%s' % (command, error))
|
||||||
@ -225,7 +225,7 @@ class OnionrUtils:
|
|||||||
|
|
||||||
def convertHumanReadableID(self, pub):
|
def convertHumanReadableID(self, pub):
|
||||||
'''Convert a human readable pubkey id to base32'''
|
'''Convert a human readable pubkey id to base32'''
|
||||||
return base64.b32encode(binascii.unhexlify(pgpwords.hexify(pub)))
|
return self.bytesToStr(base64.b32encode(binascii.unhexlify(pgpwords.hexify(pub.strip()))))
|
||||||
|
|
||||||
def getBlockMetadataFromData(self, blockData):
|
def getBlockMetadataFromData(self, blockData):
|
||||||
'''
|
'''
|
||||||
|
@ -194,7 +194,7 @@ class OnionrMail:
|
|||||||
self.sentMessages = {}
|
self.sentMessages = {}
|
||||||
for i in self.sentboxTools.listSent():
|
for i in self.sentboxTools.listSent():
|
||||||
self.sentboxList.append(i['hash'])
|
self.sentboxList.append(i['hash'])
|
||||||
self.sentMessages[i['hash']] = (i['message'], i['peer'])
|
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'])
|
||||||
if display:
|
if display:
|
||||||
logger.info('%s. %s - %s - %s' % (count, i['hash'], i['peer'][:12], i['date']))
|
logger.info('%s. %s - %s - %s' % (count, i['hash'], i['peer'][:12], i['date']))
|
||||||
count += 1
|
count += 1
|
||||||
@ -289,6 +289,13 @@ class OnionrMail:
|
|||||||
logger.warn('Invalid choice.')
|
logger.warn('Invalid choice.')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def on_insertblock(api, data={}):
|
||||||
|
print(data)
|
||||||
|
sentboxTools = sentboxdb.SentBox(api.get_core())
|
||||||
|
meta = json.dumps(data['meta'])
|
||||||
|
print('on_insertblock', data)
|
||||||
|
sentboxTools.addToSent(data['hash'], data['peer'], data['content'])
|
||||||
|
|
||||||
def on_pluginrequest(api, data=None):
|
def on_pluginrequest(api, data=None):
|
||||||
resp = ''
|
resp = ''
|
||||||
subject = ''
|
subject = ''
|
||||||
@ -302,14 +309,6 @@ def on_pluginrequest(api, data=None):
|
|||||||
cmd = path.split('/')[1]
|
cmd = path.split('/')[1]
|
||||||
if cmd == 'sentbox':
|
if cmd == 'sentbox':
|
||||||
resp = OnionrMail(api).get_sent_list(display=False)
|
resp = OnionrMail(api).get_sent_list(display=False)
|
||||||
elif cmd == 'send':
|
|
||||||
print(data['postData'])
|
|
||||||
postData = json.loads(data['postData'])
|
|
||||||
message = postData['message']
|
|
||||||
recip = postData['to']
|
|
||||||
subject = 'temp'
|
|
||||||
blockID = api.get_core().insertBlock(message, header='pm', encryptType='asym', sign=True, asymPeer=recip, meta={'subject': subject})
|
|
||||||
sentboxTools.addToSent(blockID, recip, message)
|
|
||||||
if resp != '':
|
if resp != '':
|
||||||
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user