From 32498a7784d3f92f07b0dda642bb145eb4fbd32e Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 2 Oct 2024 10:58:52 -0700 Subject: [PATCH] Expose ability to configure WebUI URL base path --- src/gui/optionsdialog.cpp | 13 +++++++++++++ src/gui/optionsdialog.ui | 18 ++++++++++++++++++ src/webui/api/appcontroller.cpp | 13 +++++++++++++ src/webui/www/private/views/preferences.html | 7 +++++++ 4 files changed, 51 insertions(+) diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index a96b353a6..d9909ab32 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -1313,6 +1313,7 @@ void OptionsDialog::loadWebUITabOptions() // Reverse proxy m_ui->groupEnableReverseProxySupport->setChecked(pref->isWebUIReverseProxySupportEnabled()); m_ui->textTrustedReverseProxiesList->setText(pref->getWebUITrustedReverseProxiesList()); + m_ui->textWebUIBasePath->setText(pref->getWebUIBasePath()); // DynDNS m_ui->checkDynDNS->setChecked(pref->isDynDNSEnabled()); m_ui->comboDNSService->setCurrentIndex(static_cast(pref->getDynDNSService())); @@ -1354,6 +1355,7 @@ void OptionsDialog::loadWebUITabOptions() connect(m_ui->groupEnableReverseProxySupport, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->textTrustedReverseProxiesList, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); + connect(m_ui->textWebUIBasePath, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkDynDNS, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->comboDNSService, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton); @@ -1400,6 +1402,17 @@ void OptionsDialog::saveWebUITabOptions() const // Reverse proxy pref->setWebUIReverseProxySupportEnabled(m_ui->groupEnableReverseProxySupport->isChecked()); pref->setWebUITrustedReverseProxiesList(m_ui->textTrustedReverseProxiesList->text()); + + QString path = m_ui->textWebUIBasePath->text(); + if (!path.startsWith(u"/"_s)) + path.prepend(u"/"); + if (!path.endsWith(u"/"_s)) + path.append(u"/"); + QUrl url; + url.setPath(path, QUrl::StrictMode); + if (url.isValid()) + pref->setWebUIBasePath(url.path()); + // DynDNS pref->setDynDNSEnabled(m_ui->checkDynDNS->isChecked()); pref->setDynDNSService(static_cast(m_ui->comboDNSService->currentIndex())); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 91bac21fc..b6be3f8e8 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -3814,6 +3814,24 @@ Use ';' to split multiple entries. Can use wildcard '*'. + + + + + + URL base path: + + + + + + + Specify the URL path qBittorent will be made accessible at (e.g. '/qbittorrent/'). + + + + + diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index c56ab79fa..c9994ec60 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -342,6 +342,7 @@ void AppController::preferencesAction() // Reverse proxy data[u"web_ui_reverse_proxy_enabled"_s] = pref->isWebUIReverseProxySupportEnabled(); data[u"web_ui_reverse_proxies_list"_s] = pref->getWebUITrustedReverseProxiesList(); + data[u"web_ui_base_path"_s] = pref->getWebUIBasePath(); // Update my dynamic domain name data[u"dyndns_enabled"_s] = pref->isDynDNSEnabled(); data[u"dyndns_service"_s] = static_cast(pref->getDynDNSService()); @@ -924,6 +925,18 @@ void AppController::setPreferencesAction() pref->setWebUIReverseProxySupportEnabled(it.value().toBool()); if (hasKey(u"web_ui_reverse_proxies_list"_s)) pref->setWebUITrustedReverseProxiesList(it.value().toString()); + if (hasKey(u"web_ui_base_path"_s)) + { + QString path = it.value().toString(); + if (!path.startsWith(u"/"_s)) + path.prepend(u"/"); + if (!path.endsWith(u"/"_s)) + path.append(u"/"); + QUrl url; + url.setPath(path, QUrl::StrictMode); + if (url.isValid()) + pref->setWebUIBasePath(url.path()); + } // Update my dynamic domain name if (hasKey(u"dyndns_enabled"_s)) pref->setDynDNSEnabled(it.value().toBool()); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index b1fee4bf7..60432ab10 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1058,6 +1058,10 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD +
+ + +
@@ -2045,6 +2049,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD const updateWebUIReverseProxySettings = () => { const isEnabled = $("webUIReverseProxySupportCheckbox").checked; $("webUIReverseProxiesListTextarea").disabled = !isEnabled; + $("webUIBasePathTextarea").disabled = !isEnabled; }; const updateDynDnsSettings = () => { @@ -2490,6 +2495,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD // Reverse Proxy $("webUIReverseProxySupportCheckbox").checked = pref.web_ui_reverse_proxy_enabled; $("webUIReverseProxiesListTextarea").value = pref.web_ui_reverse_proxies_list; + $("webUIBasePathTextarea").value = pref.web_ui_base_path; updateWebUIReverseProxySettings(); // Update my dynamic domain name @@ -2957,6 +2963,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD // Reverse Proxy settings["web_ui_reverse_proxy_enabled"] = $("webUIReverseProxySupportCheckbox").checked; settings["web_ui_reverse_proxies_list"] = $("webUIReverseProxiesListTextarea").value; + settings["web_ui_base_path"] = $("webUIBasePathTextarea").value; // Update my dynamic domain name settings["dyndns_enabled"] = $("use_dyndns_checkbox").checked;