From 4ec3d037e965cc271e581d526de5dbc56b178365 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Mon, 4 Jun 2018 22:26:11 -0700 Subject: [PATCH] Few misc changes --- onionr/communicator.py | 11 +++++++++++ onionr/core.py | 8 +++++--- onionr/onionr.py | 18 ++++++------------ onionr/static-data/default_config.json | 2 ++ onionr/static-data/header.txt | 25 +++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 onionr/static-data/header.txt diff --git a/onionr/communicator.py b/onionr/communicator.py index 48e40bf9..e73a452c 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -74,6 +74,10 @@ class OnionrCommunicate: # Loads in and starts the enabled plugins plugins.reload() + # Print nice header thing :) + if config.get('display_header', True): + self.header() + while True: command = self._core.daemonQueue() # Process blocks based on a timer @@ -754,6 +758,13 @@ class OnionrCommunicate: pass return False + def header(self, message = logger.colors.fg.pink + logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink + ' has started.'): + if os.path.exists('static-data/header.txt'): + with open('static-data/header.txt', 'rb') as file: + # only to stdout, not file or log or anything + print(file.read().decode().replace('#', logger.colors.fg.pink).replace('$', logger.colors.reset + logger.colors.bold).replace('\n', logger.colors.reset + '\n')) + logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n') + shouldRun = False debug = True developmentMode = False diff --git a/onionr/core.py b/onionr/core.py index c6aff9f9..92849d3a 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -110,7 +110,8 @@ class Core: ''' Add an address to the address database (only tor currently) ''' - if (not (config.is_set('i2p') and 'ownAddr' in config.get('i2p'))) or address == config.get('i2p')['ownAddr']: + if address == config.get('i2p', {'ownAddr' : None})['ownAddr']: + return False if self._utils.validateID(address): conn = sqlite3.connect(self.addressDB) @@ -138,6 +139,7 @@ class Core: return True else: + logger.debug('Invalid ID') return False def removeAddress(self, address): @@ -688,11 +690,11 @@ class Core: data = data.encode() retData = '' - + metadata['type'] = header metadata['powHash'] = powHash metadata['powToken'] = powToken - + sig = {} metadata = json.dumps(metadata) diff --git a/onionr/onionr.py b/onionr/onionr.py index 3ba0dc74..21ccd340 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -611,13 +611,13 @@ class Onionr: # generate stats table logger.info(colors['title'] + 'Onionr v%s Statistics' % ONIONR_VERSION + colors['reset']) - logger.info(colors['border'] + '─' * (maxlength + 1) + '┐' + colors['reset']) + logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset']) for key, val in messages.items(): if not (type(val) is bool and val is True): - logger.info(colors['key'] + str(key).rjust(maxlength) + colors['reset'] + colors['border'] + ' │ ' + colors['reset'] + colors['val'] + str(val) + colors['reset']) + logger.info(colors['key'] + str(key).rjust(maxlength) + colors['reset'] + colors['border'] + ' | ' + colors['reset'] + colors['val'] + str(val) + colors['reset']) else: - logger.info(colors['border'] + '─' * (maxlength + 1) + '┤' + colors['reset']) - logger.info(colors['border'] + '─' * (maxlength + 1) + '┘' + colors['reset']) + logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset']) + logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset']) except Exception as e: logger.error('Failed to generate statistics table.', error = e, timestamp = False) @@ -664,15 +664,9 @@ class Onionr: logger.warn('That file does not exist. Improper path?') try: - with open(filename, 'rb') as file: - contents = file.read().decode() - except: - pass - - if not contents is None: - blockhash = Block('bin', contents).save() + blockhash = Block.createChain(file = filename) logger.info('File %s saved in block %s.' % (filename, blockhash)) - else: + except: logger.error('Failed to save file in block.', timestamp = False) else: logger.error('%s add-file ' % sys.argv[0], timestamp = False) diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 1dae4f12..58df1019 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -2,6 +2,7 @@ "devmode": true, "dc_response": true, + "display_header" : true, "log": { "file": { "output": true, @@ -13,6 +14,7 @@ "color": true } }, + "i2p":{ "host": false, "connect": true, diff --git a/onionr/static-data/header.txt b/onionr/static-data/header.txt new file mode 100644 index 00000000..2136cddf --- /dev/null +++ b/onionr/static-data/header.txt @@ -0,0 +1,25 @@ + +# ' +# '' +# :'' ' +# '''''' +# :;''''': +# ::;''':: +# :::;;::: +# :::::::: +# :::::::::::: +# ::::::::::::::: +# ::::: ::::: +# ::::: :::::::: :::: +# ::: :::::: ::::::: :::: $:::::: :: :: :: ::::: ::: :: :::::: +# ::: :::: :::: ::::: ::: $:: :: ::: :: :: :: :: :::: :: :: :: +# ::: ::::: :::::: :::: :::: $:: :: :::::: :: :: :: :::: :: :: :: +# ::: :::: ::::::: :::: :::: $:: :: :: ::: :: :: :: :: :::: ::::: +# ::: ::::: :::::: :::: :::: $:: :: :: ::: :: :: :: :: ::: :: ::: +# :::: ::::: ::::: ::: $ :::: :: :: :: ::::: :: :: :: :: +# :::: :::::: :::::: :::: +# :::: :::::::::::: :::: +# ::::: :::::::: :::: +# ::::: :::::: +# :::::::::::::::: +# :::::::