onionr can now run from relative dirs and lots of bug fixes

master
Kevin Froman 2019-09-10 01:05:59 -05:00
parent 5f22387af6
commit f99ff27006
12 changed files with 52 additions and 15 deletions

View File

@ -1,4 +1,6 @@
#!/bin/sh
ORIG_ONIONR_RUN_DIR=`pwd`
export ORIG_ONIONR_RUN_DIR
cd "$(dirname "$0")"
cd onionr/
./__init__.py "$@"

View File

@ -108,7 +108,7 @@ class OnionrCommunicatorDaemon:
# Timers to periodically lookup new blocks and download them
lookup_blocks_timer = OnionrCommunicatorTimers(self, lookupblocks.lookup_blocks_from_communicator, config.get('timers.lookupBlocks', 25), myArgs=[self], requiresPeer=True, maxThreads=1)
# The block download timer is accessed by the block lookup function to trigger faster download starts
self.download_blocks_timer = OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 30), requiresPeer=True, maxThreads=5)
self.download_blocks_timer = OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 10), requiresPeer=True, maxThreads=5)
# Timer to reset the longest offline peer so contact can be attempted again
OnionrCommunicatorTimers(self, onlinepeers.clear_offline_peer, 58, myArgs=[self])

View File

@ -29,6 +29,7 @@ DEVELOPMENT_MODE = True
MAX_BLOCK_TYPE_LENGTH = 15
MAX_BLOCK_CLOCK_SKEW = 120
MAIN_PUBLIC_KEY_SIZE = 32
ORIG_RUN_DIR_ENV_VAR = 'ORIG_ONIONR_RUN_DIR'
# Begin OnionrValues migrated values
ANNOUNCE_POW = 5

View File

@ -18,6 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
from flask import Response, Blueprint, request, send_from_directory, abort
import unpaddedbase32
from httpapi import apiutils
import onionrcrypto, config
@ -111,6 +112,7 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/getHumanReadable/<name>')
def getHumanReadable(name):
name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name))
return Response(mnemonickeys.get_human_readable_ID(name))
@private_endpoints_bp.route('/getBase32FromHumanReadable/<words>')

View File

@ -124,8 +124,7 @@ class Block:
'''
Verify if a block's signature is signed by its claimed signer
'''
if signing.ed_verify(data=self.signedData, key=self.signer, sig=self.signature, encodedData=True):
if self.signer is None or signing.ed_verify(data=self.signedData, key=self.signer, sig=self.signature, encodedData=True):
self.validSig = True
else:
self.validSig = False

View File

@ -114,6 +114,7 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
# compile metadata
metadata['meta'] = jsonMeta
if len(signature) > 0: # I don't like not pattern
metadata['sig'] = signature
metadata['signer'] = signer
metadata['time'] = createTime

View File

