gui now handles NoTor successfully, and cleaned up business logic in both cli and gui

This commit is contained in:
Micah Lee 2014-05-30 21:03:53 -04:00
parent 90244d18f2
commit 837533e9c6
2 changed files with 24 additions and 18 deletions

View File

@ -15,6 +15,10 @@ from stem.control import Controller
from stem import SocketError
from flask import Flask, Markup, Response, request, make_response, send_from_directory, render_template_string
class NoTor(Exception):
pass
app = Flask(__name__)
strings = {}
@ -109,7 +113,7 @@ def start_hidden_service(port):
except SocketError:
pass
if not controller:
sys.exit(strings["cant_connect_ctrlport"].format(controlports))
raise NoTor(strings["cant_connect_ctrlport"].format(controlports))
controller.authenticate()
# set up hidden service
@ -124,7 +128,15 @@ def main():
global filename, filehash, filesize
load_strings()
# validate filename
# try starting hidden service
port = choose_port()
print strings["connecting_ctrlport"].format(port)
try:
onion_host = start_hidden_service(port)
except NoTor as e:
sys.exit(e.args[0])
# select file to share
if len(sys.argv) != 2:
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
filename = sys.argv[1]
@ -133,17 +145,10 @@ def main():
else:
filename = os.path.abspath(filename)
# startup
print strings["calculating_sha1"]
filehash, filesize = file_crunching(filename)
port = choose_port()
print strings["connecting_ctrlport"].format(port)
onion_host = start_hidden_service(port)
# punch a hole in the firewall
tails_open_port(port)
# instructions
print '\n' + strings["give_this_url"]
print 'http://{0}/{1}'.format(onion_host, slug)
print ''

View File

@ -49,9 +49,16 @@ def select_file(strings):
return filename, basename
def main():
# load strings
strings = onionshare.load_strings()
# try starting hidden service
port = onionshare.choose_port()
try:
onion_host = onionshare.start_hidden_service(port)
except onionshare.NoTor as e:
alert(e.args[0], gtk.MESSAGE_ERROR)
return
# select file to share
filename, basename = select_file(strings)
if not filename:
@ -64,17 +71,11 @@ def main():
quit_function=Global.set_quit)
time.sleep(0.1)
# startup
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
web_send("update('{0}')".format(strings['calculating_sha1']))
filehash, filesize = onionshare.file_crunching(filename)
port = onionshare.choose_port()
web_send("update('{0}')".format(strings['connecting_ctrlport'].format(port)))
onion_host = onionshare.start_hidden_service(port)
# punch a hole in the firewall
onionshare.tails_open_port(port)
url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
web_send("update('{0}')".format('Secret URL is {0}'.format(url)))
web_send("set_url('{0}')".format(url));