Skip to content

Commit

Permalink
Expose ability to configure WebUI URL base path
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Oct 4, 2024
1 parent 583ecdd commit 9834481
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,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<int>(pref->getDynDNSService()));
Expand Down Expand Up @@ -1323,6 +1324,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);
Expand Down Expand Up @@ -1369,6 +1371,15 @@ 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.endsWith(u"/"_s))
path += u"/"_s;
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<DNS::Service>(m_ui->comboDNSService->currentIndex()));
Expand Down
18 changes: 18 additions & 0 deletions src/gui/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3765,6 +3765,24 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_132">
<item>
<widget class="QLabel" name="lblWebUIBasePath">
<property name="text">
<string>URL base path:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="textWebUIBasePath">
<property name="toolTip">
<string>Specify the URL path qBittorent will be made accessible at (e.g. '/qbittorrent').</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelReverseProxyLink">
<property name="text">
Expand Down
11 changes: 11 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,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<int>(pref->getDynDNSService());
Expand Down Expand Up @@ -919,6 +920,16 @@ 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.endsWith(u"/"_s))
path += u"/"_s;
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());
Expand Down
7 changes: 7 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@
<label for="webUIReverseProxiesListTextarea">QBT_TR(Trusted proxies list:)QBT_TR[CONTEXT=OptionsDialog]</label>
<input type="text" id="webUIReverseProxiesListTextarea" title="QBT_TR(Specify reverse proxy IPs (or subnets, e.g. 0.0.0.0/24) in order to use forwarded client address (X-Forwarded-For header). Use ';' to split multiple entries.)QBT_TR[CONTEXT=OptionsDialog]">
</div>
<div class="formRow">
<label for="webUIBasePathTextarea">QBT_TR(URL base path:)QBT_TR[CONTEXT=OptionsDialog]</label>
<input type="text" id="webUIBasePathTextarea" title="QBT_TR(Specify the URL path qBittorent will be made accessible at (e.g. '/qbittorrent').)QBT_TR[CONTEXT=OptionsDialog]">
</div>
<div class="formRow">
<a href="https://github.com/qbittorrent/qBittorrent/wiki#reverse-proxy-setup-for-webui-access" target="_blank">QBT_TR(Reverse proxy setup examples)QBT_TR[CONTEXT=HttpServer]</a>
</div>
Expand Down Expand Up @@ -2021,6 +2025,7 @@
const updateWebUIReverseProxySettings = function() {
const isEnabled = $("webUIReverseProxySupportCheckbox").checked;
$("webUIReverseProxiesListTextarea").disabled = !isEnabled;
$("webUIBasePathTextarea").disabled = !isEnabled;
};

const updateDynDnsSettings = function() {
Expand Down Expand Up @@ -2453,6 +2458,7 @@
// 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
Expand Down Expand Up @@ -2912,6 +2918,7 @@
// 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;
Expand Down

0 comments on commit 9834481

Please sign in to comment.