mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Rename "slug" to "password"
This commit is contained in:
parent
fe64a5a059
commit
7d89f80f20
@ -121,9 +121,9 @@ def main(cwd=None):
|
||||
try:
|
||||
common.settings.load()
|
||||
if not common.settings.get('public_mode'):
|
||||
web.generate_slug(common.settings.get('slug'))
|
||||
web.generate_password(common.settings.get('password'))
|
||||
else:
|
||||
web.slug = None
|
||||
web.password = None
|
||||
app = OnionShare(common, onion, local_only, autostop_timer)
|
||||
app.set_stealth(stealth)
|
||||
app.choose_port()
|
||||
@ -132,7 +132,7 @@ def main(cwd=None):
|
||||
if common.settings.get('public_mode'):
|
||||
url = 'http://{0:s}'.format(app.onion_host)
|
||||
else:
|
||||
url = 'http://onionshare:{0:s}@{1:s}'.format(web.slug, app.onion_host)
|
||||
url = 'http://onionshare:{0:s}@{1:s}'.format(web.password, app.onion_host)
|
||||
|
||||
# Delay the startup if a startup timer was set
|
||||
if autostart_timer > 0:
|
||||
@ -200,22 +200,22 @@ def main(cwd=None):
|
||||
print('')
|
||||
|
||||
# Start OnionShare http service in new thread
|
||||
t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), web.slug))
|
||||
t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), web.password))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
try: # Trap Ctrl-C
|
||||
# Wait for web.generate_slug() to finish running
|
||||
# Wait for web.generate_password() to finish running
|
||||
time.sleep(0.2)
|
||||
|
||||
# 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
|
||||
# Save the web password if we are using a persistent private key
|
||||
if common.settings.get('save_private_key'):
|
||||
if not common.settings.get('slug'):
|
||||
common.settings.set('slug', web.slug)
|
||||
if not common.settings.get('password'):
|
||||
common.settings.set('password', web.password)
|
||||
common.settings.save()
|
||||
|
||||
print('')
|
||||
|
@ -143,7 +143,7 @@ class Common(object):
|
||||
os.makedirs(onionshare_data_dir, 0o700, True)
|
||||
return onionshare_data_dir
|
||||
|
||||
def build_slug(self):
|
||||
def build_password(self):
|
||||
"""
|
||||
Returns a random string made from two words from the wordlist, such as "deter-trig".
|
||||
"""
|
||||
|
@ -111,7 +111,7 @@ class Settings(object):
|
||||
'save_private_key': False,
|
||||
'private_key': '',
|
||||
'public_mode': False,
|
||||
'slug': '',
|
||||
'password': '',
|
||||
'hidservauth_string': '',
|
||||
'data_dir': self.build_default_data_dir(),
|
||||
'locale': None # this gets defined in fill_in_defaults()
|
||||
|
@ -38,7 +38,7 @@ class ReceiveModeWeb(object):
|
||||
if self.common.settings.get('public_mode'):
|
||||
upload_action = '/upload'
|
||||
else:
|
||||
upload_action = '/{}/upload'.format(self.web.slug)
|
||||
upload_action = '/{}/upload'.format(self.web.password)
|
||||
|
||||
r = make_response(render_template(
|
||||
'receive.html',
|
||||
@ -87,7 +87,7 @@ class ReceiveModeWeb(object):
|
||||
if self.common.settings.get('public_mode'):
|
||||
return redirect('/')
|
||||
else:
|
||||
return redirect('/{}'.format(slug_candidate))
|
||||
return redirect('/{}'.format(password_candidate))
|
||||
|
||||
# Note that flash strings are in English, and not translated, on purpose,
|
||||
# to avoid leaking the locale of the OnionShare user
|
||||
@ -117,7 +117,7 @@ class ReceiveModeWeb(object):
|
||||
if self.common.settings.get('public_mode'):
|
||||
path = '/'
|
||||
else:
|
||||
path = '/{}'.format(slug_candidate)
|
||||
path = '/{}'.format(password_candidate)
|
||||
return redirect('{}'.format(path))
|
||||
else:
|
||||
if ajax:
|
||||
@ -238,7 +238,7 @@ class ReceiveModeRequest(Request):
|
||||
if self.path == '/upload' or self.path == '/upload-ajax':
|
||||
self.upload_request = True
|
||||
else:
|
||||
if self.path == '/{}/upload'.format(self.web.slug) or self.path == '/{}/upload-ajax'.format(self.web.slug):
|
||||
if self.path == '/{}/upload'.format(self.web.password) or self.path == '/{}/upload-ajax'.format(self.web.password):
|
||||
self.upload_request = True
|
||||
|
||||
if self.upload_request:
|
||||
|
@ -64,10 +64,10 @@ class ShareModeWeb(object):
|
||||
else:
|
||||
self.filesize = self.download_filesize
|
||||
|
||||
if self.web.slug:
|
||||
if self.web.password:
|
||||
r = make_response(render_template(
|
||||
'send.html',
|
||||
slug=self.web.slug,
|
||||
password=self.web.password,
|
||||
file_info=self.file_info,
|
||||
filename=os.path.basename(self.download_filename),
|
||||
filesize=self.filesize,
|
||||
|
@ -45,7 +45,7 @@ class Web(object):
|
||||
REQUEST_UPLOAD_FINISHED = 8
|
||||
REQUEST_UPLOAD_CANCELED = 9
|
||||
REQUEST_ERROR_DATA_DIR_CANNOT_CREATE = 10
|
||||
REQUEST_INVALID_SLUG = 11
|
||||
REQUEST_INVALID_PASSWORD = 11
|
||||
|
||||
def __init__(self, common, is_gui, mode='share'):
|
||||
self.common = common
|
||||
@ -97,14 +97,14 @@ class Web(object):
|
||||
]
|
||||
|
||||
self.q = queue.Queue()
|
||||
self.slug = None
|
||||
self.password = None
|
||||
|
||||
self.reset_invalid_slugs()
|
||||
self.reset_invalid_passwords()
|
||||
|
||||
self.done = False
|
||||
|
||||
# shutting down the server only works within the context of flask, so the easiest way to do it is over http
|
||||
self.shutdown_slug = self.common.random_string(16)
|
||||
self.shutdown_password = self.common.random_string(16)
|
||||
|
||||
# Keep track if the server is running
|
||||
self.running = False
|
||||
@ -131,7 +131,7 @@ class Web(object):
|
||||
@self.auth.get_password
|
||||
def get_pw(username):
|
||||
if username == 'onionshare':
|
||||
return self.slug
|
||||
return self.password
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -148,12 +148,12 @@ class Web(object):
|
||||
def not_found(e):
|
||||
return self.error404()
|
||||
|
||||
@self.app.route("/<slug_candidate>/shutdown")
|
||||
def shutdown(slug_candidate):
|
||||
@self.app.route("/<password_candidate>/shutdown")
|
||||
def shutdown(password_candidate):
|
||||
"""
|
||||
Stop the flask web server, from the context of an http request.
|
||||
"""
|
||||
if slug_candidate == self.shutdown_slug:
|
||||
if password_candidate == self.shutdown_password:
|
||||
self.force_shutdown()
|
||||
return ""
|
||||
abort(404)
|
||||
@ -169,14 +169,14 @@ class Web(object):
|
||||
def error401(self):
|
||||
auth = request.authorization
|
||||
if auth:
|
||||
if auth['username'] == 'onionshare' and auth['password'] not in self.invalid_slugs:
|
||||
if auth['username'] == 'onionshare' and auth['password'] not in self.invalid_passwords:
|
||||
print('Invalid password guess: {}'.format(auth['password']))
|
||||
self.add_request(Web.REQUEST_INVALID_SLUG, data=auth['password'])
|
||||
self.add_request(Web.REQUEST_INVALID_PASSWORD, data=auth['password'])
|
||||
|
||||
self.invalid_slugs.append(auth['password'])
|
||||
self.invalid_slugs_count += 1
|
||||
self.invalid_passwords.append(auth['password'])
|
||||
self.invalid_passwords_count += 1
|
||||
|
||||
if self.invalid_slugs_count == 20:
|
||||
if self.invalid_passwords_count == 20:
|
||||
self.add_request(Web.REQUEST_RATE_LIMIT)
|
||||
self.force_shutdown()
|
||||
print("Someone has made too many wrong attempts to guess your password, so OnionShare has stopped the server. Start sharing again and send the recipient a new address to share.")
|
||||
@ -218,14 +218,14 @@ class Web(object):
|
||||
'data': data
|
||||
})
|
||||
|
||||
def generate_slug(self, persistent_slug=None):
|
||||
self.common.log('Web', 'generate_slug', 'persistent_slug={}'.format(persistent_slug))
|
||||
if persistent_slug != None and persistent_slug != '':
|
||||
self.slug = persistent_slug
|
||||
self.common.log('Web', 'generate_slug', 'persistent_slug sent, so slug is: "{}"'.format(self.slug))
|
||||
def generate_password(self, persistent_password=None):
|
||||
self.common.log('Web', 'generate_password', 'persistent_password={}'.format(persistent_password))
|
||||
if persistent_password != None and persistent_password != '':
|
||||
self.password = persistent_password
|
||||
self.common.log('Web', 'generate_password', 'persistent_password sent, so password is: "{}"'.format(self.password))
|
||||
else:
|
||||
self.slug = self.common.build_slug()
|
||||
self.common.log('Web', 'generate_slug', 'built random slug: "{}"'.format(self.slug))
|
||||
self.password = self.common.build_password()
|
||||
self.common.log('Web', 'generate_password', 'built random password: "{}"'.format(self.password))
|
||||
|
||||
def verbose_mode(self):
|
||||
"""
|
||||
@ -236,9 +236,9 @@ class Web(object):
|
||||
log_handler.setLevel(logging.WARNING)
|
||||
self.app.logger.addHandler(log_handler)
|
||||
|
||||
def reset_invalid_slugs(self):
|
||||
self.invalid_slugs_count = 0
|
||||
self.invalid_slugs = []
|
||||
def reset_invalid_passwords(self):
|
||||
self.invalid_passwords_count = 0
|
||||
self.invalid_passwords = []
|
||||
|
||||
def force_shutdown(self):
|
||||
"""
|
||||
@ -254,11 +254,11 @@ class Web(object):
|
||||
pass
|
||||
self.running = False
|
||||
|
||||
def start(self, port, stay_open=False, public_mode=False, slug=None):
|
||||
def start(self, port, stay_open=False, public_mode=False, password=None):
|
||||
"""
|
||||
Start the flask web server.
|
||||
"""
|
||||
self.common.log('Web', 'start', 'port={}, stay_open={}, public_mode={}, slug={}'.format(port, stay_open, public_mode, slug))
|
||||
self.common.log('Web', 'start', 'port={}, stay_open={}, public_mode={}, password={}'.format(port, stay_open, public_mode, password))
|
||||
|
||||
self.stay_open = stay_open
|
||||
|
||||
@ -287,11 +287,11 @@ class Web(object):
|
||||
# Let the mode know that the user stopped the server
|
||||
self.stop_q.put(True)
|
||||
|
||||
# To stop flask, load http://shutdown:[shutdown_slug]@127.0.0.1/[shutdown_slug]/shutdown
|
||||
# (We're putting the shutdown_slug in the path as well to make routing simpler)
|
||||
# To stop flask, load http://shutdown:[shutdown_password]@127.0.0.1/[shutdown_password]/shutdown
|
||||
# (We're putting the shutdown_password in the path as well to make routing simpler)
|
||||
if self.running:
|
||||
requests.get('http://127.0.0.1:{}/{}/shutdown'.format(port, self.shutdown_slug),
|
||||
auth=requests.auth.HTTPBasicAuth('onionshare', self.slug))
|
||||
requests.get('http://127.0.0.1:{}/{}/shutdown'.format(port, self.shutdown_password),
|
||||
auth=requests.auth.HTTPBasicAuth('onionshare', self.password))
|
||||
|
||||
# Reset any slug that was in use
|
||||
self.slug = None
|
||||
# Reset any password that was in use
|
||||
self.password = None
|
||||
|
@ -24,7 +24,7 @@ from onionshare.common import AutoStopTimer
|
||||
|
||||
from ..server_status import ServerStatus
|
||||
from ..threads import OnionThread
|
||||
from ..threads import AutoStartTimer
|
||||
from ..threads import AutoStartTimer
|
||||
from ..widgets import Alert
|
||||
|
||||
class Mode(QtWidgets.QWidget):
|
||||
@ -181,7 +181,7 @@ class Mode(QtWidgets.QWidget):
|
||||
self.app.port = None
|
||||
|
||||
# Start the onion thread. If this share was scheduled for a future date,
|
||||
# the OnionThread will start and exit 'early' to obtain the port, slug
|
||||
# the OnionThread will start and exit 'early' to obtain the port, password
|
||||
# and onion address, but it will not start the WebThread yet.
|
||||
if self.server_status.autostart_timer_datetime:
|
||||
self.start_onion_thread(obtain_onion_early=True)
|
||||
|
@ -113,7 +113,7 @@ class ReceiveMode(Mode):
|
||||
"""
|
||||
# Reset web counters
|
||||
self.web.receive_mode.upload_count = 0
|
||||
self.web.reset_invalid_slugs()
|
||||
self.web.reset_invalid_passwords()
|
||||
|
||||
# Hide and reset the uploads if we have previously shared
|
||||
self.reset_info_counters()
|
||||
|
@ -147,7 +147,7 @@ class ShareMode(Mode):
|
||||
"""
|
||||
# Reset web counters
|
||||
self.web.share_mode.download_count = 0
|
||||
self.web.reset_invalid_slugs()
|
||||
self.web.reset_invalid_passwords()
|
||||
|
||||
# Hide and reset the downloads if we have previously shared
|
||||
self.reset_info_counters()
|
||||
|
@ -143,7 +143,7 @@ class WebsiteMode(Mode):
|
||||
"""
|
||||
# Reset web counters
|
||||
self.web.website_mode.visit_count = 0
|
||||
self.web.reset_invalid_slugs()
|
||||
self.web.reset_invalid_passwords()
|
||||
|
||||
# Hide and reset the downloads if we have previously shared
|
||||
self.reset_info_counters()
|
||||
|
@ -471,11 +471,11 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
Alert(self.common, strings._('error_cannot_create_data_dir').format(event["data"]["receive_mode_dir"]))
|
||||
|
||||
if event["type"] == Web.REQUEST_OTHER:
|
||||
if event["path"] != '/favicon.ico' and event["path"] != "/{}/shutdown".format(mode.web.shutdown_slug):
|
||||
if event["path"] != '/favicon.ico' and event["path"] != "/{}/shutdown".format(mode.web.shutdown_password):
|
||||
self.status_bar.showMessage('{0:s}: {1:s}'.format(strings._('other_page_loaded'), event["path"]))
|
||||
|
||||
if event["type"] == Web.REQUEST_INVALID_SLUG:
|
||||
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.invalid_slugs_count, strings._('invalid_slug_guess'), event["data"]))
|
||||
if event["type"] == Web.REQUEST_INVALID_PASSWORD:
|
||||
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.invalid_passwords_count, strings._('invalid_password_guess'), event["data"]))
|
||||
|
||||
mode.timer_callback()
|
||||
|
||||
|
@ -243,8 +243,8 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.show_url()
|
||||
|
||||
if self.common.settings.get('save_private_key'):
|
||||
if not self.common.settings.get('slug'):
|
||||
self.common.settings.set('slug', self.web.slug)
|
||||
if not self.common.settings.get('password'):
|
||||
self.common.settings.set('password', self.web.password)
|
||||
self.common.settings.save()
|
||||
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
@ -421,5 +421,5 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
if self.common.settings.get('public_mode'):
|
||||
url = 'http://{0:s}'.format(self.app.onion_host)
|
||||
else:
|
||||
url = 'http://onionshare:{0:s}@{1:s}'.format(self.web.slug, self.app.onion_host)
|
||||
url = 'http://onionshare:{0:s}@{1:s}'.format(self.web.password, self.app.onion_host)
|
||||
return url
|
||||
|
@ -54,7 +54,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
|
||||
# General settings
|
||||
|
||||
# Use a slug or not ('public mode')
|
||||
# Use a password or not ('public mode')
|
||||
self.public_mode_checkbox = QtWidgets.QCheckBox()
|
||||
self.public_mode_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.public_mode_checkbox.setText(strings._("gui_settings_public_mode_checkbox"))
|
||||
@ -968,12 +968,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
if self.save_private_key_checkbox.isChecked():
|
||||
settings.set('save_private_key', True)
|
||||
settings.set('private_key', self.old_settings.get('private_key'))
|
||||
settings.set('slug', self.old_settings.get('slug'))
|
||||
settings.set('password', self.old_settings.get('password'))
|
||||
settings.set('hidservauth_string', self.old_settings.get('hidservauth_string'))
|
||||
else:
|
||||
settings.set('save_private_key', False)
|
||||
settings.set('private_key', '')
|
||||
settings.set('slug', '')
|
||||
settings.set('password', '')
|
||||
# Also unset the HidServAuth if we are removing our reusable private key
|
||||
settings.set('hidservauth_string', '')
|
||||
|
||||
|
@ -42,13 +42,13 @@ class OnionThread(QtCore.QThread):
|
||||
def run(self):
|
||||
self.mode.common.log('OnionThread', 'run')
|
||||
|
||||
# Choose port and slug early, because we need them to exist in advance for scheduled shares
|
||||
# Choose port and password early, because we need them to exist in advance for scheduled shares
|
||||
self.mode.app.stay_open = not self.mode.common.settings.get('close_after_first_download')
|
||||
if not self.mode.app.port:
|
||||
self.mode.app.choose_port()
|
||||
if not self.mode.common.settings.get('public_mode'):
|
||||
if not self.mode.web.slug:
|
||||
self.mode.web.generate_slug(self.mode.common.settings.get('slug'))
|
||||
if not self.mode.web.password:
|
||||
self.mode.web.generate_password(self.mode.common.settings.get('password'))
|
||||
|
||||
try:
|
||||
if self.mode.obtain_onion_early:
|
||||
@ -86,7 +86,7 @@ class WebThread(QtCore.QThread):
|
||||
|
||||
def run(self):
|
||||
self.mode.common.log('WebThread', 'run')
|
||||
self.mode.web.start(self.mode.app.port, self.mode.app.stay_open, self.mode.common.settings.get('public_mode'), self.mode.web.slug)
|
||||
self.mode.web.start(self.mode.app.port, self.mode.app.stay_open, self.mode.common.settings.get('public_mode'), self.mode.web.password)
|
||||
self.success.emit()
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"not_a_readable_file": "{0:s} is not a readable file.",
|
||||
"no_available_port": "Could not find an available port to start the onion service",
|
||||
"other_page_loaded": "Address loaded",
|
||||
"invalid_slug_guess": "Invalid password guess",
|
||||
"invalid_password_guess": "Invalid password guess",
|
||||
"close_on_autostop_timer": "Stopped because auto-stop timer ran out",
|
||||
"closing_automatically": "Stopped because transfer is complete",
|
||||
"large_filesize": "Warning: Sending a large share could take hours",
|
||||
|
Loading…
Reference in New Issue
Block a user