diff --git a/onionr/coredb/keydb/removekeys.py b/onionr/coredb/keydb/removekeys.py index e4585b41..7e8baaab 100644 --- a/onionr/coredb/keydb/removekeys.py +++ b/onionr/coredb/keydb/removekeys.py @@ -20,7 +20,9 @@ import sqlite3 from onionrplugins import onionrevents as events from onionrutils import stringvalidators +from onionrutils import mnemonickeys from .. import dbfiles + def remove_address(address): ''' Remove an address from the address database @@ -37,4 +39,21 @@ def remove_address(address): #events.event('address_remove', data = {'address': address}, onionr = core_inst.onionrInst) return True else: - return False \ No newline at end of file + return False + +def remove_user(pubkey: str)->bool: + ''' + Remove a user from the user database + ''' + pubkey = mnemonickeys.get_base32(pubkey) + if stringvalidators.validate_pub_key(pubkey): + conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=30) + c = conn.cursor() + t = (pubkey,) + c.execute('Delete from peers where id=?;', t) + conn.commit() + conn.close() + + return True + else: + return False diff --git a/onionr/httpapi/friendsapi/__init__.py b/onionr/httpapi/friendsapi/__init__.py index ee19c0ab..4447cc9c 100755 --- a/onionr/httpapi/friendsapi/__init__.py +++ b/onionr/httpapi/friendsapi/__init__.py @@ -20,6 +20,7 @@ import json from onionrusers import contactmanager from flask import Blueprint, Response, request, abort, redirect +from coredb import keydb friends = Blueprint('friends', __name__) @@ -38,7 +39,9 @@ def add_friend(pubkey): @friends.route('/friends/remove/', methods=['POST']) def remove_friend(pubkey): + contactmanager.ContactManager(pubkey).setTrust(0) contactmanager.ContactManager(pubkey).delete_contact() + keydb.removekeys.remove_user(pubkey) return redirect(request.referrer + '#' + request.form['token']) @friends.route('/friends/setinfo//', methods=['POST']) diff --git a/onionr/httpapi/miscclientapi/endpoints.py b/onionr/httpapi/miscclientapi/endpoints.py index 4062e2ec..6f8de33c 100644 --- a/onionr/httpapi/miscclientapi/endpoints.py +++ b/onionr/httpapi/miscclientapi/endpoints.py @@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +import os +import subprocess + from flask import Response, Blueprint, request, send_from_directory, abort import unpaddedbase32 @@ -26,11 +29,14 @@ from netcontroller import NetController from serializeddata import SerializedData from onionrutils import mnemonickeys from onionrutils import bytesconverter +from etc import onionrvalues from utils import reconstructhash from onionrcommands import restartonionr pub_key = onionrcrypto.pub_key.replace('=', '') +SCRIPT_NAME = os.path.dirname(os.path.realpath(__file__)) + f'/../../../{onionrvalues.SCRIPT_NAME}' + class PrivateEndpoints: def __init__(self, client_api): private_endpoints_bp = Blueprint('privateendpoints', __name__) @@ -94,7 +100,7 @@ class PrivateEndpoints: @private_endpoints_bp.route('/restartclean') def restart_clean(): - restartonionr.restart() + subprocess.Popen([SCRIPT_NAME, 'restart']) return Response("bye") @private_endpoints_bp.route('/getstats') diff --git a/onionr/onionrcommands/banblocks.py b/onionr/onionrcommands/banblocks.py index f9642837..c5aadd61 100755 --- a/onionr/onionrcommands/banblocks.py +++ b/onionr/onionrcommands/banblocks.py @@ -21,19 +21,26 @@ import sys import logger from onionrutils import stringvalidators from onionrstorage import removeblock +from onionrstorage import deleteBlock from onionrblocks import onionrblacklist +from utils import reconstructhash def ban_block(): + """Deletes a block, permanently blacklisting it""" blacklist = onionrblacklist.OnionrBlackList() try: ban = sys.argv[2] except IndexError: - ban = logger.readline('Enter a block hash:') + # Get the hash if its not provided as a CLI argument + ban = logger.readline('Enter a block hash:').strip() + # Make sure the hash has no truncated zeroes + ban = reconstructhash.reconstruct_hash(ban) if stringvalidators.validate_hash(ban): if not blacklist.inBlacklist(ban): try: blacklist.addToDB(ban) removeblock.remove_block(ban) + deleteBlock(ban) except Exception as error: logger.error('Could not blacklist block', error=error, terminal=True) else: diff --git a/onionr/onionrcommands/restartonionr.py b/onionr/onionrcommands/restartonionr.py index f21b5a70..81adc073 100644 --- a/onionr/onionrcommands/restartonionr.py +++ b/onionr/onionrcommands/restartonionr.py @@ -36,8 +36,8 @@ def restart(): daemonlaunch.kill_daemon() while localcommand.local_command('ping', maxWait=8) == 'pong!': time.sleep(0.3) - time.sleep(9) - while os.path.exists(filepaths.private_API_host_file): + time.sleep(15) + while os.path.exists(filepaths.private_API_host_file) or os.path.exists(filepaths.daemon_mark_file): time.sleep(1) subprocess.Popen([SCRIPT_NAME, 'start']) diff --git a/onionr/onionrstorage/__init__.py b/onionr/onionrstorage/__init__.py index bad34447..c65787fb 100755 --- a/onionr/onionrstorage/__init__.py +++ b/onionr/onionrstorage/__init__.py @@ -46,7 +46,7 @@ def _dbFetch(blockHash): return None def deleteBlock(blockHash): - # You should call core.removeBlock if you automatically want to remove storage byte count + # You should call removeblock.remove_block if you automatically want to remove storage byte count if os.path.exists('%s/%s.dat' % (filepaths.block_data_location, blockHash)): os.remove('%s/%s.dat' % (filepaths.block_data_location, blockHash)) return True diff --git a/onionr/onionrstorage/removeblock.py b/onionr/onionrstorage/removeblock.py index 1a6830d9..afe79bf2 100644 --- a/onionr/onionrstorage/removeblock.py +++ b/onionr/onionrstorage/removeblock.py @@ -20,4 +20,4 @@ def remove_block(block): dataSize = sys.getsizeof(onionrstorage.getData(block)) storagecounter.StorageCounter().remove_bytes(dataSize) else: - raise onionrexceptions.InvalidHexHash \ No newline at end of file + raise onionrexceptions.InvalidHexHash diff --git a/onionr/onionrusers/contactmanager.py b/onionr/onionrusers/contactmanager.py index 0fbd2de9..d5910b51 100755 --- a/onionr/onionrusers/contactmanager.py +++ b/onionr/onionrusers/contactmanager.py @@ -30,7 +30,7 @@ class ContactManager(onionrusers.OnionrUser): def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5): try: if mnemonickeys.DELIMITER in publicKey: - publicKey = mnemonickeys.get_base32(publicKey.split(mnemonickeys.DELIMITER)) + publicKey = mnemonickeys.get_base32(publicKey) #publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey)) except ValueError: pass diff --git a/onionr/onionrutils/mnemonickeys.py b/onionr/onionrutils/mnemonickeys.py index d1384571..2f6ed44d 100644 --- a/onionr/onionrutils/mnemonickeys.py +++ b/onionr/onionrutils/mnemonickeys.py @@ -40,6 +40,8 @@ def get_human_readable_ID(pub=''): def get_base32(words): '''converts mnemonic to base32''' + if DELIMITER not in words and not type(words) in (type(list), type(tuple)): return words + try: return unpaddedbase32.b32encode(niceware.passphrase_to_bytes(words.split(DELIMITER))) except AttributeError: diff --git a/static-data/www/mail/mail.js b/static-data/www/mail/mail.js index e411a4c1..82afa137 100755 --- a/static-data/www/mail/mail.js +++ b/static-data/www/mail/mail.js @@ -180,6 +180,7 @@ function loadInboxEntries(bHash){ var entry = document.createElement('div') var bHashDisplay = document.createElement('span') var senderInput = document.createElement('input') + //var senderInput = document.createElement('div') var subjectLine = document.createElement('span') var dateStr = document.createElement('span') var validSig = document.createElement('span')