work on plugins doing http endpoints

This commit is contained in:
Kevin Froman 2019-03-02 00:22:59 -06:00
parent 11625b297a
commit c89bf5b430
31 changed files with 76 additions and 17 deletions

0
.gitlab-ci.yml Normal file → Executable file
View File

View File

@ -2,6 +2,9 @@ PREFIX = /usr/local
.DEFAULT_GOAL := setup .DEFAULT_GOAL := setup
SHELL := env ONIONR_HOME=$(ONIONR_HOME) $(SHELL)
ONIONR_HOME ?= "data"
setup: setup:
sudo pip3 install -r requirements.txt sudo pip3 install -r requirements.txt
-@cd onionr/static-data/ui/; ./compile.py -@cd onionr/static-data/ui/; ./compile.py

0
onionr/__init__.py Normal file → Executable file
View File

View File

@ -25,7 +25,8 @@ import sys, random, threading, hmac, base64, time, os, json, socket
import core import core
from onionrblockapi import Block from onionrblockapi import Block
import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config
from httpapi import friendsapi import httpapi
from httpapi import friendsapi, simplecache
import onionr import onionr
class FDSafeHandler(WSGIHandler): class FDSafeHandler(WSGIHandler):
@ -279,6 +280,8 @@ class API:
self.queueResponse = {} self.queueResponse = {}
onionrInst.setClientAPIInst(self) onionrInst.setClientAPIInst(self)
app.register_blueprint(friendsapi.friends) app.register_blueprint(friendsapi.friends)
app.register_blueprint(simplecache.simplecache)
httpapi.load_plugin_blueprints(app)
@app.before_request @app.before_request
def validateRequest(): def validateRequest():
@ -521,13 +524,13 @@ class API:
responseTimeout = 20 responseTimeout = 20
startTime = self._core._utils.getEpoch() startTime = self._core._utils.getEpoch()
postData = {} postData = {}
print('spth', subpath)
if request.method == 'POST': if request.method == 'POST':
postData = request.form['postData'] postData = request.form['postData']
if len(subpath) > 1: if len(subpath) > 1:
data = subpath.split('/') data = subpath.split('/')
if len(data) > 1: if len(data) > 1:
plName = data[0] plName = data[0]
events.event('pluginRequest', {'name': plName, 'path': subpath, 'pluginResponse': pluginResponseCode, 'postData': postData}, onionr=onionrInst) events.event('pluginRequest', {'name': plName, 'path': subpath, 'pluginResponse': pluginResponseCode, 'postData': postData}, onionr=onionrInst)
while True: while True:
try: try:

0
onionr/communicatorutils/onionrcommunicatortimers.py Normal file → Executable file
View File

View File

@ -19,7 +19,7 @@
''' '''
import sqlite3, os, sys, time, math, base64, tarfile, nacl, logger, json, netcontroller, math, config, uuid import sqlite3, os, sys, time, math, base64, tarfile, nacl, logger, json, netcontroller, math, config, uuid
from onionrblockapi import Block from onionrblockapi import Block
import deadsimplekv as simplekv
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions
import onionrblacklist import onionrblacklist
from onionrusers import onionrusers from onionrusers import onionrusers
@ -65,6 +65,7 @@ class Core:
self.dataNonceFile = self.dataDir + 'block-nonces.dat' self.dataNonceFile = self.dataDir + 'block-nonces.dat'
self.dbCreate = dbcreator.DBCreator(self) self.dbCreate = dbcreator.DBCreator(self)
self.forwardKeysFile = self.dataDir + 'forward-keys.db' self.forwardKeysFile = self.dataDir + 'forward-keys.db'
#self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
# Socket data, defined here because of multithreading constraints with gevent # Socket data, defined here because of multithreading constraints with gevent
self.killSockets = False self.killSockets = False
@ -105,7 +106,6 @@ class Core:
logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation) logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation)
self._utils = onionrutils.OnionrUtils(self) self._utils = onionrutils.OnionrUtils(self)
self.blockCache = onionrstorage.BlockCache()
# Initialize the crypto object # Initialize the crypto object
self._crypto = onionrcrypto.OnionrCrypto(self) self._crypto = onionrcrypto.OnionrCrypto(self)
self._blacklist = onionrblacklist.OnionrBlackList(self) self._blacklist = onionrblacklist.OnionrBlackList(self)

10
onionr/httpapi/__init__.py Executable file
View File

@ -0,0 +1,10 @@
from flask import request
import onionrplugins
def load_plugin_blueprints(flaskapp):
for plugin in onionrplugins.get_enabled_plugins():
plugin = onionrplugins.get_plugin(plugin)
try:
flaskapp.register_blueprint(getattr(plugin, 'flask_blueprint'))
except AttributeError:
pass

0
onionr/httpapi/friendsapi/__init__.py Normal file → Executable file
View File

View File

