mirror of
https://github.com/onionshare/onionshare.git
synced 2025-07-25 07:35:36 -04:00
Make the Web object load from mode settings instead of global settings
This commit is contained in:
parent
1b635b1646
commit
30df0c4bd8
6 changed files with 10 additions and 16 deletions
|
@ -292,7 +292,7 @@ class ReceiveModeRequest(Request):
|
||||||
date_dir = now.strftime("%Y-%m-%d")
|
date_dir = now.strftime("%Y-%m-%d")
|
||||||
time_dir = now.strftime("%H.%M.%S")
|
time_dir = now.strftime("%H.%M.%S")
|
||||||
self.receive_mode_dir = os.path.join(
|
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
|
# Create that directory, which shouldn't exist yet
|
||||||
|
|
|
@ -18,8 +18,8 @@ class ShareModeWeb(SendBaseModeWeb):
|
||||||
self.common.log("ShareModeWeb", "init")
|
self.common.log("ShareModeWeb", "init")
|
||||||
|
|
||||||
# Allow downloading individual files if "Stop sharing after files have been sent" is unchecked
|
# Allow downloading individual files if "Stop sharing after files have been sent" is unchecked
|
||||||
self.download_individual_files = not self.common.settings.get(
|
self.download_individual_files = not self.web.settings.get(
|
||||||
"close_after_first_download"
|
"share", "autostop_sharing"
|
||||||
)
|
)
|
||||||
|
|
||||||
def define_routes(self):
|
def define_routes(self):
|
||||||
|
|
|
@ -60,9 +60,7 @@ class Web:
|
||||||
REQUEST_OTHER = 13
|
REQUEST_OTHER = 13
|
||||||
REQUEST_INVALID_PASSWORD = 14
|
REQUEST_INVALID_PASSWORD = 14
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, common, is_gui, mode_settings, mode="share"):
|
||||||
self, common, is_gui, tab_settings_get=None, tab_settings_set=None, mode="share"
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
tab_settings_get and tab_settings_set are getter and setter functions for tab settings
|
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 = common
|
||||||
self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}")
|
self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}")
|
||||||
|
|
||||||
self.settings_get = tab_settings_get
|
self.settings = mode_settings
|
||||||
self.settings_set = tab_settings_set
|
|
||||||
|
|
||||||
# The flask app
|
# The flask app
|
||||||
self.app = Flask(
|
self.app = Flask(
|
||||||
|
@ -195,7 +192,7 @@ class Web:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# If public mode is disabled, require authentication
|
# 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
|
@self.auth.login_required
|
||||||
def _check_login():
|
def _check_login():
|
||||||
|
@ -293,10 +290,7 @@ class Web:
|
||||||
for header, value in self.security_headers:
|
for header, value in self.security_headers:
|
||||||
r.headers.set(header, value)
|
r.headers.set(header, value)
|
||||||
# Set a CSP header unless in website mode and the user has disabled it
|
# Set a CSP header unless in website mode and the user has disabled it
|
||||||
if (
|
if not self.settings.get("website", "disable_csp") or self.mode != "website":
|
||||||
not self.common.settings.get("csp_header_disabled")
|
|
||||||
or self.mode != "website"
|
|
||||||
):
|
|
||||||
r.headers.set(
|
r.headers.set(
|
||||||
"Content-Security-Policy",
|
"Content-Security-Policy",
|
||||||
"default-src 'self'; style-src 'self'; script-src 'self'; img-src 'self' data:;",
|
"default-src 'self'; style-src 'self'; script-src 'self'; img-src 'self' data:;",
|
||||||
|
|
|
@ -36,7 +36,7 @@ class ReceiveMode(Mode):
|
||||||
Custom initialization for ReceiveMode.
|
Custom initialization for ReceiveMode.
|
||||||
"""
|
"""
|
||||||
# Create the Web object
|
# Create the Web object
|
||||||
self.web = Web(self.common, True, "receive")
|
self.web = Web(self.common, True, self.settings, "receive")
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
self.header_label.setText(strings._("gui_new_tab_receive_button"))
|
self.header_label.setText(strings._("gui_new_tab_receive_button"))
|
||||||
|
|
|
@ -45,7 +45,7 @@ class ShareMode(Mode):
|
||||||
self.compress_thread = None
|
self.compress_thread = None
|
||||||
|
|
||||||
# Create the Web object
|
# Create the Web object
|
||||||
self.web = Web(self.common, True, "share")
|
self.web = Web(self.common, True, self.settings, "share")
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
self.header_label.setText(strings._("gui_new_tab_share_button"))
|
self.header_label.setText(strings._("gui_new_tab_share_button"))
|
||||||
|
|
|
@ -47,7 +47,7 @@ class WebsiteMode(Mode):
|
||||||
Custom initialization for ReceiveMode.
|
Custom initialization for ReceiveMode.
|
||||||
"""
|
"""
|
||||||
# Create the Web object
|
# Create the Web object
|
||||||
self.web = Web(self.common, True, "website")
|
self.web = Web(self.common, True, self.settings, "website")
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
self.header_label.setText(strings._("gui_new_tab_website_button"))
|
self.header_label.setText(strings._("gui_new_tab_website_button"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue