From cf37823fd7747c1d3acae3c1a2866196e0234060 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 4 Sep 2018 13:56:05 -0500 Subject: [PATCH] removed board plugin for now, added getfile command --- RUN-LINUX.sh | 1 + onionr/onionr.py | 29 ++++++++- onionr/onionrblockapi.py | 1 + onionr/onionrusers.py | 2 +- .../default-plugins/boards/info.json | 5 -- .../default-plugins/boards/main.py | 63 ------------------- 6 files changed, 30 insertions(+), 71 deletions(-) delete mode 100644 onionr/static-data/default-plugins/boards/info.json delete mode 100644 onionr/static-data/default-plugins/boards/main.py diff --git a/RUN-LINUX.sh b/RUN-LINUX.sh index 8f9a4b37..286a0f7f 100755 --- a/RUN-LINUX.sh +++ b/RUN-LINUX.sh @@ -1,3 +1,4 @@ #!/bin/sh +cd "$(dirname "$0")" cd onionr/ ./onionr.py "$@" diff --git a/onionr/onionr.py b/onionr/onionr.py index 21b3bd20..c8bb2873 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -50,6 +50,7 @@ class Onionr: Main Onionr class. This is for the CLI program, and does not handle much of the logic. In general, external programs and plugins should not use this class. ''' + self.userRunDir = os.getcwd() # Directory user runs the program from try: os.chdir(sys.path[0]) except FileNotFoundError: @@ -190,6 +191,10 @@ class Onionr: 'add-file': self.addFile, 'addfile': self.addFile, + + 'get-file': self.getFile, + 'getfile': self.getFile, + 'listconn': self.listConn, 'import-blocks': self.onionrUtils.importNewBlocks, @@ -230,6 +235,7 @@ class Onionr: 'add-peer': 'Adds a peer to database', 'list-peers': 'Displays a list of peers', 'add-file': 'Create an Onionr block from a file', + 'get-file': 'Get a file from Onionr blocks', 'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)', 'listconn': 'list connected peers', 'kex': 'exchange keys with peers (done automatically)', @@ -780,6 +786,24 @@ class Onionr: return columns + def getFile(self): + ''' + Get a file from onionr blocks + ''' + if len(sys.argv) >= 3: + fileName = sys.argv[2] + print(fileName) + contents = None + bHash = sys.argv[3] + if os.path.exists(fileName): + logger.error("File already exists") + return + if not self.onionrUtils.validateHash(bHash): + logger.error('Block hash is invalid') + return + Block.mergeChain(bHash, fileName) + return + def addFile(self): ''' Adds a file to the onionr network @@ -790,8 +814,9 @@ class Onionr: contents = None if not os.path.exists(filename): - logger.warn('That file does not exist. Improper path?') - + logger.error('That file does not exist. Improper path (specify full path)?') + return + logger.info('Adding file... this might take a long time.') try: blockhash = Block.createChain(file = filename) logger.info('File %s saved in block %s.' % (filename, blockhash)) diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index 97b34730..78d3e71e 100644 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -177,6 +177,7 @@ class Block: # signed data is jsonMeta + block content (no linebreak) self.signedData = (None if not self.isSigned() else self.getHeader('meta') + self.getContent()) self.date = self.getCore().getBlockDate(self.getHash()) + self.claimedTime = self.getHeader('time', None) if not self.getDate() is None: self.date = datetime.datetime.fromtimestamp(self.getDate()) diff --git a/onionr/onionrusers.py b/onionr/onionrusers.py index 29b9375b..7340fed3 100644 --- a/onionr/onionrusers.py +++ b/onionr/onionrusers.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import onionrblockapi, logger, onionrexceptions +import onionrblockapi, logger, onionrexceptions, json class OnionrUser: def __init__(self, coreInst, publicKey): self.trust = 0 diff --git a/onionr/static-data/default-plugins/boards/info.json b/onionr/static-data/default-plugins/boards/info.json deleted file mode 100644 index f3e80e1c..00000000 --- a/onionr/static-data/default-plugins/boards/info.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name" : "boards", - "version" : "1.0", - "author" : "onionr" -} diff --git a/onionr/static-data/default-plugins/boards/main.py b/onionr/static-data/default-plugins/boards/main.py deleted file mode 100644 index 573e6237..00000000 --- a/onionr/static-data/default-plugins/boards/main.py +++ /dev/null @@ -1,63 +0,0 @@ -''' - Onionr - P2P Anonymous Storage Network - - This is an interactive menu-driven CLI interface for Onionr -''' -''' - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -''' - -# Imports some useful libraries -import logger, config, sys -from onionrblockapi import Block -try: - import tkinter -except (ImportError, NameError) as e: - TK_ENABLED = False -else: - TK_ENABLED = True - - -plugin_name = 'cliui' -PLUGIN_VERSION = '0.0.1' - -class OnionrBoards: - def __init__(self, apiInst): - self.api = apiInst - self.myCore = apiInst.get_core() - - if TK_ENABLED: - self.gui = tkinter.Tk() - - return - - def start(self): - return - -def on_init(api, data = None): - ''' - This event is called after Onionr is initialized, but before the command - inputted is executed. Could be called when daemon is starting or when - just the client is running. - ''' - - # Doing this makes it so that the other functions can access the api object - # by simply referencing the variable `pluginapi`. - pluginapi = api - ui = OnionrBoards(api) - api.commands.register('boards', ui.start) - api.commands.register_help('boards', 'Open the board viewer') - - - return