From 4e3c32cbff369683b618c22d194e1960a4e6f5a5 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:21:39 -0400 Subject: [PATCH 1/8] gave file argument a help description --- onionshare/onionshare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index e8f374d6..78ed7dae 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -239,7 +239,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--local-only', action='store_true', dest='local_only', help='Do not attempt to use tor: for development only') parser.add_argument('--stay-open', action='store_true', dest='stay_open', help='Keep hidden service running after download has finished') - parser.add_argument('filename', nargs=1) + parser.add_argument('filename', nargs=1, help='File to share') args = parser.parse_args() filename = os.path.abspath(args.filename[0]) From 2b8be2781c6b4a4999cf03d98d0a7bb0c544e4e6 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:22:32 -0400 Subject: [PATCH 2/8] adding argparse to GUI (#58, also #50) --- onionshare_gui/onionshare_gui.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3516f558..2781e401 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -1,4 +1,4 @@ -import os, sys, subprocess, inspect, platform +import os, sys, subprocess, inspect, platform, argparse from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * @@ -54,11 +54,9 @@ def alert(msg, icon=QMessageBox.NoIcon): dialog.setIcon(icon) dialog.exec_() -def select_file(strings): +def select_file(strings, filename=None): # get filename, either from argument or file chooser dialog - if len(sys.argv) == 2: - filename = sys.argv[1] - else: + if not filename: args = {} if onionshare.get_platform() == 'Tails': args['directory'] = '/home/amnesia' @@ -89,6 +87,19 @@ def main(): subprocess.call(['/usr/bin/gksudo']+sys.argv) return + # parse arguments + parser = argparse.ArgumentParser() + parser.add_argument('--local-only', action='store_true', dest='local_only', help='Do not attempt to use tor: for development only') + parser.add_argument('--stay-open', action='store_true', dest='stay_open', help='Keep hidden service running after download has finished') + parser.add_argument('--debug', action='store_true', dest='debug', help='Log errors to disk') + parser.add_argument('filename', nargs='?', help='File to share') + args = parser.parse_args() + + filename = args.filename + local_only = args.local_only + stay_open = args.stay_open + debug = args.debug + # create the onionshare icon global window_icon, onionshare_gui_dir window_icon = QIcon("{0}/onionshare-icon.png".format(onionshare_gui_dir)) @@ -103,7 +114,7 @@ def main(): onionshare.tails_open_port(onionshare_port) # select file to share - filename, basename = select_file(onionshare.strings) + filename, basename = select_file(onionshare.strings, filename) if not filename: return From c74e259fb4f0b4cc0f59f97c92e6be3c3c219938 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:26:41 -0400 Subject: [PATCH 3/8] made --local-only work in GUI (#58) --- onionshare_gui/onionshare_gui.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 2781e401..8369fba9 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -106,11 +106,13 @@ def main(): # try starting hidden service onionshare_port = onionshare.choose_port() - try: - onion_host = onionshare.start_hidden_service(onionshare_port) - except onionshare.NoTor as e: - alert(e.args[0], QMessageBox.Warning) - return + local_host = "127.0.0.1:{0}".format(onionshare_port) + if not local_only: + try: + onion_host = onionshare.start_hidden_service(onionshare_port) + except onionshare.NoTor as e: + alert(e.args[0], QMessageBox.Warning) + return onionshare.tails_open_port(onionshare_port) # select file to share @@ -122,7 +124,10 @@ def main(): webapp.onionshare = onionshare webapp.onionshare_port = onionshare_port webapp.filename = filename - webapp.onion_host = onion_host + if not local_only: + webapp.onion_host = onion_host + else: + webapp.onion_host = local_host webapp.qtapp = app webapp.clipboard = app.clipboard() From 8fce3adeb563a858e07c59ef73cf4906071ab45d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:31:29 -0400 Subject: [PATCH 4/8] made --stay-open work in GUI (#58) --- onionshare_gui/onionshare_gui.py | 1 + onionshare_gui/static/onionshare.js | 4 ++++ onionshare_gui/webapp.py | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 8369fba9..f078b224 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -130,6 +130,7 @@ def main(): webapp.onion_host = local_host webapp.qtapp = app webapp.clipboard = app.clipboard() + webapp.stay_open = bool(stay_open) # run the web app in a new thread webapp_port = onionshare.choose_port() diff --git a/onionshare_gui/static/onionshare.js b/onionshare_gui/static/onionshare.js index 6c7b7fa0..c2a39f71 100644 --- a/onionshare_gui/static/onionshare.js +++ b/onionshare_gui/static/onionshare.js @@ -86,6 +86,10 @@ $(function(){ $('#filehash .label').html(onionshare.strings['sha1_checksum']+':'); $('#close-on-finish-wrapper label').html(onionshare.strings['close_on_finish']); $('#loading .calculating').html(onionshare.strings['calculating_sha1']); + + if(onionshare.stay_open) { + $('#close-on-finish').removeAttr('checked'); + } // after getting the initial info, start the onionshare server $.ajax({ diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index 80f2c3f8..42057da4 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -7,6 +7,7 @@ filename = None onion_host = None qtapp = None clipboard = None +stay_open = None url = None @@ -35,12 +36,13 @@ def index(): @app.route("/init_info") def init_info(): - global onionshare, filename + global onionshare, filename, stay_open basename = os.path.basename(filename) return json.dumps({ 'strings': onionshare.strings, - 'basename': basename + 'basename': basename, + 'stay_open': stay_open }) @app.route("/start_onionshare") From d0d4cebbffbba1526b7eae1b686de02c5cb9f951 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:45:18 -0400 Subject: [PATCH 5/8] fixed bug where hidden service still closed even if "close automatically" unchecked in GUI (#58) --- onionshare/onionshare.py | 8 +++++++- onionshare_gui/onionshare_gui.py | 6 ++++-- onionshare_gui/static/onionshare.js | 8 ++++++++ onionshare_gui/webapp.py | 10 ++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 78ed7dae..c514d16a 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -28,6 +28,12 @@ def set_file_info(new_filename, new_filehash, new_filesize): filehash = new_filehash filesize = new_filesize +# automatically close +stay_open = False +def set_stay_open(new_stay_open): + global stay_open + stay_open = new_stay_open + app = Flask(__name__) # get path of onioshare directory @@ -39,7 +45,6 @@ else: strings = {} slug = random_string(16) download_count = 0 -stay_open = False REQUEST_LOAD = 0 REQUEST_DOWNLOAD = 1 @@ -126,6 +131,7 @@ def download(): # download is finished, close the server global stay_open if not stay_open: + print "Closing automatically because download finished" if shutdown_func is None: raise RuntimeError('Not running with the Werkzeug Server') shutdown_func() diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index f078b224..eed72485 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -97,9 +97,11 @@ def main(): filename = args.filename local_only = args.local_only - stay_open = args.stay_open + stay_open = bool(args.stay_open) debug = args.debug + onionshare.set_stay_open(stay_open) + # create the onionshare icon global window_icon, onionshare_gui_dir window_icon = QIcon("{0}/onionshare-icon.png".format(onionshare_gui_dir)) @@ -130,7 +132,7 @@ def main(): webapp.onion_host = local_host webapp.qtapp = app webapp.clipboard = app.clipboard() - webapp.stay_open = bool(stay_open) + webapp.stay_open = stay_open # run the web app in a new thread webapp_port = onionshare.choose_port() diff --git a/onionshare_gui/static/onionshare.js b/onionshare_gui/static/onionshare.js index c2a39f71..7dedb6af 100644 --- a/onionshare_gui/static/onionshare.js +++ b/onionshare_gui/static/onionshare.js @@ -75,6 +75,14 @@ $(function(){ }); } + $('#close-on-finish').change(function(){ + if($('#close-on-finish').is(':checked')) { + $.ajax({ url: '/stay_open_false' }); + } else { + $.ajax({ url: '/stay_open_true' }); + } + }); + // initialize $.ajax({ url: '/init_info', diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index 42057da4..46f8b3b7 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -85,6 +85,16 @@ def copy_url(): clipboard.setText(url) return '' +@app.route("/stay_open_true") +def stay_open_true(): + global onionshare + onionshare.set_stay_open(True) + +@app.route("/stay_open_false") +def stay_open_false(): + global onionshare + onionshare.set_stay_open(False) + @app.route("/heartbeat") def check_for_requests(): global onionshare From 5f627dc9e4d78844f4401cd02f9a5201e08e258d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 14:56:29 -0400 Subject: [PATCH 6/8] passing webapp the debug flag (#50) --- onionshare_gui/onionshare_gui.py | 1 + onionshare_gui/webapp.py | 1 + 2 files changed, 2 insertions(+) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index eed72485..5c427275 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -133,6 +133,7 @@ def main(): webapp.qtapp = app webapp.clipboard = app.clipboard() webapp.stay_open = stay_open + webapp.debug = debug # run the web app in a new thread webapp_port = onionshare.choose_port() diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index 46f8b3b7..11f62cd8 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -8,6 +8,7 @@ onion_host = None qtapp = None clipboard = None stay_open = None +debug = None url = None From 954697f1f4ef15ca5f8d4a9e4e7ededb61b6eb3a Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 15:59:32 -0400 Subject: [PATCH 7/8] updated windows instructions --- BUILD.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.md b/BUILD.md index 874dbeec..2fafa76d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -76,6 +76,7 @@ The first time you're setting up your dev environment: * Open a command prompt and type: `pip install flask stem pyinstaller` * Go to http://www.riverbankcomputing.com/software/pyqt/download and download the latest PyQt4 for Windows for python 2.7, 32-bit (I downloaded `PyQt4-4.11-gpl-Py2.7-Qt4.8.6-x32.exe`), then install it. * Go to http://sourceforge.net/projects/pywin32/ and download and install the latest 32-bit pywin32 binary for python 2.7. I downloaded `pywin32-219.win32-py2.7.exe`. +* Download and install the [Microsoft Visual C++ 2008 Redistributable Package (x86)](http://www.microsoft.com/en-us/download/details.aspx?id=29). To make a .exe: From 680b92e61db8776d62a6e7c7464759ef660eb2b2 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 26 Jun 2014 16:09:08 -0400 Subject: [PATCH 8/8] updated windows instructions more --- BUILD.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.md b/BUILD.md index 2fafa76d..9c6f7976 100644 --- a/BUILD.md +++ b/BUILD.md @@ -89,7 +89,7 @@ If you want to build the installer: To build the installer: -* Follow the steps above until to make the .exe. You should have a folder called `dist\onionshare` with a bunch of files inside of it, including `onionshare.exe`. +* Follow the steps above until to make the .exe. You should have a folder called `dist\onionshare` with a bunch of files inside of it, including `onionshare.exe`. Run `onionshare.exe` once before you build the installer, to compile all the `.py` files into `.pyc` files. * Open a command prompt, cd into the onionshare directory, and type: `makensisw setup\onionshare.nsi`. You'll find the installer, `OnionShare_Setup.exe`, inside the `dist` folder. ## Tests