From f5b34066849cc0f6c8043a4c99a6c834b1d6e871 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 14 Jun 2019 13:02:02 -0500 Subject: [PATCH] + added tor data deletion command * better support multiple tor versions in tor bootstrap (latest broke on manjaro before this) * reduced interval for upload block timer to 5 seconds * show message if inbox is empty in webui mail --- onionr/communicator.py | 2 +- onionr/netcontroller.py | 6 +++--- onionr/onionrcommands/README.md | 4 +++- onionr/onionrcommands/__init__.py | 9 ++++++--- onionr/onionrcommands/resettor.py | 29 +++++++++++++++++++++++++++++ onionr/static-data/www/mail/mail.js | 1 + 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 onionr/onionrcommands/resettor.py diff --git a/onionr/communicator.py b/onionr/communicator.py index e9eeb28f..b2788e0f 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -118,7 +118,7 @@ class OnionrCommunicatorDaemon: OnionrCommunicatorTimers(self, cooldownpeer.cooldown_peer, 30, myArgs=[self], requiresPeer=True) # Timer to read the upload queue and upload the entries to peers - OnionrCommunicatorTimers(self, self.uploadBlock, 10, requiresPeer=True, maxThreads=1) + OnionrCommunicatorTimers(self, self.uploadBlock, 5, requiresPeer=True, maxThreads=1) # Timer to process the daemon command queue OnionrCommunicatorTimers(self, self.daemonCommands, 6, maxThreads=3) diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index 6edbd474..69a5f21e 100755 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -144,15 +144,15 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) # wait for tor to get to 100% bootstrap try: for line in iter(tor.stdout.readline, b''): - if 'Bootstrapped 100%: Done' in line.decode(): + if 'bootstrapped 100' in line.decode().lower(): break - elif 'Opening Socks listener' in line.decode(): + elif 'opening socks listener' in line.decode().lower(): logger.debug(line.decode().replace('\n', '')) else: logger.fatal('Failed to start Tor. Maybe a stray instance of Tor used by Onionr is still running?') return False except KeyboardInterrupt: - logger.fatal('Got keyboard interrupt.', timestamp = False, level = logger.LEVEL_IMPORTANT) + logger.fatal('Got keyboard interrupt. Onionr will exit soon.', timestamp = False, level = logger.LEVEL_IMPORTANT) return False logger.debug('Finished starting Tor.', timestamp=True) diff --git a/onionr/onionrcommands/README.md b/onionr/onionrcommands/README.md index a817cc7f..fed35bb5 100644 --- a/onionr/onionrcommands/README.md +++ b/onionr/onionrcommands/README.md @@ -22,4 +22,6 @@ openwebinterface.py: command to open the web interface (useful because it requir plugincommands.py: commands to enable/disable/reload plugins -pubkeymanager.py: commands to generate a new onionr user id, change the active id, or add/remove/list friends \ No newline at end of file +pubkeymanager.py: commands to generate a new onionr user id, change the active id, or add/remove/list friends + +resettor.py: command to delete the Tor data directory \ No newline at end of file diff --git a/onionr/onionrcommands/__init__.py b/onionr/onionrcommands/__init__.py index e561292c..3a50d59d 100644 --- a/onionr/onionrcommands/__init__.py +++ b/onionr/onionrcommands/__init__.py @@ -21,7 +21,7 @@ import webbrowser, sys import logger from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders -from . import banblocks, exportblocks, openwebinterface +from . import banblocks, exportblocks, openwebinterface, resettor def show_help(o_inst, command): @@ -128,7 +128,9 @@ def get_commands(onionr_inst): 'friend': onionr_inst.friendCmd, 'addid': onionr_inst.addID, 'add-id': onionr_inst.addID, - 'change-id': onionr_inst.changeID + 'change-id': onionr_inst.changeID, + + 'reset-tor': resettor.reset_tor } cmd_help = { @@ -159,5 +161,6 @@ cmd_help = { 'friend': '[add|remove] [public key/id]', 'add-id': 'Generate a new ID (key pair)', 'change-id': 'Change active ID', - 'open-home': 'Open your node\'s home/info screen' + 'open-home': 'Open your node\'s home/info screen', + 'reset-tor': 'Delete the Tor data directory. Only do this if Tor never starts.' } diff --git a/onionr/onionrcommands/resettor.py b/onionr/onionrcommands/resettor.py new file mode 100644 index 00000000..d49cacfe --- /dev/null +++ b/onionr/onionrcommands/resettor.py @@ -0,0 +1,29 @@ +''' + Onionr - Private P2P Communication + + Command to delete the Tor data directory if its safe to do so +''' +''' + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' +import os, shutil +import logger, core +def reset_tor(): + c = core.Core() + tor_dir = c.dataDir + 'tordata' + if os.path.exists(tor_dir): + if c._utils.localCommand('/ping') == 'pong!': + logger.warn('Cannot delete Tor data while Onionr is running') + else: + shutil.rmtree(tor_dir) \ No newline at end of file diff --git a/onionr/static-data/www/mail/mail.js b/onionr/static-data/www/mail/mail.js index d7b62765..fb7b2b3a 100644 --- a/onionr/static-data/www/mail/mail.js +++ b/onionr/static-data/www/mail/mail.js @@ -201,6 +201,7 @@ function getInbox(){ var requested = '' for(var i = 0; i < pms.length; i++) { if (pms[i].trim().length == 0){ + threadPart.innerText = 'No messages to show ¯\\_(ツ)_/¯' continue } else{