summaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-05-06 18:06:14 -0700
committerGitHub <noreply@github.com>2019-05-06 18:06:14 -0700
commitbbf6c02da645fcd4fc50db18dd341178ad4fa2e6 (patch)
treec1e2757c56f517e051c9f905f8a7a12e1b8d66ae /onionshare
parenta8201593ec0bfe7596ef530e80aa30e5172ef71d (diff)
parent9e9c29b189cb91ea495a85ed749730395926e07b (diff)
downloadonionshare-2.1.tar.gz
onionshare-2.1.zip
Merge pull request #980 from micahflee/developv2.1
Version 2.1
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/__init__.py159
-rw-r--r--onionshare/common.py12
-rw-r--r--onionshare/onion.py67
-rw-r--r--onionshare/onionshare.py18
-rw-r--r--onionshare/settings.py49
-rw-r--r--onionshare/web/receive_mode.py19
-rw-r--r--onionshare/web/share_mode.py2
-rw-r--r--onionshare/web/web.py29
8 files changed, 225 insertions, 130 deletions
diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index 2f44c846..620ada98 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -19,8 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os, sys, time, argparse, threading
+from datetime import datetime
+from datetime import timedelta
-from . import strings
from .common import Common
from .web import Web
from .onion import *
@@ -33,16 +34,8 @@ def main(cwd=None):
"""
common = Common()
- # Load the default settings and strings early, for the sake of being able to parse options.
- # These won't be in the user's chosen locale necessarily, but we need to parse them
- # early in order to even display the option to pass alternate settings (which might
- # contain a preferred locale).
- # If an alternate --config is passed, we'll reload strings later.
- common.load_settings()
- strings.load_strings(common)
-
# Display OnionShare banner
- print(strings._('version_string').format(common.version))
+ print("OnionShare {0:s} | https://onionshare.org/".format(common.version))
# OnionShare CLI in OSX needs to change current working directory (#132)
if common.platform == 'Darwin':
@@ -51,14 +44,16 @@ def main(cwd=None):
# Parse arguments
parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=28))
- 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('--shutdown-timeout', metavar='<int>', dest='shutdown_timeout', default=0, help=strings._("help_shutdown_timeout"))
- parser.add_argument('--stealth', action='store_true', dest='stealth', help=strings._("help_stealth"))
- parser.add_argument('--receive', action='store_true', dest='receive', help=strings._("help_receive"))
- parser.add_argument('--config', metavar='config', default=False, help=strings._('help_config'))
- 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('--local-only', action='store_true', dest='local_only', help="Don't use Tor (only for development)")
+ parser.add_argument('--stay-open', action='store_true', dest='stay_open', help="Continue sharing after files have been sent")
+ parser.add_argument('--auto-start-timer', metavar='<int>', dest='autostart_timer', default=0, help="Schedule this share to start N seconds from now")
+ parser.add_argument('--auto-stop-timer', metavar='<int>', dest='autostop_timer', default=0, help="Stop sharing after a given amount of seconds")
+ parser.add_argument('--connect-timeout', metavar='<int>', dest='connect_timeout', default=120, help="Give up connecting to Tor after a given amount of seconds (default: 120)")
+ parser.add_argument('--stealth', action='store_true', dest='stealth', help="Use client authorization (advanced)")
+ parser.add_argument('--receive', action='store_true', dest='receive', help="Receive shares instead of sending them")
+ parser.add_argument('--config', metavar='config', default=False, help="Custom JSON config file location (optional)")
+ parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', help="Log OnionShare errors to stdout, and web errors to disk")
+ parser.add_argument('filename', metavar='filename', nargs='*', help="List of files or folders to share")
args = parser.parse_args()
filenames = args.filename
@@ -66,9 +61,11 @@ def main(cwd=None):
filenames[i] = os.path.abspath(filenames[i])
local_only = bool(args.local_only)
- debug = bool(args.debug)
+ verbose = bool(args.verbose)
stay_open = bool(args.stay_open)
- shutdown_timeout = int(args.shutdown_timeout)
+ autostart_timer = int(args.autostart_timer)
+ autostop_timer = int(args.autostop_timer)
+ connect_timeout = int(args.connect_timeout)
stealth = bool(args.stealth)
receive = bool(args.receive)
config = args.config
@@ -88,10 +85,10 @@ def main(cwd=None):
valid = True
for filename in filenames:
if not os.path.isfile(filename) and not os.path.isdir(filename):
- print(strings._("not_a_file").format(filename))
+ print("{0:s} is not a valid file.".format(filename))
valid = False
if not os.access(filename, os.R_OK):
- print(strings._("not_a_readable_file").format(filename))
+ print("{0:s} is not a readable file.".format(filename))
valid = False
if not valid:
sys.exit()
@@ -99,11 +96,9 @@ def main(cwd=None):
# Re-load settings, if a custom config was passed in
if config:
common.load_settings(config)
- # Re-load the strings, in case the provided config has changed locale
- strings.load_strings(common)
- # Debug mode?
- common.debug = debug
+ # Verbose mode?
+ common.verbose = verbose
# Create the Web object
web = Web(common, False, mode)
@@ -111,7 +106,7 @@ def main(cwd=None):
# Start the Onion object
onion = Onion(common)
try:
- onion.connect(custom_settings=False, config=config)
+ onion.connect(custom_settings=False, config=config, connect_timeout=connect_timeout)
except KeyboardInterrupt:
print("")
sys.exit()
@@ -120,10 +115,51 @@ def main(cwd=None):
# Start the onionshare app
try:
- app = OnionShare(common, onion, local_only, shutdown_timeout)
+ common.settings.load()
+ if not common.settings.get('public_mode'):
+ web.generate_slug(common.settings.get('slug'))
+ else:
+ web.slug = None
+ app = OnionShare(common, onion, local_only, autostop_timer)
app.set_stealth(stealth)
app.choose_port()
- app.start_onion_service()
+ # Delay the startup if a startup timer was set
+ if autostart_timer > 0:
+ # Can't set a schedule that is later than the auto-stop timer
+ if app.autostop_timer > 0 and app.autostop_timer < autostart_timer:
+ print("The auto-stop time can't be the same or earlier than the auto-start time. Please update it to start sharing.")
+ sys.exit()
+
+ app.start_onion_service(False, True)
+ if common.settings.get('public_mode'):
+ url = 'http://{0:s}'.format(app.onion_host)
+ else:
+ url = 'http://{0:s}/{1:s}'.format(app.onion_host, web.slug)
+ schedule = datetime.now() + timedelta(seconds=autostart_timer)
+ if mode == 'receive':
+ print("Files sent to you appear in this folder: {}".format(common.settings.get('data_dir')))
+ print('')
+ print("Warning: Receive mode lets people upload files to your computer. Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.")
+ print('')
+ if stealth:
+ print("Give this address and HidServAuth lineto your sender, and tell them it won't be accessible until: {}".format(schedule.strftime("%I:%M:%S%p, %b %d, %y")))
+ print(app.auth_string)
+ else:
+ print("Give this address to your sender, and tell them it won't be accessible until: {}".format(schedule.strftime("%I:%M:%S%p, %b %d, %y")))
+ else:
+ if stealth:
+ print("Give this address and HidServAuth line to your recipient, and tell them it won't be accessible until: {}".format(schedule.strftime("%I:%M:%S%p, %b %d, %y")))
+ print(app.auth_string)
+ else:
+ print("Give this address to your recipient, and tell them it won't be accessible until: {}".format(schedule.strftime("%I:%M:%S%p, %b %d, %y")))
+ print(url)
+ print('')
+ print("Waiting for the scheduled time before starting...")
+ app.onion.cleanup(False)
+ time.sleep(autostart_timer)
+ app.start_onion_service()
+ else:
+ app.start_onion_service()
except KeyboardInterrupt:
print("")
sys.exit()
@@ -134,7 +170,7 @@ def main(cwd=None):
if mode == 'share':
# Prepare files to share
- print(strings._("preparing_files"))
+ print("Compressing files.")
try:
web.share_mode.set_file_info(filenames)
app.cleanup_filenames += web.share_mode.cleanup_filenames
@@ -145,11 +181,11 @@ def main(cwd=None):
# Warn about sending large files over Tor
if web.share_mode.download_filesize >= 157286400: # 150mb
print('')
- print(strings._("large_filesize"))
+ print("Warning: Sending a large share could take hours")
print('')
# Start OnionShare http service in new thread
- t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), common.settings.get('slug')))
+ t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), web.slug))
t.daemon = True
t.start()
@@ -157,9 +193,9 @@ def main(cwd=None):
# Wait for web.generate_slug() to finish running
time.sleep(0.2)
- # start shutdown timer thread
- if app.shutdown_timeout > 0:
- app.shutdown_timer.start()
+ # start auto-stop timer thread
+ if app.autostop_timer > 0:
+ app.autostop_timer_thread.start()
# Save the web slug if we are using a persistent private key
if common.settings.get('save_private_key'):
@@ -174,44 +210,47 @@ def main(cwd=None):
url = 'http://{0:s}/{1:s}'.format(app.onion_host, web.slug)
print('')
- if mode == 'receive':
- print(strings._('receive_mode_data_dir').format(common.settings.get('data_dir')))
- print('')
- print(strings._('receive_mode_warning'))
- print('')
-
- if stealth:
- print(strings._("give_this_url_receive_stealth"))
- print(url)
- print(app.auth_string)
- else:
- print(strings._("give_this_url_receive"))
- print(url)
+ if autostart_timer > 0:
+ print("Server started")
else:
- if stealth:
- print(strings._("give_this_url_stealth"))
- print(url)
- print(app.auth_string)
+ if mode == 'receive':
+ print("Files sent to you appear in this folder: {}".format(common.settings.get('data_dir')))
+ print('')
+ print("Warning: Receive mode lets people upload files to your computer. Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.")
+ print('')
+
+ if stealth:
+ print("Give this address and HidServAuth to the sender:")
+ print(url)
+ print(app.auth_string)
+ else:
+ print("Give this address to the sender:")
+ print(url)
else:
- print(strings._("give_this_url"))
- print(url)
+ if stealth:
+ print("Give this address and HidServAuth line to the recipient:")
+ print(url)
+ print(app.auth_string)
+ else:
+ print("Give this address to the recipient:")
+ print(url)
print('')
- print(strings._("ctrlc_to_stop"))
+ print("Press Ctrl+C to stop the server")
# Wait for app to close
while t.is_alive():
- if app.shutdown_timeout > 0:
- # if the shutdown timer was set and has run out, stop the server
- if not app.shutdown_timer.is_alive():
+ if app.autostop_timer > 0:
+ # if the auto-stop timer was set and has run out, stop the server
+ if not app.autostop_timer_thread.is_alive():
if mode == 'share':
# If there were no attempts to download the share, or all downloads are done, we can stop
if web.share_mode.download_count == 0 or web.done:
- print(strings._("close_on_timeout"))
+ print("Stopped because auto-stop timer ran out")
web.stop(app.port)
break
if mode == 'receive':
if web.receive_mode.upload_count == 0 or not web.receive_mode.uploads_in_progress:
- print(strings._("close_on_timeout"))
+ print("Stopped because auto-stop timer ran out")
web.stop(app.port)
break
else:
diff --git a/onionshare/common.py b/onionshare/common.py
index fcb9ca6d..325f11d4 100644
--- a/onionshare/common.py
+++ b/onionshare/common.py
@@ -36,8 +36,8 @@ class Common(object):
"""
The Common object is shared amongst all parts of OnionShare.
"""
- def __init__(self, debug=False):
- self.debug = debug
+ def __init__(self, verbose=False):
+ self.verbose = verbose
# The platform OnionShare is running on
self.platform = platform.system()
@@ -57,9 +57,9 @@ class Common(object):
def log(self, module, func, msg=None):
"""
- If debug mode is on, log error messages to stdout
+ If verbose mode is on, log error messages to stdout
"""
- if self.debug:
+ if self.verbose:
timestamp = time.strftime("%b %d %Y %X")
final_msg = "[{}] {}.{}".format(timestamp, module, func)
@@ -485,7 +485,7 @@ class Common(object):
return total_size
-class ShutdownTimer(threading.Thread):
+class AutoStopTimer(threading.Thread):
"""
Background thread sleeps t hours and returns.
"""
@@ -498,6 +498,6 @@ class ShutdownTimer(threading.Thread):
self.time = time
def run(self):
- self.common.log('Shutdown Timer', 'Server will shut down after {} seconds'.format(self.time))
+ self.common.log('AutoStopTimer', 'Server will shut down after {} seconds'.format(self.time))
time.sleep(self.time)
return 1
diff --git a/onionshare/onion.py b/onionshare/onion.py
index ed4fde7b..2f4ddffd 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -133,6 +133,8 @@ class Onion(object):
self.stealth = False
self.service_id = None
+ self.scheduled_key = None
+ self.scheduled_auth_cookie = None
# Is bundled tor supported?
if (self.common.platform == 'Windows' or self.common.platform == 'Darwin') and getattr(sys, 'onionshare_dev_mode', False):
@@ -152,15 +154,20 @@ class Onion(object):
# Start out not connected to Tor
self.connected_to_tor = False
- def connect(self, custom_settings=False, config=False, tor_status_update_func=None):
+ def connect(self, custom_settings=False, config=False, tor_status_update_func=None, connect_timeout=120):
self.common.log('Onion', 'connect')
# Either use settings that are passed in, or use them from common
if custom_settings:
self.settings = custom_settings
+ elif config:
+ self.common.load_settings(config)
+ self.settings = self.common.settings
else:
+ self.common.load_settings()
self.settings = self.common.settings
+ strings.load_strings(self.common)
# The Tor controller
self.c = None
@@ -265,7 +272,7 @@ class Onion(object):
summary = res_parts[4].split('=')[1]
# "\033[K" clears the rest of the line
- print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r")
+ print("Connecting to the Tor network: {}% - {}{}".format(progress, summary, "\033[K"), end="\r")
if callable(tor_status_update_func):
if not tor_status_update_func(progress, summary):
@@ -283,14 +290,16 @@ class Onion(object):
if self.settings.get('tor_bridges_use_custom_bridges') or \
self.settings.get('tor_bridges_use_obfs4') or \
self.settings.get('tor_bridges_use_meek_lite_azure'):
- connect_timeout = 150
- else:
- # Timeout after 120 seconds
- connect_timeout = 120
+ # Only override timeout if a custom timeout has not been passed in
+ if connect_timeout == 120:
+ connect_timeout = 150
if time.time() - start_ts > connect_timeout:
print("")
- self.tor_proc.terminate()
- raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout'))
+ try:
+ self.tor_proc.terminate()
+ raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout'))
+ except FileNotFoundError:
+ pass
elif self.settings.get('connection_type') == 'automatic':
# Automatically try to guess the right way to connect to Tor Browser
@@ -423,27 +432,31 @@ class Onion(object):
return False
- def start_onion_service(self, port):
+ def start_onion_service(self, port, await_publication, save_scheduled_key=False):
"""
Start a onion service on port 80, pointing to the given port, and
return the onion hostname.
"""
self.common.log('Onion', 'start_onion_service')
-
self.auth_string = None
+
if not self.supports_ephemeral:
raise TorTooOld(strings._('error_ephemeral_not_supported'))
if self.stealth and not self.supports_stealth:
raise TorTooOld(strings._('error_stealth_not_supported'))
- print(strings._("config_onion_service").format(int(port)))
+ if not save_scheduled_key:
+ print("Setting up onion service on port {0:d}.".format(int(port)))
if self.stealth:
if self.settings.get('hidservauth_string'):
hidservauth_string = self.settings.get('hidservauth_string').split()[2]
basic_auth = {'onionshare':hidservauth_string}
else:
- basic_auth = {'onionshare':None}
+ if self.scheduled_auth_cookie:
+ basic_auth = {'onionshare':self.scheduled_auth_cookie}
+ else:
+ basic_auth = {'onionshare':None}
else:
basic_auth = None
@@ -455,6 +468,14 @@ class Onion(object):
# Assume it was a v3 key. Stem will throw an error if it's something illegible
key_type = "ED25519-V3"
+ elif self.scheduled_key:
+ key_content = self.scheduled_key
+ if self.is_v2_key(key_content):
+ key_type = "RSA1024"
+ else:
+ # Assume it was a v3 key. Stem will throw an error if it's something illegible
+ key_type = "ED25519-V3"
+
else:
key_type = "NEW"
# Work out if we can support v3 onion services, which are preferred
@@ -474,7 +495,6 @@ class Onion(object):
if key_type == "NEW":
debug_message += ', key_content={}'.format(key_content)
self.common.log('Onion', 'start_onion_service', '{}'.format(debug_message))
- await_publication = True
try:
if basic_auth != None:
res = self.c.create_ephemeral_hidden_service({ 80: port }, await_publication=await_publication, basic_auth=basic_auth, key_type=key_type, key_content=key_content)
@@ -493,6 +513,12 @@ class Onion(object):
if not self.settings.get('private_key'):
self.settings.set('private_key', res.private_key)
+ # If we were scheduling a future share, register the private key for later re-use
+ if save_scheduled_key:
+ self.scheduled_key = res.private_key
+ else:
+ self.scheduled_key = None
+
if self.stealth:
# Similar to the PrivateKey, the Control port only returns the ClientAuth
# in the response if it was responsible for creating the basic_auth password
@@ -507,8 +533,19 @@ class Onion(object):
self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
self.settings.set('hidservauth_string', self.auth_string)
else:
- auth_cookie = list(res.client_auth.values())[0]
- self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
+ if not self.scheduled_auth_cookie:
+ auth_cookie = list(res.client_auth.values())[0]
+ self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
+ if save_scheduled_key:
+ # Register the HidServAuth for the scheduled share
+ self.scheduled_auth_cookie = auth_cookie
+ else:
+ self.scheduled_auth_cookie = None
+ else:
+ self.auth_string = 'HidServAuth {} {}'.format(onion_host, self.scheduled_auth_cookie)
+ if not save_scheduled_key:
+ # We've used the scheduled share's HidServAuth. Reset it to None for future shares
+ self.scheduled_auth_cookie = None
if onion_host is not None:
self.settings.save()
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 551b8314..e746bae1 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -22,14 +22,14 @@ import os, shutil
from . import common, strings
from .onion import TorTooOld, TorErrorProtocolError
-from .common import ShutdownTimer
+from .common import AutoStopTimer
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, common, onion, local_only=False, shutdown_timeout=0):
+ def __init__(self, common, onion, local_only=False, autostop_timer=0):
self.common = common
self.common.log('OnionShare', '__init__')
@@ -49,9 +49,9 @@ class OnionShare(object):
self.local_only = local_only
# optionally shut down after N hours
- self.shutdown_timeout = shutdown_timeout
- # init timing thread
- self.shutdown_timer = None
+ self.autostop_timer = autostop_timer
+ # init auto-stop timer thread
+ self.autostop_timer_thread = None
def set_stealth(self, stealth):
self.common.log('OnionShare', 'set_stealth', 'stealth={}'.format(stealth))
@@ -68,7 +68,7 @@ class OnionShare(object):
except:
raise OSError(strings._('no_available_port'))
- def start_onion_service(self):
+ def start_onion_service(self, await_publication=True, save_scheduled_key=False):
"""
Start the onionshare onion service.
"""
@@ -77,14 +77,14 @@ class OnionShare(object):
if not self.port:
self.choose_port()
- if self.shutdown_timeout > 0:
- self.shutdown_timer = ShutdownTimer(self.common, self.shutdown_timeout)
+ if self.autostop_timer > 0:
+ self.autostop_timer_thread = AutoStopTimer(self.common, self.autostop_timer)
if self.local_only:
self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
return
- self.onion_host = self.onion.start_onion_service(self.port)
+ self.onion_host = self.onion.start_onion_service(self.port, await_publication, save_scheduled_key)
if self.stealth:
self.auth_string = self.onion.auth_string
diff --git a/onionshare/settings.py b/onionshare/settings.py
index 68cbb857..16b64a05 100644
--- a/onionshare/settings.py
+++ b/onionshare/settings.py
@@ -44,32 +44,46 @@ class Settings(object):
self.common.log('Settings', '__init__')
- # Default config
- self.filename = self.build_filename()
-
# If a readable config file was provided, use that instead
if config:
if os.path.isfile(config):
self.filename = config
else:
self.common.log('Settings', '__init__', 'Supplied config does not exist or is unreadable. Falling back to default location')
+ self.filename = self.build_filename()
+
+ else:
+ # Default config
+ self.filename = self.build_filename()
# Dictionary of available languages in this version of OnionShare,
# mapped to the language name, in that language
self.available_locales = {
- 'bn': 'বাংলা', # Bengali
- 'ca': 'Català', # Catalan
- 'da': 'Dansk', # Danish
- 'en': 'English', # English
- 'fr': 'Français', # French
- 'el': 'Ελληνικά', # Greek
- 'it': 'Italiano', # Italian
- 'ja': '日本語', # Japanese
- 'fa': 'فارسی', # Persian
- 'pt_BR': 'Português (Brasil)', # Portuguese Brazil
- 'ru': 'Русский', # Russian
- 'es': 'Español', # Spanish
- 'sv': 'Svenska' # Swedish
+ #'bn': 'বাংলা', # Bengali (commented out because not at 90% translation)
+ 'ca': 'Català', # Catalan
+ 'zh_Hant': '正體中文 (繁體)', # Traditional Chinese
+ 'zh_Hans': '中文 (简体)', # Simplified Chinese
+ 'da': 'Dansk', # Danish
+ 'en': 'English', # English
+ 'fi': 'Suomi', # Finnish
+ 'fr': 'Français', # French
+ 'de': 'Deutsch', # German
+ 'el': 'Ελληνικά', # Greek
+ 'is': 'Íslenska', # Icelandic
+ 'ga': 'Gaeilge', # Irish
+ 'it': 'Italiano', # Italian
+ 'ja': '日本語', # Japanese
+ 'nb': 'Norsk Bokmål', # Norwegian Bokmål
+ #'fa': 'فارسی', # Persian (commented out because not at 90% translation)
+ 'pl': 'Polski', # Polish
+ 'pt_BR': 'Português (Brasil)', # Portuguese Brazil
+ 'pt_PT': 'Português (Portugal)', # Portuguese Portugal
+ 'ru': 'Русский', # Russian
+ 'es': 'Español', # Spanish
+ 'sv': 'Svenska', # Swedish
+ 'te': 'తెలుగు', # Telugu
+ 'tr': 'Türkçe', # Turkish
+ 'uk': 'Українська', # Ukrainian
}
# These are the default settings. They will get overwritten when loading from disk
@@ -84,7 +98,8 @@ class Settings(object):
'auth_type': 'no_auth',
'auth_password': '',
'close_after_first_download': True,
- 'shutdown_timeout': False,
+ 'autostop_timer': False,
+ 'autostart_timer': False,
'use_stealth': False,
'use_autoupdate': True,
'autoupdate_timestamp': None,
diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py
index d6ef86ad..bc805445 100644
--- a/onionshare/web/receive_mode.py
+++ b/onionshare/web/receive_mode.py
@@ -79,7 +79,7 @@ class ReceiveModeWeb(object):
})
self.common.log('ReceiveModeWeb', 'define_routes', '/upload, uploaded {}, saving to {}'.format(f.filename, local_path))
- print('\n' + strings._('receive_mode_received_file').format(local_path))
+ print('\n' + "Received: {}".format(local_path))
if request.upload_error:
self.common.log('ReceiveModeWeb', 'define_routes', '/upload, there was an upload error')
@@ -87,7 +87,7 @@ class ReceiveModeWeb(object):
self.web.add_request(self.web.REQUEST_ERROR_DATA_DIR_CANNOT_CREATE, request.path, {
"receive_mode_dir": request.receive_mode_dir
})
- print(strings._('error_cannot_create_data_dir').format(request.receive_mode_dir))
+ print("Could not create OnionShare data folder: {}".format(request.receive_mode_dir))
msg = 'Error uploading, please inform the OnionShare user'
if ajax:
@@ -112,12 +112,14 @@ class ReceiveModeWeb(object):
else:
flash(msg, 'info')
else:
+ msg = 'Sent '
for filename in filenames:
- msg = 'Sent {}'.format(filename)
- if ajax:
- info_flashes.append(msg)
- else:
- flash(msg, 'info')
+ msg += '{}, '.format(filename)
+ msg = msg.rstrip(', ')
+ if ajax:
+ info_flashes.append(msg)
+ else:
+ flash(msg, 'info')
if self.can_upload:
if ajax:
@@ -297,6 +299,7 @@ class ReceiveModeRequest(Request):
new_receive_mode_dir = '{}-{}'.format(self.receive_mode_dir, i)
try:
os.makedirs(new_receive_mode_dir, 0o700, exist_ok=False)
+ self.receive_mode_dir = new_receive_mode_dir
break
except OSError:
pass
@@ -310,7 +313,7 @@ class ReceiveModeRequest(Request):
self.web.add_request(self.web.REQUEST_ERROR_DATA_DIR_CANNOT_CREATE, request.path, {
"receive_mode_dir": self.receive_mode_dir
})
- print(strings._('error_cannot_create_data_dir').format(self.receive_mode_dir))
+ print("Could not create OnionShare data folder: {}".format(self.receive_mode_dir))
self.web.common.log('ReceiveModeRequest', '__init__', 'Permission denied creating receive mode directory')
self.upload_error = True
diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py
index eb487c42..560a8ba4 100644
--- a/onionshare/web/share_mode.py
+++ b/onionshare/web/share_mode.py
@@ -201,7 +201,7 @@ class ShareModeWeb(object):
# Close the server, if necessary
if not self.web.stay_open and not canceled:
- print(strings._("closing_automatically"))
+ print("Stopped because transfer is complete")
self.web.running = False
try:
if shutdown_func is None:
diff --git a/onionshare/web/web.py b/onionshare/web/web.py
index 66ba5b24..edaf75f1 100644
--- a/onionshare/web/web.py
+++ b/onionshare/web/web.py
@@ -22,7 +22,10 @@ from .receive_mode import ReceiveModeWeb, ReceiveModeWSGIMiddleware, ReceiveMode
def stubbed_show_server_banner(env, debug, app_import_path, eager_loading):
pass
-flask.cli.show_server_banner = stubbed_show_server_banner
+try:
+ flask.cli.show_server_banner = stubbed_show_server_banner
+except:
+ pass
class Web(object):
@@ -51,9 +54,9 @@ class Web(object):
template_folder=self.common.get_resource_path('templates'))
self.app.secret_key = self.common.random_string(8)
- # Debug mode?
- if self.common.debug:
- self.debug_mode()
+ # Verbose mode?
+ if self.common.verbose:
+ self.verbose_mode()
# Are we running in GUI mode?
self.is_gui = is_gui
@@ -150,7 +153,7 @@ class Web(object):
if self.error404_count == 20:
self.add_request(Web.REQUEST_RATE_LIMIT, request.path)
self.force_shutdown()
- print(strings._('error_rate_limit'))
+ print("Someone has made too many wrong attempts on your address, which means they could be trying to guess it, so OnionShare has stopped the server. Start sharing again and send the recipient a new address to share.")
r = make_response(render_template('404.html'), 404)
return self.add_security_headers(r)
@@ -193,12 +196,12 @@ class Web(object):
self.slug = self.common.build_slug()
self.common.log('Web', 'generate_slug', 'built random slug: "{}"'.format(self.slug))
- def debug_mode(self):
+ def verbose_mode(self):
"""
- Turn on debugging mode, which will log flask errors to a debug file.
+ Turn on verbose mode, which will log flask errors to a file.
"""
- flask_debug_filename = os.path.join(self.common.build_data_dir(), 'flask_debug.log')
- log_handler = logging.FileHandler(flask_debug_filename)
+ flask_log_filename = os.path.join(self.common.build_data_dir(), 'flask.log')
+ log_handler = logging.FileHandler(flask_log_filename)
log_handler.setLevel(logging.WARNING)
self.app.logger.addHandler(log_handler)
@@ -228,13 +231,11 @@ class Web(object):
pass
self.running = False
- def start(self, port, stay_open=False, public_mode=False, persistent_slug=None):
+ def start(self, port, stay_open=False, public_mode=False, slug=None):
"""
Start the flask web server.
"""
- self.common.log('Web', 'start', 'port={}, stay_open={}, public_mode={}, persistent_slug={}'.format(port, stay_open, public_mode, persistent_slug))
- if not public_mode:
- self.generate_slug(persistent_slug)
+ self.common.log('Web', 'start', 'port={}, stay_open={}, public_mode={}, slug={}'.format(port, stay_open, public_mode, slug))
self.stay_open = stay_open
@@ -264,7 +265,7 @@ class Web(object):
self.stop_q.put(True)
# Reset any slug that was in use
- self.slug = ''
+ self.slug = None
# To stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
if self.running: