mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-07 22:32:58 -04:00
Hold a share open if its timer hsa expired but a file is still uploading. Don't allow other uploads during this time
This commit is contained in:
parent
868d1ac2f8
commit
2e6bd74fa8
3 changed files with 106 additions and 82 deletions
|
@ -118,6 +118,7 @@ class Web(object):
|
||||||
self.download_in_progress = False
|
self.download_in_progress = False
|
||||||
|
|
||||||
self.done = False
|
self.done = False
|
||||||
|
self.can_upload = True
|
||||||
|
|
||||||
# If the client closes the OnionShare window while a download is in progress,
|
# If the client closes the OnionShare window while a download is in progress,
|
||||||
# it should immediately stop serving the file. The client_cancel global is
|
# it should immediately stop serving the file. The client_cancel global is
|
||||||
|
@ -343,6 +344,7 @@ class Web(object):
|
||||||
"""
|
"""
|
||||||
Upload files.
|
Upload files.
|
||||||
"""
|
"""
|
||||||
|
while self.can_upload:
|
||||||
# Make sure downloads_dir exists
|
# Make sure downloads_dir exists
|
||||||
valid = True
|
valid = True
|
||||||
try:
|
try:
|
||||||
|
@ -420,6 +422,10 @@ class Web(object):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
flash('Sent {}'.format(filename), 'info')
|
flash('Sent {}'.format(filename), 'info')
|
||||||
|
|
||||||
|
|
||||||
|
# Register that uploads were sent (for shutdown timer)
|
||||||
|
self.done = True
|
||||||
|
|
||||||
if self.common.settings.get('public_mode'):
|
if self.common.settings.get('public_mode'):
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
else:
|
else:
|
||||||
|
@ -428,11 +434,14 @@ class Web(object):
|
||||||
@self.app.route("/<slug_candidate>/upload", methods=['POST'])
|
@self.app.route("/<slug_candidate>/upload", methods=['POST'])
|
||||||
def upload(slug_candidate):
|
def upload(slug_candidate):
|
||||||
self.check_slug_candidate(slug_candidate)
|
self.check_slug_candidate(slug_candidate)
|
||||||
|
if self.can_upload:
|
||||||
return upload_logic(slug_candidate)
|
return upload_logic(slug_candidate)
|
||||||
|
else:
|
||||||
|
return self.error404()
|
||||||
|
|
||||||
@self.app.route("/upload", methods=['POST'])
|
@self.app.route("/upload", methods=['POST'])
|
||||||
def upload_public():
|
def upload_public():
|
||||||
if not self.common.settings.get('public_mode'):
|
if not self.common.settings.get('public_mode') or not self.can_upload:
|
||||||
return self.error404()
|
return self.error404()
|
||||||
return upload_logic()
|
return upload_logic()
|
||||||
|
|
||||||
|
@ -449,11 +458,14 @@ class Web(object):
|
||||||
@self.app.route("/<slug_candidate>/close", methods=['POST'])
|
@self.app.route("/<slug_candidate>/close", methods=['POST'])
|
||||||
def close(slug_candidate):
|
def close(slug_candidate):
|
||||||
self.check_slug_candidate(slug_candidate)
|
self.check_slug_candidate(slug_candidate)
|
||||||
|
if self.can_upload:
|
||||||
return close_logic(slug_candidate)
|
return close_logic(slug_candidate)
|
||||||
|
else:
|
||||||
|
return self.error404()
|
||||||
|
|
||||||
@self.app.route("/close", methods=['POST'])
|
@self.app.route("/close", methods=['POST'])
|
||||||
def close_public():
|
def close_public():
|
||||||
if not self.common.settings.get('public_mode'):
|
if not self.common.settings.get('public_mode') or not self.can_upload:
|
||||||
return self.error404()
|
return self.error404()
|
||||||
return close_logic()
|
return close_logic()
|
||||||
|
|
||||||
|
@ -745,7 +757,7 @@ class ReceiveModeRequest(Request):
|
||||||
|
|
||||||
# Is this a valid upload request?
|
# Is this a valid upload request?
|
||||||
self.upload_request = False
|
self.upload_request = False
|
||||||
if self.method == 'POST':
|
if self.method == 'POST' and self.web.can_upload:
|
||||||
if self.path == '/{}/upload'.format(self.web.slug):
|
if self.path == '/{}/upload'.format(self.web.slug):
|
||||||
self.upload_request = True
|
self.upload_request = True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -98,6 +98,17 @@ class ReceiveMode(Mode):
|
||||||
The shutdown timer expired, should we stop the server? Returns a bool
|
The shutdown timer expired, should we stop the server? Returns a bool
|
||||||
"""
|
"""
|
||||||
# TODO: wait until the final upload is done before stoppign the server?
|
# TODO: wait until the final upload is done before stoppign the server?
|
||||||
|
# If there were no attempts to upload files, or all uploads are done, we can stop
|
||||||
|
if self.web.upload_count == 0 or self.web.done:
|
||||||
|
self.server_status.stop_server()
|
||||||
|
self.server_status_label.setText(strings._('close_on_timeout', True))
|
||||||
|
return True
|
||||||
|
# An upload is probably still running - hold off on stopping the share, but block new shares.
|
||||||
|
else:
|
||||||
|
self.server_status_label.setText(strings._('timeout_upload_still_running', True))
|
||||||
|
self.web.can_upload = False
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def start_server_custom(self):
|
def start_server_custom(self):
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
"close_on_timeout": "Stopped because timer expired",
|
"close_on_timeout": "Stopped because timer expired",
|
||||||
"closing_automatically": "Stopped because download finished",
|
"closing_automatically": "Stopped because download finished",
|
||||||
"timeout_download_still_running": "Waiting for download to complete",
|
"timeout_download_still_running": "Waiting for download to complete",
|
||||||
|
"timeout_upload_still_running": "Waiting for upload to complete",
|
||||||
"large_filesize": "Warning: Sending large files could take hours",
|
"large_filesize": "Warning: Sending large files could take hours",
|
||||||
"systray_menu_exit": "Quit",
|
"systray_menu_exit": "Quit",
|
||||||
"systray_download_started_title": "OnionShare Download Started",
|
"systray_download_started_title": "OnionShare Download Started",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue