added PageSettingsSplitTunneling

- added a call to the context menu when clicking the right mouse button for textInput
This commit is contained in:
vladimir.kuznetsov 2023-08-08 19:10:14 +05:00
parent 2c429fd406
commit 90ae0b3e44
31 changed files with 1018 additions and 240 deletions

View file

@ -1,9 +1,9 @@
#ifndef CONNECTIONCONTROLLER_H
#define CONNECTIONCONTROLLER_H
#include "ui/models/servers_model.h"
#include "ui/models/containers_model.h"
#include "protocols/vpnprotocol.h"
#include "ui/models/containers_model.h"
#include "ui/models/servers_model.h"
#include "vpnconnection.h"
class ConnectionController : public QObject
@ -17,8 +17,7 @@ public:
explicit ConnectionController(const QSharedPointer<ServersModel> &serversModel,
const QSharedPointer<ContainersModel> &containersModel,
const QSharedPointer<VpnConnection> &vpnConnection,
QObject *parent = nullptr);
const QSharedPointer<VpnConnection> &vpnConnection, QObject *parent = nullptr);
bool isConnected() const;
bool isConnectionInProgress() const;
@ -32,11 +31,12 @@ public slots:
void onConnectionStateChanged(Vpn::ConnectionState state);
signals:
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig);
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &containerConfig);
void disconnectFromVpn();
void connectionStateChanged();
void connectionErrorOccurred(QString errorMessage);
void connectionErrorOccurred(const QString &errorMessage);
private:
QSharedPointer<ServersModel> m_serversModel;

View file

@ -39,7 +39,7 @@ public slots:
signals:
void generateConfig(int type);
void exportErrorOccurred(QString errorMessage);
void exportErrorOccurred(const QString &errorMessage);
void exportConfigChanged();

View file

@ -34,7 +34,7 @@ public slots:
signals:
void importFinished();
void importErrorOccurred(QString errorMessage);
void importErrorOccurred(const QString &errorMessage);
void qrDecodingFinished();

View file

@ -42,18 +42,18 @@ public slots:
void setEncryptedPassphrase(QString passphrase);
signals:
void installContainerFinished(QString finishMessage);
void installServerFinished(QString finishMessage);
void installContainerFinished(const QString &finishMessage);
void installServerFinished(const QString &finishMessage);
void updateContainerFinished();
void scanServerFinished(bool isInstalledContainerFound);
void removeCurrentlyProcessedServerFinished(QString finishedMessage);
void removeAllContainersFinished(QString finishedMessage);
void removeCurrentlyProcessedContainerFinished(QString finishedMessage);
void removeCurrentlyProcessedServerFinished(const QString &finishedMessage);
void removeAllContainersFinished(const QString &finishedMessage);
void removeCurrentlyProcessedContainerFinished(const QString &finishedMessage);
void installationErrorOccurred(QString errorMessage);
void installationErrorOccurred(const QString &errorMessage);
void serverAlreadyExists(int serverIndex);

View file

@ -28,6 +28,7 @@ namespace PageLoader
PageSettingsBackup,
PageSettingsAbout,
PageSettingsLogging,
PageSettingsSplitTunneling,
PageServiceSftpSettings,
PageServiceTorWebsiteSettings,
@ -83,8 +84,8 @@ signals:
void restorePageHomeState(bool isContainerInstalled = false);
void replaceStartPage();
void showErrorMessage(QString errorMessage);
void showNotificationMessage(QString message);
void showErrorMessage(const QString &errorMessage);
void showNotificationMessage(const QString &message);
void showBusyIndicator(bool visible);

View file

@ -14,7 +14,7 @@ SettingsController::SettingsController(const QSharedPointer<ServersModel> &serve
m_appVersion = QString("%1: %2 (%3)").arg(tr("Software version"), QString(APP_MAJOR_VERSION), __DATE__);
}
void SettingsController::setAmneziaDns(bool enable)
void SettingsController::toggleAmneziaDns(bool enable)
{
m_settings->setUseAmneziaDns(enable);
}
@ -46,7 +46,7 @@ void SettingsController::setSecondaryDns(const QString &dns)
emit secondaryDnsChanged();
}
bool SettingsController::isLoggingEnable()
bool SettingsController::isLoggingEnabled()
{
return m_settings->isSaveLogs();
}
@ -111,3 +111,13 @@ void SettingsController::clearSettings()
m_settings->clearSettings();
m_serversModel->resetModel();
}
bool SettingsController::isAutoConnectEnabled()
{
return m_settings->isAutoConnect();
}
void SettingsController::toggleAutoConnect(bool enable)
{
m_settings->setAutoConnect(enable);
}

View file

@ -16,10 +16,10 @@ public:
Q_PROPERTY(QString primaryDns READ getPrimaryDns WRITE setPrimaryDns NOTIFY primaryDnsChanged)
Q_PROPERTY(QString secondaryDns READ getSecondaryDns WRITE setSecondaryDns NOTIFY secondaryDnsChanged)
Q_PROPERTY(bool isLoggingEnable READ isLoggingEnable WRITE toggleLogging NOTIFY loggingStateChanged)
Q_PROPERTY(bool isLoggingEnabled READ isLoggingEnabled WRITE toggleLogging NOTIFY loggingStateChanged)
public slots:
void setAmneziaDns(bool enable);
void toggleAmneziaDns(bool enable);
bool isAmneziaDnsEnabled();
QString getPrimaryDns();
@ -28,7 +28,7 @@ public slots:
QString getSecondaryDns();
void setSecondaryDns(const QString &dns);
bool isLoggingEnable();
bool isLoggingEnabled();
void toggleLogging(bool enable);
void openLogsFolder();
@ -42,13 +42,16 @@ public slots:
void clearSettings();
bool isAutoConnectEnabled();
void toggleAutoConnect(bool enable);
signals:
void primaryDnsChanged();
void secondaryDnsChanged();
void loggingStateChanged();
void restoreBackupFinished();
void changeSettingsErrorOccurred(QString errorMessage);
void changeSettingsErrorOccurred(const QString &errorMessage);
private:
QSharedPointer<ServersModel> m_serversModel;

