Browse Source

Perform ip string validation inside setWebUiAuthSubnetWhitelist

adaptive-webui-19844
Thomas Piccirello 7 years ago
parent
commit
d184bd8c82
  1. 12
      src/base/preferences.cpp
  2. 2
      src/base/preferences.h
  3. 8
      src/gui/ipsubnetwhitelistoptionsdialog.cpp
  4. 12
      src/webui/prefjson.cpp

12
src/base/preferences.cpp

@ -487,10 +487,18 @@ QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const @@ -487,10 +487,18 @@ QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
return subnets;
}
void Preferences::setWebUiAuthSubnetWhitelist(const QList<Utils::Net::Subnet> &subnets)
void Preferences::setWebUiAuthSubnetWhitelist(const QStringList &subnets)
{
QList<Utils::Net::Subnet> filteredSubnets;
foreach (QString subnetString, subnets) {
bool ok = false;
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(subnetString.trimmed(), &ok);
if (ok)
filteredSubnets.append(subnet);
}
QStringList subnetsStringList;
for (const Utils::Net::Subnet &subnet : subnets)
for (const Utils::Net::Subnet &subnet : filteredSubnets)
subnetsStringList.append(Utils::Net::subnetToString(subnet));
setValue("Preferences/WebUI/AuthSubnetWhitelist", subnetsStringList);

2
src/base/preferences.h

@ -191,7 +191,7 @@ public: @@ -191,7 +191,7 @@ public:
bool isWebUiAuthSubnetWhitelistEnabled() const;
void setWebUiAuthSubnetWhitelistEnabled(bool enabled);
QList<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const;
void setWebUiAuthSubnetWhitelist(const QList<Utils::Net::Subnet> &subnets);
void setWebUiAuthSubnetWhitelist(const QStringList &subnets);
QString getWebUiUsername() const;
void setWebUiUsername(const QString &username);
QString getWebUiPassword() const;

8
src/gui/ipsubnetwhitelistoptionsdialog.cpp

@ -68,12 +68,10 @@ void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted() @@ -68,12 +68,10 @@ void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted()
{
if (m_modified) {
// save to session
QList<Utils::Net::Subnet> subnets;
QStringList subnets;
// Operate on the m_sortFilter to grab the strings in sorted order
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
const QString subnet = m_sortFilter->index(i, 0).data().toString();
subnets.append(QHostAddress::parseSubnet(subnet));
}
for (int i = 0; i < m_sortFilter->rowCount(); ++i)
subnets.append(m_sortFilter->index(i, 0).data().toString());
Preferences::instance()->setWebUiAuthSubnetWhitelist(subnets);
QDialog::accept();
}

12
src/webui/prefjson.cpp

@ -437,16 +437,8 @@ void prefjson::setPreferences(const QString& json) @@ -437,16 +437,8 @@ void prefjson::setPreferences(const QString& json)
if (m.contains("bypass_auth_subnet_whitelist_enabled"))
pref->setWebUiAuthSubnetWhitelistEnabled(m["bypass_auth_subnet_whitelist_enabled"].toBool());
if (m.contains("bypass_auth_subnet_whitelist")) {
QList<Utils::Net::Subnet> subnets;
// recognize new line and comma as delimiters
foreach (QString subnetString, m["bypass_auth_subnet_whitelist"].toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts)) {
bool ok = false;
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(subnetString.trimmed(), &ok);
if (ok)
subnets.append(subnet);
}
pref->setWebUiAuthSubnetWhitelist(subnets);
// recognize new lines and commas as delimiters
pref->setWebUiAuthSubnetWhitelist(m["bypass_auth_subnet_whitelist"].toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts));
}
// Update my dynamic domain name
if (m.contains("dyndns_enabled"))

Loading…
Cancel
Save