From 2219be9ae35ad52fcb5e3ee4ea4af47f88a4fd17 Mon Sep 17 00:00:00 2001
From: Kevin Froman
Date: Sat, 20 Apr 2019 17:55:54 -0500
Subject: [PATCH] + Work on boards * Handle ctrl-c better in main loop
---
onionr/api.py | 5 +++++
onionr/communicator.py | 2 +-
onionr/core.py | 4 ++++
onionr/onionrcommands/daemonlaunch.py | 22 ++++++++++++++--------
onionr/static-data/www/board/board.js | 19 +++++++++++++++++++
onionr/static-data/www/board/index.html | 2 +-
6 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/onionr/api.py b/onionr/api.py
index ae6368e2..2f320fbc 100755
--- a/onionr/api.py
+++ b/onionr/api.py
@@ -497,6 +497,11 @@ class API:
encrypt = False
bData = request.get_json(force=True)
message = bData['message']
+
+ # Detect if message (block body) is not specified
+ if type(message) is None:
+ return 'failure', 406
+
subject = 'temp'
encryptType = ''
sign = True
diff --git a/onionr/communicator.py b/onionr/communicator.py
index f10d37da..24907cf2 100755
--- a/onionr/communicator.py
+++ b/onionr/communicator.py
@@ -148,7 +148,7 @@ class OnionrCommunicatorDaemon:
self.shutdown = True
pass
- logger.info('Goodbye.')
+ logger.info('Goodbye. (Onionr is cleaning up, and will exit)')
try:
self.service_greenlets
except AttributeError:
diff --git a/onionr/core.py b/onionr/core.py
index 48029555..47f00fa7 100755
--- a/onionr/core.py
+++ b/onionr/core.py
@@ -686,9 +686,13 @@ class Core:
return False
retData = False
+ if type(data) is None:
+ raise ValueError('Data cannot be none')
+
createTime = self._utils.getRoundedEpoch()
# check nonce
+ print(data)
dataNonce = self._utils.bytesToStr(self._crypto.sha3Hash(data))
try:
with open(self.dataNonceFile, 'r') as nonces:
diff --git a/onionr/onionrcommands/daemonlaunch.py b/onionr/onionrcommands/daemonlaunch.py
index b5334068..dac35115 100644
--- a/onionr/onionrcommands/daemonlaunch.py
+++ b/onionr/onionrcommands/daemonlaunch.py
@@ -18,7 +18,7 @@
along with this program. If not, see .
'''
-import os, time, sys, platform, sqlite3
+import os, time, sys, platform, sqlite3, signal
from threading import Thread
import onionr, api, logger, communicator
import onionrevents as events
@@ -84,9 +84,12 @@ def daemon(o_inst):
logger.debug('Started communicator.')
events.event('daemon_start', onionr = o_inst)
- try:
- while True:
+ while True:
+ try:
time.sleep(3)
+ except KeyboardInterrupt:
+ o_inst.communicatorInst.shutdown = True
+ finally:
# Debug to print out used FDs (regular and net)
#proc = psutil.Process()
#print('api-files:',proc.open_files(), len(psutil.net_connections()))
@@ -95,16 +98,19 @@ def daemon(o_inst):
break
if o_inst.killed:
break # Break out if sigterm for clean exit
- except KeyboardInterrupt:
- pass
- finally:
- o_inst.onionrCore.daemonQueueAdd('shutdown')
- o_inst.onionrUtils.localCommand('shutdown')
+
+ signal.signal(signal.SIGINT, _ignore_sigint)
+ o_inst.onionrCore.daemonQueueAdd('shutdown')
+ o_inst.onionrUtils.localCommand('shutdown')
+
net.killTor()
time.sleep(3)
o_inst.deleteRunFiles()
return
+def _ignore_sigint(sig, frame):
+ return
+
def kill_daemon(o_inst):
'''
Shutdown the Onionr daemon
diff --git a/onionr/static-data/www/board/board.js b/onionr/static-data/www/board/board.js
index d9f35bce..7d70f9db 100644
--- a/onionr/static-data/www/board/board.js
+++ b/onionr/static-data/www/board/board.js
@@ -6,6 +6,9 @@ newPostForm = document.getElementById('addMsg')
function appendMessages(msg){
var humanDate = new Date(0)
+ if (msg.length == 0){
+ return
+ }
var msg = JSON.parse(msg)
var dateEl = document.createElement('span')
var el = document.createElement('div')
@@ -46,5 +49,21 @@ document.getElementById('refreshFeed').onclick = function(){
}
newPostForm.onsubmit = function(){
+ var message = document.getElementById('newMsgText').value
+ var postData = {'message': message, 'type': 'txt', 'encrypt': false}
+ postData = JSON.stringify(postData)
+ newPostForm.style.display = 'none'
+ fetch('/insertblock', {
+ method: 'POST',
+ body: postData,
+ headers: {
+ "content-type": "application/json",
+ "token": webpass
+ }})
+ .then((resp) => resp.text()) // Transform the data into json
+ .then(function(data) {
+ newPostForm.style.display = 'block'
+ alert('Queued for submission!')
+ })
return false
}
\ No newline at end of file
diff --git a/onionr/static-data/www/board/index.html b/onionr/static-data/www/board/index.html
index 180bf0b0..37d22ea9 100644
--- a/onionr/static-data/www/board/index.html
+++ b/onionr/static-data/www/board/index.html
@@ -16,7 +16,7 @@
Anonymous message board