moved static data one directory up

This commit is contained in:
Kevin Froman 2019-09-23 17:56:05 -05:00
parent e4df34ef29
commit 09f6735961
124 changed files with 27 additions and 54 deletions

View file

@ -0,0 +1,74 @@
'''
Onionr - Private P2P Communication
HTTP endpoints for controlling IMs
'''
'''
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 json
from flask import Response, request, redirect, Blueprint, send_from_directory
import deadsimplekv as simplekv
import filepaths
flask_blueprint = Blueprint('chat_control', __name__)
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
@flask_blueprint.route('/chatapi/ping')
def ping():
return 'pong!'
@flask_blueprint.route('/chatapi/send/<peer>', methods=['POST'])
def send_message(peer):
"""Send a message to the peer"""
data = request.get_json(force=True)
key_store.refresh()
existing = key_store.get('s' + peer)
if existing is None:
existing = []
existing.append(data)
key_store.put('s' + peer, existing)
key_store.flush()
return Response('success')
@flask_blueprint.route('/chatapi/gets/<peer>')
def get_sent(peer):
"""Get messages sent to peer"""
sent = key_store.get('s' + peer)
if sent is None:
sent = []
return Response(json.dumps(sent))
@flask_blueprint.route('/chatapi/addrec/<peer>', methods=['POST'])
def add_rec(peer):
"""Add a received message from the peer"""
data = request.get_json(force=True)
key_store.refresh()
existing = key_store.get('r' + peer)
if existing is None:
existing = []
existing.append(data)
key_store.put('r' + peer, existing)
key_store.flush()
return Response('success')
@flask_blueprint.route('/chatapi/getrec/<peer>')
def get_messages(peer):
"""Get received messages for the peer"""
key_store.refresh()
existing = key_store.get('r' + peer)
if existing is None:
existing = []
else:
existing = list(existing)
key_store.delete('r' + peer)
return Response(json.dumps(existing))

View file

@ -0,0 +1,5 @@
{
"name" : "chat",
"version" : "1.0",
"author" : "onionr"
}

View file

@ -0,0 +1,39 @@
'''
Onionr - Private P2P Communication
Instant message conversations with Onionr peers
'''
'''
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 locale, sys, os, threading, json
locale.setlocale(locale.LC_ALL, '')
import onionrservices, logger, config
from onionrservices import bootstrapservice
from onionrutils import stringvalidators, epoch, basicrequests
plugin_name = 'chat'
PLUGIN_VERSION = '0.0.0'
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import controlapi, peerserver
flask_blueprint = controlapi.flask_blueprint
direct_blueprint = peerserver.direct_blueprint
security_whitelist = ['staticfiles.chat', 'staticfiles.chatIndex']
def exit_with_error(text=''):
if text != '':
logger.error(text)
sys.exit(1)

View file

