more mail ui work
parent
898085887c
commit
30604fa23c
|
@ -458,11 +458,35 @@ class API:
|
|||
|
||||
@app.route('/insertblock', methods=['POST'])
|
||||
def insertBlock():
|
||||
encrypt = False
|
||||
bData = request.get_json(force=True)
|
||||
message = bData['message']
|
||||
to = bData['to']
|
||||
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'])
|
||||
def pluginEndpoints(subpath=''):
|
||||
|
|
|
@ -603,7 +603,7 @@ class OnionrCommunicatorDaemon:
|
|||
def detectAPICrash(self):
|
||||
'''exit if the api server crashes/stops'''
|
||||
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!'):
|
||||
break # break for loop
|
||||
time.sleep(1)
|
||||
|
|
|
@ -731,6 +731,7 @@ class Core:
|
|||
logger.error(allocationReachedMessage)
|
||||
return False
|
||||
retData = False
|
||||
|
||||
# check nonce
|
||||
dataNonce = self._utils.bytesToStr(self._crypto.sha3Hash(data))
|
||||
try:
|
||||
|
@ -746,6 +747,11 @@ class Core:
|
|||
if type(data) is bytes:
|
||||
data = data.decode()
|
||||
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 = ''
|
||||
signature = ''
|
||||
|
@ -839,7 +845,7 @@ class Core:
|
|||
self.daemonQueueAdd('uploadBlock', retData)
|
||||
|
||||
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
|
||||
|
||||
def introduceNode(self):
|
||||
|
|
|
@ -259,7 +259,7 @@ _words = [
|
|||
["wayside", "Wilmington"],
|
||||
["willow", "Wyoming"],
|
||||
["woodlark", "yesteryear"],
|
||||
["Zulu", "Yucatán"]]
|
||||
["Zulu", "Yucatan"]]
|
||||
|
||||
hexre = re.compile("[a-fA-F0-9]+")
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ class DataPOW:
|
|||
if not self.hashing:
|
||||
break
|
||||
else:
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
self.shutdown()
|
||||
logger.warn('Got keyboard interrupt while waiting for POW result, stopping')
|
||||
|
@ -299,7 +299,7 @@ class POW:
|
|||
if not self.hashing:
|
||||
break
|
||||
else:
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
self.shutdown()
|
||||
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'))
|
||||
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.
|
||||
'''
|
||||
|
@ -185,9 +185,9 @@ class OnionrUtils:
|
|||
payload = 'http://%s/%s%s' % (hostname, command, data)
|
||||
try:
|
||||
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:
|
||||
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:
|
||||
if not silent:
|
||||
logger.error('Failed to make local request (command: %s):%s' % (command, error))
|
||||
|
@ -225,7 +225,7 @@ class OnionrUtils:
|
|||
|
||||
def convertHumanReadableID(self, pub):
|
||||
'''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):
|
||||
'''
|
||||
|
|
|
@ -194,7 +194,7 @@ class OnionrMail:
|
|||
self.sentMessages = {}
|
||||
for i in self.sentboxTools.listSent():
|
||||
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:
|
||||
logger.info('%s. %s - %s - %s' % (count, i['hash'], i['peer'][:12], i['date']))
|
||||
count += 1
|
||||
|
@ -289,6 +289,13 @@ class OnionrMail:
|
|||
logger.warn('Invalid choice.')
|
||||
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):
|
||||
resp = ''
|
||||
subject = ''
|
||||
|
@ -302,14 +309,6 @@ def on_pluginrequest(api, data=None):
|
|||
cmd = path.split('/')[1]
|
||||
if cmd == 'sentbox':
|
||||
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 != '':
|
||||
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
||||
|
||||
|
|
Loading…
Reference in New Issue