From 12a1d73f91586cab4fee019cc96af859d9fd2f19 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 2 Nov 2019 14:35:51 -0700 Subject: [PATCH] Make the Web object load from mode settings instead of global settings --- onionshare/web/receive_mode.py | 2 +- onionshare/web/share_mode.py | 4 ++-- onionshare/web/web.py | 14 ++++---------- onionshare_gui/tab/mode/receive_mode/__init__.py | 2 +- onionshare_gui/tab/mode/share_mode/__init__.py | 2 +- onionshare_gui/tab/mode/website_mode/__init__.py | 2 +- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index c69a821d..55f0df8c 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -292,7 +292,7 @@ class ReceiveModeRequest(Request): date_dir = now.strftime("%Y-%m-%d") time_dir = now.strftime("%H.%M.%S") self.receive_mode_dir = os.path.join( - self.web.common.settings.get("data_dir"), date_dir, time_dir + self.web.settings.get("website", "data_dir"), date_dir, time_dir ) # Create that directory, which shouldn't exist yet diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py index da20c328..7e4f1672 100644 --- a/onionshare/web/share_mode.py +++ b/onionshare/web/share_mode.py @@ -18,8 +18,8 @@ class ShareModeWeb(SendBaseModeWeb): self.common.log("ShareModeWeb", "init") # Allow downloading individual files if "Stop sharing after files have been sent" is unchecked - self.download_individual_files = not self.common.settings.get( - "close_after_first_download" + self.download_individual_files = not self.web.settings.get( + "share", "autostop_sharing" ) def define_routes(self): diff --git a/onionshare/web/web.py b/onionshare/web/web.py index 604faf02..07fa5b6b 100644 --- a/onionshare/web/web.py +++ b/onionshare/web/web.py @@ -60,9 +60,7 @@ class Web: REQUEST_OTHER = 13 REQUEST_INVALID_PASSWORD = 14 - def __init__( - self, common, is_gui, tab_settings_get=None, tab_settings_set=None, mode="share" - ): + def __init__(self, common, is_gui, mode_settings, mode="share"): """ tab_settings_get and tab_settings_set are getter and setter functions for tab settings """ @@ -70,8 +68,7 @@ class Web: self.common = common self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}") - self.settings_get = tab_settings_get - self.settings_set = tab_settings_set + self.settings = mode_settings # The flask app self.app = Flask( @@ -195,7 +192,7 @@ class Web: return None # If public mode is disabled, require authentication - if not self.common.settings.get("public_mode"): + if not self.settings.get("general", "public"): @self.auth.login_required def _check_login(): @@ -293,10 +290,7 @@ class Web: for header, value in self.security_headers: r.headers.set(header, value) # Set a CSP header unless in website mode and the user has disabled it - if ( - not self.common.settings.get("csp_header_disabled") - or self.mode != "website" - ): + if not self.settings.get("website", "disable_csp") or self.mode != "website": r.headers.set( "Content-Security-Policy", "default-src 'self'; style-src 'self'; script-src 'self'; img-src 'self' data:;", diff --git a/onionshare_gui/tab/mode/receive_mode/__init__.py b/onionshare_gui/tab/mode/receive_mode/__init__.py index 665fceba..0c6ff031 100644 --- a/onionshare_gui/tab/mode/receive_mode/__init__.py +++ b/onionshare_gui/tab/mode/receive_mode/__init__.py @@ -36,7 +36,7 @@ class ReceiveMode(Mode): Custom initialization for ReceiveMode. """ # Create the Web object - self.web = Web(self.common, True, "receive") + self.web = Web(self.common, True, self.settings, "receive") # Header self.header_label.setText(strings._("gui_new_tab_receive_button")) diff --git a/onionshare_gui/tab/mode/share_mode/__init__.py b/onionshare_gui/tab/mode/share_mode/__init__.py index fc94944b..42478be4 100644 --- a/onionshare_gui/tab/mode/share_mode/__init__.py +++ b/onionshare_gui/tab/mode/share_mode/__init__.py @@ -45,7 +45,7 @@ class ShareMode(Mode): self.compress_thread = None # Create the Web object - self.web = Web(self.common, True, "share") + self.web = Web(self.common, True, self.settings, "share") # Header self.header_label.setText(strings._("gui_new_tab_share_button")) diff --git a/onionshare_gui/tab/mode/website_mode/__init__.py b/onionshare_gui/tab/mode/website_mode/__init__.py index 82d7b310..51ee17ef 100644 --- a/onionshare_gui/tab/mode/website_mode/__init__.py +++ b/onionshare_gui/tab/mode/website_mode/__init__.py @@ -47,7 +47,7 @@ class WebsiteMode(Mode): Custom initialization for ReceiveMode. """ # Create the Web object - self.web = Web(self.common, True, "website") + self.web = Web(self.common, True, self.settings, "website") # Header self.header_label.setText(strings._("gui_new_tab_website_button"))