@ -0,0 +1,59 @@
'''
Onionr - Private P2P Communication
HTTP endpoints for communicating with peers
'''
'''
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 utils import identifyhome
from onionrutils import localcommand
import deadsimplekv as simplekv, filepaths
from flask import Response, request, redirect, Blueprint, abort, g
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
direct_blueprint = Blueprint('chat', __name__)
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
storage_dir = identifyhome.identify_home()
@direct_blueprint.before_request
def request_setup():
key_store.refresh()
host = request.host
host = host.strip('.b32.i2p')
host = host.strip('.onion')
g.host = host
g.peer = key_store.get('dc-' + g.host)
@direct_blueprint.route('/chat/ping')
def pingdirect():
return 'pong!'
@direct_blueprint.route('/chat/sendto', methods=['POST', 'GET'])
def sendto():
"""Endpoint peers send chat messages to"""
try:
msg = request.get_json(force=True)
except json.JSONDecodeError:
msg = ''
else:
msg = json.dumps(msg)
localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg)
return Response('success')
@direct_blueprint.route('/chat/poll')
def poll_chat():
"""Endpoints peers get new messages from"""
return Response(localcommand.local_command('/chat/gets/%s' % (g.peer,)))

View file

@ -0,0 +1,5 @@
{
"name" : "encrypt",
"version" : "1.0",
"author" : "onionr"
}

View file

@ -0,0 +1,117 @@
'''
Onionr - Private P2P Communication
This default plugin allows users to encrypt/decrypt messages without using blocks
'''
'''
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, sys, json
from onionrutils import stringvalidators, bytesconverter
from onionrcrypto import encryption, keypair, signing, getourkeypair
import onionrexceptions, onionrusers
import locale
locale.setlocale(locale.LC_ALL, '')
plugin_name = 'encrypt'
class PlainEncryption:
def __init__(self, api):
self.api = api
return
def encrypt(self):
# peer, data
plaintext = ""
encrypted = ""
# detect if signing is enabled
sign = True
try:
if sys.argv[3].lower() == 'false':
sign = False
except IndexError:
pass
try:
if not stringvalidators.validate_pub_key(sys.argv[2]):
raise onionrexceptions.InvalidPubkey
except (ValueError, IndexError) as e:
logger.error("Peer public key not specified", terminal=True)
except onionrexceptions.InvalidPubkey:
logger.error("Invalid public key", terminal=True)
else:
pubkey = sys.argv[2]
# Encrypt if public key is valid
logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True)
try:
for line in sys.stdin:
if line == '-q\n':
break
plaintext += line
except KeyboardInterrupt:
sys.exit(1)
# Build Message to encrypt
data = {}
myPub = keypair[0]
if sign:
data['sig'] = signing.ed_sign(plaintext, key=keypair[1], encodeResult=True)
data['sig'] = bytesconverter.bytes_to_str(data['sig'])
data['signer'] = myPub
data['data'] = plaintext
data = json.dumps(data)
plaintext = data
encrypted = encryption.pub_key_encrypt(plaintext, pubkey, encodedData=True)
encrypted = bytesconverter.bytes_to_str(encrypted)
logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,), terminal=True)
def decrypt(self):
plaintext = ""
data = ""
logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True)
keypair = getourkeypair.get_keypair()
try:
for line in sys.stdin:
if line == '-q\n':
break
data += line
except KeyboardInterrupt:
sys.exit(1)
if len(data) <= 1:
return
encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '')
myPub = keypair[0]
decrypted = encryption.pub_key_decrypt(encrypted, privkey=keypair[1], encodedData=True)
if decrypted == False:
logger.error("Decryption failed", terminal=True)
else:
data = json.loads(decrypted)
logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True)
try:
logger.info("Signing public key: %s" % (data['signer'],), terminal=True)
if not signing.ed_verify(data['data'], data['signer'], data['sig']): raise ValueError
except (ValueError, KeyError) as e:
logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True)
else:
logger.info("Message has good signature.", terminal=True)
return
def on_decrypt_cmd(api, data=None):
PlainEncryption(api).decrypt()
def on_encrypt_cmd(api, data=None):
PlainEncryption(api).encrypt()
on_encrypt_cmd.onionr_help = """encrypt <user_key>\nEncrypt text data to an Onionr user key. Similar to PGP"""
on_decrypt_cmd.onionr_help = """decrypt\nDecrypt text data with your Onionr key. Similar to PGP"""
ONIONR_COMMANDS = ['encrypt', 'decrypt']

View file

