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 #!/bin/sh
ORIG_ONIONR_RUN_DIR=`pwd`
export ORIG_ONIONR_RUN_DIR
cd "$(dirname "$0")" cd "$(dirname "$0")"
cd onionr/ cd onionr/
./__init__.py "$@" ./__init__.py "$@"

View File

@ -108,7 +108,7 @@ class OnionrCommunicatorDaemon:
# Timers to periodically lookup new blocks and download them # 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) 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 # 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 # Timer to reset the longest offline peer so contact can be attempted again
OnionrCommunicatorTimers(self, onlinepeers.clear_offline_peer, 58, myArgs=[self]) 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_TYPE_LENGTH = 15
MAX_BLOCK_CLOCK_SKEW = 120 MAX_BLOCK_CLOCK_SKEW = 120
MAIN_PUBLIC_KEY_SIZE = 32 MAIN_PUBLIC_KEY_SIZE = 32
ORIG_RUN_DIR_ENV_VAR = 'ORIG_ONIONR_RUN_DIR'
# Begin OnionrValues migrated values # Begin OnionrValues migrated values
ANNOUNCE_POW = 5 ANNOUNCE_POW = 5

View File

@ -18,6 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
from flask import Response, Blueprint, request, send_from_directory, abort from flask import Response, Blueprint, request, send_from_directory, abort
import unpaddedbase32
from httpapi import apiutils from httpapi import apiutils
import onionrcrypto, config import onionrcrypto, config
@ -111,6 +112,7 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/getHumanReadable/<name>') @private_endpoints_bp.route('/getHumanReadable/<name>')
def getHumanReadable(name): def getHumanReadable(name):
name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name))
return Response(mnemonickeys.get_human_readable_ID(name)) return Response(mnemonickeys.get_human_readable_ID(name))
@private_endpoints_bp.route('/getBase32FromHumanReadable/<words>') @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 Verify if a block's signature is signed by its claimed signer
''' '''
if self.signer is None or signing.ed_verify(data=self.signedData, key=self.signer, sig=self.signature, encodedData=True):
if signing.ed_verify(data=self.signedData, key=self.signer, sig=self.signature, encodedData=True):
self.validSig = True self.validSig = True
else: else:
self.validSig = False self.validSig = False

View File

@ -114,8 +114,9 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
# compile metadata # compile metadata
metadata['meta'] = jsonMeta metadata['meta'] = jsonMeta
metadata['sig'] = signature if len(signature) > 0: # I don't like not pattern
metadata['signer'] = signer metadata['sig'] = signature
metadata['signer'] = signer
metadata['time'] = createTime metadata['time'] = createTime
# ensure expire is integer and of sane length # ensure expire is integer and of sane length

View File

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

View File

@ -31,6 +31,7 @@ def soft_reset():
path = filepaths.block_data_location path = filepaths.block_data_location
shutil.rmtree(path) shutil.rmtree(path)
os.remove(dbfiles.block_meta_db) os.remove(dbfiles.block_meta_db)
os.remove(filepaths.upload_list)
logger.info("Soft reset Onionr", terminal=True) logger.info("Soft reset Onionr", terminal=True)
soft_reset.onionr_help = "Deletes Onionr blocks and their associated metadata, except for any exported block files." 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 import nacl.encoding, nacl.signing, nacl.exceptions
from onionrutils import bytesconverter from onionrutils import bytesconverter
from onionrutils import mnemonickeys
import logger import logger
def ed_sign(data, key, encodeResult=False): def ed_sign(data, key, encodeResult=False):
'''Ed25519 sign data''' '''Ed25519 sign data'''

View File

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

View File

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

View File

@ -1,10 +1,21 @@
function setHumanReadableValue(el, key){ function loadHumanReadableToCache(key){
fetch('/getHumanReadable/' + key, { fetch('/getHumanReadable/' + key, {
headers: { headers: {
"token": webpass "token": webpass
}}) }})
.then((resp) => resp.text()) .then((resp) => resp.text())
.then(function(resp) { .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
}
} }