mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Merge pull request #7990 from Piccirello/subnet-whitelist-refactor
Refactor ip subnet whitelist
This commit is contained in:
commit
0a45fc9ffe
@ -35,6 +35,7 @@
|
|||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
#include <QMutableListIterator>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
@ -487,13 +488,17 @@ QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
|
|||||||
return subnets;
|
return subnets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preferences::setWebUiAuthSubnetWhitelist(const QList<Utils::Net::Subnet> &subnets)
|
void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets)
|
||||||
{
|
{
|
||||||
QStringList subnetsStringList;
|
QMutableListIterator<QString> i(subnets);
|
||||||
for (const Utils::Net::Subnet &subnet : subnets)
|
while (i.hasNext()) {
|
||||||
subnetsStringList.append(Utils::Net::subnetToString(subnet));
|
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
|
QString Preferences::getServerDomains() const
|
||||||
|
@ -191,7 +191,7 @@ public:
|
|||||||
bool isWebUiAuthSubnetWhitelistEnabled() const;
|
bool isWebUiAuthSubnetWhitelistEnabled() const;
|
||||||
void setWebUiAuthSubnetWhitelistEnabled(bool enabled);
|
void setWebUiAuthSubnetWhitelistEnabled(bool enabled);
|
||||||
QList<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const;
|
QList<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const;
|
||||||
void setWebUiAuthSubnetWhitelist(const QList<Utils::Net::Subnet> &subnets);
|
void setWebUiAuthSubnetWhitelist(QStringList subnets);
|
||||||
QString getWebUiUsername() const;
|
QString getWebUiUsername() const;
|
||||||
void setWebUiUsername(const QString &username);
|
void setWebUiUsername(const QString &username);
|
||||||
QString getWebUiPassword() const;
|
QString getWebUiPassword() const;
|
||||||
|
@ -71,12 +71,10 @@ void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted()
|
|||||||
{
|
{
|
||||||
if (m_modified) {
|
if (m_modified) {
|
||||||
// save to session
|
// save to session
|
||||||
QList<Utils::Net::Subnet> subnets;
|
QStringList subnets;
|
||||||
// Operate on the m_sortFilter to grab the strings in sorted order
|
// Operate on the m_sortFilter to grab the strings in sorted order
|
||||||
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
|
for (int i = 0; i < m_sortFilter->rowCount(); ++i)
|
||||||
const QString subnet = m_sortFilter->index(i, 0).data().toString();
|
subnets.append(m_sortFilter->index(i, 0).data().toString());
|
||||||
subnets.append(QHostAddress::parseSubnet(subnet));
|
|
||||||
}
|
|
||||||
Preferences::instance()->setWebUiAuthSubnetWhitelist(subnets);
|
Preferences::instance()->setWebUiAuthSubnetWhitelist(subnets);
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<property name="frameShadow">
|
<property name="frameShadow">
|
||||||
<enum>QFrame::Raised</enum>
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_21">
|
<layout class="QVBoxLayout" name="verticalLayout_31">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="whitelistedIPSubnetList">
|
<widget class="QTreeView" name="whitelistedIPSubnetList">
|
||||||
<property name="rootIsDecorated">
|
<property name="rootIsDecorated">
|
||||||
@ -46,7 +46,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_18">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="txtIPSubnet">
|
<widget class="QLineEdit" name="txtIPSubnet">
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
@ -54,6 +54,10 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="buttonWhitelistIPSubnet">
|
<widget class="QPushButton" name="buttonWhitelistIPSubnet">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -437,16 +437,8 @@ void prefjson::setPreferences(const QString& json)
|
|||||||
if (m.contains("bypass_auth_subnet_whitelist_enabled"))
|
if (m.contains("bypass_auth_subnet_whitelist_enabled"))
|
||||||
pref->setWebUiAuthSubnetWhitelistEnabled(m["bypass_auth_subnet_whitelist_enabled"].toBool());
|
pref->setWebUiAuthSubnetWhitelistEnabled(m["bypass_auth_subnet_whitelist_enabled"].toBool());
|
||||||
if (m.contains("bypass_auth_subnet_whitelist")) {
|
if (m.contains("bypass_auth_subnet_whitelist")) {
|
||||||
QList<Utils::Net::Subnet> subnets;
|
// recognize new lines and commas as delimiters
|
||||||
// recognize new line and comma as delimiters
|
pref->setWebUiAuthSubnetWhitelist(m["bypass_auth_subnet_whitelist"].toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
// Update my dynamic domain name
|
// Update my dynamic domain name
|
||||||
if (m.contains("dyndns_enabled"))
|
if (m.contains("dyndns_enabled"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user