diff options
author | Micah Lee <micah@micahflee.com> | 2019-09-01 20:36:30 -0700 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2019-09-01 20:36:30 -0700 |
commit | 6561d71edde50e3df4e1e585940b9a9d0d8c9a2b (patch) | |
tree | 604aef0cb12b18b5997f07a765ebc319dbfbd0b7 /onionshare | |
parent | 1c465b40fe13d7fe9db445d2d74d860a71c66a68 (diff) | |
download | onionshare-6561d71edde50e3df4e1e585940b9a9d0d8c9a2b.tar.gz onionshare-6561d71edde50e3df4e1e585940b9a9d0d8c9a2b.zip |
Only allow downloading of individual files if it is enabled in settings, and stop sharing automatically isn't
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/web/send_base_mode.py | 11 | ||||
-rw-r--r-- | onionshare/web/share_mode.py | 20 | ||||
-rw-r--r-- | onionshare/web/website_mode.py | 3 |
3 files changed, 27 insertions, 7 deletions
diff --git a/onionshare/web/send_base_mode.py b/onionshare/web/send_base_mode.py index 68f6aeca..6deb38ac 100644 --- a/onionshare/web/send_base_mode.py +++ b/onionshare/web/send_base_mode.py @@ -41,10 +41,13 @@ class SendBaseModeWeb: self.download_in_progress = False self.define_routes() + self.init() def init(self): - self.common.log('SendBaseModeWeb', '__init__') - self.define_routes() + """ + Inherited class will implement this + """ + pass def define_routes(self): """ @@ -105,6 +108,10 @@ class SendBaseModeWeb: if len(filenames) == 1 and os.path.isdir(filenames[0]): filenames = [os.path.join(filenames[0], x) for x in os.listdir(filenames[0])] + # Re-initialize + self.init() + + # Build the file list self.build_file_list(filenames) self.set_file_info_custom(filenames, processed_size_callback) diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py index 6f847fe7..c3066a03 100644 --- a/onionshare/web/share_mode.py +++ b/onionshare/web/share_mode.py @@ -14,6 +14,12 @@ class ShareModeWeb(SendBaseModeWeb): """ All of the web logic for share mode """ + def init(self): + self.common.log('ShareModeWeb', 'init') + # If "Stop sharing after files have been sent" is unchecked and "Allow downloading of individual files" is checked + self.download_individual_files = not self.common.settings.get('close_after_first_download') \ + and self.common.settings.get('share_allow_downloading_individual_files') + def define_routes(self): """ The web app routes for sharing files @@ -26,7 +32,7 @@ class ShareModeWeb(SendBaseModeWeb): """ self.web.add_request(self.web.REQUEST_LOAD, request.path) - # Deny new downloads if "Stop After First Download" is checked and there is + # Deny new downloads if "Stop sharing after files have been sent" is checked and there is # currently a download deny_download = not self.web.stay_open and self.download_in_progress if deny_download: @@ -175,7 +181,8 @@ class ShareModeWeb(SendBaseModeWeb): filesize=self.filesize, filesize_human=self.common.human_readable_filesize(self.download_filesize), is_zipped=self.is_zipped, - static_url_path=self.web.static_url_path)) + static_url_path=self.web.static_url_path, + download_individual_files=self.download_individual_files)) def set_file_info_custom(self, filenames, processed_size_callback): self.common.log("ShareModeWeb", "set_file_info_custom") @@ -200,9 +207,12 @@ class ShareModeWeb(SendBaseModeWeb): # If it's a file elif os.path.isfile(filesystem_path): - dirname = os.path.dirname(filesystem_path) - basename = os.path.basename(filesystem_path) - return send_from_directory(dirname, basename) + if self.download_individual_files: + dirname = os.path.dirname(filesystem_path) + basename = os.path.basename(filesystem_path) + return send_from_directory(dirname, basename) + else: + return self.web.error404() # If it's not a directory or file, throw a 404 else: diff --git a/onionshare/web/website_mode.py b/onionshare/web/website_mode.py index 9ddbf89b..82cebdb7 100644 --- a/onionshare/web/website_mode.py +++ b/onionshare/web/website_mode.py @@ -12,6 +12,9 @@ class WebsiteModeWeb(SendBaseModeWeb): """ All of the web logic for website mode """ + def init(self): + pass + def define_routes(self): """ The web app routes for sharing a website |