This commit is contained in:
Espen Kåsa Notodden 2014-06-26 22:51:20 +02:00
commit 4e5eb62dca
5 changed files with 69 additions and 17 deletions

View File

@ -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:
@ -88,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

View File

@ -29,6 +29,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
@ -40,7 +46,6 @@ else:
strings = {}
slug = random_string(16)
download_count = 0
stay_open = False
REQUEST_LOAD = 0
REQUEST_DOWNLOAD = 1
@ -127,6 +132,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()
@ -243,7 +249,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])

View File

@ -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,21 +87,38 @@ 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 = 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))
# 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
filename, basename = select_file(onionshare.strings)
filename, basename = select_file(onionshare.strings, filename)
if not filename:
return
@ -111,9 +126,14 @@ 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()
webapp.stay_open = stay_open
webapp.debug = debug
# run the web app in a new thread
webapp_port = onionshare.choose_port()

View File

@ -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',
@ -87,6 +95,10 @@ $(function(){
$('#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({
url: '/start_onionshare',

View File

@ -7,6 +7,8 @@ filename = None
onion_host = None
qtapp = None
clipboard = None
stay_open = None
debug = None
url = None
@ -35,12 +37,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")
@ -83,6 +86,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