@ -0,0 +1,59 @@
'''
Onionr - Private P2P Communication
This file primarily serves to allow specific fetching of flow board messages
'''
'''
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 json
import os
from flask import Response, request, redirect, Blueprint, abort
from utils import identifyhome
import deadsimplekv as simplekv
flask_blueprint = Blueprint('flow', __name__)
with open(os.path.dirname(os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
data = info_file.read().strip()
version = json.loads(data, strict=False)['version']
@flask_blueprint.route('/flow/getpostsbyboard/<board>')
def get_post_by_board(board):
board_cache = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/board-index.cache.json', flush_on_exit=False)
board_cache.refresh()
posts = board_cache.get(board)
if posts is None:
posts = ''
else:
posts = ','.join(posts)
return Response(posts)
@flask_blueprint.route('/flow/getpostsbyboard/<board>/<offset>')
def get_post_by_board_with_offset(board, offset):
offset = int(offset)
OFFSET_COUNT = 10
board_cache = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/board-index.cache.json', flush_on_exit=False)
board_cache.refresh()
posts = board_cache.get(board)
if posts is None:
posts = ''
else:
posts.reverse()
posts = ','.join(posts[offset:offset + OFFSET_COUNT])
return Response(posts)
@flask_blueprint.route('/flow/version')
def get_version():
return Response(version)

View file

@ -0,0 +1,4 @@
{ "name": "flow",
"version": "0.0.1",
"author": "onionr"
}

View file

@ -0,0 +1,133 @@
'''
Onionr - Private P2P Communication
This default plugin handles "flow" messages (global chatroom style communication)
'''
'''
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 threading, time, locale, sys, os
from onionrblocks.onionrblockapi import Block
import logger, config, onionrblocks
from onionrutils import escapeansi, epoch, bytesconverter
locale.setlocale(locale.LC_ALL, '')
from coredb import blockmetadb
from utils import identifyhome, reconstructhash
import deadsimplekv as simplekv
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import flowapi # import after path insert
flask_blueprint = flowapi.flask_blueprint
security_whitelist = ['staticfiles.boardContent', 'staticfiles.board']
plugin_name = 'flow'
PLUGIN_VERSION = '0.0.1'
class OnionrFlow:
def __init__(self):
self.alreadyOutputed = []
self.flowRunning = False
self.channel = ""
return
def start(self):
logger.warn("Please note: everything said here is public, even if a random channel name is used.", terminal=True)
message = ""
self.flowRunning = True
try:
self.channel = logger.readline("Enter a channel name or none for default:").strip()
except (KeyboardInterrupt, EOFError) as e:
self.flowRunning = False
newThread = threading.Thread(target=self.showOutput, daemon=True)
newThread.start()
while self.flowRunning:
if self.channel == "":
self.channel = "global"
try:
message = logger.readline('\nInsert message into flow:').strip().replace('\n', '\\n').replace('\r', '\\r')
except EOFError:
pass
except KeyboardInterrupt:
self.flowRunning = False
else:
if message == "q":
self.flowRunning = False
expireTime = epoch.get_epoch() + 43200
if len(message) > 0:
logger.info('Inserting message as block...', terminal=True)
onionrblocks.insert(message, header='brd', expire=expireTime, meta={'ch': self.channel})
logger.info("Flow is exiting, goodbye", terminal=True)
return
def showOutput(self):
while type(self.channel) is type(None) and self.flowRunning:
time.sleep(1)
try:
while self.flowRunning:
for block in blockmetadb.get_blocks_by_type('brd'):
if block in self.alreadyOutputed:
continue
block = Block(block)
b_hash = bytesconverter.bytes_to_str(block.getHash())
if block.getMetadata('ch') != self.channel:
continue
if not self.flowRunning:
break
logger.info('\n------------------------', prompt = False, terminal=True)
content = block.getContent()
# Escape new lines, remove trailing whitespace, and escape ansi sequences
content = escapeansi.escape_ANSI(content.replace('\n', '\\n').replace('\r', '\\r').strip())
logger.info(block.getDate().strftime("%m/%d %H:%M") + ' - ' + logger.colors.reset + content, prompt = False, terminal=True)
self.alreadyOutputed.append(b_hash)
time.sleep(5)
except KeyboardInterrupt:
self.flowRunning = False
def on_flow_cmd(api, data=None):
OnionrFlow().start()
def on_softreset(api, data=None):
try:
os.remove(identifyhome.identify_home() + '/board-index.cache.json')
logger.info('Cleared Circles board cache')
except FileNotFoundError:
pass
def on_processblocks(api, data=None):
metadata = data['block'].bmetadata # Get the block metadata
if data['type'] != 'brd':
return
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
board_cache = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/board-index.cache.json', flush_on_exit=False) # get the board index cache
board_cache.refresh()
# Validate the channel name is sane for caching
try:
ch = metadata['ch']
except KeyError:
ch = 'global'
ch_len = len(ch)
if ch_len == 0:
ch = 'global'
elif ch_len > 12:
return
existing_posts = board_cache.get(ch)
if existing_posts is None:
existing_posts = []
existing_posts.append(data['block'].hash)
board_cache.put(ch, existing_posts)
board_cache.flush()

View file

@ -0,0 +1,5 @@
{
"name" : "metadataprocessor",
"version" : "1.0",
"author" : "onionr"
}

View file

@ -0,0 +1,59 @@
'''
Onionr - Private P2P Communication
This processes metadata for Onionr blocks
'''
'''
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/>.
'''
# useful libraries
import logger, config
import os, sys, json, time, random, shutil, base64, getpass, datetime, re
import onionrusers, onionrexceptions
from onionrutils import stringvalidators
plugin_name = 'metadataprocessor'
# event listeners
def _processForwardKey(api, myBlock):
'''
Get the forward secrecy key specified by the user for us to use
'''
peer = onionrusers.OnionrUser(myBlock.signer)
key = myBlock.getMetadata('newFSKey')
# We don't need to validate here probably, but it helps
if stringvalidators.validate_pub_key(key):
peer.addForwardKey(key)
else:
raise onionrexceptions.InvalidPubkey("%s is not a valid pubkey key" % (key,))
def on_processblocks(api, data=None):
# Generally fired by utils.
myBlock = api.data['block']
blockType = api.data['type']
# Process specific block types
# forwardKey blocks, add a new forward secrecy key for a peer
if blockType == 'forwardKey':
if api.data['validSig'] == True:
_processForwardKey(api, myBlock)
def on_init(api, data = None):
pluginapi = api
return

View file

@ -0,0 +1,5 @@
{
"name" : "pms",
"version" : "1.0",
"author" : "onionr"
}

View 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

View 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)

View 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']))

View 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

View file

@ -0,0 +1,5 @@
{
"name" : "searchengine",
"version" : "0.0.0",
"author" : "0gitnick"
}

View file

@ -0,0 +1,24 @@
'''
Onionr - Private P2P Communication
Search engine plugin for Onionr, to search for
'''
'''
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 = 'searchengine'