Add command line flag for receive mode

This commit is contained in:
Micah Lee 2018-03-05 07:45:10 -08:00
parent 8299aad90b
commit 18ac830a9e
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
4 changed files with 17 additions and 5 deletions

View File

@ -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='<int>', 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:

View File

@ -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 = []

View File

@ -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)

View File

@ -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)",