moving mail over to blueprint system
parent
c89bf5b430
commit
c45c016123
3
Makefile
3
Makefile
|
@ -2,9 +2,6 @@ PREFIX = /usr/local
|
|||
|
||||
.DEFAULT_GOAL := setup
|
||||
|
||||
SHELL := env ONIONR_HOME=$(ONIONR_HOME) $(SHELL)
|
||||
ONIONR_HOME ?= "data"
|
||||
|
||||
setup:
|
||||
sudo pip3 install -r requirements.txt
|
||||
-@cd onionr/static-data/ui/; ./compile.py
|
||||
|
|
|
@ -251,9 +251,6 @@ class API:
|
|||
This initilization defines all of the API entry points and handlers for the endpoints and errors
|
||||
This also saves the used host (random localhost IP address) to the data folder in host.txt
|
||||
'''
|
||||
# assert isinstance(onionrInst, onionr.Onionr)
|
||||
# configure logger and stuff
|
||||
#onionr.Onionr.setupConfig('data/', self = self)
|
||||
|
||||
self.debug = debug
|
||||
self._core = onionrInst.onionrCore
|
||||
|
@ -524,7 +521,6 @@ class API:
|
|||
responseTimeout = 20
|
||||
startTime = self._core._utils.getEpoch()
|
||||
postData = {}
|
||||
print('spth', subpath)
|
||||
if request.method == 'POST':
|
||||
postData = request.form['postData']
|
||||
if len(subpath) > 1:
|
||||
|
|
|
@ -65,7 +65,7 @@ class Core:
|
|||
self.dataNonceFile = self.dataDir + 'block-nonces.dat'
|
||||
self.dbCreate = dbcreator.DBCreator(self)
|
||||
self.forwardKeysFile = self.dataDir + 'forward-keys.db'
|
||||
#self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
|
||||
self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
|
||||
|
||||
# Socket data, defined here because of multithreading constraints with gevent
|
||||
self.killSockets = False
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
from flask import request
|
||||
'''
|
||||
Onionr - P2P Anonymous Storage Network
|
||||
|
||||
This file registers plugin's flask blueprints for the client http server
|
||||
'''
|
||||
'''
|
||||
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 onionrplugins
|
||||
|
||||
def load_plugin_blueprints(flaskapp):
|
||||
'''Iterate enabled plugins and load any http endpoints they have'''
|
||||
for plugin in onionrplugins.get_enabled_plugins():
|
||||
plugin = onionrplugins.get_plugin(plugin)
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import onionrblockapi
|
||||
def load_inbox(myCore):
|
||||
inbox_list = []
|
||||
deleted = myCore.keyStore.get('deleted_mail')
|
||||
if deleted is None:
|
||||
deleted = []
|
||||
|
||||
for blockHash in myCore.getBlocksByType('pm'):
|
||||
block = onionrblockapi.Block(blockHash, core=myCore)
|
||||
block.decrypt()
|
||||
if block.decrypted and blockHash not in deleted:
|
||||
inbox_list.append(blockHash)
|
||||
return inbox_list
|
|
@ -0,0 +1,43 @@
|
|||
'''
|
||||
Onionr - P2P Anonymous Storage Network
|
||||
|
||||
HTTP endpoints for mail plugin.
|
||||
'''
|
||||
'''
|
||||
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, os
|
||||
from flask import Response, request, redirect, Blueprint
|
||||
import core
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import loadinbox
|
||||
|
||||
flask_blueprint = Blueprint('mail', __name__)
|
||||
c = core.Core()
|
||||
kv = c.keyStore
|
||||
|
||||
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
||||
def mail_delete(block):
|
||||
assert c._utils.validateHash(block)
|
||||
existing = kv.get('deleted_mail')
|
||||
if existing is None:
|
||||
existing = []
|
||||
if block not in existing:
|
||||
existing.append(block)
|
||||
kv.put('deleted_mail', existing)
|
||||
return 'success'
|
||||
|
||||
@flask_blueprint.route('/mail/getinbox')
|
||||
def list_inbox():
|
||||
return ','.join(loadinbox.load_inbox(c))
|
|
@ -23,21 +23,16 @@ import logger, config, threading, time, readline, datetime
|
|||
from onionrblockapi import Block
|
||||
import onionrexceptions
|
||||
from onionrusers import onionrusers
|
||||
from flask import Response, request, redirect, Blueprint
|
||||
import locale, sys, os, json
|
||||
|
||||
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__)))
|
||||
import sentboxdb # import after path insert
|
||||
|
||||
@flask_blueprint.route('/mailhello')
|
||||
def mailhello():
|
||||
return "hello world from mail"
|
||||
import sentboxdb, mailapi, loadinbox # import after path insert
|
||||
flask_blueprint = mailapi.flask_blueprint
|
||||
|
||||
def draw_border(text):
|
||||
#https://stackoverflow.com/a/20757491
|
||||
|
@ -83,7 +78,7 @@ class OnionrMail:
|
|||
displayList = []
|
||||
subject = ''
|
||||
|
||||
# this could use a lot of memory if someone has recieved a lot of messages
|
||||
# this could use a lot of memory if someone has received a lot of messages
|
||||
for blockHash in self.myCore.getBlocksByType('pm'):
|
||||
pmBlocks[blockHash] = Block(blockHash, core=self.myCore)
|
||||
pmBlocks[blockHash].decrypt()
|
||||
|
@ -327,10 +322,6 @@ def on_pluginrequest(api, data=None):
|
|||
cmd = path.split('/')[1]
|
||||
if cmd == 'sentbox':
|
||||
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 != '':
|
||||
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
||||
|
||||
|
@ -345,5 +336,4 @@ def on_init(api, data = None):
|
|||
mail = OnionrMail(pluginapi)
|
||||
api.commands.register(['mail'], mail.menu)
|
||||
api.commands.register_help('mail', 'Interact with OnionrMail')
|
||||
print("YEET2")
|
||||
return
|
||||
|
|
|
@ -203,7 +203,7 @@ function showSentboxWindow(to, content){
|
|||
overlay('sentboxDisplay')
|
||||
}
|
||||
|
||||
fetch('/getblocksbytype/pm', {
|
||||
fetch('/mail/getinbox', {
|
||||
headers: {
|
||||
"token": webpass
|
||||
}})
|
||||
|
|
Loading…
Reference in New Issue