Merge nick's fixes
This commit is contained in:
parent
1de668a9e5
commit
8a4102cbd1
@ -85,10 +85,7 @@ class PrivateAPI:
|
|||||||
logger.error("client password needs to be set")
|
logger.error("client password needs to be set")
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
if not hmac.compare_digest(self.clientToken, token):
|
return hmac.compare_digest(self.clientToken, token)
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
from onionrutils import epoch
|
from onionrutils import epoch
|
||||||
def replay_timestamp_validation(timestamp):
|
def replay_timestamp_validation(timestamp):
|
||||||
if epoch.get_epoch() - int(timestamp) > 2419200:
|
return epoch.get_epoch() - int(timestamp) <= 2419200
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
@ -41,10 +41,8 @@ def peer_cleanup():
|
|||||||
if peerprofiles.PeerProfiles(address).score < min_score:
|
if peerprofiles.PeerProfiles(address).score < min_score:
|
||||||
keydb.removekeys.remove_address(address)
|
keydb.removekeys.remove_address(address)
|
||||||
try:
|
try:
|
||||||
if (int(epoch.get_epoch()) - int(keydb.transportinfo.get_address_info(address, 'lastConnect'))) >= 600:
|
lastConnect = int(keydb.transportinfo.get_address_info(address, 'lastConnect'))
|
||||||
expireTime = 600
|
expireTime = 86400 - int(epoch.get_epoch()) - lastConnect
|
||||||
else:
|
|
||||||
expireTime = 86400
|
|
||||||
blacklist.addToDB(address, dataType=1, expire=expireTime)
|
blacklist.addToDB(address, dataType=1, expire=expireTime)
|
||||||
except sqlite3.IntegrityError: #TODO just make sure its not a unique constraint issue
|
except sqlite3.IntegrityError: #TODO just make sure its not a unique constraint issue
|
||||||
pass
|
pass
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
'''
|
'''
|
||||||
Onionr - Private P2P Communication
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
z-fill (zero fill) a string to a specific length, intended for reconstructing block hashes
|
z-fill (zero fill) a string to a specific length
|
||||||
|
intended for reconstructing block hashes
|
||||||
'''
|
'''
|
||||||
|
from typing import Union
|
||||||
'''
|
'''
|
||||||
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
|
||||||
@ -17,10 +19,16 @@
|
|||||||
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/>.
|
||||||
'''
|
'''
|
||||||
def reconstruct_hash(hex_hash, length=64):
|
|
||||||
|
|
||||||
|
def reconstruct_hash(hex_hash: Union[str, bytes],
|
||||||
|
length: int = 64) -> Union[str, bytes]:
|
||||||
|
"""Pad hash hex string with zeros, return result"""
|
||||||
return hex_hash.zfill(length)
|
return hex_hash.zfill(length)
|
||||||
|
|
||||||
def deconstruct_hash(hex_hash):
|
|
||||||
|
def deconstruct_hash(hex_hash: Union[str, bytes]) -> Union[str, bytes]:
|
||||||
|
"""Remove leading zeros from hex hash, return result"""
|
||||||
new_hash = ''
|
new_hash = ''
|
||||||
ret_bytes = False
|
ret_bytes = False
|
||||||
try:
|
try:
|
||||||
@ -40,4 +48,4 @@ def deconstruct_hash(hex_hash):
|
|||||||
if ret_bytes:
|
if ret_bytes:
|
||||||
|
|
||||||
new_hash = new_hash.encode()
|
new_hash = new_hash.encode()
|
||||||
return new_hash
|
return new_hash
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
requested = []
|
|
||||||
|
|
||||||
var windowHeight = window.innerHeight;
|
|
||||||
webpassword = webpass
|
|
||||||
newPostForm = document.getElementById('addMsg')
|
newPostForm = document.getElementById('addMsg')
|
||||||
firstLoad = true
|
firstLoad = true
|
||||||
lastLoadedBoard = 'global'
|
lastLoadedBoard = 'global'
|
||||||
@ -30,14 +26,12 @@ loadingTimeout = 8000
|
|||||||
|
|
||||||
let toggleLoadingMessage = function(){
|
let toggleLoadingMessage = function(){
|
||||||
switch (loadingMessage.style.display){
|
switch (loadingMessage.style.display){
|
||||||
case "block":
|
|
||||||
case "inline":
|
|
||||||
case "inline-block":
|
case "inline-block":
|
||||||
loadingMessage.style.display = "none"
|
loadingMessage.style.display = "none"
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loadingMessage.style.display = "initial"
|
loadingMessage.style.display = "initial"
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,37 +39,36 @@ fetch('/flow/version', {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"token": webpass
|
"token": webpass
|
||||||
}})
|
}})
|
||||||
.then((resp) => resp.text())
|
.then((ver) => ver.text())
|
||||||
.then(function(data) {
|
.then(function(ver) {
|
||||||
document.getElementById('circlesVersion').innerText = data
|
document.getElementById('circlesVersion').innerText = ver
|
||||||
})
|
})
|
||||||
|
|
||||||
function appendMessages(msg, blockHash, beforeHash, channel){
|
function appendMessages(msg, blockHash, beforeHash, channel) {
|
||||||
if (channel !== document.getElementById('feedIDInput').value){return}
|
if (channel !== document.getElementById('feedIDInput').value) return // ignore if channel name isn't matching
|
||||||
|
if (msg.length == 0) return // ignore empty messages
|
||||||
|
|
||||||
var humanDate = new Date(0)
|
var humanDate = new Date(0)
|
||||||
if (msg.length == 0){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//var msg = JSON.parse(msg)
|
|
||||||
var el = document.createElement('div')
|
|
||||||
var msgDate = msg['meta']['time']
|
var msgDate = msg['meta']['time']
|
||||||
var feed = document.getElementById("feed")
|
var feed = document.getElementById("feed")
|
||||||
var beforeEl = null
|
var beforeEl = null
|
||||||
|
|
||||||
if (msgDate === undefined){
|
if (msgDate === undefined){
|
||||||
msgDate = 'unknown'
|
msgDate = 'unknown'
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
humanDate.setUTCSeconds(msgDate)
|
humanDate.setUTCSeconds(msgDate)
|
||||||
msgDate = humanDate.toLocaleTimeString() + ' ' + humanDate.toLocaleDateString()
|
msgDate = humanDate.toLocaleTimeString() + ' ' + humanDate.toLocaleDateString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var el = document.createElement('div')
|
||||||
el.className = 'entry'
|
el.className = 'entry'
|
||||||
el.innerText = msg['content']
|
el.innerText = msg['content']
|
||||||
if (beforeHash !== null){
|
|
||||||
for (x = 0; x < feed.children.length; x++){
|
if (beforeHash !== null) {
|
||||||
if (feed.children[x].getAttribute('data-bl') === beforeHash){
|
for (i = 0; i < feed.children.length; i++) {
|
||||||
beforeEl = feed.children[x]
|
if (feed.children[i].getAttribute('data-bl') === beforeHash) {
|
||||||
|
beforeEl = feed.children[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,12 +126,13 @@ function getBlocks(){
|
|||||||
var feed = document.getElementById("feed")
|
var feed = document.getElementById("feed")
|
||||||
var ch = document.getElementById('feedIDInput').value
|
var ch = document.getElementById('feedIDInput').value
|
||||||
if (lastLoadedBoard !== ch){
|
if (lastLoadedBoard !== ch){
|
||||||
|
requested = []
|
||||||
|
|
||||||
toggleLoadingMessage()
|
toggleLoadingMessage()
|
||||||
loadedAny = false
|
loadedAny = false
|
||||||
while (feed.firstChild) {
|
|
||||||
feed.removeChild(feed.firstChild);
|
while (feed.firstChild) feed.removeChild(feed.firstChild); // remove all messages from feed
|
||||||
}
|
|
||||||
requested = [] // reset requested list
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
if (! loadedAny && ch == document.getElementById('feedIDInput').value){
|
if (! loadedAny && ch == document.getElementById('feedIDInput').value){
|
||||||
PNotify.notice("There are no posts for " + ch + ". You can be the first!")
|
PNotify.notice("There are no posts for " + ch + ". You can be the first!")
|
||||||
@ -156,13 +150,12 @@ function getBlocks(){
|
|||||||
var blockList = feedText.split(',')
|
var blockList = feedText.split(',')
|
||||||
|
|
||||||
for (i = 0; i < blockList.length; i++){
|
for (i = 0; i < blockList.length; i++){
|
||||||
while (blockList[i].length < 64) { blockList[i] = "0" + blockList[i] }
|
blockList[i] = "0".repeat(64 - blockList[i].length) + blockList[i] // pad hash with zeroes
|
||||||
|
|
||||||
if (! requested.includes(blockList[i])){
|
if (! requested.includes(blockList[i])){
|
||||||
if (blockList[i].length == 0){
|
if (blockList[i].length == 0) continue
|
||||||
continue
|
else requested.push(blockList[i])
|
||||||
}
|
loadMessage(blockList[i], blockList, i, ch);
|
||||||
requested.push(blockList[i])
|
|
||||||
loadMessage(blockList[i], blockList, i, ch)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,15 +165,14 @@ function loadMessage(blockHash, blockList, count, channel){
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"token": webpass
|
"token": webpass
|
||||||
}})
|
}})
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
let before = blockList[count - 1]
|
let before = blockList[count - 1]
|
||||||
let delay = 2000
|
let delay = 2000
|
||||||
if (typeof before == "undefined"){
|
if (typeof before == "undefined"){
|
||||||
before = null
|
before = null
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
let existing = document.getElementsByClassName('cMsgBox')
|
let existing = document.getElementsByClassName('cMsgBox')
|
||||||
for (x = 0; x < existing.length; x++){
|
for (x = 0; x < existing.length; x++){
|
||||||
if (existing[x].getAttribute('data-bl') === before){
|
if (existing[x].getAttribute('data-bl') === before){
|
||||||
@ -190,10 +182,10 @@ function loadMessage(blockHash, blockList, count, channel){
|
|||||||
}
|
}
|
||||||
setTimeout(function(){appendMessages(data, blockHash, before, channel)}, delay)
|
setTimeout(function(){appendMessages(data, blockHash, before, channel)}, delay)
|
||||||
//appendMessages(data, blockHash, before)
|
//appendMessages(data, blockHash, before)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('refreshFeed').onclick = function(){
|
document.getElementById('refreshFeed').onclick = function() {
|
||||||
getBlocks()
|
getBlocks()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +203,8 @@ newPostForm.onsubmit = function(){
|
|||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"token": webpass
|
"token": webpass
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
.then((resp) => resp.text()) // Transform the data into json
|
.then((resp) => resp.text()) // Transform the data into json
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
newPostForm.style.display = 'block'
|
newPostForm.style.display = 'block'
|
||||||
@ -223,8 +216,8 @@ newPostForm.onsubmit = function(){
|
|||||||
}
|
}
|
||||||
PNotify.success({
|
PNotify.success({
|
||||||
text: "Message queued for posting"
|
text: "Message queued for posting"
|
||||||
})
|
})
|
||||||
setTimeout(function(){getBlocks()}, 500)
|
setTimeout(function(){getBlocks()}, 500)
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user