From 31039861c20d167bafcfa8396eb12d7fe393fec2 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 23 Feb 2019 18:11:43 -0600 Subject: [PATCH] bind ip config option, use different type for deniable block, mostly finished friends UI --- onionr/api.py | 26 +++++++++++------------ onionr/httpapi/friendsapi/__init__.py | 4 ++-- onionr/onionr.py | 4 +++- onionr/onionrdaemontools.py | 2 +- onionr/static-data/default_config.json | 5 +++-- onionr/static-data/www/friends/friends.js | 14 ++++++++++++ onionr/static-data/www/friends/index.html | 3 +++ onionr/static-data/www/mail/index.html | 5 ++++- onionr/static-data/www/private/index.html | 1 + 9 files changed, 44 insertions(+), 20 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index 402622d9..6590a258 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -40,22 +40,22 @@ class FDSafeHandler(WSGIHandler): def setBindIP(filePath): '''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)''' - hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))] - data = '.'.join(hostOctets) - - # Try to bind IP. Some platforms like Mac block non normal 127.x.x.x - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind((data, 0)) - except OSError: - # if mac/non-bindable, show warning and default to 127.0.0.1 - logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.') + if config.get('general.random_bind_ip', True): + hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))] + data = '.'.join(hostOctets) + # Try to bind IP. Some platforms like Mac block non normal 127.x.x.x + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + s.bind((data, 0)) + except OSError: + # if mac/non-bindable, show warning and default to 127.0.0.1 + logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.') + data = '127.0.0.1' + s.close() + else: data = '127.0.0.1' - s.close() - with open(filePath, 'w') as bindFile: bindFile.write(data) - return data class PublicAPI: diff --git a/onionr/httpapi/friendsapi/__init__.py b/onionr/httpapi/friendsapi/__init__.py index d6a3c2f5..c935ded5 100644 --- a/onionr/httpapi/friendsapi/__init__.py +++ b/onionr/httpapi/friendsapi/__init__.py @@ -34,12 +34,12 @@ def list_friends(): @friends.route('/friends/add/', methods=['POST']) def add_friend(pubkey): contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1) - return 'success' + return redirect(request.referrer + '#' + request.form['token']) @friends.route('/friends/remove/', methods=['POST']) def remove_friend(pubkey): contactmanager.ContactManager(core.Core(), pubkey).setTrust(0) - return 'success' + return redirect(request.referrer + '#' + request.form['token']) @friends.route('/friends/setinfo//', methods=['POST']) def set_info(pubkey, key): diff --git a/onionr/onionr.py b/onionr/onionr.py index 7742f632..1a16742b 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -308,7 +308,9 @@ class Onionr: except FileNotFoundError: logger.error('Onionr seems to not be running (could not get api host)') else: - webbrowser.open_new_tab('http://%s/#%s' % (url, config.get('client.webpassword'))) + url = 'http://%s/#%s' % (url, config.get('client.webpassword')) + print('If Onionr does not open automatically, use this URL:', url) + webbrowser.open_new_tab(url) def addID(self): try: diff --git a/onionr/onionrdaemontools.py b/onionr/onionrdaemontools.py index bae9031e..73cdf0f1 100755 --- a/onionr/onionrdaemontools.py +++ b/onionr/onionrdaemontools.py @@ -200,6 +200,6 @@ class DaemonTools: if secrets.randbelow(chance) == (chance - 1): fakePeer = self.daemon._core._crypto.generatePubKey()[0] data = secrets.token_hex(secrets.randbelow(500) + 1) - self.daemon._core.insertBlock(data, header='pm', encryptType='asym', asymPeer=fakePeer, meta={'subject': 'foo'}) + self.daemon._core.insertBlock(data, header='db', encryptType='asym', asymPeer=fakePeer, meta={'subject': 'foo'}) self.daemon.decrementThreadCount('insertDeniableBlock') return \ No newline at end of file diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index ba5e5566..86261502 100755 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -8,7 +8,8 @@ "security_level": 0, "max_block_age": 2678400, "bypass_tor_check": false, - "public_key": "" + "public_key": "", + "random_bind_ip": true }, "www" : { @@ -48,7 +49,7 @@ "verbosity" : "default", "file": { - "output": true, + "output": false, "path": "output.log" }, diff --git a/onionr/static-data/www/friends/friends.js b/onionr/static-data/www/friends/friends.js index 51e5fc21..68cc8661 100644 --- a/onionr/static-data/www/friends/friends.js +++ b/onionr/static-data/www/friends/friends.js @@ -20,6 +20,10 @@ friendListDisplay = document.getElementById('friendList') addForm = document.getElementById('addFriend') +function removeFriend(pubkey){ + post_to_url('/friends/remove/' + pubkey, {'token': webpass}) +} + addForm.onsubmit = function(){ var friend = document.getElementsByName('addKey')[0] var alias = document.getElementsByName('data')[0] @@ -68,4 +72,14 @@ fetch('/friends/list', { entry.appendChild(nameText) friendListDisplay.appendChild(entry) } + // If friend delete buttons are pressed + + var friendRemoveBtns = document.getElementsByClassName('friendRemove') + + for (var x = 0; x < friendRemoveBtns.length; x++){ + var friendKey = friendRemoveBtns[x].parentElement.getAttribute('data-pubkey') + friendRemoveBtns[x].onclick = function(){ + removeFriend(friendKey) + } + } }) \ No newline at end of file diff --git a/onionr/static-data/www/friends/index.html b/onionr/static-data/www/friends/index.html index 6110a29d..8c1074fe 100644 --- a/onionr/static-data/www/friends/index.html +++ b/onionr/static-data/www/friends/index.html @@ -5,6 +5,7 @@ Onionr + @@ -13,6 +14,8 @@
Onionr Web Control Panel +

+ Home

Friend Manager

diff --git a/onionr/static-data/www/mail/index.html b/onionr/static-data/www/mail/index.html index 03b0b8ec..1b1c0e84 100755 --- a/onionr/static-data/www/mail/index.html +++ b/onionr/static-data/www/mail/index.html @@ -16,7 +16,10 @@
Onionr Mail ✉️ -
Current Used Identity:
+

+
Home
+
+
Current Used Identity:


diff --git a/onionr/static-data/www/private/index.html b/onionr/static-data/www/private/index.html index 0b61cd45..8d5d5861 100755 --- a/onionr/static-data/www/private/index.html +++ b/onionr/static-data/www/private/index.html @@ -5,6 +5,7 @@ Onionr +