Browse Source

Merge pull request #7990 from Piccirello/subnet-whitelist-refactor

Refactor ip subnet whitelist
adaptive-webui-19844
Vladimir Golovnev 7 years ago committed by GitHub
parent
commit
0a45fc9ffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/base/preferences.cpp
  2. 2
      src/base/preferences.h
  3. 8
      src/gui/ipsubnetwhitelistoptionsdialog.cpp
  4. 8
      src/gui/ipsubnetwhitelistoptionsdialog.ui
  5. 12
      src/webui/prefjson.cpp

15
src/base/preferences.cpp

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include <QCryptographicHash>
#include <QDir>
#include <QLocale>
#include <QMutableListIterator>
#include <QPair>
#include <QSettings>
@ -487,13 +488,17 @@ QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const @@ -487,13 +488,17 @@ QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
return subnets;
}
void Preferences::setWebUiAuthSubnetWhitelist(const QList<Utils::Net::Subnet> &subnets)
void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets)
{
QStringList subnetsStringList;
for (const Utils::Net::Subnet &subnet : subnets)
subnetsStringList.append(Utils::Net::subnetToString(subnet));
QMutableListIterator<QString> i(subnets);
while (i.hasNext()) {
bool ok = false;
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(i.next().trimmed(), &ok);
if (!ok)
i.remove();
}
setValue("Preferences/WebUI/AuthSubnetWhitelist", subnetsStringList);
setValue("Preferences/WebUI/AuthSubnetWhitelist", subnets);
}
QString Preferences::getServerDomains() const

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(QStringList subnets);
QString getWebUiUsername() const;
void setWebUiUsername(const QString &username);
QString getWebUiPassword() const;

8
src/gui/ipsubnetwhitelistoptionsdialog.cpp

@ -71,12 +71,10 @@ void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted() @@ -71,12 +71,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();
}

8
src/gui/ipsubnetwhitelistoptionsdialog.ui

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
<layout class="QVBoxLayout" name="verticalLayout_31">
<item>
<widget class="QTreeView" name="whitelistedIPSubnetList">
<property name="rootIsDecorated">
@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_18">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="txtIPSubnet">
<property name="placeholderText">
@ -54,6 +54,10 @@ @@ -54,6 +54,10 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QPushButton" name="buttonWhitelistIPSubnet">
<property name="text">

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