mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 11:47:27 -03:00
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:
parent
dff13d9568
commit
bb990ff574
4 changed files with 35 additions and 53 deletions
|
@ -28,11 +28,13 @@ class OnionShare(object):
|
|||
OnionShare is the main application class. Pass in options and run
|
||||
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):
|
||||
self.port = None
|
||||
self.onion = None
|
||||
def __init__(self, onion, debug=False, local_only=False, stay_open=False):
|
||||
# The Onion object
|
||||
self.onion = onion
|
||||
|
||||
self.hidserv_dir = None
|
||||
self.onion_host = None
|
||||
self.stealth = None
|
||||
|
||||
# files and dirs to delete on shutdown
|
||||
self.cleanup_filenames = []
|
||||
|
@ -47,15 +49,8 @@ class OnionShare(object):
|
|||
# automatically close when download is finished
|
||||
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):
|
||||
self.stealth = stealth
|
||||
if self.onion:
|
||||
self.onion.stealth = stealth
|
||||
|
||||
def choose_port(self):
|
||||
|
@ -117,16 +112,15 @@ def main(cwd=None):
|
|||
strings.load_strings(helpers)
|
||||
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 cwd:
|
||||
os.chdir(cwd)
|
||||
|
||||
# parse arguments
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
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('--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('--debug', action='store_true', dest='debug', help=strings._("help_debug"))
|
||||
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)
|
||||
debug = bool(args.debug)
|
||||
stay_open = bool(args.stay_open)
|
||||
transparent_torification = bool(args.transparent_torification)
|
||||
stealth = bool(args.stealth)
|
||||
|
||||
# validation
|
||||
# Validation
|
||||
valid = True
|
||||
for filename in filenames:
|
||||
if not os.path.exists(filename):
|
||||
|
@ -151,30 +144,38 @@ def main(cwd=None):
|
|||
if not valid:
|
||||
sys.exit()
|
||||
|
||||
# start the onionshare app
|
||||
# Start the Onion object
|
||||
onion = Onion()
|
||||
try:
|
||||
app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth)
|
||||
app.choose_port()
|
||||
app.start_onion_service()
|
||||
onion.connect()
|
||||
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
|
||||
sys.exit(e.args[0])
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
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"))
|
||||
web.set_file_info(filenames)
|
||||
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
|
||||
print('')
|
||||
print(strings._("large_filesize"))
|
||||
print('')
|
||||
|
||||
# start onionshare http service in new thread
|
||||
t = threading.Thread(target=web.start, args=(app.port, app.stay_open, app.transparent_torification))
|
||||
# Start OnionShare http service in new thread
|
||||
t = threading.Thread(target=web.start, args=(app.port, app.stay_open))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
|
@ -192,16 +193,16 @@ def main(cwd=None):
|
|||
print('')
|
||||
print(strings._("ctrlc_to_stop"))
|
||||
|
||||
# wait for app to close
|
||||
# Wait for app to close
|
||||
while t.is_alive():
|
||||
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
|
||||
time.sleep(100)
|
||||
except KeyboardInterrupt:
|
||||
web.stop(app.port)
|
||||
finally:
|
||||
# shutdown
|
||||
# Shutdown
|
||||
app.cleanup()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -332,7 +332,7 @@ class Onion(object):
|
|||
# ephemeral stealth onion services are not supported
|
||||
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
|
||||
return the onion hostname.
|
||||
|
|
|
@ -126,18 +126,6 @@ def get_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?
|
||||
gui_mode = False
|
||||
|
@ -350,14 +338,13 @@ def force_shutdown():
|
|||
func()
|
||||
|
||||
|
||||
def start(port, stay_open=False, transparent_torification=False):
|
||||
def start(port, stay_open=False):
|
||||
"""
|
||||
Start the flask web server.
|
||||
"""
|
||||
generate_slug()
|
||||
|
||||
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)
|
||||
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
|
||||
try:
|
||||
if transparent_torification:
|
||||
s = socket.socket()
|
||||
s.connect(('127.0.0.1', port))
|
||||
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:
|
||||
pass
|
||||
|
|
|
@ -172,7 +172,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||
self.app.choose_port()
|
||||
|
||||
# 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.start()
|
||||
# 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('--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('--transparent', action='store_true', dest='transparent_torification', help=strings._("help_transparent_torification"))
|
||||
parser.add_argument('--filenames', metavar='filenames', nargs='+', help=strings._('help_filename'))
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -435,7 +434,6 @@ def main():
|
|||
local_only = bool(args.local_only)
|
||||
stay_open = bool(args.stay_open)
|
||||
debug = bool(args.debug)
|
||||
transparent_torification = bool(args.transparent_torification)
|
||||
|
||||
# validation
|
||||
if filenames:
|
||||
|
@ -449,8 +447,7 @@ def main():
|
|||
|
||||
# start the onionshare app
|
||||
web.set_stay_open(stay_open)
|
||||
web.set_transparent_torification(transparent_torification)
|
||||
app = onionshare.OnionShare(debug, local_only, stay_open, transparent_torification)
|
||||
app = onionshare.OnionShare(debug, local_only, stay_open)
|
||||
|
||||
# clean up when app quits
|
||||
def shutdown():
|
||||
|
|
Loading…
Reference in a new issue