@ -0,0 +1,31 @@
'''
Onionr - P2P Anonymous Storage Network
This file creates http endpoints for friend management
'''
'''
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 core
from flask import Blueprint, Response, request, abort
simplecache = Blueprint('simplecache', __name__)
@simplecache.route('/get/<key>')
def get_key(key):
return
@simplecache.route('/set/<key>', methods=['POST'])
def set_key(key):
return

0
onionr/onionrfragment.py Normal file → Executable file
View File

View File

@ -59,7 +59,6 @@ def reload(onionr = None, stop_event = True):
return False return False
def enable(name, onionr = None, start_event = True): def enable(name, onionr = None, start_event = True):
''' '''
Enables a plugin Enables a plugin

View File

@ -21,13 +21,6 @@ import core, sys, sqlite3, os, dbcreator
DB_ENTRY_SIZE_LIMIT = 10000 # Will be a config option DB_ENTRY_SIZE_LIMIT = 10000 # Will be a config option
class BlockCache:
def __init__(self):
self.blocks = {}
def cleanCache(self):
while sys.getsizeof(self.blocks) > 100000000:
self.blocks.pop(list(self.blocks.keys())[0])
def dbCreate(coreInst): def dbCreate(coreInst):
try: try:
dbcreator.DBCreator(coreInst).createBlockDataDB() dbcreator.DBCreator(coreInst).createBlockDataDB()
@ -84,7 +77,6 @@ def store(coreInst, data, blockHash=''):
else: else:
with open('%s/%s.dat' % (coreInst.blockDataLocation, blockHash), 'wb') as blockFile: with open('%s/%s.dat' % (coreInst.blockDataLocation, blockHash), 'wb') as blockFile:
blockFile.write(data) blockFile.write(data)
coreInst.blockCache.cleanCache()
def getData(coreInst, bHash): def getData(coreInst, bHash):
assert isinstance(coreInst, core.Core) assert isinstance(coreInst, core.Core)

0
onionr/onionrusers/contactmanager.py Normal file → Executable file
View File

View File

View File

View File

@ -23,15 +23,21 @@ import logger, config, threading, time, readline, datetime
from onionrblockapi import Block from onionrblockapi import Block
import onionrexceptions import onionrexceptions
from onionrusers import onionrusers from onionrusers import onionrusers
from flask import Response, request, redirect, Blueprint
import locale, sys, os, json import locale, sys, os, json
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
plugin_name = 'pms'
PLUGIN_VERSION = '0.0.1'
flask_blueprint = Blueprint('mail', __name__)
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import sentboxdb # import after path insert import sentboxdb # import after path insert
plugin_name = 'pms' @flask_blueprint.route('/mailhello')
PLUGIN_VERSION = '0.0.1' def mailhello():
return "hello world from mail"
def draw_border(text): def draw_border(text):
#https://stackoverflow.com/a/20757491 #https://stackoverflow.com/a/20757491
@ -190,7 +196,6 @@ class OnionrMail:
finally: finally:
if choice == '-q': if choice == '-q':
entering = False entering = False
return return
def get_sent_list(self, display=True): def get_sent_list(self, display=True):
@ -293,6 +298,15 @@ class OnionrMail:
logger.warn('Invalid choice.') logger.warn('Invalid choice.')
return return
def add_deleted(keyStore, bHash):
existing = keyStore.get('deleted_mail')
if existing is None:
existing = []
else:
if bHash in existing:
return
keyStore.put('deleted_mail', existing.append(bHash))
def on_insertblock(api, data={}): def on_insertblock(api, data={}):
sentboxTools = sentboxdb.SentBox(api.get_core()) sentboxTools = sentboxdb.SentBox(api.get_core())
meta = json.loads(data['meta']) meta = json.loads(data['meta'])
@ -306,11 +320,17 @@ def on_pluginrequest(api, data=None):
postData = {} postData = {}
blockID = '' blockID = ''
sentboxTools = sentboxdb.SentBox(api.get_core()) sentboxTools = sentboxdb.SentBox(api.get_core())
keyStore = api.get_core().keyStore
if data['name'] == 'mail': if data['name'] == 'mail':
path = data['path'] path = data['path']
print(cmd)
cmd = path.split('/')[1] cmd = path.split('/')[1]
if cmd == 'sentbox': if cmd == 'sentbox':
resp = OnionrMail(api).get_sent_list(display=False) resp = OnionrMail(api).get_sent_list(display=False)
elif cmd == 'deletemsg':
print('path', data['path'])
#add_deleted(keyStore, data['path'].split('/')[2])
resp = 'success'
if resp != '': if resp != '':
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
@ -325,4 +345,5 @@ def on_init(api, data = None):
mail = OnionrMail(pluginapi) mail = OnionrMail(pluginapi)
api.commands.register(['mail'], mail.menu) api.commands.register(['mail'], mail.menu)
api.commands.register_help('mail', 'Interact with OnionrMail') api.commands.register_help('mail', 'Interact with OnionrMail')
print("YEET2")
return return

0
onionr/static-data/www/friends/friends.js Normal file → Executable file
View File

0
onionr/static-data/www/friends/index.html Normal file → Executable file
View File

0
onionr/static-data/www/friends/style.css Normal file → Executable file
View File

View File

@ -233,7 +233,6 @@ for (var i = 0; i < idStrings.length; i++){
} }
} }
for (var i = 0; i < document.getElementsByClassName('refresh').length; i++){ for (var i = 0; i < document.getElementsByClassName('refresh').length; i++){
document.getElementsByClassName('refresh')[i].style.float = 'right' document.getElementsByClassName('refresh')[i].style.float = 'right'
} }

0
onionr/static-data/www/mail/sendmail.js Normal file → Executable file
View File

0
onionr/tests/test_blocks.py Normal file → Executable file
View File

0
onionr/tests/test_database_actions.py Normal file → Executable file
View File

0
onionr/tests/test_database_creation.py Normal file → Executable file
View File

0
onionr/tests/test_forward_secrecy.py Normal file → Executable file
View File

0
onionr/tests/test_highlevelcrypto.py Normal file → Executable file
View File

0
onionr/tests/test_onionrusers.py Normal file → Executable file
View File

0
onionr/tests/test_stringvalidations.py Normal file → Executable file
View File

0
onionr/utils/netutils.py Normal file → Executable file
View File

0
onionr/utils/networkmerger.py Normal file → Executable file
View File

View File

@ -6,3 +6,4 @@ defusedxml==0.5.0
Flask==1.0.2 Flask==1.0.2
PySocks==1.6.8 PySocks==1.6.8
stem==1.6.0 stem==1.6.0
deadsimplekv==0.0.1