@ -21,8 +21,15 @@
import base64, sys, os
import logger
from onionrblockapi import Block
import onionrexceptions
from onionrutils import stringvalidators
from etc import onionrvalues
from onionrblocks import insert
_ORIG_DIR = onionrvalues.ORIG_RUN_DIR_ENV_VAR
def _get_dir(path: str)->str:
if not os.getenv(_ORIG_DIR) is None: return os.getenv(_ORIG_DIR) + '/' + path
else: return path
def add_html(singleBlock=True, blockType='html'):
add_file(singleBlock, blockType)
@ -35,13 +42,12 @@ def add_file(singleBlock=False, blockType='bin'):
if len(sys.argv) >= 3:
filename = sys.argv[2]
contents = None
if not os.path.exists(filename):
if not os.path.exists(_get_dir(filename)):
logger.error('That file does not exist. Improper path (specify full path)?', terminal=True)
return
logger.info('Adding file... this might take a long time.', terminal=True)
try:
with open(filename, 'rb') as singleFile:
with open(_get_dir(filename), 'rb') as singleFile:
blockhash = insert(base64.b64encode(singleFile.read()), header=blockType)
if len(blockhash) > 0:
logger.info('File %s saved in block %s' % (filename, blockhash), terminal=True)
@ -55,7 +61,7 @@ def get_file():
Get a file from onionr blocks
'''
try:
fileName = sys.argv[2]
fileName = _get_dir(sys.argv[2])
bHash = sys.argv[3]
except IndexError:
logger.error("Syntax %s %s" % (sys.argv[0], '/path/to/filename <blockhash>'), terminal=True)
@ -70,6 +76,9 @@ def get_file():
logger.error('Block hash is invalid', terminal=True)
return
try:
with open(fileName, 'wb') as myFile:
myFile.write(base64.b64decode(Block(bHash).bcontent))
except onionrexceptions.NoDataAvailable:
logger.error('That block is not available. Trying again later may work.', terminal=True)
return

View File

@ -31,6 +31,7 @@ def soft_reset():
path = filepaths.block_data_location
shutil.rmtree(path)
os.remove(dbfiles.block_meta_db)
os.remove(filepaths.upload_list)
logger.info("Soft reset Onionr", terminal=True)
soft_reset.onionr_help = "Deletes Onionr blocks and their associated metadata, except for any exported block files."

View File

@ -4,6 +4,7 @@ import unpaddedbase32
import nacl.encoding, nacl.signing, nacl.exceptions
from onionrutils import bytesconverter
from onionrutils import mnemonickeys
import logger
def ed_sign(data, key, encodeResult=False):
'''Ed25519 sign data'''

View File

@ -59,7 +59,7 @@
Mail
</h1>
<h2 class="subtitle">
Send email style messages
Private and safe messages
</h2>
</div>
<div class="column is-7">

View File

@ -26,6 +26,7 @@ threadContent = {}
replyBtn = document.getElementById('replyBtn')
addUnknownContact = document.getElementById('addUnknownContact')
noInbox = document.getElementById('noInbox')
humanReadableCache = {}
function addContact(pubkey, friendName){
fetch('/friends/add/' + pubkey, {
@ -61,7 +62,14 @@ function openReply(bHash, quote, subject){
for (var x = 0; x < splitQuotes.length; x++){
splitQuotes[x] = '> ' + splitQuotes[x]
}
if (typeof humanReadableCache[key] != 'undefined'){
document.getElementById('draftID').value = humanReadableCache[key]
quote = '\n' + humanReadableCache[key].split(' ').slice(0,3).join(' ') + ' wrote:\n' + splitQuotes.join('\n')
}
else{
quote = '\n' + key.substring(0, 12) + ' wrote:' + '\n' + splitQuotes.join('\n')
}
document.getElementById('draftText').value = quote
setActiveTab('compose')
}
@ -184,6 +192,7 @@ function loadInboxEntries(bHash){
entry.setAttribute('data-nameSet', false)
}
else{
loadHumanReadableToCache(resp['meta']['signer'])
senderInput.value = name
entry.setAttribute('data-nameSet', true)
}
@ -295,6 +304,7 @@ function getSentbox(){
sentDate.innerText = humanDate.substring(0, humanDate.indexOf('('))
if (resp[i]['name'] == null || resp[i]['name'].toLowerCase() == 'anonymous'){
toEl.value = resp[i]['peer']
setHumanReadableValue(toEl, resp[i]['peer'])
}
else{
toEl.value = resp[i]['name']

View File

@ -1,10 +1,21 @@
function setHumanReadableValue(el, key){
function loadHumanReadableToCache(key){
fetch('/getHumanReadable/' + key, {
headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(resp) {
el.value = resp
humanReadableCache[key] = resp
})
}
function setHumanReadableValue(el, key){
if (typeof humanReadableCache[key] != 'undefined'){
el.value = humanReadableCache[key]
return
}
else{
setTimeout(function(){setHumanReadableValue(el, key)})
return
}
}