work on UI friends manager
parent
30a2ae8d06
commit
c61c833658
|
@ -290,9 +290,11 @@ class API:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if not hmac.compare_digest(request.headers['token'], self.clientToken):
|
if not hmac.compare_digest(request.headers['token'], self.clientToken):
|
||||||
abort(403)
|
if not hmac.compare_digest(request.form['token'], self.clientToken):
|
||||||
|
abort(403)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
abort(403)
|
if not hmac.compare_digest(request.form['token'], self.clientToken):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def afterReq(resp):
|
def afterReq(resp):
|
||||||
|
@ -417,14 +419,16 @@ class API:
|
||||||
if self._core._utils.validateHash(bHash):
|
if self._core._utils.validateHash(bHash):
|
||||||
try:
|
try:
|
||||||
resp = Block(bHash).bcontent
|
resp = Block(bHash).bcontent
|
||||||
|
except onionrexceptions.NoDataAvailable:
|
||||||
|
abort(404)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
resp = base64.b64decode(resp)
|
resp = base64.b64decode(resp)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if resp == 'Not Found':
|
if resp == 'Not Found' or not resp:
|
||||||
abourt(404)
|
abort(404)
|
||||||
return Response(resp)
|
return Response(resp)
|
||||||
|
|
||||||
@app.route('/waitforshare/<name>', methods=['post'])
|
@app.route('/waitforshare/<name>', methods=['post'])
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
'''
|
'''
|
||||||
import core, json
|
import core, json
|
||||||
from onionrusers import contactmanager
|
from onionrusers import contactmanager
|
||||||
from flask import Blueprint, Response, request, abort
|
from flask import Blueprint, Response, request, abort, redirect
|
||||||
|
|
||||||
friends = Blueprint('friends', __name__)
|
friends = Blueprint('friends', __name__)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ def remove_friend(pubkey):
|
||||||
def set_info(pubkey, key):
|
def set_info(pubkey, key):
|
||||||
data = request.form['data']
|
data = request.form['data']
|
||||||
contactmanager.ContactManager(core.Core(), pubkey).set_info(key, data)
|
contactmanager.ContactManager(core.Core(), pubkey).set_info(key, data)
|
||||||
return 'success'
|
return redirect(request.referrer + '#' + request.form['token'])
|
||||||
|
|
||||||
@friends.route('/friends/getinfo/<pubkey>/<key>')
|
@friends.route('/friends/getinfo/<pubkey>/<key>')
|
||||||
def get_info(pubkey, key):
|
def get_info(pubkey, key):
|
||||||
|
|
|
@ -139,32 +139,10 @@ class Block:
|
||||||
|
|
||||||
# import from file
|
# import from file
|
||||||
if blockdata is None:
|
if blockdata is None:
|
||||||
blockdata = onionrstorage.getData(self.core, self.getHash()).decode()
|
try:
|
||||||
'''
|
|
||||||
|
|
||||||
filelocation = file
|
|
||||||
|
|
||||||
readfile = True
|
|
||||||
|
|
||||||
if filelocation is None:
|
|
||||||
if self.getHash() is None:
|
|
||||||
return False
|
|
||||||
elif self.getHash() in Block.getCache():
|
|
||||||
# get the block from cache, if it's in it
|
|
||||||
blockdata = Block.getCache(self.getHash())
|
|
||||||
readfile = False
|
|
||||||
|
|
||||||
# read from file if it's still None
|
|
||||||
if blockdata is None:
|
|
||||||
filelocation = self.core.dataDir + 'blocks/%s.dat' % self.getHash()
|
|
||||||
|
|
||||||
if readfile:
|
|
||||||
blockdata = onionrstorage.getData(self.core, self.getHash()).decode()
|
blockdata = onionrstorage.getData(self.core, self.getHash()).decode()
|
||||||
#with open(filelocation, 'rb') as f:
|
except AttributeError:
|
||||||
#blockdata = f.read().decode()
|
raise onionrexceptions.NoDataAvailable('Block does not exist')
|
||||||
|
|
||||||
self.blockFile = filelocation
|
|
||||||
'''
|
|
||||||
else:
|
else:
|
||||||
self.blockFile = None
|
self.blockFile = None
|
||||||
# parse block
|
# parse block
|
||||||
|
@ -200,11 +178,11 @@ class Block:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to parse block %s.' % self.getHash(), error = e, timestamp = False)
|
logger.warn('Failed to parse block %s.' % self.getHash(), error = e, timestamp = False)
|
||||||
|
|
||||||
# if block can't be parsed, it's a waste of precious space. Throw it away.
|
# if block can't be parsed, it's a waste of precious space. Throw it away.
|
||||||
if not self.delete():
|
if not self.delete():
|
||||||
logger.error('Failed to delete invalid block %s.' % self.getHash(), error = e)
|
logger.warn('Failed to delete invalid block %s.' % self.getHash(), error = e)
|
||||||
else:
|
else:
|
||||||
logger.debug('Deleted invalid block %s.' % self.getHash(), timestamp = False)
|
logger.debug('Deleted invalid block %s.' % self.getHash(), timestamp = False)
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,8 @@ class DaemonTools:
|
||||||
'''Check if we are connected to the internet or not when we can't connect to any peers'''
|
'''Check if we are connected to the internet or not when we can't connect to any peers'''
|
||||||
if len(self.daemon.onlinePeers) == 0:
|
if len(self.daemon.onlinePeers) == 0:
|
||||||
if not netutils.checkNetwork(self.daemon._core._utils, torPort=self.daemon.proxyPort):
|
if not netutils.checkNetwork(self.daemon._core._utils, torPort=self.daemon.proxyPort):
|
||||||
logger.warn('Network check failed, are you connected to the internet?')
|
if not self.daemon.shutdown:
|
||||||
|
logger.warn('Network check failed, are you connected to the internet?')
|
||||||
self.daemon.isOnline = False
|
self.daemon.isOnline = False
|
||||||
else:
|
else:
|
||||||
self.daemon.isOnline = True
|
self.daemon.isOnline = True
|
||||||
|
|
|
@ -18,6 +18,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
friendListDisplay = document.getElementById('friendList')
|
friendListDisplay = document.getElementById('friendList')
|
||||||
|
addForm = document.getElementById('addFriend')
|
||||||
|
|
||||||
|
addForm.onsubmit = function(){
|
||||||
|
var friend = document.getElementsByName('addKey')[0]
|
||||||
|
var alias = document.getElementsByName('data')[0]
|
||||||
|
|
||||||
|
fetch('/friends/add/' + friend.value, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"token": webpass
|
||||||
|
}}).then(function(data) {
|
||||||
|
if (alias.value.trim().length > 0){
|
||||||
|
post_to_url('/friends/setinfo/' + friend.value + '/name', {'data': alias.value, 'token': webpass})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fetch('/friends/list', {
|
fetch('/friends/list', {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -28,16 +46,26 @@ fetch('/friends/list', {
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for(var k in resp) keys.push(k);
|
for(var k in resp) keys.push(k);
|
||||||
console.log(keys)
|
console.log(keys)
|
||||||
|
friendListDisplay.innerHTML = 'Click name to view info<br><br>'
|
||||||
for (var i = 0; i < keys.length; i++){
|
for (var i = 0; i < keys.length; i++){
|
||||||
friendListDisplay.innerText = ''
|
|
||||||
var peer = keys[i]
|
var peer = keys[i]
|
||||||
var name = resp[keys[i]]['name']
|
var name = resp[keys[i]]['name']
|
||||||
if (name === null || name === ''){
|
if (name === null || name === ''){
|
||||||
name = 'Anonymous'
|
name = peer
|
||||||
}
|
}
|
||||||
var entry = document.createElement('div')
|
var entry = document.createElement('div')
|
||||||
|
var nameText = document.createElement('input')
|
||||||
|
removeButton = document.createElement('button')
|
||||||
|
removeButton.classList.add('friendRemove')
|
||||||
|
removeButton.classList.add('dangerBtn')
|
||||||
|
entry.setAttribute('data-pubkey', peer)
|
||||||
|
removeButton.innerText = 'X'
|
||||||
|
nameText.value = name
|
||||||
|
nameText.readOnly = true
|
||||||
|
nameText.style.fontStyle = "italic"
|
||||||
entry.style.paddingTop = '8px'
|
entry.style.paddingTop = '8px'
|
||||||
entry.innerText = name + ' - ' + peer
|
entry.appendChild(removeButton)
|
||||||
|
entry.appendChild(nameText)
|
||||||
friendListDisplay.appendChild(entry)
|
friendListDisplay.appendChild(entry)
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -16,8 +16,8 @@
|
||||||
<h2>Friend Manager</h2>
|
<h2>Friend Manager</h2>
|
||||||
<form id='addFriend' action='/' method='POST'>
|
<form id='addFriend' action='/' method='POST'>
|
||||||
<label>Friend ID: <input type='text' name='addKey' placeholder='public key/ID' required></label>
|
<label>Friend ID: <input type='text' name='addKey' placeholder='public key/ID' required></label>
|
||||||
<label>Set Alias: <input type='text' name='addAlias' placeholder='what to call them' required></label>
|
<label>Set Alias: <input type='text' name='data' placeholder='what to call them'></label>
|
||||||
<input type='submit' value='Add Friend'>
|
<input type='submit' value='Add Friend' class='successBtn'>
|
||||||
</form>
|
</form>
|
||||||
<h2>Friend List:</h2>
|
<h2>Friend List:</h2>
|
||||||
<div id='friendList'>None Yet :(</div>
|
<div id='friendList'>None Yet :(</div>
|
||||||
|
|
|
@ -13,3 +13,14 @@ form label{
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#friendList{
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
#friendList span{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#friendList button{
|
||||||
|
display: inline;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
|
@ -151,3 +151,21 @@ body{
|
||||||
content: '❌';
|
content: '❌';
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn, .warnBtn, .dangerBtn, .successBtn{
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 2px solid black;
|
||||||
|
}
|
||||||
|
.warnBtn{
|
||||||
|
background-color: orange;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
.dangerBtn{
|
||||||
|
background-color: #f44336;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
.successBtn{
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: black;
|
||||||
|
}
|
|
@ -20,6 +20,25 @@
|
||||||
webpass = document.location.hash.replace('#', '')
|
webpass = document.location.hash.replace('#', '')
|
||||||
nowebpass = false
|
nowebpass = false
|
||||||
|
|
||||||
|
function post_to_url(path, params) {
|
||||||
|
|
||||||
|
var form = document.createElement("form")
|
||||||
|
|
||||||
|
form.setAttribute("method", "POST")
|
||||||
|
form.setAttribute("action", path)
|
||||||
|
|
||||||
|
for(var key in params) {
|
||||||
|
var hiddenField = document.createElement("input")
|
||||||
|
hiddenField.setAttribute("type", "hidden")
|
||||||
|
hiddenField.setAttribute("name", key)
|
||||||
|
hiddenField.setAttribute("value", params[key])
|
||||||
|
form.appendChild(hiddenField)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(form)
|
||||||
|
form.submit()
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof webpass == "undefined"){
|
if (typeof webpass == "undefined"){
|
||||||
webpass = localStorage['webpass']
|
webpass = localStorage['webpass']
|
||||||
}
|
}
|
||||||
|
@ -67,3 +86,4 @@ for(var i = 0; i < refreshLinks.length; i++) {
|
||||||
location.reload()
|
location.reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue