moved static data one directory up
This commit is contained in:
parent
e4df34ef29
commit
09f6735961
124 changed files with 27 additions and 54 deletions
5
static-data/default-plugins/pms/info.json
Executable file
5
static-data/default-plugins/pms/info.json
Executable file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name" : "pms",
|
||||
"version" : "1.0",
|
||||
"author" : "onionr"
|
||||
}
|
36
static-data/default-plugins/pms/loadinbox.py
Executable file
36
static-data/default-plugins/pms/loadinbox.py
Executable file
|
@ -0,0 +1,36 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
Load the user's inbox and return it as a list
|
||||
'''
|
||||
'''
|
||||
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/>.
|
||||
'''
|
||||
from onionrblocks import onionrblockapi
|
||||
from coredb import blockmetadb
|
||||
import filepaths
|
||||
from utils import reconstructhash, identifyhome
|
||||
import deadsimplekv as simplekv
|
||||
def load_inbox():
|
||||
inbox_list = []
|
||||
deleted = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat').get('deleted_mail')
|
||||
if deleted is None:
|
||||
deleted = []
|
||||
|
||||
for blockHash in blockmetadb.get_blocks_by_type('pm'):
|
||||
block = onionrblockapi.Block(blockHash)
|
||||
block.decrypt()
|
||||
if block.decrypted and reconstructhash.deconstruct_hash(blockHash) not in deleted:
|
||||
inbox_list.append(blockHash)
|
||||
return inbox_list
|
68
static-data/default-plugins/pms/mailapi.py
Executable file
68
static-data/default-plugins/pms/mailapi.py
Executable file
|
@ -0,0 +1,68 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
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, json
|
||||
from flask import Response, request, redirect, Blueprint, abort
|
||||
from onionrusers import contactmanager
|
||||
from onionrutils import stringvalidators
|
||||
from utils import reconstructhash, identifyhome
|
||||
import filepaths
|
||||
import deadsimplekv as simplekv
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import loadinbox, sentboxdb
|
||||
|
||||
flask_blueprint = Blueprint('mail', __name__)
|
||||
kv = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat')
|
||||
|
||||
@flask_blueprint.route('/mail/ping')
|
||||
def mail_ping():
|
||||
return 'pong!'
|
||||
|
||||
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
||||
def mail_delete(block):
|
||||
if not stringvalidators.validate_hash(block):
|
||||
abort(504)
|
||||
block = reconstructhash.deconstruct_hash(block)
|
||||
existing = kv.get('deleted_mail')
|
||||
if existing is None:
|
||||
existing = []
|
||||
if block not in existing:
|
||||
existing.append(block)
|
||||
kv.put('deleted_mail', existing)
|
||||
kv.flush()
|
||||
return 'success'
|
||||
|
||||
@flask_blueprint.route('/mail/getinbox')
|
||||
def list_inbox():
|
||||
return ','.join(loadinbox.load_inbox())
|
||||
|
||||
@flask_blueprint.route('/mail/getsentbox')
|
||||
def list_sentbox():
|
||||
kv.refresh()
|
||||
sentbox_list = sentboxdb.SentBox().listSent()
|
||||
list_copy = list(sentbox_list)
|
||||
deleted = kv.get('deleted_mail')
|
||||
if deleted is None:
|
||||
deleted = []
|
||||
for sent in list_copy:
|
||||
if sent['hash'] in deleted:
|
||||
sentbox_list.remove(sent)
|
||||
continue
|
||||
sent['name'] = contactmanager.ContactManager(sent['peer'], saveUser=False).get_info('name')
|
||||
return json.dumps(sentbox_list)
|
71
static-data/default-plugins/pms/main.py
Executable file
71
static-data/default-plugins/pms/main.py
Executable file
|
@ -0,0 +1,71 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
This default plugin handles private messages in an email like fashion
|
||||
'''
|
||||
'''
|
||||
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, threading, time, datetime
|
||||
import onionrexceptions
|
||||
from onionrusers import onionrusers, contactmanager
|
||||
from utils import reconstructhash
|
||||
from onionrutils import stringvalidators, escapeansi, bytesconverter
|
||||
import notifier
|
||||
import locale, sys, os, json
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
plugin_name = 'pms'
|
||||
PLUGIN_VERSION = '0.0.1'
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import sentboxdb, mailapi, loadinbox # import after path insert
|
||||
flask_blueprint = mailapi.flask_blueprint
|
||||
security_whitelist = ['staticfiles.mail', 'staticfiles.mailindex']
|
||||
|
||||
def add_deleted(keyStore, b_hash):
|
||||
existing = keyStore.get('deleted_mail')
|
||||
bHash = reconstructhash.reconstruct_hash(b_hash)
|
||||
if existing is None:
|
||||
existing = []
|
||||
else:
|
||||
if bHash in existing:
|
||||
return
|
||||
keyStore.put('deleted_mail', existing.append(b_hash))
|
||||
|
||||
def on_insertblock(api, data={}):
|
||||
meta = json.loads(data['meta'])
|
||||
if meta['type'] == 'pm':
|
||||
sentboxTools = sentboxdb.SentBox()
|
||||
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
||||
|
||||
def on_processblocks(api, data=None):
|
||||
if data['type'] != 'pm':
|
||||
return
|
||||
data['block'].decrypt()
|
||||
metadata = data['block'].bmetadata
|
||||
|
||||
signer = bytesconverter.bytes_to_str(data['block'].signer)
|
||||
user = contactmanager.ContactManager(signer, saveUser=False)
|
||||
name = user.get_info("name")
|
||||
if name != 'anonymous' and name != None:
|
||||
signer = name.title()
|
||||
else:
|
||||
signer = signer[:5]
|
||||
|
||||
if data['block'].decrypted:
|
||||
notifier.notify(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject']))
|
76
static-data/default-plugins/pms/sentboxdb.py
Executable file
76
static-data/default-plugins/pms/sentboxdb.py
Executable file
|
@ -0,0 +1,76 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
This file handles the sentbox for the 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 sqlite3, os
|
||||
from onionrutils import epoch
|
||||
from utils import identifyhome, reconstructhash
|
||||
class SentBox:
|
||||
def __init__(self):
|
||||
self.dbLocation = identifyhome.identify_home() + '/sentbox.db'
|
||||
if not os.path.exists(self.dbLocation):
|
||||
self.createDB()
|
||||
return
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self.dbLocation)
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
def createDB(self):
|
||||
conn = sqlite3.connect(self.dbLocation)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE sent(
|
||||
hash id not null,
|
||||
peer text not null,
|
||||
message text not null,
|
||||
subject text not null,
|
||||
date int not null
|
||||
);
|
||||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return
|
||||
|
||||
def listSent(self):
|
||||
self.connect()
|
||||
retData = []
|
||||
for entry in self.cursor.execute('SELECT * FROM sent;'):
|
||||
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
|
||||
self.close()
|
||||
return retData
|
||||
|
||||
def addToSent(self, blockID, peer, message, subject=''):
|
||||
blockID = reconstructhash.deconstruct_hash(blockID)
|
||||
self.connect()
|
||||
args = (blockID, peer, message, subject, epoch.get_epoch())
|
||||
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
|
||||
self.conn.commit()
|
||||
self.close()
|
||||
return
|
||||
|
||||
def removeSent(self, blockID):
|
||||
blockID = reconstructhash.deconstruct_hash(blockID)
|
||||
self.connect()
|
||||
args = (blockID,)
|
||||
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
||||
self.conn.commit()
|
||||
self.close()
|
||||
return
|
Loading…
Add table
Add a link
Reference in a new issue