From 30604fa23c25fdf8494d2095bbb6b648af84e322 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 10 Feb 2019 12:43:45 -0600 Subject: [PATCH] more mail ui work --- onionr/api.py | 28 +++++++++++++++++-- onionr/communicator.py | 2 +- onionr/core.py | 8 +++++- onionr/etc/pgpwords.py | 2 +- onionr/onionrproofs.py | 4 +-- onionr/onionrutils.py | 8 +++--- .../static-data/default-plugins/pms/main.py | 17 ++++++----- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index 306d8194..3b3cc7e3 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -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/', methods=['POST', 'GET']) def pluginEndpoints(subpath=''): diff --git a/onionr/communicator.py b/onionr/communicator.py index 52f41871..3cb455dd 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -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) diff --git a/onionr/core.py b/onionr/core.py index 90e44f5e..a4852dba 100755 --- a/onionr/core.py +++ b/onionr/core.py @@ -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): diff --git a/onionr/etc/pgpwords.py b/onionr/etc/pgpwords.py index 16aeda1c..a1fc7c6b 100755 --- a/onionr/etc/pgpwords.py +++ b/onionr/etc/pgpwords.py @@ -259,7 +259,7 @@ _words = [ ["wayside", "Wilmington"], ["willow", "Wyoming"], ["woodlark", "yesteryear"], - ["Zulu", "Yucatán"]] + ["Zulu", "Yucatan"]] hexre = re.compile("[a-fA-F0-9]+") diff --git a/onionr/onionrproofs.py b/onionr/onionrproofs.py index 2c479a8a..202500f1 100755 --- a/onionr/onionrproofs.py +++ b/onionr/onionrproofs.py @@ -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') diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 655605fd..4181ba4b 100755 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -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): ''' diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index b393f6eb..f2421ca5 100755 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -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