log to terminal again in places where it should
This commit is contained in:
parent
065e97ab11
commit
6630071802
@ -78,6 +78,9 @@ def lookup_blocks_from_communicator(comm_inst):
|
|||||||
if len(comm_inst.blockQueue[i]) < 10:
|
if len(comm_inst.blockQueue[i]) < 10:
|
||||||
comm_inst.blockQueue[i].append(peer)
|
comm_inst.blockQueue[i].append(peer)
|
||||||
if new_block_count > 0:
|
if new_block_count > 0:
|
||||||
logger.info('Discovered %s new blocks' % (new_block_count,), terminal=True)
|
block_string = ""
|
||||||
|
if new_block_count > 1:
|
||||||
|
block_string = "s"
|
||||||
|
logger.info('Discovered %s new block%s' % (new_block_count, block_string), terminal=True)
|
||||||
comm_inst.decrementThreadCount('lookupBlocks')
|
comm_inst.decrementThreadCount('lookupBlocks')
|
||||||
return
|
return
|
@ -200,7 +200,7 @@ class Onionr:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def exportBlock(self):
|
def exportBlock(self):
|
||||||
commands.exportblocks(self)
|
commands.exportblocks.export_block(self)
|
||||||
|
|
||||||
def showDetails(self):
|
def showDetails(self):
|
||||||
commands.onionrstatistics.show_details(self)
|
commands.onionrstatistics.show_details(self)
|
||||||
@ -347,7 +347,7 @@ class Onionr:
|
|||||||
Displays a "command not found" message
|
Displays a "command not found" message
|
||||||
'''
|
'''
|
||||||
|
|
||||||
logger.error('Command not found.', timestamp = False)
|
logger.error('Command not found.', timestamp = False, terminal=True)
|
||||||
|
|
||||||
def showHelpSuggestion(self):
|
def showHelpSuggestion(self):
|
||||||
'''
|
'''
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import sys
|
import sys, os
|
||||||
import logger, onionrstorage
|
import logger, onionrstorage
|
||||||
def doExport(o_inst, bHash):
|
def doExport(o_inst, bHash):
|
||||||
exportDir = o_inst.dataDir + 'block-export/'
|
exportDir = o_inst.dataDir + 'block-export/'
|
||||||
@ -25,18 +25,19 @@ def doExport(o_inst, bHash):
|
|||||||
if os.path.exists(o_inst.dataDir):
|
if os.path.exists(o_inst.dataDir):
|
||||||
os.mkdir(exportDir)
|
os.mkdir(exportDir)
|
||||||
else:
|
else:
|
||||||
logger.error('Onionr Not initialized')
|
logger.error('Onionr Not initialized', terminal=True)
|
||||||
data = onionrstorage.getData(o_inst.onionrCore, bHash)
|
data = onionrstorage.getData(o_inst.onionrCore, bHash)
|
||||||
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
|
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
|
||||||
exportFile.write(data)
|
exportFile.write(data)
|
||||||
|
logger.info('Block exported as file', terminal=True)
|
||||||
|
|
||||||
def export_block(o_inst):
|
def export_block(o_inst):
|
||||||
exportDir = o_inst.dataDir + 'block-export/'
|
exportDir = o_inst.dataDir + 'block-export/'
|
||||||
try:
|
try:
|
||||||
assert o_inst.onionrUtils.validateHash(sys.argv[2])
|
assert o_inst.onionrUtils.validateHash(sys.argv[2])
|
||||||
except (IndexError, AssertionError):
|
except (IndexError, AssertionError):
|
||||||
logger.error('No valid block hash specified.')
|
logger.error('No valid block hash specified.', terminal=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
bHash = sys.argv[2]
|
bHash = sys.argv[2]
|
||||||
o_inst.doExport(bHash)
|
doExport(o_inst, bHash)
|
@ -31,18 +31,18 @@ def add_file(o_inst, singleBlock=False, blockType='bin'):
|
|||||||
contents = None
|
contents = None
|
||||||
|
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
logger.error('That file does not exist. Improper path (specify full path)?')
|
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.')
|
logger.info('Adding file... this might take a long time.', terminal=True)
|
||||||
try:
|
try:
|
||||||
with open(filename, 'rb') as singleFile:
|
with open(filename, 'rb') as singleFile:
|
||||||
blockhash = o_inst.onionrCore.insertBlock(base64.b64encode(singleFile.read()), header=blockType)
|
blockhash = o_inst.onionrCore.insertBlock(base64.b64encode(singleFile.read()), header=blockType)
|
||||||
if len(blockhash) > 0:
|
if len(blockhash) > 0:
|
||||||
logger.info('File %s saved in block %s' % (filename, blockhash))
|
logger.info('File %s saved in block %s' % (filename, blockhash), terminal=True)
|
||||||
except:
|
except:
|
||||||
logger.error('Failed to save file in block.', timestamp = False)
|
logger.error('Failed to save file in block.', timestamp = False, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('%s add-file <filename>' % sys.argv[0], timestamp = False)
|
logger.error('%s add-file <filename>' % sys.argv[0], timestamp = False, terminal=True)
|
||||||
|
|
||||||
def getFile(o_inst):
|
def getFile(o_inst):
|
||||||
'''
|
'''
|
||||||
@ -52,16 +52,16 @@ def getFile(o_inst):
|
|||||||
fileName = sys.argv[2]
|
fileName = 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>'))
|
logger.error("Syntax %s %s" % (sys.argv[0], '/path/to/filename <blockhash>'), terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info(fileName)
|
logger.info(fileName, terminal=True)
|
||||||
|
|
||||||
contents = None
|
contents = None
|
||||||
if os.path.exists(fileName):
|
if os.path.exists(fileName):
|
||||||
logger.error("File already exists")
|
logger.error("File already exists", terminal=True)
|
||||||
return
|
return
|
||||||
if not o_inst.onionrUtils.validateHash(bHash):
|
if not o_inst.onionrUtils.validateHash(bHash):
|
||||||
logger.error('Block hash is invalid')
|
logger.error('Block hash is invalid', terminal=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(fileName, 'wb') as myFile:
|
with open(fileName, 'wb') as myFile:
|
||||||
|
@ -26,14 +26,14 @@ def add_peer(o_inst):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if o_inst.onionrUtils.hasKey(newPeer):
|
if o_inst.onionrUtils.hasKey(newPeer):
|
||||||
logger.info('We already have that key')
|
logger.info('We already have that key', terminal=True)
|
||||||
return
|
return
|
||||||
logger.info("Adding peer: " + logger.colors.underline + newPeer)
|
logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True)
|
||||||
try:
|
try:
|
||||||
if o_inst.onionrCore.addPeer(newPeer):
|
if o_inst.onionrCore.addPeer(newPeer):
|
||||||
logger.info('Successfully added key')
|
logger.info('Successfully added key', terminal=True)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
logger.error('Failed to add key')
|
logger.error('Failed to add key', terminal=True)
|
||||||
|
|
||||||
def add_address(o_inst):
|
def add_address(o_inst):
|
||||||
try:
|
try:
|
||||||
@ -42,8 +42,8 @@ def add_address(o_inst):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.info("Adding address: " + logger.colors.underline + newAddress)
|
logger.info("Adding address: " + logger.colors.underline + newAddress, terminal=True)
|
||||||
if o_inst.onionrCore.addAddress(newAddress):
|
if o_inst.onionrCore.addAddress(newAddress):
|
||||||
logger.info("Successfully added address.")
|
logger.info("Successfully added address.", terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn("Unable to add address.")
|
logger.warn("Unable to add address.", terminal=True)
|
@ -23,7 +23,7 @@ def open_home(o_inst):
|
|||||||
try:
|
try:
|
||||||
url = o_inst.onionrUtils.getClientAPIServer()
|
url = o_inst.onionrUtils.getClientAPIServer()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.error('Onionr seems to not be running (could not get api host)')
|
logger.error('Onionr seems to not be running (could not get api host)', terminal=True)
|
||||||
else:
|
else:
|
||||||
url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword'))
|
url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword'))
|
||||||
logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True)
|
logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True)
|
||||||
|
@ -24,18 +24,18 @@ import logger, onionrplugins as plugins
|
|||||||
def enable_plugin(o_inst):
|
def enable_plugin(o_inst):
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Enabling plugin "%s"...' % plugin_name)
|
logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
|
||||||
plugins.enable(plugin_name, o_inst)
|
plugins.enable(plugin_name, o_inst)
|
||||||
else:
|
else:
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
||||||
|
|
||||||
def disable_plugin(o_inst):
|
def disable_plugin(o_inst):
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Disabling plugin "%s"...' % plugin_name)
|
logger.info('Disabling plugin "%s"...' % plugin_name, terminal=True)
|
||||||
plugins.disable(plugin_name, o_inst)
|
plugins.disable(plugin_name, o_inst)
|
||||||
else:
|
else:
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
||||||
|
|
||||||
def reload_plugin(o_inst):
|
def reload_plugin(o_inst):
|
||||||
'''
|
'''
|
||||||
@ -44,11 +44,11 @@ def reload_plugin(o_inst):
|
|||||||
|
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Reloading plugin "%s"...' % plugin_name)
|
logger.info('Reloading plugin "%s"...' % plugin_name, terminal=True)
|
||||||
plugins.stop(plugin_name, o_inst)
|
plugins.stop(plugin_name, o_inst)
|
||||||
plugins.start(plugin_name, o_inst)
|
plugins.start(plugin_name, o_inst)
|
||||||
else:
|
else:
|
||||||
logger.info('Reloading all plugins...')
|
logger.info('Reloading all plugins...', terminal=True)
|
||||||
plugins.reload(o_inst)
|
plugins.reload(o_inst)
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ def create_plugin(o_inst):
|
|||||||
plugin_name = re.sub('[^0-9a-zA-Z_]+', '', str(sys.argv[2]).lower())
|
plugin_name = re.sub('[^0-9a-zA-Z_]+', '', str(sys.argv[2]).lower())
|
||||||
|
|
||||||
if not plugins.exists(plugin_name):
|
if not plugins.exists(plugin_name):
|
||||||
logger.info('Creating plugin "%s"...' % plugin_name)
|
logger.info('Creating plugin "%s"...' % plugin_name, terminal=True)
|
||||||
|
|
||||||
os.makedirs(plugins.get_plugins_folder(plugin_name))
|
os.makedirs(plugins.get_plugins_folder(plugin_name))
|
||||||
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
|
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
|
||||||
@ -76,12 +76,12 @@ def create_plugin(o_inst):
|
|||||||
with open(plugins.get_plugins_folder(plugin_name) + '/info.json', 'a') as main:
|
with open(plugins.get_plugins_folder(plugin_name) + '/info.json', 'a') as main:
|
||||||
main.write(json.dumps({'author' : 'anonymous', 'description' : 'the default description of the plugin', 'version' : '1.0'}))
|
main.write(json.dumps({'author' : 'anonymous', 'description' : 'the default description of the plugin', 'version' : '1.0'}))
|
||||||
|
|
||||||
logger.info('Enabling plugin "%s"...' % plugin_name)
|
logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
|
||||||
plugins.enable(plugin_name, o_inst)
|
plugins.enable(plugin_name, o_inst)
|
||||||
else:
|
else:
|
||||||
logger.warn('Cannot create plugin directory structure; plugin "%s" exists.' % plugin_name)
|
logger.warn('Cannot create plugin directory structure; plugin "%s" exists.' % plugin_name, terminal=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to create plugin directory structure.', e)
|
logger.error('Failed to create plugin directory structure.', e, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
@ -29,42 +29,42 @@ def add_ID(o_inst):
|
|||||||
except (IndexError, AssertionError) as e:
|
except (IndexError, AssertionError) as e:
|
||||||
newID = o_inst.onionrCore._crypto.keyManager.addKey()[0]
|
newID = o_inst.onionrCore._crypto.keyManager.addKey()[0]
|
||||||
else:
|
else:
|
||||||
logger.warn('Deterministic keys require random and long passphrases.')
|
logger.warn('Deterministic keys require random and long passphrases.', terminal=True)
|
||||||
logger.warn('If a good passphrase is not used, your key can be easily stolen.')
|
logger.warn('If a good passphrase is not used, your key can be easily stolen.', terminal=True)
|
||||||
logger.warn('You should use a series of hard to guess words, see this for reference: https://www.xkcd.com/936/')
|
logger.warn('You should use a series of hard to guess words, see this for reference: https://www.xkcd.com/936/', terminal=True)
|
||||||
pass1 = getpass.getpass(prompt='Enter at least %s characters: ' % (o_inst.onionrCore._crypto.deterministicRequirement,))
|
pass1 = getpass.getpass(prompt='Enter at least %s characters: ' % (o_inst.onionrCore._crypto.deterministicRequirement,))
|
||||||
pass2 = getpass.getpass(prompt='Confirm entry: ')
|
pass2 = getpass.getpass(prompt='Confirm entry: ')
|
||||||
if o_inst.onionrCore._crypto.safeCompare(pass1, pass2):
|
if o_inst.onionrCore._crypto.safeCompare(pass1, pass2):
|
||||||
try:
|
try:
|
||||||
logger.info('Generating deterministic key. This can take a while.')
|
logger.info('Generating deterministic key. This can take a while.', terminal=True)
|
||||||
newID, privKey = o_inst.onionrCore._crypto.generateDeterministic(pass1)
|
newID, privKey = o_inst.onionrCore._crypto.generateDeterministic(pass1)
|
||||||
except onionrexceptions.PasswordStrengthError:
|
except onionrexceptions.PasswordStrengthError:
|
||||||
logger.error('Passphrase must use at least %s characters.' % (o_inst.onionrCore._crypto.deterministicRequirement,))
|
logger.error('Passphrase must use at least %s characters.' % (o_inst.onionrCore._crypto.deterministicRequirement,), terminal=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
logger.error('Passwords do not match.')
|
logger.error('Passwords do not match.', terminal=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
o_inst.onionrCore._crypto.keyManager.addKey(pubKey=newID,
|
o_inst.onionrCore._crypto.keyManager.addKey(pubKey=newID,
|
||||||
privKey=privKey)
|
privKey=privKey)
|
||||||
logger.info('Added ID: %s' % (o_inst.onionrUtils.bytesToStr(newID),))
|
logger.info('Added ID: %s' % (o_inst.onionrUtils.bytesToStr(newID),), terminal=True)
|
||||||
|
|
||||||
def change_ID(o_inst):
|
def change_ID(o_inst):
|
||||||
try:
|
try:
|
||||||
key = sys.argv[2]
|
key = sys.argv[2]
|
||||||
key = unpaddedbase32.repad(key.encode()).decode()
|
key = unpaddedbase32.repad(key.encode()).decode()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warn('Specify pubkey to use')
|
logger.warn('Specify pubkey to use', terminal=True)
|
||||||
else:
|
else:
|
||||||
if o_inst.onionrUtils.validatePubKey(key):
|
if o_inst.onionrUtils.validatePubKey(key):
|
||||||
if key in o_inst.onionrCore._crypto.keyManager.getPubkeyList():
|
if key in o_inst.onionrCore._crypto.keyManager.getPubkeyList():
|
||||||
o_inst.onionrCore.config.set('general.public_key', key)
|
o_inst.onionrCore.config.set('general.public_key', key)
|
||||||
o_inst.onionrCore.config.save()
|
o_inst.onionrCore.config.save()
|
||||||
logger.info('Set active key to: %s' % (key,))
|
logger.info('Set active key to: %s' % (key,), terminal=True)
|
||||||
logger.info('Restart Onionr if it is running.')
|
logger.info('Restart Onionr if it is running.', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn('That key does not exist')
|
logger.warn('That key does not exist', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn('Invalid key %s' % (key,))
|
logger.warn('Invalid key %s' % (key,), terminal=True)
|
||||||
|
|
||||||
def friend_command(o_inst):
|
def friend_command(o_inst):
|
||||||
friend = ''
|
friend = ''
|
||||||
@ -72,13 +72,13 @@ def friend_command(o_inst):
|
|||||||
# Get the friend command
|
# Get the friend command
|
||||||
action = sys.argv[2]
|
action = sys.argv[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.info('Syntax: friend add/remove/list [address]')
|
logger.info('Syntax: friend add/remove/list [address]', terminal=True)
|
||||||
else:
|
else:
|
||||||
action = action.lower()
|
action = action.lower()
|
||||||
if action == 'list':
|
if action == 'list':
|
||||||
# List out peers marked as our friend
|
# List out peers marked as our friend
|
||||||
for friend in contactmanager.ContactManager.list_friends(o_inst.onionrCore):
|
for friend in contactmanager.ContactManager.list_friends(o_inst.onionrCore):
|
||||||
logger.info(friend.publicKey + ' - ' + friend.get_info('name'))
|
logger.info(friend.publicKey + ' - ' + friend.get_info('name'), terminal=True)
|
||||||
elif action in ('add', 'remove'):
|
elif action in ('add', 'remove'):
|
||||||
try:
|
try:
|
||||||
friend = sys.argv[3]
|
friend = sys.argv[3]
|
||||||
@ -88,7 +88,7 @@ def friend_command(o_inst):
|
|||||||
raise onionrexceptions.KeyNotKnown
|
raise onionrexceptions.KeyNotKnown
|
||||||
friend = onionrusers.OnionrUser(o_inst.onionrCore, friend)
|
friend = onionrusers.OnionrUser(o_inst.onionrCore, friend)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warn('Friend ID is required.')
|
logger.warn('Friend ID is required.', terminal=True)
|
||||||
action = 'error' # set to 'error' so that the finally block does not process anything
|
action = 'error' # set to 'error' so that the finally block does not process anything
|
||||||
except onionrexceptions.KeyNotKnown:
|
except onionrexceptions.KeyNotKnown:
|
||||||
o_inst.onionrCore.addPeer(friend)
|
o_inst.onionrCore.addPeer(friend)
|
||||||
@ -96,9 +96,9 @@ def friend_command(o_inst):
|
|||||||
finally:
|
finally:
|
||||||
if action == 'add':
|
if action == 'add':
|
||||||
friend.setTrust(1)
|
friend.setTrust(1)
|
||||||
logger.info('Added %s as friend.' % (friend.publicKey,))
|
logger.info('Added %s as friend.' % (friend.publicKey,), terminal=True)
|
||||||
elif action == 'remove':
|
elif action == 'remove':
|
||||||
friend.setTrust(0)
|
friend.setTrust(0)
|
||||||
logger.info('Removed %s as friend.' % (friend.publicKey,))
|
logger.info('Removed %s as friend.' % (friend.publicKey,), terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info('Syntax: friend add/remove/list [address]')
|
logger.info('Syntax: friend add/remove/list [address]', terminal=True)
|
@ -24,6 +24,6 @@ def reset_tor():
|
|||||||
tor_dir = c.dataDir + 'tordata'
|
tor_dir = c.dataDir + 'tordata'
|
||||||
if os.path.exists(tor_dir):
|
if os.path.exists(tor_dir):
|
||||||
if c._utils.localCommand('/ping') == 'pong!':
|
if c._utils.localCommand('/ping') == 'pong!':
|
||||||
logger.warn('Cannot delete Tor data while Onionr is running')
|
logger.warn('Cannot delete Tor data while Onionr is running', terminal=True)
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(tor_dir)
|
shutil.rmtree(tor_dir)
|
@ -100,7 +100,7 @@ class OnionrCLIUI:
|
|||||||
elif choice == "":
|
elif choice == "":
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.error("Invalid choice")
|
logger.error("Invalid choice", terminal=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_init(api, data = None):
|
def on_init(api, data = None):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'''
|
'''
|
||||||
Onionr - P2P Microblogging Platform & Social network
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
This default plugin allows users to encrypt/decrypt messages without using blocks
|
This default plugin allows users to encrypt/decrypt messages without using blocks
|
||||||
'''
|
'''
|
||||||
@ -46,13 +46,13 @@ class PlainEncryption:
|
|||||||
if not self.api.get_core()._utils.validatePubKey(sys.argv[2]):
|
if not self.api.get_core()._utils.validatePubKey(sys.argv[2]):
|
||||||
raise onionrexceptions.InvalidPubkey
|
raise onionrexceptions.InvalidPubkey
|
||||||
except (ValueError, IndexError) as e:
|
except (ValueError, IndexError) as e:
|
||||||
logger.error("Peer public key not specified")
|
logger.error("Peer public key not specified", terminal=True)
|
||||||
except onionrexceptions.InvalidPubkey:
|
except onionrexceptions.InvalidPubkey:
|
||||||
logger.error("Invalid public key")
|
logger.error("Invalid public key", terminal=True)
|
||||||
else:
|
else:
|
||||||
pubkey = sys.argv[2]
|
pubkey = sys.argv[2]
|
||||||
# Encrypt if public key is valid
|
# Encrypt if public key is valid
|
||||||
logger.info("Please enter your message (ctrl-d or -q to stop):")
|
logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True)
|
||||||
try:
|
try:
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
if line == '-q\n':
|
if line == '-q\n':
|
||||||
@ -72,12 +72,12 @@ class PlainEncryption:
|
|||||||
plaintext = data
|
plaintext = data
|
||||||
encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, encodedData=True)
|
encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, encodedData=True)
|
||||||
encrypted = self.api.get_core()._utils.bytesToStr(encrypted)
|
encrypted = self.api.get_core()._utils.bytesToStr(encrypted)
|
||||||
logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,))
|
logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,), terminal=True)
|
||||||
|
|
||||||
def decrypt(self):
|
def decrypt(self):
|
||||||
plaintext = ""
|
plaintext = ""
|
||||||
data = ""
|
data = ""
|
||||||
logger.info("Please enter your message (ctrl-d or -q to stop):")
|
logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True)
|
||||||
try:
|
try:
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
if line == '-q\n':
|
if line == '-q\n':
|
||||||
@ -91,17 +91,17 @@ class PlainEncryption:
|
|||||||
myPub = self.api.get_core()._crypto.pubKey
|
myPub = self.api.get_core()._crypto.pubKey
|
||||||
decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, privkey=self.api.get_core()._crypto.privKey, encodedData=True)
|
decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, privkey=self.api.get_core()._crypto.privKey, encodedData=True)
|
||||||
if decrypted == False:
|
if decrypted == False:
|
||||||
logger.error("Decryption failed")
|
logger.error("Decryption failed", terminal=True)
|
||||||
else:
|
else:
|
||||||
data = json.loads(decrypted)
|
data = json.loads(decrypted)
|
||||||
logger.info('Decrypted Message: \n\n%s' % data['data'])
|
logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True)
|
||||||
try:
|
try:
|
||||||
logger.info("Signing public key: %s" % (data['signer'],))
|
logger.info("Signing public key: %s" % (data['signer'],), terminal=True)
|
||||||
assert self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']) != False
|
assert self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']) != False
|
||||||
except (AssertionError, KeyError) as e:
|
except (AssertionError, KeyError) as e:
|
||||||
logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE")
|
logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info("Message has good signature.")
|
logger.info("Message has good signature.", terminal=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_init(api, data = None):
|
def on_init(api, data = None):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'''
|
'''
|
||||||
Onionr - P2P Microblogging Platform & Social network.
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
This plugin acts as a plugin manager, and allows the user to install other plugins distributed over Onionr.
|
This plugin acts as a plugin manager, and allows the user to install other plugins distributed over Onionr.
|
||||||
'''
|
'''
|
||||||
@ -180,11 +180,11 @@ def blockToPlugin(block):
|
|||||||
shutil.unpack_archive(source, destination)
|
shutil.unpack_archive(source, destination)
|
||||||
pluginapi.plugins.enable(name)
|
pluginapi.plugins.enable(name)
|
||||||
|
|
||||||
logger.info('Installation of %s complete.' % name)
|
logger.info('Installation of %s complete.' % name, terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to install plugin.', error = e, timestamp = False)
|
logger.error('Failed to install plugin.', error = e, timestamp = False, terminal=True)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -240,9 +240,9 @@ def pluginToBlock(plugin, import_block = True):
|
|||||||
|
|
||||||
return hash
|
return hash
|
||||||
else:
|
else:
|
||||||
logger.error('Plugin %s does not exist.' % plugin)
|
logger.error('Plugin %s does not exist.' % plugin, terminal=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to convert plugin to block.', error = e, timestamp = False)
|
logger.error('Failed to convert plugin to block.', error = e, timestamp = False, terminal=True)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ def installBlock(block):
|
|||||||
|
|
||||||
install = False
|
install = False
|
||||||
|
|
||||||
logger.info(('Will install %s' + (' v' + version if not version is None else '') + ' (%s), by %s') % (name, date, author))
|
logger.info(('Will install %s' + (' v' + version if not version is None else '') + ' (%s), by %s') % (name, date, author), terminal=True)
|
||||||
|
|
||||||
# TODO: Convert to single line if statement
|
# TODO: Convert to single line if statement
|
||||||
if os.path.exists(pluginapi.plugins.get_folder(name)):
|
if os.path.exists(pluginapi.plugins.get_folder(name)):
|
||||||
@ -273,12 +273,12 @@ def installBlock(block):
|
|||||||
blockToPlugin(block.getHash())
|
blockToPlugin(block.getHash())
|
||||||
addPlugin(name)
|
addPlugin(name)
|
||||||
else:
|
else:
|
||||||
logger.info('Installation cancelled.')
|
logger.info('Installation cancelled.', terminal=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to install plugin.', error = e, timestamp = False)
|
logger.error('Failed to install plugin.', error = e, timestamp = False, terminal=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def uninstallPlugin(plugin):
|
def uninstallPlugin(plugin):
|
||||||
@ -291,12 +291,12 @@ def uninstallPlugin(plugin):
|
|||||||
remove = False
|
remove = False
|
||||||
|
|
||||||
if not exists:
|
if not exists:
|
||||||
logger.warn('Plugin %s does not exist.' % plugin, timestamp = False)
|
logger.warn('Plugin %s does not exist.' % plugin, timestamp = False, terminal=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
default = 'y'
|
default = 'y'
|
||||||
if not installedByPluginManager:
|
if not installedByPluginManager:
|
||||||
logger.warn('The plugin %s was not installed by %s.' % (plugin, plugin_name), timestamp = False)
|
logger.warn('The plugin %s was not installed by %s.' % (plugin, plugin_name), timestamp = False, terminal=True)
|
||||||
default = 'n'
|
default = 'n'
|
||||||
remove = logger.confirm(message = 'All plugin data will be lost. Are you sure you want to proceed %s?', default = default)
|
remove = logger.confirm(message = 'All plugin data will be lost. Are you sure you want to proceed %s?', default = default)
|
||||||
|
|
||||||
@ -306,20 +306,20 @@ def uninstallPlugin(plugin):
|
|||||||
pluginapi.plugins.disable(plugin)
|
pluginapi.plugins.disable(plugin)
|
||||||
shutil.rmtree(pluginFolder)
|
shutil.rmtree(pluginFolder)
|
||||||
|
|
||||||
logger.info('Uninstallation of %s complete.' % plugin)
|
logger.info('Uninstallation of %s complete.' % plugin, terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.info('Uninstallation cancelled.')
|
logger.info('Uninstallation cancelled.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to uninstall plugin.', error = e)
|
logger.error('Failed to uninstall plugin.', error = e, terminal=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# command handlers
|
# command handlers
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]', terminal=True)
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]', terminal=True)
|
||||||
|
|
||||||
def commandInstallPlugin():
|
def commandInstallPlugin():
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
@ -345,20 +345,20 @@ def commandInstallPlugin():
|
|||||||
|
|
||||||
if pkobh is None:
|
if pkobh is None:
|
||||||
# still nothing found, try searching repositories
|
# still nothing found, try searching repositories
|
||||||
logger.info('Searching for public key in repositories...')
|
logger.info('Searching for public key in repositories...', terminal=True)
|
||||||
try:
|
try:
|
||||||
repos = getRepositories()
|
repos = getRepositories()
|
||||||
distributors = list()
|
distributors = list()
|
||||||
for repo, records in repos.items():
|
for repo, records in repos.items():
|
||||||
if pluginname in records:
|
if pluginname in records:
|
||||||
logger.debug('Found %s in repository %s for plugin %s.' % (records[pluginname], repo, pluginname))
|
logger.debug('Found %s in repository %s for plugin %s.' % (records[pluginname], repo, pluginname), terminal=True)
|
||||||
distributors.append(records[pluginname])
|
distributors.append(records[pluginname])
|
||||||
|
|
||||||
if len(distributors) != 0:
|
if len(distributors) != 0:
|
||||||
distributor = None
|
distributor = None
|
||||||
|
|
||||||
if len(distributors) == 1:
|
if len(distributors) == 1:
|
||||||
logger.info('Found distributor: %s' % distributors[0])
|
logger.info('Found distributor: %s' % distributors[0], terminal=True)
|
||||||
distributor = distributors[0]
|
distributor = distributors[0]
|
||||||
else:
|
else:
|
||||||
distributors_message = ''
|
distributors_message = ''
|
||||||
@ -368,11 +368,11 @@ def commandInstallPlugin():
|
|||||||
distributors_message += ' ' + logger.colors.bold + str(index) + ') ' + logger.colors.reset + str(dist) + '\n'
|
distributors_message += ' ' + logger.colors.bold + str(index) + ') ' + logger.colors.reset + str(dist) + '\n'
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
logger.info((logger.colors.bold + 'Found distributors (%s):' + logger.colors.reset + '\n' + distributors_message) % len(distributors))
|
logger.info((logger.colors.bold + 'Found distributors (%s):' + logger.colors.reset + '\n' + distributors_message) % len(distributors), terminal=True)
|
||||||
|
|
||||||
valid = False
|
valid = False
|
||||||
while not valid:
|
while not valid:
|
||||||
choice = logger.readline('Select the number of the key to use, from 1 to %s, or press Ctrl+C to cancel:' % (index - 1))
|
choice = logger.readline('Select the number of the key to use, from 1 to %s, or press Ctrl+C to cancel:' % (index - 1), terminal=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
choice = int(choice)
|
choice = int(choice)
|
||||||
@ -380,7 +380,7 @@ def commandInstallPlugin():
|
|||||||
distributor = distributors[int(choice)]
|
distributor = distributors[int(choice)]
|
||||||
valid = True
|
valid = True
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info('Installation cancelled.')
|
logger.info('Installation cancelled.', terminal=True)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -388,11 +388,11 @@ def commandInstallPlugin():
|
|||||||
if not distributor is None:
|
if not distributor is None:
|
||||||
pkobh = distributor
|
pkobh = distributor
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn('Failed to lookup plugin in repositories.', timestamp = False)
|
logger.warn('Failed to lookup plugin in repositories.', timestamp = False, terminal=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if pkobh is None:
|
if pkobh is None:
|
||||||
logger.error('No key for this plugin found in keystore or repositories, please specify.', timestamp = False)
|
logger.error('No key for this plugin found in keystore or repositories, please specify.', timestamp = False, terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -409,21 +409,21 @@ def commandInstallPlugin():
|
|||||||
blockhash = None
|
blockhash = None
|
||||||
|
|
||||||
if valid_hash and not real_block:
|
if valid_hash and not real_block:
|
||||||
logger.error('Block hash not found. Perhaps it has not been synced yet?', timestamp = False)
|
logger.error('Block hash not found. Perhaps it has not been synced yet?', timestamp = False, terminal=True)
|
||||||
logger.debug('Is valid hash, but does not belong to a known block.')
|
logger.debug('Is valid hash, but does not belong to a known block.', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
elif valid_hash and real_block:
|
elif valid_hash and real_block:
|
||||||
blockhash = str(pkobh)
|
blockhash = str(pkobh)
|
||||||
logger.debug('Using block %s...' % blockhash)
|
logger.debug('Using block %s...' % blockhash, terminal=True)
|
||||||
|
|
||||||
installBlock(blockhash)
|
installBlock(blockhash)
|
||||||
elif valid_key and not real_key:
|
elif valid_key and not real_key:
|
||||||
logger.error('Public key not found. Try adding the node by address manually, if possible.', timestamp = False)
|
logger.error('Public key not found. Try adding the node by address manually, if possible.', timestamp = False, terminal=True)
|
||||||
logger.debug('Is valid key, but the key is not a known one.')
|
logger.debug('Is valid key, but the key is not a known one.', terminal=True)
|
||||||
elif valid_key and real_key:
|
elif valid_key and real_key:
|
||||||
publickey = str(pkobh)
|
publickey = str(pkobh)
|
||||||
logger.debug('Using public key %s...' % publickey)
|
logger.debug('Using public key %s...' % publickey, terminal=True)
|
||||||
|
|
||||||
saveKey(pluginname, pkobh)
|
saveKey(pluginname, pkobh)
|
||||||
|
|
||||||
@ -455,14 +455,14 @@ def commandInstallPlugin():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.warn('Only continue the installation if you are absolutely certain that you trust the plugin distributor. Public key of plugin distributor: %s' % publickey, timestamp = False)
|
logger.warn('Only continue the installation if you are absolutely certain that you trust the plugin distributor. Public key of plugin distributor: %s' % publickey, timestamp = False, terminal=True)
|
||||||
logger.debug('Most recent block matching parameters is %s' % mostRecentVersionBlock)
|
logger.debug('Most recent block matching parameters is %s' % mostRecentVersionBlock, terminal=True)
|
||||||
installBlock(mostRecentVersionBlock)
|
installBlock(mostRecentVersionBlock)
|
||||||
else:
|
else:
|
||||||
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh), timestamp = False)
|
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh), timestamp = False, terminal=True)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -470,12 +470,12 @@ def commandUninstallPlugin():
|
|||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
uninstallPlugin(sys.argv[2])
|
uninstallPlugin(sys.argv[2])
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def commandSearchPlugin():
|
def commandSearchPlugin():
|
||||||
logger.info('This feature has not been created yet. Please check back later.')
|
logger.info('This feature has not been created yet. Please check back later.', terminal=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def commandAddRepository():
|
def commandAddRepository():
|
||||||
@ -495,22 +495,22 @@ def commandAddRepository():
|
|||||||
if pluginapi.get_utils().validatePubKey(distributor):
|
if pluginapi.get_utils().validatePubKey(distributor):
|
||||||
pluginslist[pluginname] = distributor
|
pluginslist[pluginname] = distributor
|
||||||
|
|
||||||
logger.debug('Found %s records in repository.' % len(pluginslist))
|
logger.debug('Found %s records in repository.' % len(pluginslist), terminal=True)
|
||||||
|
|
||||||
if len(pluginslist) != 0:
|
if len(pluginslist) != 0:
|
||||||
addRepository(blockhash, pluginslist)
|
addRepository(blockhash, pluginslist)
|
||||||
logger.info('Successfully added repository.')
|
logger.info('Successfully added repository.', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Repository contains no records, not importing.', timestamp = False)
|
logger.error('Repository contains no records, not importing.', timestamp = False, terminal=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to parse block.', error = e)
|
logger.error('Failed to parse block.', error = e, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Block hash not found. Perhaps it has not been synced yet?', timestamp = False)
|
logger.error('Block hash not found. Perhaps it has not been synced yet?', timestamp = False, terminal=True)
|
||||||
logger.debug('Is valid hash, but does not belong to a known block.')
|
logger.debug('Is valid hash, but does not belong to a known block.')
|
||||||
else:
|
else:
|
||||||
logger.error('Unknown data "%s"; must be block hash.' % str(pkobh), timestamp = False)
|
logger.error('Unknown data "%s"; must be block hash.' % str(pkobh), timestamp = False, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -524,15 +524,15 @@ def commandRemoveRepository():
|
|||||||
if blockhash in getRepositories():
|
if blockhash in getRepositories():
|
||||||
try:
|
try:
|
||||||
removeRepository(blockhash)
|
removeRepository(blockhash)
|
||||||
logger.info('Successfully removed repository.')
|
logger.info('Successfully removed repository.', terminal=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to parse block.', error = e)
|
logger.error('Failed to parse block.', error = e, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Repository has not been imported, nothing to remove.', timestamp = False)
|
logger.error('Repository has not been imported, nothing to remove.', timestamp = False, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Unknown data "%s"; must be block hash.' % str(pkobh))
|
logger.error('Unknown data "%s"; must be block hash.' % str(pkobh), terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -545,11 +545,11 @@ def commandPublishPlugin():
|
|||||||
|
|
||||||
if os.path.exists(pluginfolder) and not os.path.isfile(pluginfolder):
|
if os.path.exists(pluginfolder) and not os.path.isfile(pluginfolder):
|
||||||
block = pluginToBlock(pluginname)
|
block = pluginToBlock(pluginname)
|
||||||
logger.info('Plugin saved in block %s.' % block)
|
logger.info('Plugin saved in block %s.' % block, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Plugin %s does not exist.' % pluginname, timestamp = False)
|
logger.error('Plugin %s does not exist.' % pluginname, timestamp = False, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>', terminal=True)
|
||||||
|
|
||||||
def commandCreateRepository():
|
def commandCreateRepository():
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
@ -573,22 +573,22 @@ def commandCreateRepository():
|
|||||||
if distributor is None:
|
if distributor is None:
|
||||||
distributor = getKey(pluginname)
|
distributor = getKey(pluginname)
|
||||||
if distributor is None:
|
if distributor is None:
|
||||||
logger.error('No distributor key was found for the plugin %s.' % pluginname, timestamp = False)
|
logger.error('No distributor key was found for the plugin %s.' % pluginname, timestamp = False, terminal=True)
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
plugins.append([pluginname, distributor])
|
plugins.append([pluginname, distributor])
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
logger.error('Please correct the above errors, then recreate the repository.')
|
logger.error('Please correct the above errors, then recreate the repository.', terminal=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
blockhash = createRepository(plugins)
|
blockhash = createRepository(plugins)
|
||||||
if not blockhash is None:
|
if not blockhash is None:
|
||||||
logger.info('Successfully created repository. Execute the following command to add the repository:\n ' + logger.colors.underline + '%s --add-repository %s' % (script, blockhash))
|
logger.info('Successfully created repository. Execute the following command to add the repository:\n ' + logger.colors.underline + '%s --add-repository %s' % (script, blockhash), terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.error('Failed to create repository, an unknown error occurred.')
|
logger.error('Failed to create repository, an unknown error occurred.', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [plugins...]')
|
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [plugins...]', terminal=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class OnionrMail:
|
|||||||
blockCount = 0
|
blockCount = 0
|
||||||
pmBlockMap = {}
|
pmBlockMap = {}
|
||||||
pmBlocks = {}
|
pmBlocks = {}
|
||||||
logger.info('Decrypting messages...')
|
logger.info('Decrypting messages...', terminal=True)
|
||||||
choice = ''
|
choice = ''
|
||||||
displayList = []
|
displayList = []
|
||||||
subject = ''
|
subject = ''
|
||||||
@ -108,7 +108,7 @@ class OnionrMail:
|
|||||||
displayList.append('%s. %s - %s - <%s>: %s' % (blockCount, blockDate, senderDisplay[:12], subject[:10], blockHash))
|
displayList.append('%s. %s - %s - <%s>: %s' % (blockCount, blockDate, senderDisplay[:12], subject[:10], blockHash))
|
||||||
while choice not in ('-q', 'q', 'quit'):
|
while choice not in ('-q', 'q', 'quit'):
|
||||||
for i in displayList:
|
for i in displayList:
|
||||||
logger.info(i)
|
logger.info(i, terminal=True)
|
||||||
try:
|
try:
|
||||||
choice = logger.readline('Enter a block number, -r to refresh, or -q to stop: ').strip().lower()
|
choice = logger.readline('Enter a block number, -r to refresh, or -q to stop: ').strip().lower()
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
@ -138,18 +138,18 @@ class OnionrMail:
|
|||||||
senderDisplay = self.myCore._utils.bytesToStr(readBlock.signer)
|
senderDisplay = self.myCore._utils.bytesToStr(readBlock.signer)
|
||||||
if len(senderDisplay.strip()) == 0:
|
if len(senderDisplay.strip()) == 0:
|
||||||
senderDisplay = 'Anonymous'
|
senderDisplay = 'Anonymous'
|
||||||
logger.info('Message received from %s' % (senderDisplay,))
|
logger.info('Message received from %s' % (senderDisplay,), terminal=True)
|
||||||
logger.info('Valid signature: %s' % readBlock.validSig)
|
logger.info('Valid signature: %s' % readBlock.validSig, terminal=True)
|
||||||
|
|
||||||
if not readBlock.validSig:
|
if not readBlock.validSig:
|
||||||
logger.warn('This message has an INVALID/NO signature. ANYONE could have sent this message.')
|
logger.warn('This message has an INVALID/NO signature. ANYONE could have sent this message.', terminal=True)
|
||||||
cancel = logger.readline('Press enter to continue to message, or -q to not open the message (recommended).')
|
cancel = logger.readline('Press enter to continue to message, or -q to not open the message (recommended).')
|
||||||
print('')
|
print('')
|
||||||
if cancel != '-q':
|
if cancel != '-q':
|
||||||
try:
|
try:
|
||||||
print(draw_border(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode().strip())))
|
print(draw_border(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode().strip())))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warn('Error presenting message. This is usually due to a malformed or blank message.')
|
logger.warn('Error presenting message. This is usually due to a malformed or blank message.', terminal=True)
|
||||||
pass
|
pass
|
||||||
if readBlock.validSig:
|
if readBlock.validSig:
|
||||||
reply = logger.readline("Press enter to continue, or enter %s to reply" % ("-r",))
|
reply = logger.readline("Press enter to continue, or enter %s to reply" % ("-r",))
|
||||||
@ -168,7 +168,7 @@ class OnionrMail:
|
|||||||
entering = True
|
entering = True
|
||||||
while entering:
|
while entering:
|
||||||
self.get_sent_list()
|
self.get_sent_list()
|
||||||
logger.info('Enter a block number or -q to return')
|
logger.info('Enter a block number or -q to return', terminal=True)
|
||||||
try:
|
try:
|
||||||
choice = input('>')
|
choice = input('>')
|
||||||
except (EOFError, KeyboardInterrupt) as e:
|
except (EOFError, KeyboardInterrupt) as e:
|
||||||
@ -182,11 +182,11 @@ class OnionrMail:
|
|||||||
try:
|
try:
|
||||||
self.sentboxList[int(choice)]
|
self.sentboxList[int(choice)]
|
||||||
except (IndexError, ValueError) as e:
|
except (IndexError, ValueError) as e:
|
||||||
logger.warn('Invalid block.')
|
logger.warn('Invalid block.', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.info('Sent to: ' + self.sentMessages[self.sentboxList[int(choice)]][1])
|
logger.info('Sent to: ' + self.sentMessages[self.sentboxList[int(choice)]][1], terminal=True)
|
||||||
# Print ansi escaped sent message
|
# Print ansi escaped sent message
|
||||||
logger.info(self.myCore._utils.escapeAnsi(self.sentMessages[self.sentboxList[int(choice)]][0]))
|
logger.info(self.myCore._utils.escapeAnsi(self.sentMessages[self.sentboxList[int(choice)]][0]), terminal=True)
|
||||||
input('Press enter to continue...')
|
input('Press enter to continue...')
|
||||||
finally:
|
finally:
|
||||||
if choice == '-q':
|
if choice == '-q':
|
||||||
@ -201,7 +201,7 @@ class OnionrMail:
|
|||||||
self.sentboxList.append(i['hash'])
|
self.sentboxList.append(i['hash'])
|
||||||
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'], i['subject'])
|
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'], i['subject'])
|
||||||
if display:
|
if display:
|
||||||
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']))
|
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']), terminal=True)
|
||||||
count += 1
|
count += 1
|
||||||
return json.dumps(self.sentMessages)
|
return json.dumps(self.sentMessages)
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ class OnionrMail:
|
|||||||
if not self.myCore._utils.validatePubKey(recip):
|
if not self.myCore._utils.validatePubKey(recip):
|
||||||
raise onionrexceptions.InvalidPubkey('Must be a valid ed25519 base32 encoded public key')
|
raise onionrexceptions.InvalidPubkey('Must be a valid ed25519 base32 encoded public key')
|
||||||
except onionrexceptions.InvalidPubkey:
|
except onionrexceptions.InvalidPubkey:
|
||||||
logger.warn('Invalid public key')
|
logger.warn('Invalid public key', terminal=True)
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
entering = False
|
entering = False
|
||||||
else:
|
else:
|
||||||
@ -234,7 +234,7 @@ class OnionrMail:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
cancelEnter = False
|
cancelEnter = False
|
||||||
logger.info('Enter your message, stop by entering -q on a new line. -c to cancel')
|
logger.info('Enter your message, stop by entering -q on a new line. -c to cancel', terminal=True)
|
||||||
while newLine != '-q':
|
while newLine != '-q':
|
||||||
try:
|
try:
|
||||||
newLine = input()
|
newLine = input()
|
||||||
@ -249,7 +249,7 @@ class OnionrMail:
|
|||||||
message += newLine
|
message += newLine
|
||||||
|
|
||||||
if not cancelEnter:
|
if not cancelEnter:
|
||||||
logger.info('Inserting encrypted message as Onionr block....')
|
logger.info('Inserting encrypted message as Onionr block....', terminal=True)
|
||||||
|
|
||||||
blockID = self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=self.doSigs, meta={'subject': subject})
|
blockID = self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=self.doSigs, meta={'subject': subject})
|
||||||
|
|
||||||
@ -261,16 +261,16 @@ class OnionrMail:
|
|||||||
while True:
|
while True:
|
||||||
sigMsg = 'Message Signing: %s'
|
sigMsg = 'Message Signing: %s'
|
||||||
|
|
||||||
logger.info(self.strings.programTag + '\n\nUser ID: ' + self.myCore._crypto.pubKey)
|
logger.info(self.strings.programTag + '\n\nUser ID: ' + self.myCore._crypto.pubKey, terminal=True)
|
||||||
if self.doSigs:
|
if self.doSigs:
|
||||||
sigMsg = sigMsg % ('enabled',)
|
sigMsg = sigMsg % ('enabled',)
|
||||||
else:
|
else:
|
||||||
sigMsg = sigMsg % ('disabled (Your messages cannot be trusted)',)
|
sigMsg = sigMsg % ('disabled (Your messages cannot be trusted)',)
|
||||||
if self.doSigs:
|
if self.doSigs:
|
||||||
logger.info(sigMsg)
|
logger.info(sigMsg, terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn(sigMsg)
|
logger.warn(sigMsg, terminal=True)
|
||||||
logger.info(self.strings.mainMenu.title()) # print out main menu
|
logger.info(self.strings.mainMenu.title(), terminal=True) # print out main menu
|
||||||
try:
|
try:
|
||||||
choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower().strip()
|
choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower().strip()
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
@ -285,12 +285,12 @@ class OnionrMail:
|
|||||||
elif choice in (self.strings.mainMenuChoices[3], '4'):
|
elif choice in (self.strings.mainMenuChoices[3], '4'):
|
||||||
self.toggle_signing()
|
self.toggle_signing()
|
||||||
elif choice in (self.strings.mainMenuChoices[4], '5'):
|
elif choice in (self.strings.mainMenuChoices[4], '5'):
|
||||||
logger.info('Goodbye.')
|
logger.info('Goodbye.', terminal=True)
|
||||||
break
|
break
|
||||||
elif choice == '':
|
elif choice == '':
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.warn('Invalid choice.')
|
logger.warn('Invalid choice.', terminal=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def add_deleted(keyStore, bHash):
|
def add_deleted(keyStore, bHash):
|
||||||
|
Loading…
Reference in New Issue
Block a user