View file

@ -0,0 +1,149 @@
#include "sitesController.h"
#include <QHostInfo>
#include "utilities.h"
SitesController::SitesController(const std::shared_ptr<Settings> &settings,
const QSharedPointer<VpnConnection> &vpnConnection,
const QSharedPointer<SitesModel> &sitesModel, QObject *parent)
: QObject(parent), m_settings(settings), m_vpnConnection(vpnConnection), m_sitesModel(sitesModel)
{
}
void SitesController::addSite(QString hostname)
{
if (hostname.isEmpty()) {
return;
}
if (!hostname.contains(".")) {
emit errorOccurred(tr("Hostname not look like ip adress or domain name"));
return;
}
if (!Utils::ipAddressWithSubnetRegExp().exactMatch(hostname)) {
// get domain name if it present
hostname.replace("https://", "");
hostname.replace("http://", "");
hostname.replace("ftp://", "");
hostname = hostname.split("/", Qt::SkipEmptyParts).first();
}
const auto &processSite = [this](const QString &hostname, const QString &ip) {
m_sitesModel->addSite(hostname, ip);
if (!ip.isEmpty()) {
m_vpnConnection->addRoutes(QStringList() << ip);
m_vpnConnection->flushDns();
} else if (Utils::ipAddressWithSubnetRegExp().exactMatch(hostname)) {
m_vpnConnection->addRoutes(QStringList() << hostname);
m_vpnConnection->flushDns();
}
};
const auto &resolveCallback = [this, processSite](const QHostInfo &hostInfo) {
const QList<QHostAddress> &addresses = hostInfo.addresses();
for (const QHostAddress &addr : hostInfo.addresses()) {
if (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol) {
processSite(hostInfo.hostName(), addr.toString());
break;
}
}
};
if (Utils::ipAddressWithSubnetRegExp().exactMatch(hostname)) {
processSite(hostname, "");
} else {
processSite(hostname, "");
QHostInfo::lookupHost(hostname, this, resolveCallback);
}
emit finished(tr("New site added: ") + hostname);
}
void SitesController::removeSite(int index)
{
auto modelIndex = m_sitesModel->index(index);
auto hostname = m_sitesModel->data(modelIndex, SitesModel::Roles::UrlRole).toString();
m_sitesModel->removeSite(modelIndex);
emit finished(tr("Site removed: ") + hostname);
}
void SitesController::importSites(bool replaceExisting)
{
QString fileName = Utils::getFileName(Q_NULLPTR, tr("Open sites file"),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.json");
if (fileName.isEmpty()) {
return;
}
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
emit errorOccurred(tr("Can't open file: ") + fileName);
return;
}
QByteArray jsonData = file.readAll();
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonData);
if (jsonDocument.isNull()) {
emit errorOccurred(tr("Failed to parse JSON data from file: ") + fileName);
return;
}
if (!jsonDocument.isArray()) {
emit errorOccurred(tr("The JSON data is not an array in file: ") + fileName);
return;
}
auto jsonArray = jsonDocument.array();
QMap<QString, QString> sites;
QStringList ips;
for (auto jsonValue : jsonArray) {
auto jsonObject = jsonValue.toObject();
auto hostname = jsonObject.value("hostname").toString("");
auto ip = jsonObject.value("ip").toString("");
if (!hostname.contains(".") && !Utils::ipAddressWithSubnetRegExp().exactMatch(hostname)) {
qDebug() << hostname << " not look like ip adress or domain name";
continue;
}
if (ip.isEmpty()) {
ips.append(hostname);
} else {
ips.append(ip);
}
sites.insert(hostname, ip);
}
m_sitesModel->addSites(sites, replaceExisting);
m_vpnConnection->addRoutes(QStringList() << ips);
m_vpnConnection->flushDns();
emit finished(tr("Import completed"));
}
void SitesController::exportSites()
{
auto sites = m_sitesModel->getCurrentSites();
QJsonArray jsonArray;
for (const auto &site : sites) {
QJsonObject jsonObject { { "hostname", site.first }, { "ip", site.second } };
jsonArray.append(jsonObject);
}
QJsonDocument jsonDocument(jsonArray);
QByteArray jsonData = jsonDocument.toJson();
Utils::saveFile(".json", tr("Export sites file"), "sites", jsonData);
emit finished(tr("Export completed"));
}

View file

@ -0,0 +1,36 @@
#ifndef SITESCONTROLLER_H
#define SITESCONTROLLER_H
#include <QObject>
#include "settings.h"
#include "ui/models/sites_model.h"
#include "vpnconnection.h"
class SitesController : public QObject
{
Q_OBJECT
public:
explicit SitesController(const std::shared_ptr<Settings> &settings,
const QSharedPointer<VpnConnection> &vpnConnection,
const QSharedPointer<SitesModel> &sitesModel, QObject *parent = nullptr);
public slots:
void addSite(QString hostname);
void removeSite(int index);
void importSites(bool replaceExisting);
void exportSites();
signals:
void errorOccurred(const QString &errorMessage);
void finished(const QString &message);
private:
std::shared_ptr<Settings> m_settings;
QSharedPointer<VpnConnection> m_vpnConnection;
QSharedPointer<SitesModel> m_sitesModel;
};
#endif // SITESCONTROLLER_H