Move default-plugins, debug gui
This commit is contained in:
parent
54a3557fd0
commit
07eb512977
3 changed files with 10 additions and 9 deletions
122
onionr/static-data/default_plugins/gui/main.py
Normal file
122
onionr/static-data/default_plugins/gui/main.py
Normal file
|
@ -0,0 +1,122 @@
|
|||
#!/usr/bin/python
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network
|
||||
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/>.
|
||||
'''
|
||||
|
||||
# Imports some useful libraries
|
||||
import logger, config
|
||||
import os, sqlite3, core
|
||||
|
||||
def sendMessage():
|
||||
global sendEntry
|
||||
|
||||
messageToAdd = '-txt-' + sendEntry.get()
|
||||
#addedHash = pluginapi.get_core().setData(messageToAdd)
|
||||
#pluginapi.get_core().addToBlockDB(addedHash, selfInsert=True)
|
||||
#pluginapi.get_core().setBlockType(addedHash, 'txt')
|
||||
pluginapi.get_core().insertBlock(messageToAdd, header='txt', sign=True)
|
||||
sendEntry.delete(0, END)
|
||||
|
||||
def update():
|
||||
global listedBlocks, listbox, runningCheckDelayCount, runningCheckDelay, root, daemonStatus
|
||||
|
||||
# TO DO: migrate to new header format
|
||||
for i in pluginapi.get_core().getBlocksByType('txt'):
|
||||
if i.strip() == '' or i in listedBlocks:
|
||||
continue
|
||||
blockFile = open('./data/blocks/' + i + '.dat')
|
||||
listbox.insert(END, str(blockFile.read().replace('-txt-', '')))
|
||||
blockFile.close()
|
||||
listedBlocks.append(i)
|
||||
listbox.see(END)
|
||||
blocksList = os.listdir('./data/blocks/') # dir is your directory path
|
||||
number_blocks = len(blocksList)
|
||||
runningCheckDelayCount += 1
|
||||
|
||||
if runningCheckDelayCount == runningCheckDelay:
|
||||
resp = pluginapi.get_core()._utils.localCommand('ping')
|
||||
if resp == 'pong':
|
||||
daemonStatus.config(text="Onionr Daemon Status: Running")
|
||||
else:
|
||||
daemonStatus.config(text="Onionr Daemon Status: Not Running")
|
||||
runningCheckDelayCount = 0
|
||||
root.after(10000, update)
|
||||
|
||||
|
||||
def openGUI():
|
||||
import tkinter
|
||||
global root, runningCheckDelay, runningCheckDelayCount, scrollbar, listedBlocks, nodeInfo, keyInfo, idText, idEntry, pubKeyEntry, listbox, daemonStatus, sendEntry
|
||||
|
||||
root = tkinter.Tk()
|
||||
|
||||
root.title("Onionr GUI")
|
||||
|
||||
runningCheckDelay = 5
|
||||
runningCheckDelayCount = 4
|
||||
|
||||
scrollbar = tkinter.Scrollbar(root)
|
||||
scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
|
||||
|
||||
listedBlocks = []
|
||||
|
||||
nodeInfo = tkinter.Frame(root)
|
||||
keyInfo = tkinter.Frame(root)
|
||||
|
||||
hostname = pluginapi.get_onionr().get_hostname()
|
||||
logger.debug('hostname: %s' % hostname)
|
||||
idText = hostname
|
||||
|
||||
idEntry = tkinter.Entry(nodeInfo)
|
||||
tkinter.Label(nodeInfo, text="Node Address: ").pack(side=tkinter.LEFT)
|
||||
idEntry.pack()
|
||||
idEntry.insert(0, idText.strip())
|
||||
idEntry.configure(state="readonly")
|
||||
|
||||
nodeInfo.pack()
|
||||
|
||||
pubKeyEntry = tkinter.Entry(keyInfo)
|
||||
|
||||
tkinter.Label(keyInfo, text="Public key: ").pack(side=tkinter.LEFT)
|
||||
|
||||
pubKeyEntry.pack()
|
||||
pubKeyEntry.insert(0, pluginapi.get_core()._crypto.pubKey)
|
||||
pubKeyEntry.configure(state="readonly")
|
||||
|
||||
keyInfo.pack()
|
||||
|
||||
sendEntry = tkinter.Entry(root)
|
||||
sendBtn = tkinter.Button(root, text='Send Message', command=sendMessage)
|
||||
sendEntry.pack(side=tkinter.TOP, pady=5)
|
||||
sendBtn.pack(side=tkinter.TOP)
|
||||
|
||||
listbox = tkinter.Listbox(root, yscrollcommand=tkinter.Scrollbar.set, height=15)
|
||||
|
||||
listbox.pack(fill=tkinter.BOTH, pady=25)
|
||||
|
||||
daemonStatus = tkinter.Label(root, text="Onionr Daemon Status: unknown")
|
||||
daemonStatus.pack()
|
||||
|
||||
scrollbar.config(command=tkinter.Listbox.yview)
|
||||
root.after(2000, update)
|
||||
root.mainloop()
|
||||
|
||||
def on_init(api, data = None):
|
||||
global pluginapi
|
||||
pluginapi = api
|
||||
|
||||
api.commands.register(['gui', 'launch-gui', 'open-gui'], openGUI)
|
||||
api.commands.register_help('gui', 'Opens a graphical interface for Onionr')
|
||||
|
||||
return
|
141
onionr/static-data/default_plugins/pluginmanager/main.py
Normal file
141
onionr/static-data/default_plugins/pluginmanager/main.py
Normal file
|
@ -0,0 +1,141 @@
|
|||
'''
|
||||
This is the future Onionr plugin manager. TODO: Add better description.
|
||||
'''
|
||||
|
||||
# useful libraries
|
||||
import logger, config
|
||||
import os, sys, json
|
||||
|
||||
plugin_name = 'pluginmanager'
|
||||
|
||||
keys_data = {'keys' : {}}
|
||||
|
||||
# key functions
|
||||
|
||||
def writeKeys():
|
||||
'''
|
||||
Serializes and writes the keystore in memory to file
|
||||
'''
|
||||
|
||||
file = open(keys_file, 'w')
|
||||
file.write(json.dumps(keys_data, indent=4, sort_keys=True))
|
||||
file.close()
|
||||
|
||||
def readKeys():
|
||||
'''
|
||||
Loads the keystore into memory
|
||||
'''
|
||||
|
||||
global keys_data
|
||||
keys_data = json.loads(open(keys_file).read())
|
||||
return keys_data
|
||||
|
||||
def getKey(plugin):
|
||||
'''
|
||||
Returns the public key for a given plugin
|
||||
'''
|
||||
|
||||
readKeys()
|
||||
return (keys_data['keys'][plugin] if plugin in keys_data['keys'] else None)
|
||||
|
||||
def saveKey(plugin, key):
|
||||
'''
|
||||
Saves the public key for a plugin to keystore
|
||||
'''
|
||||
|
||||
keys_data['keys'][plugin] = key
|
||||
writeKeys()
|
||||
|
||||
def check():
|
||||
'''
|
||||
Checks to make sure the keystore file still exists
|
||||
'''
|
||||
|
||||
global keys_file
|
||||
keys_file = pluginapi.plugins.get_data_folder(plugin_name) + 'keystore.json'
|
||||
if not os.path.isfile(keys_file):
|
||||
writeKeys()
|
||||
|
||||
# command handlers
|
||||
|
||||
def help():
|
||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin> [public key/block hash]')
|
||||
|
||||
def commandInstallPlugin():
|
||||
logger.warn('This feature is not functional or is still in development.')
|
||||
if len(sys.argv) >= 3:
|
||||
check()
|
||||
|
||||
pluginname = sys.argv[2]
|
||||
pkobh = None # public key or block hash
|
||||
|
||||
if len(sys.argv) >= 4:
|
||||
# public key or block hash specified
|
||||
pkobh = sys.argv[3]
|
||||
else:
|
||||
# none specified, check if in config file
|
||||
pkobh = getKey(pluginname)
|
||||
|
||||
if pkobh is None:
|
||||
logger.error('No key for this plugin found in keystore, please specify.')
|
||||
help()
|
||||
return True
|
||||
|
||||
valid_hash = pluginapi.get_utils().validateHash(pkobh)
|
||||
real_block = False
|
||||
valid_key = pluginapi.get_utils().validatePubKey(pkobh)
|
||||
real_key = False
|
||||
|
||||
if valid_hash:
|
||||
real_block = pluginapi.get_utils().hasBlock(pkobh)
|
||||
elif valid_key:
|
||||
real_key = pluginapi.get_utils().hasKey(pkobh)
|
||||
|
||||
blockhash = None
|
||||
|
||||
if valid_hash and not real_block:
|
||||
logger.error('Block hash not found. Perhaps it has not been synced yet?')
|
||||
logger.debug('Is valid hash, but does not belong to a known block.')
|
||||
return True
|
||||
elif valid_hash and real_block:
|
||||
blockhash = str(pkobh)
|
||||
logger.debug('Using block %s...' % blockhash)
|
||||
elif valid_key and not real_key:
|
||||
logger.error('Public key not found. Try adding the node by address manually, if possible.')
|
||||
logger.debug('Is valid key, but the key is not a known one.')
|
||||
elif valid_key and real_key:
|
||||
publickey = str(pkobh)
|
||||
logger.debug('Using public key %s...' % publickey)
|
||||
|
||||
saveKey(pluginname, pkobh)
|
||||
else:
|
||||
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh))
|
||||
return
|
||||
else:
|
||||
help()
|
||||
|
||||
return True
|
||||
|
||||
def commandUninstallPlugin():
|
||||
logger.info('This feature has not been created yet. Please check back later.')
|
||||
return
|
||||
|
||||
def commandSearchPlugin():
|
||||
logger.info('This feature has not been created yet. Please check back later.')
|
||||
return
|
||||
|
||||
# event listeners
|
||||
|
||||
def on_init(api, data = None):
|
||||
global pluginapi
|
||||
pluginapi = api
|
||||
check()
|
||||
|
||||
# register some commands
|
||||
api.commands.register(['install-plugin', 'installplugin', 'plugin-install', 'install', 'plugininstall'], commandInstallPlugin)
|
||||
api.commands.register(['remove-plugin', 'removeplugin', 'plugin-remove', 'uninstall-plugin', 'uninstallplugin', 'plugin-uninstall', 'uninstall', 'remove', 'pluginremove'], commandUninstallPlugin)
|
||||
api.commands.register(['search', 'filter-plugins', 'search-plugins', 'searchplugins', 'search-plugin', 'searchplugin', 'findplugin', 'find-plugin', 'filterplugin', 'plugin-search', 'pluginsearch'], commandSearchPlugin)
|
||||
|
||||
# add help menus once the features are actually implemented
|
||||
|
||||
return
|
Loading…
Add table
Add a link
Reference in a new issue