[Pkg-privacy-commits] [onionshare] 52/66: If "Stop sharing automatically" is selected, only allow one download at a time (fixes #248)
Ulrike Uhlig
u-guest at moszumanska.debian.org
Wed Apr 13 22:17:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch master
in repository onionshare.
commit c07f4e5f8389d07a9b8fe7c44c2dbb0a5f24ebeb
Author: Micah Lee <micah at micahflee.com>
Date: Tue Apr 12 15:59:49 2016 -0700
If "Stop sharing automatically" is selected, only allow one download at a time (fixes #248)
---
onionshare/web.py | 35 ++++++++++++++++++++++++++++++++---
resources/html/denied.html | 18 ++++++++++++++++++
resources/html/index.html | 2 +-
setup.py | 3 ++-
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/onionshare/web.py b/onionshare/web.py
index 72b74cd..e1f8050 100644
--- a/onionshare/web.py
+++ b/onionshare/web.py
@@ -144,6 +144,11 @@ def check_slug_candidate(slug_candidate, slug_compare = None):
if not helpers.constant_time_compare(slug_compare.encode('ascii'), slug_candidate.encode('ascii')):
abort(404)
+
+# If "Stop sharing automatically" is checked (stay_open == False), only allow
+# one download at a time.
+download_in_progress = False
+
@app.route("/<slug_candidate>")
def index(slug_candidate):
"""
@@ -152,14 +157,22 @@ def index(slug_candidate):
check_slug_candidate(slug_candidate)
add_request(REQUEST_LOAD, request.path)
+
+ # Deny new downloads if "Stop sharing automatically" is checked and there is
+ # currently a download
+ global stay_open, download_in_progress
+ deny_download = not stay_open and download_in_progress
+ if deny_download:
+ return render_template_string(open(helpers.get_resource_path('html/denied.html')).read())
+
+ # If download is allowed to continue, serve download page
return render_template_string(
open(helpers.get_resource_path('html/index.html')).read(),
slug=slug,
file_info=file_info,
filename=os.path.basename(zip_filename),
filesize=zip_filesize,
- filesize_human=helpers.human_readable_filesize(zip_filesize)
- )
+ filesize_human=helpers.human_readable_filesize(zip_filesize))
# 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
@@ -173,6 +186,13 @@ def download(slug_candidate):
"""
check_slug_candidate(slug_candidate)
+ # Deny new downloads if "Stop sharing automatically" is checked and there is
+ # currently a download
+ global stay_open, download_in_progress
+ deny_download = not stay_open and download_in_progress
+ if deny_download:
+ return render_template_string(open(helpers.get_resource_path('html/denied.html')).read())
+
global download_count
# each download has a unique id
@@ -195,6 +215,11 @@ def download(slug_candidate):
global client_cancel
client_cancel = False
+ # Starting a new download
+ global stay_open, download_in_progress
+ if not stay_open:
+ download_in_progress = True
+
chunk_size = 102400 # 100kb
fp = open(zip_filename, 'rb')
@@ -237,7 +262,11 @@ def download(slug_candidate):
if helpers.get_platform() != 'Darwin':
sys.stdout.write("\n")
- # download is finished, close the server
+ # Download is finished
+ if not stay_open:
+ download_in_progress = False
+
+ # Close the server, if necessary
if not stay_open and not canceled:
print(strings._("closing_automatically"))
if shutdown_func is None:
diff --git a/resources/html/denied.html b/resources/html/denied.html
new file mode 100644
index 0000000..ef77642
--- /dev/null
+++ b/resources/html/denied.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>OnionShare</title>
+ <style>
+ body {
+ background-color: #222222;
+ color: #ffffff;
+ text-align: center;
+ font-family: sans-serif;
+ padding: 5em 1em;
+ }
+ </style>
+ </head>
+ <body>
+ <p>OnionShare download in progress</p>
+ </body>
+</html>
diff --git a/resources/html/index.html b/resources/html/index.html
index 252c628..9b857a6 100644
--- a/resources/html/index.html
+++ b/resources/html/index.html
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html>
- <head>
+ <head>
<title>OnionShare</title>
<style type="text/css">
body {
diff --git a/setup.py b/setup.py
index 48e5469..8e25f91 100644
--- a/setup.py
+++ b/setup.py
@@ -73,7 +73,8 @@ locale = [
html = [
'resources/html/index.html',
- 'resources/html/404.html',
+ 'resources/html/denied.html',
+ 'resources/html/404.html'
]
setup(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git
More information about the Pkg-privacy-commits
mailing list