Removed transparent_torification from the full app, and refactored OnionShare class to get passed in an Onion, and doesn't get passed in stealth.

This commit is contained in:
Micah Lee 2017-04-17 19:12:02 -07:00
parent dff13d9568
commit bb990ff574
4 changed files with 35 additions and 53 deletions

View file

@ -28,11 +28,13 @@ class OnionShare(object):
OnionShare is the main application class. Pass in options and run OnionShare is the main application class. Pass in options and run
start_onion_service and it will do the magic. start_onion_service and it will do the magic.
""" """
def __init__(self, debug=False, local_only=False, stay_open=False, transparent_torification=False, stealth=False): def __init__(self, onion, debug=False, local_only=False, stay_open=False):
self.port = None # The Onion object
self.onion = None self.onion = onion
self.hidserv_dir = None self.hidserv_dir = None
self.onion_host = None self.onion_host = None
self.stealth = None
# files and dirs to delete on shutdown # files and dirs to delete on shutdown
self.cleanup_filenames = [] self.cleanup_filenames = []
@ -47,16 +49,9 @@ class OnionShare(object):
# automatically close when download is finished # automatically close when download is finished
self.stay_open = stay_open self.stay_open = stay_open
# traffic automatically goes through Tor
self.transparent_torification = transparent_torification
# use stealth onion service
self.set_stealth(stealth)
def set_stealth(self, stealth): def set_stealth(self, stealth):
self.stealth = stealth self.stealth = stealth
if self.onion: self.onion.stealth = stealth
self.onion.stealth = stealth
def choose_port(self): def choose_port(self):
""" """
@ -117,16 +112,15 @@ def main(cwd=None):
strings.load_strings(helpers) strings.load_strings(helpers)
print(strings._('version_string').format(helpers.get_version())) print(strings._('version_string').format(helpers.get_version()))
# onionshare CLI in OSX needs to change current working directory (#132) # OnionShare CLI in OSX needs to change current working directory (#132)
if helpers.get_platform() == 'Darwin': if helpers.get_platform() == 'Darwin':
if cwd: if cwd:
os.chdir(cwd) os.chdir(cwd)
# parse arguments # Parse arguments
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--local-only', action='store_true', dest='local_only', help=strings._("help_local_only")) parser.add_argument('--local-only', action='store_true', dest='local_only', help=strings._("help_local_only"))
parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open")) parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open"))
parser.add_argument('--transparent', action='store_true', dest='transparent_torification', help=strings._("help_transparent_torification"))
parser.add_argument('--stealth', action='store_true', dest='stealth', help=strings._("help_stealth")) 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('--debug', action='store_true', dest='debug', help=strings._("help_debug"))
parser.add_argument('filename', metavar='filename', nargs='+', help=strings._('help_filename')) parser.add_argument('filename', metavar='filename', nargs='+', help=strings._('help_filename'))
@ -139,10 +133,9 @@ def main(cwd=None):
local_only = bool(args.local_only) local_only = bool(args.local_only)
debug = bool(args.debug) debug = bool(args.debug)
stay_open = bool(args.stay_open) stay_open = bool(args.stay_open)
transparent_torification = bool(args.transparent_torification)
stealth = bool(args.stealth) stealth = bool(args.stealth)
# validation # Validation
valid = True valid = True
for filename in filenames: for filename in filenames:
if not os.path.exists(filename): if not os.path.exists(filename):
@ -151,30 +144,38 @@ def main(cwd=None):
if not valid: if not valid:
sys.exit() sys.exit()
# start the onionshare app # Start the Onion object
onion = Onion()
try: try:
app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth) onion.connect()
app.choose_port()
app.start_onion_service()
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e: except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
sys.exit(e.args[0]) sys.exit(e.args[0])
except KeyboardInterrupt: except KeyboardInterrupt:
print("") print("")
sys.exit() sys.exit()
# prepare files to share # Start the onionshare app
try:
app = OnionShare(onion, debug, local_only, stay_open)
app.set_stealth(stealth)
app.start_onion_service()
except KeyboardInterrupt:
print("")
sys.exit()
# Prepare files to share
print(strings._("preparing_files")) print(strings._("preparing_files"))
web.set_file_info(filenames) web.set_file_info(filenames)
app.cleanup_filenames.append(web.zip_filename) app.cleanup_filenames.append(web.zip_filename)
# warn about sending large files over Tor # Warn about sending large files over Tor
if web.zip_filesize >= 157286400: # 150mb if web.zip_filesize >= 157286400: # 150mb
print('') print('')
print(strings._("large_filesize")) print(strings._("large_filesize"))
print('') print('')
# start onionshare http service in new thread # Start OnionShare http service in new thread
t = threading.Thread(target=web.start, args=(app.port, app.stay_open, app.transparent_torification)) t = threading.Thread(target=web.start, args=(app.port, app.stay_open))
t.daemon = True t.daemon = True
t.start() t.start()
@ -192,16 +193,16 @@ def main(cwd=None):
print('') print('')
print(strings._("ctrlc_to_stop")) print(strings._("ctrlc_to_stop"))
# wait for app to close # Wait for app to close
while t.is_alive(): while t.is_alive():
t.join() t.join()
# allow KeyboardInterrupt exception to be handled with threads # Allow KeyboardInterrupt exception to be handled with threads
# https://stackoverflow.com/questions/3788208/python-threading-ignores-keyboardinterrupt-exception # https://stackoverflow.com/questions/3788208/python-threading-ignores-keyboardinterrupt-exception
time.sleep(100) time.sleep(100)
except KeyboardInterrupt: except KeyboardInterrupt:
web.stop(app.port) web.stop(app.port)
finally: finally:
# shutdown # Shutdown
app.cleanup() app.cleanup()
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -332,7 +332,7 @@ class Onion(object):
# ephemeral stealth onion services are not supported # ephemeral stealth onion services are not supported
self.supports_stealth = False self.supports_stealth = False
def start(self, port): def start_onion_service(self, port):
""" """
Start a onion service on port 80, pointing to the given port, and Start a onion service on port 80, pointing to the given port, and
return the onion hostname. return the onion hostname.

