progress removing onionr.py
parent
3a90185cd3
commit
3409a2888f
|
@ -19,6 +19,7 @@
|
||||||
'''
|
'''
|
||||||
from onionrutils import bytesconverter
|
from onionrutils import bytesconverter
|
||||||
from onionrcrypto import generate
|
from onionrcrypto import generate
|
||||||
|
import os
|
||||||
import filepaths
|
import filepaths
|
||||||
class KeyManager:
|
class KeyManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -35,6 +36,7 @@ class KeyManager:
|
||||||
raise ValueError('Pubkey already in list: %s' % (pubKey,))
|
raise ValueError('Pubkey already in list: %s' % (pubKey,))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(self.keyFile, "a") as keyFile:
|
with open(self.keyFile, "a") as keyFile:
|
||||||
keyFile.write(pubKey + ',' + privKey + '\n')
|
keyFile.write(pubKey + ',' + privKey + '\n')
|
||||||
return (pubKey, privKey)
|
return (pubKey, privKey)
|
||||||
|
|
|
@ -1,162 +0,0 @@
|
||||||
'''
|
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
This module defines commands for CLI usage
|
|
||||||
'''
|
|
||||||
'''
|
|
||||||
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 <https://www.gnu.org/licenses/>.
|
|
||||||
'''
|
|
||||||
'''
|
|
||||||
import webbrowser, sys
|
|
||||||
import logger
|
|
||||||
from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders
|
|
||||||
from . import banblocks, exportblocks, openwebinterface, resettor, dopex
|
|
||||||
from onionrutils import importnewblocks
|
|
||||||
'''
|
|
||||||
def show_help(o_inst, command):
|
|
||||||
|
|
||||||
helpmenu = o_inst.getHelp()
|
|
||||||
|
|
||||||
if command is None and len(sys.argv) >= 3:
|
|
||||||
for cmd in sys.argv[2:]:
|
|
||||||
o_inst.showHelp(cmd)
|
|
||||||
elif not command is None:
|
|
||||||
if command.lower() in helpmenu:
|
|
||||||
logger.info(logger.colors.bold + command + logger.colors.reset + logger.colors.fg.blue + ' : ' + logger.colors.reset + helpmenu[command.lower()], timestamp = False)
|
|
||||||
else:
|
|
||||||
logger.warn(logger.colors.bold + command + logger.colors.reset + logger.colors.fg.blue + ' : ' + logger.colors.reset + 'No help menu entry was found', timestamp = False)
|
|
||||||
else:
|
|
||||||
o_inst.version(0)
|
|
||||||
for command, helpmessage in helpmenu.items():
|
|
||||||
o_inst.showHelp(command)
|
|
||||||
|
|
||||||
def get_commands(onionr_inst):
|
|
||||||
return {'': onionr_inst.showHelpSuggestion,
|
|
||||||
'help': onionr_inst.showHelp,
|
|
||||||
'start': onionr_inst.start,
|
|
||||||
'stop': onionr_inst.killDaemon,
|
|
||||||
'status': onionr_inst.showStats,
|
|
||||||
'statistics': onionr_inst.showStats,
|
|
||||||
'stats': onionr_inst.showStats,
|
|
||||||
'details' : onionr_inst.showDetails,
|
|
||||||
'detail' : onionr_inst.showDetails,
|
|
||||||
'show-details' : onionr_inst.showDetails,
|
|
||||||
'show-detail' : onionr_inst.showDetails,
|
|
||||||
'showdetails' : onionr_inst.showDetails,
|
|
||||||
'showdetail' : onionr_inst.showDetails,
|
|
||||||
'get-details' : onionr_inst.showDetails,
|
|
||||||
'get-detail' : onionr_inst.showDetails,
|
|
||||||
'getdetails' : onionr_inst.showDetails,
|
|
||||||
'getdetail' : onionr_inst.showDetails,
|
|
||||||
|
|
||||||
'enable-plugin': onionr_inst.enablePlugin,
|
|
||||||
'enplugin': onionr_inst.enablePlugin,
|
|
||||||
'enableplugin': onionr_inst.enablePlugin,
|
|
||||||
'enmod': onionr_inst.enablePlugin,
|
|
||||||
'disable-plugin': onionr_inst.disablePlugin,
|
|
||||||
'displugin': onionr_inst.disablePlugin,
|
|
||||||
'disableplugin': onionr_inst.disablePlugin,
|
|
||||||
'dismod': onionr_inst.disablePlugin,
|
|
||||||
'reload-plugin': onionr_inst.reloadPlugin,
|
|
||||||
'reloadplugin': onionr_inst.reloadPlugin,
|
|
||||||
'reload-plugins': onionr_inst.reloadPlugin,
|
|
||||||
'reloadplugins': onionr_inst.reloadPlugin,
|
|
||||||
'create-plugin': onionr_inst.createPlugin,
|
|
||||||
'createplugin': onionr_inst.createPlugin,
|
|
||||||
'plugin-create': onionr_inst.createPlugin,
|
|
||||||
|
|
||||||
'listkeys': onionr_inst.listKeys,
|
|
||||||
'list-keys': onionr_inst.listKeys,
|
|
||||||
|
|
||||||
'addpeer': onionr_inst.addPeer,
|
|
||||||
'add-peer': onionr_inst.addPeer,
|
|
||||||
'add-address': onionr_inst.addAddress,
|
|
||||||
'add-addr': onionr_inst.addAddress,
|
|
||||||
'addaddr': onionr_inst.addAddress,
|
|
||||||
'addaddress': onionr_inst.addAddress,
|
|
||||||
'list-peers': onionr_inst.listPeers,
|
|
||||||
|
|
||||||
'blacklist-block': onionr_inst.banBlock,
|
|
||||||
|
|
||||||
'add-file': onionr_inst.addFile,
|
|
||||||
'addfile': onionr_inst.addFile,
|
|
||||||
'addhtml': onionr_inst.addWebpage,
|
|
||||||
'add-html': onionr_inst.addWebpage,
|
|
||||||
'add-site': onionr_inst.addWebpage,
|
|
||||||
'addsite': onionr_inst.addWebpage,
|
|
||||||
|
|
||||||
'openhome': onionr_inst.openHome,
|
|
||||||
'open-home': onionr_inst.openHome,
|
|
||||||
|
|
||||||
'export-block': onionr_inst.exportBlock,
|
|
||||||
'exportblock': onionr_inst.exportBlock,
|
|
||||||
|
|
||||||
'get-file': onionr_inst.getFile,
|
|
||||||
'getfile': onionr_inst.getFile,
|
|
||||||
|
|
||||||
'listconn': onionr_inst.listConn,
|
|
||||||
'list-conn': onionr_inst.listConn,
|
|
||||||
|
|
||||||
'import-blocks': importnewblocks.import_new_blocks,
|
|
||||||
'importblocks': importnewblocks.import_new_blocks,
|
|
||||||
|
|
||||||
'pex': dopex.do_PEX,
|
|
||||||
|
|
||||||
'getpassword': onionr_inst.printWebPassword,
|
|
||||||
'get-password': onionr_inst.printWebPassword,
|
|
||||||
'getpwd': onionr_inst.printWebPassword,
|
|
||||||
'get-pwd': onionr_inst.printWebPassword,
|
|
||||||
'getpass': onionr_inst.printWebPassword,
|
|
||||||
'get-pass': onionr_inst.printWebPassword,
|
|
||||||
'getpasswd': onionr_inst.printWebPassword,
|
|
||||||
'get-passwd': onionr_inst.printWebPassword,
|
|
||||||
|
|
||||||
'friend': onionr_inst.friendCmd,
|
|
||||||
'addid': onionr_inst.addID,
|
|
||||||
'add-id': onionr_inst.addID,
|
|
||||||
'change-id': onionr_inst.changeID,
|
|
||||||
|
|
||||||
'reset-tor': resettor.reset_tor
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd_help = {
|
|
||||||
'help': 'Displays this Onionr help menu',
|
|
||||||
'version': 'Displays the Onionr version',
|
|
||||||
'config': 'Configures something and adds it to the file',
|
|
||||||
|
|
||||||
'start': 'Starts the Onionr daemon',
|
|
||||||
'stop': 'Stops the Onionr daemon',
|
|
||||||
|
|
||||||
'stats': 'Displays node statistics',
|
|
||||||
'details': 'Displays the web password, public key, and human readable public key',
|
|
||||||
|
|
||||||
'enable-plugin': 'Enables and starts a plugin',
|
|
||||||
'disable-plugin': 'Disables and stops a plugin',
|
|
||||||
'reload-plugin': 'Reloads a plugin',
|
|
||||||
'create-plugin': 'Creates directory structure for a plugin',
|
|
||||||
|
|
||||||
'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',
|
|
||||||
'pex': 'exchange addresses with peers (done automatically)',
|
|
||||||
'blacklist-block': 'deletes a block by hash and permanently removes it from your node',
|
|
||||||
'friend': '[add|remove] [public key/id]',
|
|
||||||
'add-id': 'Generate a new ID (key pair)',
|
|
||||||
'change-id': 'Change active ID',
|
|
||||||
'open-home': 'Open your node\'s home/info screen',
|
|
||||||
'reset-tor': 'Delete the Tor data directory. Only do this if Tor never starts.'
|
|
||||||
}
|
|
|
@ -21,15 +21,17 @@ import sys
|
||||||
import logger
|
import logger
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
from onionrstorage import removeblock
|
from onionrstorage import removeblock
|
||||||
def ban_block(o_inst):
|
import onionrblacklist
|
||||||
|
def ban_block():
|
||||||
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
try:
|
try:
|
||||||
ban = sys.argv[2]
|
ban = sys.argv[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
ban = logger.readline('Enter a block hash:')
|
ban = logger.readline('Enter a block hash:')
|
||||||
if stringvalidators.validate_hash(ban):
|
if stringvalidators.validate_hash(ban):
|
||||||
if not o_inst.blacklist.inBlacklist(ban):
|
if not blacklist.inBlacklist(ban):
|
||||||
try:
|
try:
|
||||||
o_inst.blacklist.addToDB(ban)
|
blacklist.addToDB(ban)
|
||||||
removeblock.remove_block(ban)
|
removeblock.remove_block(ban)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error('Could not blacklist block', error=error, terminal=True)
|
logger.error('Could not blacklist block', error=error, terminal=True)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
from coredb import daemonqueue
|
|
||||||
def do_PEX():
|
|
||||||
daemonqueue.daemon_queue_add('pex')
|
|
|
@ -23,7 +23,11 @@ import logger
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
from onionrblocks import insert
|
from onionrblocks import insert
|
||||||
def add_file(o_inst, singleBlock=False, blockType='bin'):
|
|
||||||
|
def add_html(singleBlock=True, blockType='html'):
|
||||||
|
add_file(singleBlock, blockType)
|
||||||
|
|
||||||
|
def add_file(singleBlock=False, blockType='bin'):
|
||||||
'''
|
'''
|
||||||
Adds a file to the onionr network
|
Adds a file to the onionr network
|
||||||
'''
|
'''
|
||||||
|
@ -46,7 +50,7 @@ def add_file(o_inst, singleBlock=False, blockType='bin'):
|
||||||
else:
|
else:
|
||||||
logger.error('%s add-file <filename>' % sys.argv[0], timestamp = False, terminal=True)
|
logger.error('%s add-file <filename>' % sys.argv[0], timestamp = False, terminal=True)
|
||||||
|
|
||||||
def getFile(o_inst):
|
def get_file():
|
||||||
'''
|
'''
|
||||||
Get a file from onionr blocks
|
Get a file from onionr blocks
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -20,21 +20,6 @@
|
||||||
import sys
|
import sys
|
||||||
import logger
|
import logger
|
||||||
from coredb import keydb
|
from coredb import keydb
|
||||||
def add_peer(o_inst):
|
|
||||||
try:
|
|
||||||
newPeer = sys.argv[2]
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if newPeer in keydb.listkeys.list_peers():
|
|
||||||
logger.info('We already have that key', terminal=True)
|
|
||||||
return
|
|
||||||
logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True)
|
|
||||||
try:
|
|
||||||
if keydb.addkeys.add_peer(newPeer):
|
|
||||||
logger.info('Successfully added key', terminal=True)
|
|
||||||
except AssertionError:
|
|
||||||
logger.error('Failed to add key', terminal=True)
|
|
||||||
|
|
||||||
def add_address():
|
def add_address():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -21,13 +21,15 @@ import os, uuid, time
|
||||||
import logger
|
import logger
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
from onionrutils import checkcommunicator, mnemonickeys
|
from onionrutils import checkcommunicator, mnemonickeys
|
||||||
from utils import sizeutils, gethostname, getconsolewidth
|
from utils import sizeutils, gethostname, getconsolewidth, identifyhome
|
||||||
from coredb import blockmetadb, daemonqueue, keydb
|
from coredb import blockmetadb, daemonqueue, keydb
|
||||||
import onionrcrypto, config
|
import onionrcrypto, config
|
||||||
def show_stats(o_inst):
|
from etc import onionrvalues
|
||||||
|
def show_stats():
|
||||||
try:
|
try:
|
||||||
# define stats messages here
|
# define stats messages here
|
||||||
totalBlocks = len(blockmetadb.get_block_list())
|
totalBlocks = len(blockmetadb.get_block_list())
|
||||||
|
home = identifyhome.identify_home()
|
||||||
signedBlocks = len(Block.getBlocks(signed = True))
|
signedBlocks = len(Block.getBlocks(signed = True))
|
||||||
messages = {
|
messages = {
|
||||||
# info about local client
|
# info about local client
|
||||||
|
@ -35,14 +37,14 @@ def show_stats(o_inst):
|
||||||
|
|
||||||
# file and folder size stats
|
# file and folder size stats
|
||||||
'div1' : True, # this creates a solid line across the screen, a div
|
'div1' : True, # this creates a solid line across the screen, a div
|
||||||
'Total Block Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'blocks/')),
|
'Total Block Size' : sizeutils.human_size(sizeutils.size(home + 'blocks/')),
|
||||||
'Total Plugin Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'plugins/')),
|
'Total Plugin Size' : sizeutils.human_size(sizeutils.size(home + 'plugins/')),
|
||||||
'Log File Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'output.log')),
|
'Log File Size' : sizeutils.human_size(sizeutils.size(home + 'output.log')),
|
||||||
|
|
||||||
# count stats
|
# count stats
|
||||||
'div2' : True,
|
'div2' : True,
|
||||||
'Known Peers' : str(max(len(keydb.listkeys.list_peers()) - 1, 0)),
|
'Known Peers' : str(max(len(keydb.listkeys.list_peers()) - 1, 0)),
|
||||||
'Enabled Plugins' : str(len(config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))),
|
'Enabled Plugins' : str(len(config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(home + 'plugins/'))),
|
||||||
'Stored Blocks' : str(totalBlocks),
|
'Stored Blocks' : str(totalBlocks),
|
||||||
'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%'
|
'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%'
|
||||||
}
|
}
|
||||||
|
@ -67,7 +69,7 @@ def show_stats(o_inst):
|
||||||
groupsize = width - prewidth - len('[+] ')
|
groupsize = width - prewidth - len('[+] ')
|
||||||
|
|
||||||
# generate stats table
|
# generate stats table
|
||||||
logger.info(colors['title'] + 'Onionr v%s Statistics' % onionr.ONIONR_VERSION + colors['reset'], terminal=True)
|
logger.info(colors['title'] + 'Onionr v%s Statistics' % onionrvalues.ONIONR_VERSION + colors['reset'], terminal=True)
|
||||||
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'], terminal=True)
|
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'], terminal=True)
|
||||||
for key, val in messages.items():
|
for key, val in messages.items():
|
||||||
if not (type(val) is bool and val is True):
|
if not (type(val) is bool and val is True):
|
||||||
|
|
|
@ -1,15 +1,32 @@
|
||||||
from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface
|
from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface
|
||||||
|
from .. import banblocks # Command to blacklist a block by its hash
|
||||||
|
from .. import filecommands # commands to share files with onionr
|
||||||
|
from .. import exportblocks # commands to export blocks
|
||||||
|
from .. import pubkeymanager # commands to add or change id
|
||||||
|
from .. import resettor # command to reset the tor data directory
|
||||||
import onionrexceptions
|
import onionrexceptions
|
||||||
|
from onionrutils import importnewblocks # func to import new blocks
|
||||||
import onionrevents as events
|
import onionrevents as events
|
||||||
def get_arguments():
|
def get_arguments():
|
||||||
'''This is a function because we need to be able to dynamically modify them with plugins'''
|
'''This is a function because we need to be able to dynamically modify them with plugins'''
|
||||||
args = {
|
args = {
|
||||||
|
('blacklist', 'blacklist-block', 'remove-block', 'removeblock'): banblocks.ban_block,
|
||||||
('details', 'info'): onionrstatistics.show_details,
|
('details', 'info'): onionrstatistics.show_details,
|
||||||
|
('stats', 'statistics'): onionrstatistics.show_stats,
|
||||||
('version'): version.version,
|
('version'): version.version,
|
||||||
('start', 'daemon'): daemonlaunch.start,
|
('start', 'daemon'): daemonlaunch.start,
|
||||||
('stop', 'kill'): daemonlaunch.kill_daemon,
|
('stop', 'kill'): daemonlaunch.kill_daemon,
|
||||||
('add-address', 'addaddress', 'addadder'): keyadders.add_address,
|
('add-address', 'addaddress', 'addadder'): keyadders.add_address,
|
||||||
('openhome', 'gui', 'openweb', 'open-home', 'open-web'): openwebinterface.open_home
|
('openhome', 'gui', 'openweb', 'open-home', 'open-web'): openwebinterface.open_home,
|
||||||
|
('add-site', 'addsite', 'addhtml', 'add-html'): filecommands.add_html,
|
||||||
|
('addfile', 'add-file'): filecommands.add_file,
|
||||||
|
('get-file', 'getfile'): filecommands.get_file,
|
||||||
|
('export-block', 'exportblock'): exportblocks.export_block,
|
||||||
|
('importblocks', 'import-blocks'): importnewblocks.import_new_blocks,
|
||||||
|
('addid', 'add-id'): pubkeymanager.add_ID,
|
||||||
|
('changeid', 'change-id'): pubkeymanager.change_ID,
|
||||||
|
('resettor', 'reset-tor'): resettor.reset_tor
|
||||||
|
|
||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
'''
|
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
plugin CLI commands
|
|
||||||
'''
|
|
||||||
'''
|
|
||||||
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 <https://www.gnu.org/licenses/>.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import logger, onionrplugins as plugins
|
|
||||||
|
|
||||||
def enable_plugin(o_inst):
|
|
||||||
if len(sys.argv) >= 3:
|
|
||||||
plugin_name = sys.argv[2]
|
|
||||||
logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
|
|
||||||
plugins.enable(plugin_name, o_inst)
|
|
||||||
else:
|
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
|
||||||
|
|
||||||
def disable_plugin(o_inst):
|
|
||||||
if len(sys.argv) >= 3:
|
|
||||||
plugin_name = sys.argv[2]
|
|
||||||
logger.info('Disabling plugin "%s"...' % plugin_name, terminal=True)
|
|
||||||
plugins.disable(plugin_name, o_inst)
|
|
||||||
else:
|
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
|
||||||
|
|
||||||
def reload_plugin(o_inst):
|
|
||||||
'''
|
|
||||||
Reloads (stops and starts) all plugins, or the given plugin
|
|
||||||
'''
|
|
||||||
|
|
||||||
if len(sys.argv) >= 3:
|
|
||||||
plugin_name = sys.argv[2]
|
|
||||||
logger.info('Reloading plugin "%s"...' % plugin_name, terminal=True)
|
|
||||||
plugins.stop(plugin_name, o_inst)
|
|
||||||
plugins.start(plugin_name, o_inst)
|
|
||||||
else:
|
|
||||||
logger.info('Reloading all plugins...', terminal=True)
|
|
||||||
plugins.reload(o_inst)
|
|
||||||
|
|
||||||
|
|
||||||
def create_plugin(o_inst):
|
|
||||||
'''
|
|
||||||
Creates the directory structure for a plugin name
|
|
||||||
'''
|
|
||||||
|
|
||||||
if len(sys.argv) >= 3:
|
|
||||||
try:
|
|
||||||
plugin_name = re.sub('[^0-9a-zA-Z_]+', '', str(sys.argv[2]).lower())
|
|
||||||
|
|
||||||
if not plugins.exists(plugin_name):
|
|
||||||
logger.info('Creating plugin "%s"...' % plugin_name, terminal=True)
|
|
||||||
|
|
||||||
os.makedirs(plugins.get_plugins_folder(plugin_name))
|
|
||||||
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
|
|
||||||
contents = ''
|
|
||||||
with open('static-data/default_plugin.py', 'rb') as file:
|
|
||||||
contents = file.read().decode()
|
|
||||||
|
|
||||||
# TODO: Fix $user. os.getlogin() is B U G G Y
|
|
||||||
main.write(contents.replace('$user', 'some random developer').replace('$date', datetime.datetime.now().strftime('%Y-%m-%d')).replace('$name', plugin_name))
|
|
||||||
|
|
||||||
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'}))
|
|
||||||
|
|
||||||
logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
|
|
||||||
plugins.enable(plugin_name, o_inst)
|
|
||||||
else:
|
|
||||||
logger.warn('Cannot create plugin directory structure; plugin "%s" exists.' % plugin_name, terminal=True)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Failed to create plugin directory structure.', e, terminal=True)
|
|
||||||
else:
|
|
||||||
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]), terminal=True)
|
|
|
@ -22,12 +22,13 @@ import sys, getpass
|
||||||
import logger, onionrexceptions
|
import logger, onionrexceptions
|
||||||
from onionrutils import stringvalidators, bytesconverter
|
from onionrutils import stringvalidators, bytesconverter
|
||||||
from onionrusers import onionrusers, contactmanager
|
from onionrusers import onionrusers, contactmanager
|
||||||
|
import config
|
||||||
from coredb import keydb
|
from coredb import keydb
|
||||||
import keymanager, onionrcrypto
|
import keymanager, onionrcrypto
|
||||||
import unpaddedbase32
|
import unpaddedbase32
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
DETERMINISTIC_REQUIREMENT = onionrvalues.PASSWORD_LENGTH
|
DETERMINISTIC_REQUIREMENT = onionrvalues.PASSWORD_LENGTH
|
||||||
def add_ID(o_inst):
|
def add_ID():
|
||||||
key_manager = keymanager.KeyManager()
|
key_manager = keymanager.KeyManager()
|
||||||
try:
|
try:
|
||||||
sys.argv[2]
|
sys.argv[2]
|
||||||
|
@ -58,7 +59,7 @@ def add_ID(o_inst):
|
||||||
return
|
return
|
||||||
logger.info('Added ID: %s' % (bytesconverter.bytes_to_str(newID),), terminal=True)
|
logger.info('Added ID: %s' % (bytesconverter.bytes_to_str(newID),), terminal=True)
|
||||||
|
|
||||||
def change_ID(o_inst):
|
def change_ID():
|
||||||
key_manager = keymanager.KeyManager()
|
key_manager = keymanager.KeyManager()
|
||||||
try:
|
try:
|
||||||
key = sys.argv[2]
|
key = sys.argv[2]
|
||||||
|
@ -68,48 +69,11 @@ def change_ID(o_inst):
|
||||||
else:
|
else:
|
||||||
if stringvalidators.validate_pub_key(key):
|
if stringvalidators.validate_pub_key(key):
|
||||||
if key in key_manager.getPubkeyList():
|
if key in key_manager.getPubkeyList():
|
||||||
o_inst.config.set('general.public_key', key)
|
config.set('general.public_key', key)
|
||||||
o_inst.config.save()
|
config.save()
|
||||||
logger.info('Set active key to: %s' % (key,), terminal=True)
|
logger.info('Set active key to: %s' % (key,), terminal=True)
|
||||||
logger.info('Restart Onionr if it is running.', terminal=True)
|
logger.info('Restart Onionr if it is running.', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn('That key does not exist', terminal=True)
|
logger.warn('That key does not exist', terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn('Invalid key %s' % (key,), terminal=True)
|
logger.warn('Invalid key %s' % (key,), terminal=True)
|
||||||
|
|
||||||
def friend_command(o_inst):
|
|
||||||
friend = ''
|
|
||||||
try:
|
|
||||||
# Get the friend command
|
|
||||||
action = sys.argv[2]
|
|
||||||
except IndexError:
|
|
||||||
logger.info('Syntax: friend add/remove/list [address]', terminal=True)
|
|
||||||
else:
|
|
||||||
action = action.lower()
|
|
||||||
if action == 'list':
|
|
||||||
# List out peers marked as our friend
|
|
||||||
for friend in contactmanager.ContactManager.list_friends():
|
|
||||||
logger.info(friend.publicKey + ' - ' + friend.get_info('name'), terminal=True)
|
|
||||||
elif action in ('add', 'remove'):
|
|
||||||
try:
|
|
||||||
friend = sys.argv[3]
|
|
||||||
if not stringvalidators.validate_pub_key(friend):
|
|
||||||
raise onionrexceptions.InvalidPubkey('Public key is invalid')
|
|
||||||
if friend not in keydb.listkeys.list_peers():
|
|
||||||
raise onionrexceptions.KeyNotKnown
|
|
||||||
friend = onionrusers.OnionrUser(friend)
|
|
||||||
except IndexError:
|
|
||||||
logger.warn('Friend ID is required.', terminal=True)
|
|
||||||
action = 'error' # set to 'error' so that the finally block does not process anything
|
|
||||||
except onionrexceptions.KeyNotKnown:
|
|
||||||
o_inst.addPeer(friend)
|
|
||||||
friend = onionrusers.OnionrUser(friend)
|
|
||||||
finally:
|
|
||||||
if action == 'add':
|
|
||||||
friend.setTrust(1)
|
|
||||||
logger.info('Added %s as friend.' % (friend.publicKey,), terminal=True)
|
|
||||||
elif action == 'remove':
|
|
||||||
friend.setTrust(0)
|
|
||||||
logger.info('Removed %s as friend.' % (friend.publicKey,), terminal=True)
|
|
||||||
else:
|
|
||||||
logger.info('Syntax: friend add/remove/list [address]', terminal=True)
|
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"name" : "contactmanager",
|
|
||||||
"version" : "1.0",
|
|
||||||
"author" : "onionr"
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
'''
|
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
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 <https://www.gnu.org/licenses/>.
|
|
||||||
'''
|
|
||||||
|
|
||||||
plugin_name = 'contactmanager'
|
|
||||||
|
|
||||||
class OnionrContactManager:
|
|
||||||
def __init__(self, api):
|
|
||||||
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 = OnionrContactManager(api)
|
|
||||||
#api.commands.register('interactive', ui.start)
|
|
||||||
return
|
|
|
@ -113,6 +113,8 @@ def on_init(api, data = None):
|
||||||
def on_processblocks(api, data=None):
|
def on_processblocks(api, data=None):
|
||||||
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
|
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
|
||||||
metadata = data['block'].bmetadata # Get the block metadata
|
metadata = data['block'].bmetadata # Get the block metadata
|
||||||
|
if data['block'].bheader['type'] != 'brd':
|
||||||
|
return
|
||||||
|
|
||||||
# Validate the channel name is sane for caching
|
# Validate the channel name is sane for caching
|
||||||
try:
|
try:
|
||||||
|
@ -120,9 +122,9 @@ def on_processblocks(api, data=None):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
ch = 'global'
|
ch = 'global'
|
||||||
ch_len = len(ch)
|
ch_len = len(ch)
|
||||||
if len(metadata['ch']) == 0:
|
if ch_len == 0:
|
||||||
ch = 'global'
|
ch = 'global'
|
||||||
elif len(metadata['ch']) > 12:
|
elif ch_len > 12:
|
||||||
return
|
return
|
||||||
|
|
||||||
existing_posts = board_cache.get(ch)
|
existing_posts = board_cache.get(ch)
|
||||||
|
|
|
@ -4,12 +4,16 @@ sys.path.append(".")
|
||||||
import unittest, uuid
|
import unittest, uuid
|
||||||
TEST_DIR_1 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
TEST_DIR_1 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||||
TEST_DIR_2 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
TEST_DIR_2 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||||
import onionr, time
|
import time
|
||||||
|
|
||||||
|
os.environ["ONIONR_HOME"] = TEST_DIR_1
|
||||||
|
from utils import createdirs
|
||||||
|
createdirs.create_dirs()
|
||||||
|
|
||||||
import onionrexceptions, onionrcrypto as crypto
|
import onionrexceptions, onionrcrypto as crypto
|
||||||
from onionrusers import onionrusers
|
from onionrusers import onionrusers
|
||||||
from onionrusers import contactmanager
|
from onionrusers import contactmanager
|
||||||
from utils import createdirs
|
|
||||||
|
|
||||||
class OnionrForwardSecrecyTests(unittest.TestCase):
|
class OnionrForwardSecrecyTests(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
|
@ -17,8 +21,6 @@ class OnionrForwardSecrecyTests(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def test_forward_encrypt(self):
|
def test_forward_encrypt(self):
|
||||||
os.environ["ONIONR_HOME"] = TEST_DIR_1
|
|
||||||
createdirs.create_dirs()
|
|
||||||
|
|
||||||
friend = crypto.generate()
|
friend = crypto.generate()
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ sys.path.append(".")
|
||||||
import unittest, uuid, hashlib, base64
|
import unittest, uuid, hashlib, base64
|
||||||
import nacl.exceptions
|
import nacl.exceptions
|
||||||
import nacl.signing, nacl.hash, nacl.encoding
|
import nacl.signing, nacl.hash, nacl.encoding
|
||||||
from onionrutils import stringvalidators, mnemonickeys
|
|
||||||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||||
print("Test directory:", TEST_DIR)
|
print("Test directory:", TEST_DIR)
|
||||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||||
|
from utils import createdirs
|
||||||
|
createdirs.create_dirs()
|
||||||
|
from onionrutils import stringvalidators, mnemonickeys
|
||||||
import onionrcrypto as crypto, onionrexceptions
|
import onionrcrypto as crypto, onionrexceptions
|
||||||
|
|
||||||
class OnionrCryptoTests(unittest.TestCase):
|
class OnionrCryptoTests(unittest.TestCase):
|
||||||
|
|
|
@ -8,10 +8,10 @@ print("Test directory:", TEST_DIR)
|
||||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||||
from utils import createdirs
|
from utils import createdirs
|
||||||
from coredb import keydb
|
from coredb import keydb
|
||||||
import setupconfig, keymanager, filepaths
|
import setup, keymanager, filepaths
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
createdirs.create_dirs()
|
createdirs.create_dirs()
|
||||||
setupconfig.setup_config()
|
setup.setup_config()
|
||||||
pub_key = keymanager.KeyManager().getPubkeyList()[0]
|
pub_key = keymanager.KeyManager().getPubkeyList()[0]
|
||||||
class KeyManagerTest(unittest.TestCase):
|
class KeyManagerTest(unittest.TestCase):
|
||||||
def test_sane_default(self):
|
def test_sane_default(self):
|
||||||
|
|
|
@ -8,10 +8,10 @@ print("Test directory:", TEST_DIR)
|
||||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||||
from utils import networkmerger, createdirs
|
from utils import networkmerger, createdirs
|
||||||
from coredb import keydb
|
from coredb import keydb
|
||||||
import setupconfig
|
import setup
|
||||||
from utils import createdirs
|
from utils import createdirs
|
||||||
createdirs.create_dirs()
|
createdirs.create_dirs()
|
||||||
setupconfig.setup_config()
|
setup.setup_config()
|
||||||
class NetworkMergerTest(unittest.TestCase):
|
class NetworkMergerTest(unittest.TestCase):
|
||||||
def test_valid_merge(self):
|
def test_valid_merge(self):
|
||||||
adders = 'facebookcorewwwi.onion,mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion'
|
adders = 'facebookcorewwwi.onion,mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion'
|
||||||
|
|
Loading…
Reference in New Issue