+ added address adding input to web ui in sidebar

fixes #10
master
Kevin Froman 2020-10-03 22:43:18 +00:00
parent 092233027c
commit 45940b2dba
5 changed files with 66 additions and 2 deletions

View File

@ -0,0 +1,14 @@
from onionrutils.stringvalidators import validate_transport
from coredb.keydb.addkeys import add_address
from coredb.keydb.listkeys import list_adders
def add_peer(peer):
# this is ok for security since add_address does this manually
assert validate_transport(peer)
if peer in list_adders():
return "already added"
if add_address(peer):
return "success"
else:
return "failure, invalid address"

View File

@ -20,6 +20,7 @@ from onionrutils import bytesconverter
from etc import onionrvalues from etc import onionrvalues
from utils import reconstructhash from utils import reconstructhash
from utils.gettransports import get as get_tor from utils.gettransports import get as get_tor
from .addpeer import add_peer
""" """
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -46,6 +47,14 @@ class PrivateEndpoints:
private_endpoints_bp = Blueprint('privateendpoints', __name__) private_endpoints_bp = Blueprint('privateendpoints', __name__)
self.private_endpoints_bp = private_endpoints_bp self.private_endpoints_bp = private_endpoints_bp
@private_endpoints_bp.route('/addpeer/<name>', methods=['post'])
def add_peer_endpoint(name):
result = add_peer(name)
if result == "success":
return Response("success")
else:
return Response(result, 409)
@private_endpoints_bp.route('/www/<path:path>', endpoint='www') @private_endpoints_bp.route('/www/<path:path>', endpoint='www')
def wwwPublic(path): def wwwPublic(path):
if not config.get("www.private.run", True): if not config.get("www.private.run", True):

View File

@ -205,7 +205,7 @@ def insert_block(data: Union[str, bytes], header: str = 'txt',
# send block data (and metadata) to POW module to get tokenized block data # send block data (and metadata) to POW module to get tokenized block data
payload = subprocesspow.SubprocessPOW(data, metadata).start() payload = subprocesspow.SubprocessPOW(data, metadata).start()
print(payload)
if payload != False: # noqa if payload != False: # noqa
try: try:
retData = onionrstorage.set_data(payload) retData = onionrstorage.set_data(payload)

View File

@ -10,6 +10,18 @@
<div class="quickview-block"> <div class="quickview-block">
Blocks to upload: <span id="uploadBlocks">unknown</span> Blocks to upload: <span id="uploadBlocks">unknown</span>
</div> </div>
<div class="quickview-block">
<div class="field has-addons">
<div class="control">
<input class="input" type="text" placeholder="Node address" id="addPeerInput">
</div>
<div class="control">
<a class="button is-info" id="addPeerBtn">
Add Peer
</a>
</div>
</div>
</div>
</div> </div>
</div> </div>
<button class="button is-primary is-hidden sidebarBtn" data-show="quickview" data-target="quickviewDefault">Show quickview</button> <button class="button is-primary is-hidden sidebarBtn" data-show="quickview" data-target="quickviewDefault">Show quickview</button>

View File

@ -7,8 +7,38 @@ fetch('/shared/sidebar/sidebar.html', {
.then(function(resp) { .then(function(resp) {
document.getElementById('sidebarContainer').innerHTML = resp document.getElementById('sidebarContainer').innerHTML = resp
var quickviews = bulmaQuickview.attach() var quickviews = bulmaQuickview.attach()
sidebarAddPeerRegister()
}) })
function sidebarAddPeerRegister(){
document.getElementById('addPeerBtn').onclick = function(){
let newPeer = document.getElementById('addPeerInput').value
fetch('/addpeer/' + newPeer, {
method: 'POST',
headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(data) {
alert(data)
if (data == "success"){
PNotify.success({
text: 'Peer added'
})
return
}
else if(data == "already added"){
PNotify.notice({
text: 'Peer already added'
})
return
}
PNotify.error({text: data})
})
}
}
window.addEventListener("keydown", function(event) { window.addEventListener("keydown", function(event) {
if (event.key === "s"){ if (event.key === "s"){
if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){ if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){
@ -44,7 +74,6 @@ window.addEventListener("keydown", function(event) {
}}) }})
.then((resp) => resp.text()) .then((resp) => resp.text())
.then(function(resp) { .then(function(resp) {
console.debug(resp.length, existingUploadValue)
if (resp.length <= 2 && existingUploadValue !== "0"){ if (resp.length <= 2 && existingUploadValue !== "0"){
document.getElementById("uploadBlocks").innerText = "0" document.getElementById("uploadBlocks").innerText = "0"
return return