* improved friend removal
* made restart more reliable * fixed banblock not deleting blocks * somewhat fixed friend endpoints not working with niceware keys * started working on adjusting mail interface to use div instead of inputs
This commit is contained in:
parent
e5fc15acc2
commit
63fced9cff
@ -20,7 +20,9 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from onionrplugins import onionrevents as events
|
from onionrplugins import onionrevents as events
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
|
from onionrutils import mnemonickeys
|
||||||
from .. import dbfiles
|
from .. import dbfiles
|
||||||
|
|
||||||
def remove_address(address):
|
def remove_address(address):
|
||||||
'''
|
'''
|
||||||
Remove an address from the address database
|
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)
|
#events.event('address_remove', data = {'address': address}, onionr = core_inst.onionrInst)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
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
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
import json
|
import json
|
||||||
from onionrusers import contactmanager
|
from onionrusers import contactmanager
|
||||||
from flask import Blueprint, Response, request, abort, redirect
|
from flask import Blueprint, Response, request, abort, redirect
|
||||||
|
from coredb import keydb
|
||||||
|
|
||||||
friends = Blueprint('friends', __name__)
|
friends = Blueprint('friends', __name__)
|
||||||
|
|
||||||
@ -38,7 +39,9 @@ def add_friend(pubkey):
|
|||||||
|
|
||||||
@friends.route('/friends/remove/<pubkey>', methods=['POST'])
|
@friends.route('/friends/remove/<pubkey>', methods=['POST'])
|
||||||
def remove_friend(pubkey):
|
def remove_friend(pubkey):
|
||||||
|
contactmanager.ContactManager(pubkey).setTrust(0)
|
||||||
contactmanager.ContactManager(pubkey).delete_contact()
|
contactmanager.ContactManager(pubkey).delete_contact()
|
||||||
|
keydb.removekeys.remove_user(pubkey)
|
||||||
return redirect(request.referrer + '#' + request.form['token'])
|
return redirect(request.referrer + '#' + request.form['token'])
|
||||||
|
|
||||||
@friends.route('/friends/setinfo/<pubkey>/<key>', methods=['POST'])
|
@friends.route('/friends/setinfo/<pubkey>/<key>', methods=['POST'])
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from flask import Response, Blueprint, request, send_from_directory, abort
|
from flask import Response, Blueprint, request, send_from_directory, abort
|
||||||
import unpaddedbase32
|
import unpaddedbase32
|
||||||
|
|
||||||
@ -26,11 +29,14 @@ from netcontroller import NetController
|
|||||||
from serializeddata import SerializedData
|
from serializeddata import SerializedData
|
||||||
from onionrutils import mnemonickeys
|
from onionrutils import mnemonickeys
|
||||||
from onionrutils import bytesconverter
|
from onionrutils import bytesconverter
|
||||||
|
from etc import onionrvalues
|
||||||
from utils import reconstructhash
|
from utils import reconstructhash
|
||||||
from onionrcommands import restartonionr
|
from onionrcommands import restartonionr
|
||||||
|
|
||||||
pub_key = onionrcrypto.pub_key.replace('=', '')
|
pub_key = onionrcrypto.pub_key.replace('=', '')
|
||||||
|
|
||||||
|
SCRIPT_NAME = os.path.dirname(os.path.realpath(__file__)) + f'/../../../{onionrvalues.SCRIPT_NAME}'
|
||||||
|
|
||||||
class PrivateEndpoints:
|
class PrivateEndpoints:
|
||||||
def __init__(self, client_api):
|
def __init__(self, client_api):
|
||||||
private_endpoints_bp = Blueprint('privateendpoints', __name__)
|
private_endpoints_bp = Blueprint('privateendpoints', __name__)
|
||||||
@ -94,7 +100,7 @@ class PrivateEndpoints:
|
|||||||
|
|
||||||
@private_endpoints_bp.route('/restartclean')
|
@private_endpoints_bp.route('/restartclean')
|
||||||
def restart_clean():
|
def restart_clean():
|
||||||
restartonionr.restart()
|
subprocess.Popen([SCRIPT_NAME, 'restart'])
|
||||||
return Response("bye")
|
return Response("bye")
|
||||||
|
|
||||||
@private_endpoints_bp.route('/getstats')
|
@private_endpoints_bp.route('/getstats')
|
||||||
|
@ -21,19 +21,26 @@ import sys
|
|||||||
import logger
|
import logger
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
from onionrstorage import removeblock
|
from onionrstorage import removeblock
|
||||||
|
from onionrstorage import deleteBlock
|
||||||
from onionrblocks import onionrblacklist
|
from onionrblocks import onionrblacklist
|
||||||
|
from utils import reconstructhash
|
||||||
|
|
||||||
def ban_block():
|
def ban_block():
|
||||||
|
"""Deletes a block, permanently blacklisting it"""
|
||||||
blacklist = onionrblacklist.OnionrBlackList()
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
try:
|
try:
|
||||||
ban = sys.argv[2]
|
ban = sys.argv[2]
|
||||||
except IndexError:
|
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 stringvalidators.validate_hash(ban):
|
||||||
if not blacklist.inBlacklist(ban):
|
if not blacklist.inBlacklist(ban):
|
||||||
try:
|
try:
|
||||||
blacklist.addToDB(ban)
|
blacklist.addToDB(ban)
|
||||||
removeblock.remove_block(ban)
|
removeblock.remove_block(ban)
|
||||||
|
deleteBlock(ban)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error('Could not blacklist block', error=error, terminal=True)
|
logger.error('Could not blacklist block', error=error, terminal=True)
|
||||||
else:
|
else:
|
||||||
|
@ -36,8 +36,8 @@ def restart():
|
|||||||
daemonlaunch.kill_daemon()
|
daemonlaunch.kill_daemon()
|
||||||
while localcommand.local_command('ping', maxWait=8) == 'pong!':
|
while localcommand.local_command('ping', maxWait=8) == 'pong!':
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
time.sleep(9)
|
time.sleep(15)
|
||||||
while os.path.exists(filepaths.private_API_host_file):
|
while os.path.exists(filepaths.private_API_host_file) or os.path.exists(filepaths.daemon_mark_file):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
subprocess.Popen([SCRIPT_NAME, 'start'])
|
subprocess.Popen([SCRIPT_NAME, 'start'])
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ def _dbFetch(blockHash):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def deleteBlock(blockHash):
|
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)):
|
if os.path.exists('%s/%s.dat' % (filepaths.block_data_location, blockHash)):
|
||||||
os.remove('%s/%s.dat' % (filepaths.block_data_location, blockHash))
|
os.remove('%s/%s.dat' % (filepaths.block_data_location, blockHash))
|
||||||
return True
|
return True
|
||||||
|
@ -20,4 +20,4 @@ def remove_block(block):
|
|||||||
dataSize = sys.getsizeof(onionrstorage.getData(block))
|
dataSize = sys.getsizeof(onionrstorage.getData(block))
|
||||||
storagecounter.StorageCounter().remove_bytes(dataSize)
|
storagecounter.StorageCounter().remove_bytes(dataSize)
|
||||||
else:
|
else:
|
||||||
raise onionrexceptions.InvalidHexHash
|
raise onionrexceptions.InvalidHexHash
|
||||||
|
@ -30,7 +30,7 @@ class ContactManager(onionrusers.OnionrUser):
|
|||||||
def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5):
|
def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5):
|
||||||
try:
|
try:
|
||||||
if mnemonickeys.DELIMITER in publicKey:
|
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))
|
#publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
@ -40,6 +40,8 @@ def get_human_readable_ID(pub=''):
|
|||||||
|
|
||||||
def get_base32(words):
|
def get_base32(words):
|
||||||
'''converts mnemonic to base32'''
|
'''converts mnemonic to base32'''
|
||||||
|
if DELIMITER not in words and not type(words) in (type(list), type(tuple)): return words
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return unpaddedbase32.b32encode(niceware.passphrase_to_bytes(words.split(DELIMITER)))
|
return unpaddedbase32.b32encode(niceware.passphrase_to_bytes(words.split(DELIMITER)))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -180,6 +180,7 @@ function loadInboxEntries(bHash){
|
|||||||
var entry = document.createElement('div')
|
var entry = document.createElement('div')
|
||||||
var bHashDisplay = document.createElement('span')
|
var bHashDisplay = document.createElement('span')
|
||||||
var senderInput = document.createElement('input')
|
var senderInput = document.createElement('input')
|
||||||
|
//var senderInput = document.createElement('div')
|
||||||
var subjectLine = document.createElement('span')
|
var subjectLine = document.createElement('span')
|
||||||
var dateStr = document.createElement('span')
|
var dateStr = document.createElement('span')
|
||||||
var validSig = document.createElement('span')
|
var validSig = document.createElement('span')
|
||||||
|
Loading…
Reference in New Issue
Block a user