View file

@ -126,18 +126,6 @@ def get_stay_open():
""" """
return stay_open return stay_open
transparent_torification = False
def set_transparent_torification(new_transparent_torification):
"""
Set transparent_torification variable.
"""
global transparent_torification
stay_open = new_transparent_torification
def get_transparent_torification():
"""
Get transparent_torification variable."
"""
return transparent_torification
# Are we running in GUI mode? # Are we running in GUI mode?
gui_mode = False gui_mode = False
@ -350,14 +338,13 @@ def force_shutdown():
func() func()
def start(port, stay_open=False, transparent_torification=False): def start(port, stay_open=False):
""" """
Start the flask web server. Start the flask web server.
""" """
generate_slug() generate_slug()
set_stay_open(stay_open) set_stay_open(stay_open)
set_transparent_torification(transparent_torification)
# In Whonix, listen on 0.0.0.0 instead of 127.0.0.1 (#220) # In Whonix, listen on 0.0.0.0 instead of 127.0.0.1 (#220)
if os.path.exists('/usr/share/anon-ws-base-files/workstation'): if os.path.exists('/usr/share/anon-ws-base-files/workstation'):
@ -380,11 +367,8 @@ def stop(port):
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown # to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
try: try:
if transparent_torification: s = socket.socket()
s = socket.socket() s.connect(('127.0.0.1', port))
s.connect(('127.0.0.1', port)) s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug))
s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug))
else:
urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read()
except: except:
pass pass

View file

@ -172,7 +172,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.app.choose_port() self.app.choose_port()
# start onionshare http service in new thread # start onionshare http service in new thread
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open, self.app.transparent_torification)) t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open))
t.daemon = True t.daemon = True
t.start() t.start()
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash # wait for modules in thread to load, preventing a thread-related cx_Freeze crash
@ -423,7 +423,6 @@ def main():
parser.add_argument('--local-only', action='store_true', dest='local_only', help=strings._("help_local_only")) parser.add_argument('--local-only', action='store_true', dest='local_only', help=strings._("help_local_only"))
parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open")) parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open"))
parser.add_argument('--debug', action='store_true', dest='debug', help=strings._("help_debug")) parser.add_argument('--debug', action='store_true', dest='debug', help=strings._("help_debug"))
parser.add_argument('--transparent', action='store_true', dest='transparent_torification', help=strings._("help_transparent_torification"))
parser.add_argument('--filenames', metavar='filenames', nargs='+', help=strings._('help_filename')) parser.add_argument('--filenames', metavar='filenames', nargs='+', help=strings._('help_filename'))
args = parser.parse_args() args = parser.parse_args()
@ -435,7 +434,6 @@ def main():
local_only = bool(args.local_only) local_only = bool(args.local_only)
stay_open = bool(args.stay_open) stay_open = bool(args.stay_open)
debug = bool(args.debug) debug = bool(args.debug)
transparent_torification = bool(args.transparent_torification)
# validation # validation
if filenames: if filenames:
@ -449,8 +447,7 @@ def main():
# start the onionshare app # start the onionshare app
web.set_stay_open(stay_open) web.set_stay_open(stay_open)
web.set_transparent_torification(transparent_torification) app = onionshare.OnionShare(debug, local_only, stay_open)
app = onionshare.OnionShare(debug, local_only, stay_open, transparent_torification)
# clean up when app quits # clean up when app quits
def shutdown(): def shutdown():