Browse Source

Add WebUi\Address config option

adaptive-webui-19844
Matthew Fioravante 7 years ago
parent
commit
8cd243b06b
  1. 10
      src/base/preferences.cpp
  2. 2
      src/base/preferences.h
  3. 10
      src/gui/optionsdlg.cpp
  4. 1
      src/gui/optionsdlg.h
  5. 47
      src/gui/optionsdlg.ui
  6. 3
      src/webui/prefjson.cpp
  7. 6
      src/webui/webui.cpp
  8. 6
      src/webui/www/public/preferences_content.html

10
src/base/preferences.cpp

@ -463,6 +463,16 @@ void Preferences::setServerDomains(const QString &str)
setValue("Preferences/WebUI/ServerDomains", str); setValue("Preferences/WebUI/ServerDomains", str);
} }
QString Preferences::getWebUiAddress() const
{
return value("Preferences/WebUI/Address", "*").toString().trimmed();
}
void Preferences::setWebUiAddress(const QString &addr)
{
setValue("Preferences/WebUI/Address", addr.trimmed());
}
quint16 Preferences::getWebUiPort() const quint16 Preferences::getWebUiPort() const
{ {
return value("Preferences/WebUI/Port", 8080).toInt(); return value("Preferences/WebUI/Port", 8080).toInt();

2
src/base/preferences.h

@ -174,6 +174,8 @@ public:
void setWebUiLocalAuthEnabled(bool enabled); void setWebUiLocalAuthEnabled(bool enabled);
QString getServerDomains() const; QString getServerDomains() const;
void setServerDomains(const QString &str); void setServerDomains(const QString &str);
QString getWebUiAddress() const;
void setWebUiAddress(const QString &addr);
quint16 getWebUiPort() const; quint16 getWebUiPort() const;
void setWebUiPort(quint16 port); void setWebUiPort(quint16 port);
bool useUPnPForWebUIPort() const; bool useUPnPForWebUIPort() const;

10
src/gui/optionsdlg.cpp

@ -340,6 +340,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
// Web UI tab // Web UI tab
connect(m_ui->textServerDomains, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->textServerDomains, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkWebUi, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkWebUi, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->textWebUiAddress, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinWebUiPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinWebUiPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkWebUIUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkWebUIUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkWebUiHttps, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkWebUiHttps, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
@ -648,7 +649,8 @@ void OptionsDialog::saveOptions()
pref->setWebUiEnabled(isWebUiEnabled()); pref->setWebUiEnabled(isWebUiEnabled());
if (isWebUiEnabled()) { if (isWebUiEnabled()) {
pref->setServerDomains(m_ui->textServerDomains->text()); pref->setServerDomains(m_ui->textServerDomains->text());
pref->setWebUiPort(webUiPort()); pref->setWebUiAddress(m_ui->textWebUiAddress->text());
pref->setWebUiPort(m_ui->spinWebUiPort->value());
pref->setUPnPForWebUIPort(m_ui->checkWebUIUPnP->isChecked()); pref->setUPnPForWebUIPort(m_ui->checkWebUIUPnP->isChecked());
pref->setWebUiHttpsEnabled(m_ui->checkWebUiHttps->isChecked()); pref->setWebUiHttpsEnabled(m_ui->checkWebUiHttps->isChecked());
if (m_ui->checkWebUiHttps->isChecked()) { if (m_ui->checkWebUiHttps->isChecked()) {
@ -1038,6 +1040,7 @@ void OptionsDialog::loadOptions()
// Web UI preferences // Web UI preferences
m_ui->textServerDomains->setText(pref->getServerDomains()); m_ui->textServerDomains->setText(pref->getServerDomains());
m_ui->checkWebUi->setChecked(pref->isWebUiEnabled()); m_ui->checkWebUi->setChecked(pref->isWebUiEnabled());
m_ui->textWebUiAddress->setText(pref->getWebUiAddress());
m_ui->spinWebUiPort->setValue(pref->getWebUiPort()); m_ui->spinWebUiPort->setValue(pref->getWebUiPort());
m_ui->checkWebUIUPnP->setChecked(pref->useUPnPForWebUIPort()); m_ui->checkWebUIUPnP->setChecked(pref->useUPnPForWebUIPort());
m_ui->checkWebUiHttps->setChecked(pref->isWebUiHttpsEnabled()); m_ui->checkWebUiHttps->setChecked(pref->isWebUiHttpsEnabled());
@ -1505,11 +1508,6 @@ bool OptionsDialog::isWebUiEnabled() const
return m_ui->checkWebUi->isChecked(); return m_ui->checkWebUi->isChecked();
} }
quint16 OptionsDialog::webUiPort() const
{
return m_ui->spinWebUiPort->value();
}
QString OptionsDialog::webUiUsername() const QString OptionsDialog::webUiUsername() const
{ {
return m_ui->textWebUiUsername->text(); return m_ui->textWebUiUsername->text();

1
src/gui/optionsdlg.h

@ -168,7 +168,6 @@ private:
int getMaxActiveUploads() const; int getMaxActiveUploads() const;
int getMaxActiveTorrents() const; int getMaxActiveTorrents() const;
bool isWebUiEnabled() const; bool isWebUiEnabled() const;
quint16 webUiPort() const;
QString webUiUsername() const; QString webUiUsername() const;
QString webUiPassword() const; QString webUiPassword() const;

47
src/gui/optionsdlg.ui

@ -2758,29 +2758,23 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_10"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLabel" name="labelServerDomains"> <widget class="QLabel" name="lblWebUiAddress">
<property name="text"> <property name="text">
<string>Server domains:</string> <string>IP address:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="textServerDomains"> <widget class="QLineEdit" name="textWebUiAddress">
<property name="toolTip"> <property name="toolTip">
<string>Whitelist for filtering HTTP Host header values. <string>IP address that the Web UI will bind to.
In order to defend against DNS rebinding attack, Specify an IPv4 or IPv6 address. You can specify "0.0.0.0" for any IPv4 address,
you should put in domain names used by WebUI server. "::" for any IPv6 address, or "*" for both IPv4 and IPv6.</string>
Use ';' to split multiple entries. Can use wildcard '*'.</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLabel" name="lblWebUiPort"> <widget class="QLabel" name="lblWebUiPort">
<property name="text"> <property name="text">
@ -2801,18 +2795,27 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<spacer> <layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="orientation"> <item>
<enum>Qt::Horizontal</enum> <widget class="QLabel" name="labelServerDomains">
<property name="text">
<string>Server domains:</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size> </item>
<width>21</width> <item>
<height>29</height> <widget class="QLineEdit" name="textServerDomains">
</size> <property name="toolTip">
<string>Whitelist for filtering HTTP Host header values.
In order to defend against DNS rebinding attack,
you should put in domain names used by WebUI server.
Use ';' to split multiple entries. Can use wildcard '*'.</string>
</property> </property>
</spacer> </widget>
</item> </item>
</layout> </layout>
</item> </item>

3
src/webui/prefjson.cpp

@ -163,6 +163,7 @@ QByteArray prefjson::getPreferences()
data["locale"] = pref->getLocale(); data["locale"] = pref->getLocale();
// HTTP Server // HTTP Server
data["web_ui_domain_list"] = pref->getServerDomains(); data["web_ui_domain_list"] = pref->getServerDomains();
data["web_ui_address"] = pref->getWebUiAddress();
data["web_ui_port"] = pref->getWebUiPort(); data["web_ui_port"] = pref->getWebUiPort();
data["web_ui_upnp"] = pref->useUPnPForWebUIPort(); data["web_ui_upnp"] = pref->useUPnPForWebUIPort();
data["use_https"] = pref->isWebUiHttpsEnabled(); data["use_https"] = pref->isWebUiHttpsEnabled();
@ -399,6 +400,8 @@ void prefjson::setPreferences(const QString& json)
// HTTP Server // HTTP Server
if (m.contains("web_ui_domain_list")) if (m.contains("web_ui_domain_list"))
pref->setServerDomains(m["web_ui_domain_list"].toString()); pref->setServerDomains(m["web_ui_domain_list"].toString());
if (m.contains("web_ui_address"))
pref->setWebUiAddress(m["web_ui_address"].toString());
if (m.contains("web_ui_port")) if (m.contains("web_ui_port"))
pref->setWebUiPort(m["web_ui_port"].toUInt()); pref->setWebUiPort(m["web_ui_port"].toUInt());
if (m.contains("web_ui_upnp")) if (m.contains("web_ui_upnp"))

6
src/webui/webui.cpp

@ -93,7 +93,11 @@ void WebUI::init()
#endif #endif
if (!m_httpServer->isListening()) { if (!m_httpServer->isListening()) {
bool success = m_httpServer->listen(QHostAddress::Any, m_port); const QString addressString = pref->getWebUiAddress();
const auto address = (addressString == "*" || addressString.isEmpty())
? QHostAddress::Any : QHostAddress(addressString);
bool success = m_httpServer->listen(address, m_port);
if (success) { if (success) {
logger->addMessage(tr("Web UI: Now listening on port %1").arg(m_port)); logger->addMessage(tr("Web UI: Now listening on port %1").arg(m_port));
} }

6
src/webui/www/public/preferences_content.html

@ -410,8 +410,9 @@
<fieldset class="settings"> <fieldset class="settings">
<legend>QBT_TR(Web User Interface (Remote control))QBT_TR[CONTEXT=OptionsDialog]</legend> <legend>QBT_TR(Web User Interface (Remote control))QBT_TR[CONTEXT=OptionsDialog]</legend>
<label for="webui_domain_textarea">QBT_TR(Server domains:)QBT_TR[CONTEXT=OptionsDialog]</label><textarea id="webui_domain_textarea" rows="1" cols="70"></textarea><br/> <label for="webui_address_value">QBT_TR(IP address:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="webui_address_value"/>
<label for="webui_port_value">QBT_TR(Port:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="webui_port_value" style="width: 4em;"/><br/> <label for="webui_port_value">QBT_TR(Port:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="webui_port_value" style="width: 4em;"/><br/>
<label for="webui_domain_textarea">QBT_TR(Server domains:)QBT_TR[CONTEXT=OptionsDialog]</label><textarea id="webui_domain_textarea" rows="1" cols="70"></textarea><br/>
<input type="checkbox" id="webui_upnp_checkbox"/> <input type="checkbox" id="webui_upnp_checkbox"/>
<label for="webui_upnp_checkbox">QBT_TR(Use UPnP / NAT-PMP to forward the port from my router)QBT_TR[CONTEXT=OptionsDialog]</label><br/> <label for="webui_upnp_checkbox">QBT_TR(Use UPnP / NAT-PMP to forward the port from my router)QBT_TR[CONTEXT=OptionsDialog]</label><br/>
<fieldset class="settings"> <fieldset class="settings">
@ -1046,6 +1047,7 @@ loadPreferences = function() {
// HTTP Server // HTTP Server
$('webui_domain_textarea').setProperty('value', pref.web_ui_domain_list); $('webui_domain_textarea').setProperty('value', pref.web_ui_domain_list);
$('webui_address_value').setProperty('value', pref.web_ui_address);
$('webui_port_value').setProperty('value', pref.web_ui_port); $('webui_port_value').setProperty('value', pref.web_ui_port);
$('webui_upnp_checkbox').setProperty('checked', pref.web_ui_upnp); $('webui_upnp_checkbox').setProperty('checked', pref.web_ui_upnp);
$('use_https_checkbox').setProperty('checked', pref.use_https); $('use_https_checkbox').setProperty('checked', pref.use_https);
@ -1314,11 +1316,13 @@ applyPreferences = function() {
// HTTP Server // HTTP Server
settings.set('web_ui_domain_list', $('webui_domain_textarea').getProperty('value')); settings.set('web_ui_domain_list', $('webui_domain_textarea').getProperty('value'));
var web_ui_address = $('webui_address_value').getProperty('value').toString();
var web_ui_port = $('webui_port_value').getProperty('value').toInt(); var web_ui_port = $('webui_port_value').getProperty('value').toInt();
if(isNaN(web_ui_port) || web_ui_port < 1 || web_ui_port > 65535) { if(isNaN(web_ui_port) || web_ui_port < 1 || web_ui_port > 65535) {
alert("QBT_TR(The port used for the Web UI must be between 1 and 65535.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(The port used for the Web UI must be between 1 and 65535.)QBT_TR[CONTEXT=HttpServer]");
return; return;
} }
settings.set('web_ui_address', web_ui_address);
settings.set('web_ui_port', web_ui_port); settings.set('web_ui_port', web_ui_port);
settings.set('web_ui_upnp', $('webui_upnp_checkbox').getProperty('checked')); settings.set('web_ui_upnp', $('webui_upnp_checkbox').getProperty('checked'));
settings.set('use_https', $('use_https_checkbox').getProperty('checked')); settings.set('use_https', $('use_https_checkbox').getProperty('checked'));

Loading…
Cancel
Save