From 18ac830a9e63d44bb5c1bbbbe85e01235b6b14e3 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 5 Mar 2018 07:45:10 -0800 Subject: [PATCH] Add command line flag for receive mode --- onionshare/__init__.py | 13 ++++++++++--- onionshare/onionshare.py | 5 ++++- onionshare_gui/__init__.py | 2 +- share/locale/en.json | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 76d2b601..ad1d300b 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -44,9 +44,10 @@ def main(cwd=None): parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open")) parser.add_argument('--shutdown-timeout', metavar='', dest='shutdown_timeout', default=0, help=strings._("help_shutdown_timeout")) parser.add_argument('--stealth', action='store_true', dest='stealth', help=strings._("help_stealth")) - parser.add_argument('--debug', action='store_true', dest='debug', help=strings._("help_debug")) + parser.add_argument('--receive', action='store_true', dest='receive', help=strings._("help_receive")) parser.add_argument('--config', metavar='config', default=False, help=strings._('help_config')) - parser.add_argument('filename', metavar='filename', nargs='+', help=strings._('help_filename')) + parser.add_argument('--debug', action='store_true', dest='debug', help=strings._("help_debug")) + parser.add_argument('filename', metavar='filename', nargs='*', help=strings._('help_filename')) args = parser.parse_args() filenames = args.filename @@ -58,8 +59,14 @@ def main(cwd=None): stay_open = bool(args.stay_open) shutdown_timeout = int(args.shutdown_timeout) stealth = bool(args.stealth) + receive = bool(args.receive) config = args.config + # Make sure filenames given if not using receiver mode + if not receive and len(filenames) == 0: + print(strings._('no_filenames')) + sys.exit() + # Debug mode? if debug: common.set_debug(debug) @@ -92,7 +99,7 @@ def main(cwd=None): # Start the onionshare app try: - app = OnionShare(onion, local_only, stay_open, shutdown_timeout) + app = OnionShare(onion, receive, local_only, stay_open, shutdown_timeout) app.set_stealth(stealth) app.start_onion_service() except KeyboardInterrupt: diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 85bfaf22..a8f2ceb0 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -27,7 +27,7 @@ class OnionShare(object): OnionShare is the main application class. Pass in options and run start_onion_service and it will do the magic. """ - def __init__(self, onion, local_only=False, stay_open=False, shutdown_timeout=0): + def __init__(self, onion, receive, local_only=False, stay_open=False, shutdown_timeout=0): common.log('OnionShare', '__init__') # The Onion object @@ -37,6 +37,9 @@ class OnionShare(object): self.onion_host = None self.stealth = None + # Receiver mode + self.receive = receive + # files and dirs to delete on shutdown self.cleanup_filenames = [] diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 24e627bb..945487fc 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -105,7 +105,7 @@ def main(): # Start the OnionShare app web.set_stay_open(stay_open) - app = OnionShare(onion, local_only, stay_open, shutdown_timeout) + app = OnionShare(onion, False, local_only, stay_open, shutdown_timeout) # Launch the gui gui = OnionShareGui(onion, qtapp, app, filenames, config) diff --git a/share/locale/en.json b/share/locale/en.json index 09ead591..e72686b8 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -10,6 +10,7 @@ "ctrlc_to_stop": "Press Ctrl-C to stop server", "not_a_file": "{0:s} is not a valid file.", "not_a_readable_file": "{0:s} is not a readable file.", + "no_filenames": "You must specify a list of files to share.", "no_available_port": "Could not start the Onion service as there was no available port.", "download_page_loaded": "Download page loaded", "other_page_loaded": "Address loaded", @@ -31,6 +32,7 @@ "help_shutdown_timeout": "Shut down the onion service after N seconds", "help_transparent_torification": "My system is transparently torified", "help_stealth": "Create stealth onion service (advanced)", + "help_receive": "Receive files instead of sending them", "help_debug": "Log application errors to stdout, and log web errors to disk", "help_filename": "List of files or folders to share", "help_config": "Path to a custom JSON config file (optional)",