Thomas Piccirello
7 years ago
15 changed files with 503 additions and 19 deletions
@ -0,0 +1,111 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2017 Thomas Piccirello <thomas@piccirello.com> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* as published by the Free Software Foundation; either version 2 |
||||||
|
* of the License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program; if not, write to the Free Software |
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
* |
||||||
|
* In addition, as a special exception, the copyright holders give permission to |
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with |
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library), |
||||||
|
* and distribute the linked executables. You must obey the GNU General Public |
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you |
||||||
|
* modify file(s), you may extend this exception to your version of the file(s), |
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
||||||
|
* exception statement from your version. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "ipsubnetwhitelistoptionsdialog.h" |
||||||
|
|
||||||
|
#include <QHostAddress> |
||||||
|
#include <QMessageBox> |
||||||
|
#include <QPair> |
||||||
|
#include <QSortFilterProxyModel> |
||||||
|
#include <QStringListModel> |
||||||
|
|
||||||
|
#include "base/preferences.h" |
||||||
|
#include "base/utils/net.h" |
||||||
|
#include "ui_ipsubnetwhitelistoptionsdialog.h" |
||||||
|
|
||||||
|
IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent) |
||||||
|
: QDialog(parent) |
||||||
|
, m_ui(new Ui::IPSubnetWhitelistOptionsDialog) |
||||||
|
, m_modified(false) |
||||||
|
{ |
||||||
|
m_ui->setupUi(this); |
||||||
|
|
||||||
|
QStringList authSubnetWhitelistStringList; |
||||||
|
for (const Utils::Net::Subnet &subnet : Preferences::instance()->getWebUiAuthSubnetWhitelist()) |
||||||
|
authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet); |
||||||
|
m_model = new QStringListModel(authSubnetWhitelistStringList, this); |
||||||
|
|
||||||
|
m_sortFilter = new QSortFilterProxyModel(this); |
||||||
|
m_sortFilter->setDynamicSortFilter(true); |
||||||
|
m_sortFilter->setSourceModel(m_model); |
||||||
|
|
||||||
|
m_ui->whitelistedIPSubnetList->setModel(m_sortFilter); |
||||||
|
m_ui->whitelistedIPSubnetList->sortByColumn(0, Qt::AscendingOrder); |
||||||
|
m_ui->buttonWhitelistIPSubnet->setEnabled(false); |
||||||
|
} |
||||||
|
|
||||||
|
IPSubnetWhitelistOptionsDialog::~IPSubnetWhitelistOptionsDialog() |
||||||
|
{ |
||||||
|
delete m_ui; |
||||||
|
} |
||||||
|
|
||||||
|
void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted() |
||||||
|
{ |
||||||
|
if (m_modified) { |
||||||
|
// save to session
|
||||||
|
QList<Utils::Net::Subnet> 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)); |
||||||
|
} |
||||||
|
Preferences::instance()->setWebUiAuthSubnetWhitelist(subnets); |
||||||
|
QDialog::accept(); |
||||||
|
} |
||||||
|
else { |
||||||
|
QDialog::reject(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void IPSubnetWhitelistOptionsDialog::on_buttonWhitelistIPSubnet_clicked() |
||||||
|
{ |
||||||
|
bool ok = false; |
||||||
|
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(m_ui->txtIPSubnet->text(), &ok); |
||||||
|
if (!ok) { |
||||||
|
QMessageBox::critical(this, tr("Error"), tr("The entered subnet is invalid.")); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
m_model->insertRow(m_model->rowCount()); |
||||||
|
m_model->setData(m_model->index(m_model->rowCount() - 1, 0), Utils::Net::subnetToString(subnet)); |
||||||
|
m_ui->txtIPSubnet->clear(); |
||||||
|
m_modified = true; |
||||||
|
} |
||||||
|
|
||||||
|
void IPSubnetWhitelistOptionsDialog::on_buttonDeleteIPSubnet_clicked() |
||||||
|
{ |
||||||
|
for (const auto &i : m_ui->whitelistedIPSubnetList->selectionModel()->selectedIndexes()) |
||||||
|
m_sortFilter->removeRow(i.row()); |
||||||
|
|
||||||
|
m_modified = true; |
||||||
|
} |
||||||
|
|
||||||
|
void IPSubnetWhitelistOptionsDialog::on_txtIPSubnet_textChanged(const QString &subnetStr) |
||||||
|
{ |
||||||
|
m_ui->buttonWhitelistIPSubnet->setEnabled(Utils::Net::canParseSubnet(subnetStr)); |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2017 Thomas Piccirello <thomas@piccirello.com> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* as published by the Free Software Foundation; either version 2 |
||||||
|
* of the License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program; if not, write to the Free Software |
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
* |
||||||
|
* In addition, as a special exception, the copyright holders give permission to |
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with |
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library), |
||||||
|
* and distribute the linked executables. You must obey the GNU General Public |
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you |
||||||
|
* modify file(s), you may extend this exception to your version of the file(s), |
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
||||||
|
* exception statement from your version. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OPTIONS_IPSUBNETWHITELIST_H |
||||||
|
#define OPTIONS_IPSUBNETWHITELIST_H |
||||||
|
|
||||||
|
#include <QDialog> |
||||||
|
|
||||||
|
class QSortFilterProxyModel; |
||||||
|
class QStringListModel; |
||||||
|
|
||||||
|
namespace Ui |
||||||
|
{ |
||||||
|
class IPSubnetWhitelistOptionsDialog; |
||||||
|
} |
||||||
|
|
||||||
|
class IPSubnetWhitelistOptionsDialog : public QDialog |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
Q_DISABLE_COPY(IPSubnetWhitelistOptionsDialog) |
||||||
|
|
||||||
|
public: |
||||||
|
explicit IPSubnetWhitelistOptionsDialog(QWidget *parent = nullptr); |
||||||
|
~IPSubnetWhitelistOptionsDialog(); |
||||||
|
|
||||||
|
private slots: |
||||||
|
void on_buttonBox_accepted(); |
||||||
|
void on_buttonWhitelistIPSubnet_clicked(); |
||||||
|
void on_buttonDeleteIPSubnet_clicked(); |
||||||
|
void on_txtIPSubnet_textChanged(const QString &subnetStr); |
||||||
|
|
||||||
|
private: |
||||||
|
Ui::IPSubnetWhitelistOptionsDialog *m_ui; |
||||||
|
QStringListModel *m_model; |
||||||
|
QSortFilterProxyModel *m_sortFilter; |
||||||
|
bool m_modified; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // OPTIONS_IPSUBNETWHITELIST_H
|
@ -0,0 +1,110 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<ui version="4.0"> |
||||||
|
<class>IPSubnetWhitelistOptionsDialog</class> |
||||||
|
<widget class="QDialog" name="IPSubnetWhitelistOptionsDialog"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>360</width> |
||||||
|
<height>450</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="windowTitle"> |
||||||
|
<string>List of whitelisted IP subnets</string> |
||||||
|
</property> |
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"> |
||||||
|
<item> |
||||||
|
<widget class="QFrame" name="whitelistedIPSubnetBox"> |
||||||
|
<property name="autoFillBackground"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
<property name="frameShape"> |
||||||
|
<enum>QFrame::Panel</enum> |
||||||
|
</property> |
||||||
|
<property name="frameShadow"> |
||||||
|
<enum>QFrame::Raised</enum> |
||||||
|
</property> |
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_21"> |
||||||
|
<item> |
||||||
|
<widget class="QTreeView" name="whitelistedIPSubnetList"> |
||||||
|
<property name="rootIsDecorated"> |
||||||
|
<bool>false</bool> |
||||||
|
</property> |
||||||
|
<property name="uniformRowHeights"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
<property name="itemsExpandable"> |
||||||
|
<bool>false</bool> |
||||||
|
</property> |
||||||
|
<property name="sortingEnabled"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
<attribute name="headerVisible"> |
||||||
|
<bool>false</bool> |
||||||
|
</attribute> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_18"> |
||||||
|
<item> |
||||||
|
<widget class="QLineEdit" name="txtIPSubnet"> |
||||||
|
<property name="placeholderText"> |
||||||
|
<string>Example: 172.17.32.0/24, fdff:ffff:c8::/40</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="buttonWhitelistIPSubnet"> |
||||||
|
<property name="text"> |
||||||
|
<string>Add subnet</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="buttonDeleteIPSubnet"> |
||||||
|
<property name="text"> |
||||||
|
<string>Delete</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QDialogButtonBox" name="buttonBox"> |
||||||
|
<property name="standardButtons"> |
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
<tabstops> |
||||||
|
<tabstop>whitelistedIPSubnetList</tabstop> |
||||||
|
<tabstop>txtIPSubnet</tabstop> |
||||||
|
<tabstop>buttonWhitelistIPSubnet</tabstop> |
||||||
|
<tabstop>buttonDeleteIPSubnet</tabstop> |
||||||
|
</tabstops> |
||||||
|
<resources/> |
||||||
|
<connections> |
||||||
|
<connection> |
||||||
|
<sender>buttonBox</sender> |
||||||
|
<signal>rejected()</signal> |
||||||
|
<receiver>IPSubnetWhitelistOptionsDialog</receiver> |
||||||
|
<slot>reject()</slot> |
||||||
|
<hints> |
||||||
|
<hint type="sourcelabel"> |
||||||
|
<x>179</x> |
||||||
|
<y>427</y> |
||||||
|
</hint> |
||||||
|
<hint type="destinationlabel"> |
||||||
|
<x>179</x> |
||||||
|
<y>224</y> |
||||||
|
</hint> |
||||||
|
</hints> |
||||||
|
</connection> |
||||||
|
</connections> |
||||||
|
</ui> |
Loading…
Reference in new issue