From 583c5290d4223ae17b8bbe9703731dfc99b2600b Mon Sep 17 00:00:00 2001 From: Arinerron Date: Fri, 26 Jan 2018 16:52:20 -0800 Subject: [PATCH 1/8] Add input functions --- onionr/communicator.py | 2 +- onionr/data/host.txt | 1 + onionr/data/hs/hostname | 1 + onionr/data/torrc | 4 ++++ onionr/logger.py | 47 ++++++++++++++++++++++++++++++++++++++++- onionr/onionrutils.py | 24 ++++++++++----------- onionr/tests.py | 6 +++--- 7 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 onionr/data/host.txt create mode 100644 onionr/data/hs/hostname create mode 100644 onionr/data/torrc diff --git a/onionr/communicator.py b/onionr/communicator.py index febbd103..6c1e1906 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -98,7 +98,7 @@ class OnionrCommunicate: return def performGet(self, action, peer, data=None, type='tor'): - '''performs a request to a peer through Tor or i2p (currently only tor)''' + '''Performs a request to a peer through Tor or i2p (currently only tor)''' if not peer.endswith('.onion') and not peer.endswith('.onion/'): raise PeerError('Currently only Tor .onion peers are supported. You must manually specify .onion') socksPort = sys.argv[2] diff --git a/onionr/data/host.txt b/onionr/data/host.txt new file mode 100644 index 00000000..e56ea71e --- /dev/null +++ b/onionr/data/host.txt @@ -0,0 +1 @@ +127.0.0.1 \ No newline at end of file diff --git a/onionr/data/hs/hostname b/onionr/data/hs/hostname new file mode 100644 index 00000000..5172f43b --- /dev/null +++ b/onionr/data/hs/hostname @@ -0,0 +1 @@ +aaron-optiplex diff --git a/onionr/data/torrc b/onionr/data/torrc new file mode 100644 index 00000000..bc783e55 --- /dev/null +++ b/onionr/data/torrc @@ -0,0 +1,4 @@ +SocksPort 16712 +HiddenServiceDir data/hs/ +HiddenServicePort 80 127.0.0.1:1337 + \ No newline at end of file diff --git a/onionr/logger.py b/onionr/logger.py index fad5e95e..f147f44b 100644 --- a/onionr/logger.py +++ b/onionr/logger.py @@ -18,7 +18,7 @@ along with this program. If not, see . ''' -import re +import re, sys class colors: ''' @@ -127,6 +127,51 @@ def log(prefix, data, color = ''): raw(output) +''' + Takes in input from the console, not stored in logs + message: The message to display before taking input +''' +def input(message = 'Enter input: '): + color = colors.fg.green + colors.bold + output = colors.reset + str(color) + '... ' + colors.reset + str(message) + colors.reset + + if not get_settings() & USE_ANSI: + output = colors.filter(output) + + sys.stdout.write(output) + return raw_input() + +''' + Displays an "Are you sure" message, returns True for Y and False for N + message: The confirmation message, use %s for (y/n) + default: which to prefer-- y or n +''' +def confirm(default = 'y', message = 'Are you sure %s? '): + color = colors.fg.green + colors.bold + + default = default.lower() + confirm = colors.bold + if default.startswith('y'): + confirm += '(Y/n)' + else: + confirm += '(y/N)' + confirm += colors.reset + color + + output = colors.reset + str(color) + '... ' + colors.reset + str(message) + colors.reset + + if not get_settings() & USE_ANSI: + output = colors.filter(output) + + sys.stdout.write(output.replace('%s', confirm)) + inp = raw_input().lower() + + if 'y' in inp: + return True + if 'n' in inp: + return False + else: + return default == 'y' + # debug: when there is info that could be useful for debugging purposes only def debug(data): if get_level() <= LEVEL_DEBUG: diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index a1213341..b36dbff4 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -31,9 +31,6 @@ class OnionrUtils: self.fingerprintFile = 'data/own-fingerprint.txt' self._core = coreInstance return - def printErr(self, text='an error occured'): - '''Print an error message to stderr with a new line''' - logger.error(text) def localCommand(self, command): '''Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.''' config = configparser.ConfigParser() @@ -42,27 +39,30 @@ class OnionrUtils: else: return requests.get('http://' + open('data/host.txt', 'r').read() + ':' + str(config['CLIENT']['PORT']) + '/client/?action=' + command + '&token=' + config['CLIENT']['CLIENT HMAC']) - def getPassword(self, message='Enter password: '): + def getPassword(self, message='Enter password: ', confirm = True): '''Get a password without showing the users typing and confirm the input''' # Get a password safely with confirmation and return it while True: print(message) pass1 = getpass.getpass() - print('Confirm password: ') - pass2 = getpass.getpass() - if pass1 != pass2: - logger.error("Passwords do not match.") - input() + if confirm: + print('Confirm password: ') + pass2 = getpass.getpass() + if pass1 != pass2: + logger.error("Passwords do not match.") + input() + else: + break else: break return pass1 - def checkPort(self, port): + def checkPort(self, port, host = ''): '''Checks if a port is available, returns bool''' # inspired by https://www.reddit.com/r/learnpython/comments/2i4qrj/how_to_write_a_python_script_that_checks_to_see/ckzarux/ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) retVal = False try: - sock.bind(('', port)) + sock.bind((host, port)) except OSError as e: if e.errno is 98: retVal = True @@ -92,7 +92,7 @@ class OnionrUtils: return dataHash def validateHash(self, data, length=64): - '''validate if a string is a valid hex formatted hash''' + '''Validate if a string is a valid hex formatted hash''' retVal = True if len(data) != length: retVal = False diff --git a/onionr/tests.py b/onionr/tests.py index 93c5ba38..8735a1a4 100755 --- a/onionr/tests.py +++ b/onionr/tests.py @@ -115,13 +115,13 @@ class OnionrTests(unittest.TestCase): while True: command = myCore.daemonQueue() if command == False: - print('The queue is empty (false)') + logger.debug('The queue is empty (false)') break else: - print(command[0]) + logger.debug(command[0]) myCore.daemonQueueAdd('testCommand', 'testData') command = myCore.daemonQueue() if command[0] == 'testCommand': if myCore.daemonQueue() == False: - print('Succesfully added and read command') + logger.info('Succesfully added and read command') unittest.main() From 504d4960c5ca4b0545b6c2f8a44dd24f5bb5c32c Mon Sep 17 00:00:00 2001 From: Arinerron Date: Fri, 26 Jan 2018 16:55:33 -0800 Subject: [PATCH 2/8] Fix gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4f406e73..0d9c0eda 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ onionr/data/*.db onionr/data-old/* onionr/*.pyc onionr/*.log +onionr/data/hs/hostname +onionr/data/* From 2486b8ffcd7ccf32c1d392351b8fc75047d68b36 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:04:02 -0600 Subject: [PATCH 3/8] Update hostname --- onionr/data/hs/hostname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionr/data/hs/hostname b/onionr/data/hs/hostname index 5172f43b..8b137891 100644 --- a/onionr/data/hs/hostname +++ b/onionr/data/hs/hostname @@ -1 +1 @@ -aaron-optiplex + From 70351b0b5c2651f39ff9548d9a9ad3a52ad58063 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:07:37 -0600 Subject: [PATCH 4/8] Update host.txt --- onionr/data/host.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionr/data/host.txt b/onionr/data/host.txt index e56ea71e..8b137891 100644 --- a/onionr/data/host.txt +++ b/onionr/data/host.txt @@ -1 +1 @@ -127.0.0.1 \ No newline at end of file + From 946d5fb25c6ef19b5e6d58e4648a754b0023d38a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:07:47 -0600 Subject: [PATCH 5/8] Update torrc --- onionr/data/torrc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/onionr/data/torrc b/onionr/data/torrc index bc783e55..8b137891 100644 --- a/onionr/data/torrc +++ b/onionr/data/torrc @@ -1,4 +1 @@ -SocksPort 16712 -HiddenServiceDir data/hs/ -HiddenServicePort 80 127.0.0.1:1337 - \ No newline at end of file + From ff23a4dc6de8d4a3cd92a72f195af84ba8cd10d8 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:09:29 -0600 Subject: [PATCH 6/8] Delete host.txt --- onionr/data/host.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 onionr/data/host.txt diff --git a/onionr/data/host.txt b/onionr/data/host.txt deleted file mode 100644 index 8b137891..00000000 --- a/onionr/data/host.txt +++ /dev/null @@ -1 +0,0 @@ - From 192aee9dc2a5ac5fdb1c0d0069a8a6642a3fe304 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:09:38 -0600 Subject: [PATCH 7/8] Delete torrc --- onionr/data/torrc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 onionr/data/torrc diff --git a/onionr/data/torrc b/onionr/data/torrc deleted file mode 100644 index 8b137891..00000000 --- a/onionr/data/torrc +++ /dev/null @@ -1 +0,0 @@ - From 383c936e682f422f4e59cb81341cd1d2716777bc Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 26 Jan 2018 19:09:51 -0600 Subject: [PATCH 8/8] Delete hostname --- onionr/data/hs/hostname | 1 - 1 file changed, 1 deletion(-) delete mode 100644 onionr/data/hs/hostname diff --git a/onionr/data/hs/hostname b/onionr/data/hs/hostname deleted file mode 100644 index 8b137891..00000000 --- a/onionr/data/hs/hostname +++ /dev/null @@ -1 +0,0 @@ -