mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
gui now handles NoTor successfully, and cleaned up business logic in both cli and gui
This commit is contained in:
parent
90244d18f2
commit
837533e9c6
@ -15,6 +15,10 @@ from stem.control import Controller
|
|||||||
from stem import SocketError
|
from stem import SocketError
|
||||||
|
|
||||||
from flask import Flask, Markup, Response, request, make_response, send_from_directory, render_template_string
|
from flask import Flask, Markup, Response, request, make_response, send_from_directory, render_template_string
|
||||||
|
|
||||||
|
class NoTor(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
strings = {}
|
strings = {}
|
||||||
@ -109,7 +113,7 @@ def start_hidden_service(port):
|
|||||||
except SocketError:
|
except SocketError:
|
||||||
pass
|
pass
|
||||||
if not controller:
|
if not controller:
|
||||||
sys.exit(strings["cant_connect_ctrlport"].format(controlports))
|
raise NoTor(strings["cant_connect_ctrlport"].format(controlports))
|
||||||
controller.authenticate()
|
controller.authenticate()
|
||||||
|
|
||||||
# set up hidden service
|
# set up hidden service
|
||||||
@ -124,7 +128,15 @@ def main():
|
|||||||
global filename, filehash, filesize
|
global filename, filehash, filesize
|
||||||
load_strings()
|
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:
|
if len(sys.argv) != 2:
|
||||||
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
|
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
|
||||||
filename = sys.argv[1]
|
filename = sys.argv[1]
|
||||||
@ -133,17 +145,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
filename = os.path.abspath(filename)
|
filename = os.path.abspath(filename)
|
||||||
|
|
||||||
|
# startup
|
||||||
print strings["calculating_sha1"]
|
print strings["calculating_sha1"]
|
||||||
filehash, filesize = file_crunching(filename)
|
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)
|
tails_open_port(port)
|
||||||
|
|
||||||
# instructions
|
|
||||||
print '\n' + strings["give_this_url"]
|
print '\n' + strings["give_this_url"]
|
||||||
print 'http://{0}/{1}'.format(onion_host, slug)
|
print 'http://{0}/{1}'.format(onion_host, slug)
|
||||||
print ''
|
print ''
|
||||||
|
@ -49,9 +49,16 @@ def select_file(strings):
|
|||||||
return filename, basename
|
return filename, basename
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# load strings
|
|
||||||
strings = onionshare.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
|
# select file to share
|
||||||
filename, basename = select_file(strings)
|
filename, basename = select_file(strings)
|
||||||
if not filename:
|
if not filename:
|
||||||
@ -64,17 +71,11 @@ def main():
|
|||||||
quit_function=Global.set_quit)
|
quit_function=Global.set_quit)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# startup
|
||||||
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
|
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
|
||||||
web_send("update('{0}')".format(strings['calculating_sha1']))
|
web_send("update('{0}')".format(strings['calculating_sha1']))
|
||||||
filehash, filesize = onionshare.file_crunching(filename)
|
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)
|
onionshare.tails_open_port(port)
|
||||||
|
|
||||||
url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
|
url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
|
||||||
web_send("update('{0}')".format('Secret URL is {0}'.format(url)))
|
web_send("update('{0}')".format('Secret URL is {0}'.format(url)))
|
||||||
web_send("set_url('{0}')".format(url));
|
web_send("set_url('{0}')".format(url));
|
||||||
|
Loading…
Reference in New Issue
Block a user