mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
refactoring: attempting to move to MVVM
This commit is contained in:
@@ -12,8 +12,13 @@ set(HEADERS ${HEADERS}
|
||||
${CLIENT_ROOT_DIR}/core/api/apiDefs.h
|
||||
${CLIENT_ROOT_DIR}/core/qrCodeUtils.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/coreController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/gatewayController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/serverController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/api/gatewayController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/serverController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/serverConfigController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/installationController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/settingsConfigController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/protocolConfigController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/vpnConnectionController.h
|
||||
${CLIENT_ROOT_DIR}/core/controllers/vpnConfigurationController.h
|
||||
${CLIENT_ROOT_DIR}/protocols/protocols_defs.h
|
||||
${CLIENT_ROOT_DIR}/protocols/qml_register_protocols.h
|
||||
@@ -60,8 +65,13 @@ set(SOURCES ${SOURCES}
|
||||
${CLIENT_ROOT_DIR}/core/server_defs.cpp
|
||||
${CLIENT_ROOT_DIR}/core/qrCodeUtils.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/coreController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/gatewayController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/serverController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/api/gatewayController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/serverController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/serverConfigController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/selfhosted/installationController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/settingsConfigController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/protocolConfigController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/vpnConnectionController.cpp
|
||||
${CLIENT_ROOT_DIR}/core/controllers/vpnConfigurationController.cpp
|
||||
${CLIENT_ROOT_DIR}/protocols/protocols_defs.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/qautostart.cpp
|
||||
@@ -115,6 +125,7 @@ file(GLOB UI_MODELS_H CONFIGURE_DEPENDS
|
||||
${CLIENT_ROOT_DIR}/ui/models/protocols/*.h
|
||||
${CLIENT_ROOT_DIR}/ui/models/services/*.h
|
||||
${CLIENT_ROOT_DIR}/ui/models/api/*.h
|
||||
${CLIENT_ROOT_DIR}/ui/models/selfhosted/*.h
|
||||
)
|
||||
|
||||
file(GLOB UI_MODELS_CPP CONFIGURE_DEPENDS
|
||||
@@ -122,16 +133,19 @@ file(GLOB UI_MODELS_CPP CONFIGURE_DEPENDS
|
||||
${CLIENT_ROOT_DIR}/ui/models/protocols/*.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/models/services/*.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/models/api/*.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/models/selfhosted/*.cpp
|
||||
)
|
||||
|
||||
file(GLOB UI_CONTROLLERS_H CONFIGURE_DEPENDS
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/*.h
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/api/*.h
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/selfhosted/*.h
|
||||
)
|
||||
|
||||
file(GLOB UI_CONTROLLERS_CPP CONFIGURE_DEPENDS
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/*.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/api/*.cpp
|
||||
${CLIENT_ROOT_DIR}/ui/controllers/selfhosted/*.cpp
|
||||
)
|
||||
|
||||
file(GLOB CORE_MODELS_H CONFIGURE_DEPENDS
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
|
||||
CloakConfigurator::CloakConfigurator(std::shared_ptr<Settings> settings, const QSharedPointer<ServerController> &serverController, QObject *parent)
|
||||
: ConfiguratorBase(settings, serverController, parent)
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "settings.h"
|
||||
|
||||
class ConfiguratorBase : public QObject
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <QTemporaryFile>
|
||||
#include <QUuid>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "core/server_defs.h"
|
||||
#include "utilities.h"
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#endif
|
||||
|
||||
#include "core/networkUtilities.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "settings.h"
|
||||
#include "utilities.h"
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
|
||||
ShadowSocksConfigurator::ShadowSocksConfigurator(std::shared_ptr<Settings> settings, const QSharedPointer<ServerController> &serverController,
|
||||
QObject *parent)
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "core/server_defs.h"
|
||||
#include "settings.h"
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <QUuid>
|
||||
#include "logger.h"
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/scripts_registry.h"
|
||||
|
||||
namespace {
|
||||
|
||||
153
client/core/controllers/configController.cpp
Normal file
153
client/core/controllers/configController.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include "configController.h"
|
||||
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/servers/apiV1ServerConfig.h"
|
||||
#include "core/models/servers/apiV2ServerConfig.h"
|
||||
#include "core/models/servers/selfHostedServerConfig.h"
|
||||
#include "core/networkUtilities.h"
|
||||
#include "protocols/protocols_defs.h"
|
||||
#include "settings.h"
|
||||
|
||||
ConfigController::ConfigController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
void ConfigController::addServer(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
m_settings->addServer(serverConfig->toJson());
|
||||
emit serverAdded(m_settings->serversCount() - 1);
|
||||
}
|
||||
|
||||
void ConfigController::editServer(const QSharedPointer<ServerConfig> &serverConfig, int serverIndex)
|
||||
{
|
||||
updateServerInSettings(serverConfig, serverIndex);
|
||||
emit serverEdited(serverIndex);
|
||||
}
|
||||
|
||||
void ConfigController::removeServer(int serverIndex)
|
||||
{
|
||||
m_settings->removeServer(serverIndex);
|
||||
emit serverRemoved(serverIndex);
|
||||
}
|
||||
|
||||
void ConfigController::setDefaultServer(int serverIndex)
|
||||
{
|
||||
m_settings->setDefaultServer(serverIndex);
|
||||
emit defaultServerChanged(serverIndex);
|
||||
}
|
||||
|
||||
void ConfigController::setDefaultContainer(int serverIndex, int containerIndex)
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
auto container = static_cast<DockerContainer>(containerIndex);
|
||||
serverConfig->defaultContainer = ContainerProps::containerToString(container);
|
||||
|
||||
updateServerInSettings(serverConfig, serverIndex);
|
||||
emit defaultContainerChanged(serverIndex, container);
|
||||
}
|
||||
|
||||
bool ConfigController::isServerFromApiAlreadyExists(quint16 crc) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
for (const auto &server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
if (static_cast<quint16>(serverConfig->crc) == crc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigController::isServerFromApiAlreadyExists(const QString &userCountryCode,
|
||||
const QString &serviceType,
|
||||
const QString &serviceProtocol) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
for (const auto &server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
|
||||
if (serverConfig->hostName == "api.amnezia.org") {
|
||||
auto apiV2Config = serverConfig.dynamicCast<ApiV2ServerConfig>();
|
||||
if (apiV2Config &&
|
||||
apiV2Config->apiConfigData.countryCode == userCountryCode &&
|
||||
apiV2Config->apiConfigData.serviceInfo.serviceType == serviceType &&
|
||||
apiV2Config->apiConfigData.serviceInfo.serviceProtocol == serviceProtocol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigController::isApiKeyExpired(int serverIndex) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return false;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
|
||||
if (serverConfig->hostName == "api.amnezia.org") {
|
||||
auto apiV2Config = serverConfig.dynamicCast<ApiV2ServerConfig>();
|
||||
if (apiV2Config) {
|
||||
QDateTime expiresAt = QDateTime::fromString(apiV2Config->apiConfigData.serviceInfo.expiresAt, Qt::ISODate);
|
||||
return QDateTime::currentDateTime() > expiresAt;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConfigController::removeApiConfig(int serverIndex)
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
|
||||
if (serverConfig->hostName == "api.amnezia.org") {
|
||||
auto apiV2Config = serverConfig.dynamicCast<ApiV2ServerConfig>();
|
||||
if (apiV2Config) {
|
||||
apiV2Config->apiConfigData = ApiV2ServerConfig::ApiConfigData{};
|
||||
updateServerInSettings(apiV2Config, serverIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ConfigController::getAllInstalledServicesName(int serverIndex) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return {};
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
|
||||
QStringList serviceNames;
|
||||
for (auto it = serverConfig->containerConfigs.constBegin();
|
||||
it != serverConfig->containerConfigs.constEnd(); ++it) {
|
||||
const QString &containerName = it.key();
|
||||
serviceNames.append(containerName);
|
||||
}
|
||||
return serviceNames;
|
||||
}
|
||||
|
||||
void ConfigController::clearCachedProfile(int serverIndex, DockerContainer container)
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
|
||||
QString containerName = ContainerProps::containerToString(container);
|
||||
if (serverConfig->containerConfigs.contains(containerName)) {
|
||||
auto &containerConfig = serverConfig->containerConfigs[containerName];
|
||||
containerConfig.clearProfile();
|
||||
updateServerInSettings(serverConfig, serverIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigController::updateServerInSettings(const QSharedPointer<ServerConfig> &serverConfig, int serverIndex)
|
||||
{
|
||||
m_settings->editServer(serverIndex, serverConfig->toJson());
|
||||
}
|
||||
58
client/core/controllers/configController.h
Normal file
58
client/core/controllers/configController.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef CONFIGCONTROLLER_H
|
||||
#define CONFIGCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/models/servers/serverConfig.h"
|
||||
|
||||
class Settings;
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class ConfigController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
virtual ~ConfigController() = default;
|
||||
|
||||
// Basic server management
|
||||
virtual void addServer(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
virtual void editServer(const QSharedPointer<ServerConfig> &serverConfig, int serverIndex);
|
||||
virtual void removeServer(int serverIndex);
|
||||
|
||||
// Default settings management
|
||||
void setDefaultServer(int serverIndex);
|
||||
void setDefaultContainer(int serverIndex, int containerIndex);
|
||||
|
||||
// API server utilities
|
||||
bool isServerFromApiAlreadyExists(quint16 crc) const;
|
||||
bool isServerFromApiAlreadyExists(const QString &userCountryCode,
|
||||
const QString &serviceType,
|
||||
const QString &serviceProtocol) const;
|
||||
bool isApiKeyExpired(int serverIndex) const;
|
||||
void removeApiConfig(int serverIndex);
|
||||
|
||||
// General utilities
|
||||
QStringList getAllInstalledServicesName(int serverIndex) const;
|
||||
void clearCachedProfile(int serverIndex, DockerContainer container);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
||||
// Protected helper methods for derived classes
|
||||
void updateServerInSettings(const QSharedPointer<ServerConfig> &serverConfig, int serverIndex);
|
||||
|
||||
signals:
|
||||
// Common server management signals
|
||||
void serverAdded(int serverIndex);
|
||||
void serverEdited(int serverIndex);
|
||||
void serverRemoved(int serverIndex);
|
||||
void defaultServerChanged(int serverIndex);
|
||||
void defaultContainerChanged(int serverIndex, DockerContainer container);
|
||||
};
|
||||
|
||||
#endif // CONFIGCONTROLLER_H
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "ui/controllers/exportController.h"
|
||||
#include "ui/controllers/focusController.h"
|
||||
#include "ui/controllers/importController.h"
|
||||
#include "ui/controllers/installController.h"
|
||||
#include "ui/controllers/selfhosted/installController.h"
|
||||
#include "ui/controllers/pageController.h"
|
||||
#include "ui/controllers/settingsController.h"
|
||||
#include "ui/controllers/sitesController.h"
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "ui/models/api/apiDevicesModel.h"
|
||||
#include "ui/models/api/apiServicesModel.h"
|
||||
#include "ui/models/appSplitTunnelingModel.h"
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/models/selfhosted/clientManagementModel.h"
|
||||
#include "ui/models/protocols/awgConfigModel.h"
|
||||
#include "ui/models/protocols/openvpnConfigModel.h"
|
||||
#include "ui/models/protocols/shadowsocksConfigModel.h"
|
||||
|
||||
61
client/core/controllers/dnsController.cpp
Normal file
61
client/core/controllers/dnsController.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "dnsController.h"
|
||||
|
||||
DnsController::DnsController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
bool DnsController::addDns(const QString &ip)
|
||||
{
|
||||
QStringList currentDnsServers = m_settings->allowedDnsServers();
|
||||
|
||||
if (currentDnsServers.contains(ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentDnsServers.append(ip);
|
||||
m_settings->setAllowedDnsServers(currentDnsServers);
|
||||
|
||||
emit dnsAdded(ip);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DnsController::addDnsList(const QStringList &dnsServers, bool replaceExisting)
|
||||
{
|
||||
QStringList currentDnsServers;
|
||||
|
||||
if (!replaceExisting) {
|
||||
currentDnsServers = m_settings->allowedDnsServers();
|
||||
}
|
||||
|
||||
for (const QString &ip : dnsServers) {
|
||||
if (!currentDnsServers.contains(ip)) {
|
||||
currentDnsServers.append(ip);
|
||||
}
|
||||
}
|
||||
|
||||
m_settings->setAllowedDnsServers(currentDnsServers);
|
||||
|
||||
emit dnsListAdded(dnsServers);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DnsController::removeDns(const QString &ip)
|
||||
{
|
||||
QStringList currentDnsServers = m_settings->allowedDnsServers();
|
||||
|
||||
if (!currentDnsServers.contains(ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentDnsServers.removeAll(ip);
|
||||
m_settings->setAllowedDnsServers(currentDnsServers);
|
||||
|
||||
emit dnsRemoved(ip);
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList DnsController::getAllowedDnsServers() const
|
||||
{
|
||||
return m_settings->allowedDnsServers();
|
||||
}
|
||||
32
client/core/controllers/dnsController.h
Normal file
32
client/core/controllers/dnsController.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef DNSCONTROLLER_H
|
||||
#define DNSCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
class DnsController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DnsController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
// DNS management
|
||||
bool addDns(const QString &ip);
|
||||
bool addDnsList(const QStringList &dnsServers, bool replaceExisting = false);
|
||||
bool removeDns(const QString &ip);
|
||||
QStringList getAllowedDnsServers() const;
|
||||
|
||||
signals:
|
||||
void dnsAdded(const QString &ip);
|
||||
void dnsListAdded(const QStringList &dnsServers);
|
||||
void dnsRemoved(const QString &ip);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // DNSCONTROLLER_H
|
||||
109
client/core/controllers/selfhosted/installationController.cpp
Normal file
109
client/core/controllers/selfhosted/installationController.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "installationController.h"
|
||||
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "core/controllers/vpnConfigurationController.h"
|
||||
#include "core/networkUtilities.h"
|
||||
#include "settings.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("InstallationController");
|
||||
}
|
||||
|
||||
InstallationController::InstallationController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::installContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container, containerConfig]() -> ErrorCode {
|
||||
// TODO: Implement container installation logic
|
||||
// This will be moved from UI InstallController
|
||||
logger.info() << "Installing container" << ContainerProps::containerToString(container);
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::scanServerForInstalledContainers(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig]() -> ErrorCode {
|
||||
// TODO: Implement server scanning logic
|
||||
// This will be moved from UI InstallController
|
||||
logger.info() << "Scanning server for installed containers";
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::removeContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container]() -> ErrorCode {
|
||||
// TODO: Implement container removal logic
|
||||
logger.info() << "Removing container" << ContainerProps::containerToString(container);
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::updateContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container, containerConfig]() -> ErrorCode {
|
||||
// TODO: Implement container update logic
|
||||
logger.info() << "Updating container" << ContainerProps::containerToString(container);
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::rebootServer(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig]() -> ErrorCode {
|
||||
// TODO: Implement server reboot logic
|
||||
logger.info() << "Rebooting server";
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::removeAllContainers(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig]() -> ErrorCode {
|
||||
// TODO: Implement all containers removal logic
|
||||
logger.info() << "Removing all containers";
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<bool> InstallationController::checkSshConnection(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig]() -> bool {
|
||||
// TODO: Implement SSH connection check logic
|
||||
logger.info() << "Checking SSH connection";
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> InstallationController::mountSftpDrive(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
const QString &port,
|
||||
const QString &password,
|
||||
const QString &username)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, port, password, username]() -> ErrorCode {
|
||||
// TODO: Implement SFTP mounting logic
|
||||
logger.info() << "Mounting SFTP drive";
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
ErrorCode InstallationController::getAlreadyInstalledContainers(const ServerCredentials &serverCredentials,
|
||||
const QSharedPointer<ServerController> &serverController,
|
||||
QMap<DockerContainer, QJsonObject> &installedContainers)
|
||||
{
|
||||
// TODO: Implement logic to get already installed containers
|
||||
// This will be moved from UI InstallController
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
61
client/core/controllers/selfhosted/installationController.h
Normal file
61
client/core/controllers/selfhosted/installationController.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef INSTALLATIONCONTROLLER_H
|
||||
#define INSTALLATIONCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFuture>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/servers/serverConfig.h"
|
||||
#include "serverController.h"
|
||||
|
||||
class Settings;
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class InstallationController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InstallationController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
QFuture<ErrorCode> installContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig);
|
||||
|
||||
QFuture<ErrorCode> scanServerForInstalledContainers(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
|
||||
QFuture<ErrorCode> removeContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container);
|
||||
|
||||
QFuture<ErrorCode> updateContainer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig);
|
||||
|
||||
QFuture<ErrorCode> rebootServer(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
|
||||
QFuture<ErrorCode> removeAllContainers(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
|
||||
QFuture<bool> checkSshConnection(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
|
||||
QFuture<ErrorCode> mountSftpDrive(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
const QString &port,
|
||||
const QString &password,
|
||||
const QString &username);
|
||||
|
||||
signals:
|
||||
void installationFinished(const QString &finishMessage, bool isServiceInstall);
|
||||
void installationProgress(const QString &message);
|
||||
void installationError(ErrorCode errorCode);
|
||||
|
||||
private:
|
||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &serverCredentials,
|
||||
const QSharedPointer<ServerController> &serverController,
|
||||
QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // INSTALLATIONCONTROLLER_H
|
||||
@@ -0,0 +1,181 @@
|
||||
#include "selfhostedConfigController.h"
|
||||
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
||||
#include "core/models/protocols/wireguardProtocolConfig.h"
|
||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
||||
#include "core/networkUtilities.h"
|
||||
#include "settings.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("SelfhostedConfigController");
|
||||
}
|
||||
|
||||
SelfhostedConfigController::SelfhostedConfigController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: ConfigController(settings, parent)
|
||||
{
|
||||
m_isAmneziaDnsEnabled = m_settings->useAmneziaDns();
|
||||
}
|
||||
|
||||
bool SelfhostedConfigController::isDefaultServerDefaultContainerHasSplitTunneling() const
|
||||
{
|
||||
int defaultServerIndex = m_settings->defaultServerIndex();
|
||||
auto servers = m_settings->serversArray();
|
||||
if (defaultServerIndex >= servers.size()) return false;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(defaultServerIndex).toObject());
|
||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
|
||||
if (!serverConfig->containerConfigs.contains(serverConfig->defaultContainer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &containerConfig = serverConfig->containerConfigs[serverConfig->defaultContainer];
|
||||
return checkSplitTunnelingInContainer(containerConfig, serverConfig->defaultContainer);
|
||||
}
|
||||
|
||||
void SelfhostedConfigController::toggleAmneziaDns(bool enabled)
|
||||
{
|
||||
m_isAmneziaDnsEnabled = enabled;
|
||||
m_settings->setUseAmneziaDns(enabled);
|
||||
emit amneziaDnsToggled(enabled);
|
||||
}
|
||||
|
||||
QPair<QString, QString> SelfhostedConfigController::getDnsPair(int serverIndex) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return {};
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
QPair<QString, QString> dns;
|
||||
|
||||
bool isDnsContainerInstalled = isAmneziaDnsContainerInstalled(serverIndex);
|
||||
|
||||
dns.first = serverConfig->dns1;
|
||||
dns.second = serverConfig->dns2;
|
||||
|
||||
if (isDnsContainerInstalled && m_isAmneziaDnsEnabled) {
|
||||
dns.first = serverConfig->hostName;
|
||||
dns.second = "";
|
||||
}
|
||||
|
||||
return dns;
|
||||
}
|
||||
|
||||
bool SelfhostedConfigController::isAmneziaDnsContainerInstalled(int serverIndex) const
|
||||
{
|
||||
auto servers = m_settings->serversArray();
|
||||
if (serverIndex >= servers.size()) return false;
|
||||
|
||||
auto serverConfig = ServerConfig::createServerConfig(servers.at(serverIndex).toObject());
|
||||
|
||||
for (const auto &container : serverConfig->containerConfigs) {
|
||||
auto containerType = ContainerProps::containerFromString(container.containerName);
|
||||
if (containerType == DockerContainer::Dns) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Protocol management methods (from ProtocolConfigController)
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> SelfhostedConfigController::getProtocolConfigs(const QVector<QSharedPointer<ProtocolConfig>> &protocols)
|
||||
{
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> protocolConfigs;
|
||||
|
||||
for (const auto &config : protocols) {
|
||||
Proto protocol = ProtocolProps::protoFromString(config->protocolName);
|
||||
|
||||
if (isProtocolSupported(protocol)) {
|
||||
protocolConfigs.insert(config->protocolName, config);
|
||||
}
|
||||
}
|
||||
|
||||
return protocolConfigs;
|
||||
}
|
||||
|
||||
void SelfhostedConfigController::updateProtocolConfiguration(Proto protocol, const QSharedPointer<ProtocolConfig> &protocolConfig)
|
||||
{
|
||||
if (!isProtocolSupported(protocol)) {
|
||||
logger.warning() << "Protocol not supported:" << ProtocolProps::protoToString(protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info() << "Updating protocol configuration for:" << ProtocolProps::protoToString(protocol);
|
||||
|
||||
emit protocolConfigUpdated(protocol, protocolConfig);
|
||||
}
|
||||
|
||||
QSharedPointer<ProtocolConfig> SelfhostedConfigController::createProtocolConfig(Proto protocol)
|
||||
{
|
||||
if (!isProtocolSupported(protocol)) {
|
||||
logger.warning() << "Attempting to create unsupported protocol config:" << ProtocolProps::protoToString(protocol);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
switch (protocol) {
|
||||
case Proto::Awg:
|
||||
return QSharedPointer<AwgProtocolConfig>::create();
|
||||
case Proto::Cloak:
|
||||
return QSharedPointer<CloakProtocolConfig>::create();
|
||||
case Proto::OpenVpn:
|
||||
return QSharedPointer<OpenVpnProtocolConfig>::create();
|
||||
case Proto::ShadowSocks:
|
||||
return QSharedPointer<ShadowsocksProtocolConfig>::create();
|
||||
case Proto::WireGuard:
|
||||
return QSharedPointer<WireGuardProtocolConfig>::create();
|
||||
case Proto::Xray:
|
||||
return QSharedPointer<XrayProtocolConfig>::create();
|
||||
default:
|
||||
logger.warning() << "Unknown protocol in createProtocolConfig:" << ProtocolProps::protoToString(protocol);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool SelfhostedConfigController::isProtocolSupported(Proto protocol) const
|
||||
{
|
||||
switch (protocol) {
|
||||
case Proto::Awg:
|
||||
case Proto::Cloak:
|
||||
case Proto::OpenVpn:
|
||||
case Proto::ShadowSocks:
|
||||
case Proto::WireGuard:
|
||||
case Proto::Xray:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SelfhostedConfigController::checkSplitTunnelingInContainer(const ContainerConfig &containerConfig,
|
||||
const QString &defaultContainer) const
|
||||
{
|
||||
for (const auto &protocol : containerConfig.protocolConfigs) {
|
||||
Proto protoType = ProtocolProps::protoFromString(protocol->protocolName);
|
||||
|
||||
switch (protoType) {
|
||||
case Proto::Awg: {
|
||||
auto awgConfig = protocol.dynamicCast<AwgProtocolConfig>();
|
||||
if (awgConfig && awgConfig->clientConfig.awgConfig.mtu != 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Proto::WireGuard: {
|
||||
auto wgConfig = protocol.dynamicCast<WireGuardProtocolConfig>();
|
||||
if (wgConfig && wgConfig->clientConfig.mtu != 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef SELFHOSTEDCONFIGCONTROLLER_H
|
||||
#define SELFHOSTEDCONFIGCONTROLLER_H
|
||||
|
||||
#include "../configController.h"
|
||||
#include "core/models/containers/containerConfig.h"
|
||||
#include "core/models/protocols/protocolConfig.h"
|
||||
|
||||
#include <QMap>
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class SelfhostedConfigController : public ConfigController
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SelfhostedConfigController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
// Self-hosted specific functionality
|
||||
bool isDefaultServerDefaultContainerHasSplitTunneling() const;
|
||||
|
||||
// Amnezia DNS management
|
||||
void toggleAmneziaDns(bool enabled);
|
||||
QPair<QString, QString> getDnsPair(int serverIndex) const;
|
||||
bool isAmneziaDnsContainerInstalled(int serverIndex) const;
|
||||
|
||||
// Protocol management (from ProtocolConfigController)
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> getProtocolConfigs(const QVector<QSharedPointer<ProtocolConfig>> &protocols);
|
||||
void updateProtocolConfiguration(Proto protocol, const QSharedPointer<ProtocolConfig> &protocolConfig);
|
||||
QSharedPointer<ProtocolConfig> createProtocolConfig(Proto protocol);
|
||||
bool isProtocolSupported(Proto protocol) const;
|
||||
|
||||
private:
|
||||
bool m_isAmneziaDnsEnabled;
|
||||
|
||||
// Helper methods
|
||||
bool checkSplitTunnelingInContainer(const ContainerConfig &containerConfig,
|
||||
const QString &defaultContainer) const;
|
||||
|
||||
signals:
|
||||
// Self-hosted specific signals
|
||||
void amneziaDnsToggled(bool enabled);
|
||||
void protocolConfigUpdated(Proto protocol, const QSharedPointer<ProtocolConfig> &config);
|
||||
};
|
||||
|
||||
#endif // SELFHOSTEDCONFIGCONTROLLER_H
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/networkUtilities.h"
|
||||
#include "core/scripts_registry.h"
|
||||
#include "core/server_defs.h"
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/sshclient.h"
|
||||
|
||||
146
client/core/controllers/settingsConfigController.cpp
Normal file
146
client/core/controllers/settingsConfigController.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include "settingsConfigController.h"
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
#include "settings.h"
|
||||
#include "logger.h"
|
||||
#include "ui/qautostart.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("SettingsConfigController");
|
||||
}
|
||||
|
||||
SettingsConfigController::SettingsConfigController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsConfigController::resetAllSettings()
|
||||
{
|
||||
logger.info() << "Resetting all settings to defaults";
|
||||
m_settings->clearSettings();
|
||||
emit settingsReset();
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureDns(const QString &primaryDns, const QString &secondaryDns)
|
||||
{
|
||||
m_settings->setPrimaryDns(primaryDns);
|
||||
m_settings->setSecondaryDns(secondaryDns);
|
||||
emit dnsConfigChanged();
|
||||
}
|
||||
|
||||
void SettingsConfigController::toggleAmneziaDns(bool enable)
|
||||
{
|
||||
m_settings->setUseAmneziaDns(enable);
|
||||
emit dnsConfigChanged();
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureLogging(bool enable)
|
||||
{
|
||||
m_settings->setSaveLogs(enable);
|
||||
if (enable) {
|
||||
m_settings->setLogEnableDate(QDateTime::currentDateTime());
|
||||
}
|
||||
emit loggingConfigChanged();
|
||||
}
|
||||
|
||||
void SettingsConfigController::checkLoggingExpiration()
|
||||
{
|
||||
if (m_settings->isSaveLogs()) {
|
||||
QDateTime loggingDisableDate = m_settings->getLogEnableDate().addDays(14);
|
||||
if (loggingDisableDate <= QDateTime::currentDateTime()) {
|
||||
configureLogging(false);
|
||||
clearLogs();
|
||||
emit loggingExpired();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsConfigController::clearLogs()
|
||||
{
|
||||
// TODO: Implement log clearing logic
|
||||
logger.info() << "Clearing logs";
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureKillSwitch(bool enable, bool strict)
|
||||
{
|
||||
m_settings->setKillSwitchEnabled(enable);
|
||||
if (enable) {
|
||||
m_settings->setStrictKillSwitchEnabled(strict);
|
||||
} else {
|
||||
m_settings->setStrictKillSwitchEnabled(false);
|
||||
}
|
||||
emit killSwitchConfigChanged();
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureAutoStart(bool enable)
|
||||
{
|
||||
Autostart::setAutostart(enable);
|
||||
emit autoStartConfigChanged();
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureAutoConnect(bool enable)
|
||||
{
|
||||
m_settings->setAutoConnect(enable);
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureStartMinimized(bool enable)
|
||||
{
|
||||
m_settings->setStartMinimized(enable);
|
||||
}
|
||||
|
||||
void SettingsConfigController::configureScreenshots(bool enable)
|
||||
{
|
||||
m_settings->setScreenshotsEnabled(enable);
|
||||
}
|
||||
|
||||
QString SettingsConfigController::getPrimaryDns() const
|
||||
{
|
||||
return m_settings->primaryDns();
|
||||
}
|
||||
|
||||
QString SettingsConfigController::getSecondaryDns() const
|
||||
{
|
||||
return m_settings->secondaryDns();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isAmneziaDnsEnabled() const
|
||||
{
|
||||
return m_settings->useAmneziaDns();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isLoggingEnabled() const
|
||||
{
|
||||
return m_settings->isSaveLogs();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isKillSwitchEnabled() const
|
||||
{
|
||||
return m_settings->isKillSwitchEnabled();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isStrictKillSwitchEnabled() const
|
||||
{
|
||||
return m_settings->isStrictKillSwitchEnabled();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isAutoStartEnabled() const
|
||||
{
|
||||
return Autostart::isAutostart();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isAutoConnectEnabled() const
|
||||
{
|
||||
return m_settings->isAutoConnect();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isStartMinimizedEnabled() const
|
||||
{
|
||||
return m_settings->isStartMinimized();
|
||||
}
|
||||
|
||||
bool SettingsConfigController::isScreenshotsEnabled() const
|
||||
{
|
||||
return m_settings->isScreenshotsEnabled();
|
||||
}
|
||||
59
client/core/controllers/settingsConfigController.h
Normal file
59
client/core/controllers/settingsConfigController.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef SETTINGSCONFIGCONTROLLER_H
|
||||
#define SETTINGSCONFIGCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFuture>
|
||||
|
||||
#include "core/defs.h"
|
||||
|
||||
class Settings;
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class SettingsConfigController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsConfigController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
void resetAllSettings();
|
||||
|
||||
void configureDns(const QString &primaryDns, const QString &secondaryDns);
|
||||
void toggleAmneziaDns(bool enable);
|
||||
|
||||
void configureLogging(bool enable);
|
||||
void checkLoggingExpiration();
|
||||
void clearLogs();
|
||||
|
||||
void configureKillSwitch(bool enable, bool strict = false);
|
||||
|
||||
void configureAutoStart(bool enable);
|
||||
void configureAutoConnect(bool enable);
|
||||
void configureStartMinimized(bool enable);
|
||||
void configureScreenshots(bool enable);
|
||||
|
||||
QString getPrimaryDns() const;
|
||||
QString getSecondaryDns() const;
|
||||
bool isAmneziaDnsEnabled() const;
|
||||
bool isLoggingEnabled() const;
|
||||
bool isKillSwitchEnabled() const;
|
||||
bool isStrictKillSwitchEnabled() const;
|
||||
bool isAutoStartEnabled() const;
|
||||
bool isAutoConnectEnabled() const;
|
||||
bool isStartMinimizedEnabled() const;
|
||||
bool isScreenshotsEnabled() const;
|
||||
|
||||
signals:
|
||||
void settingsReset();
|
||||
void dnsConfigChanged();
|
||||
void loggingConfigChanged();
|
||||
void killSwitchConfigChanged();
|
||||
void autoStartConfigChanged();
|
||||
void loggingExpired();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // SETTINGSCONFIGCONTROLLER_H
|
||||
140
client/core/controllers/splitTunnelingController.cpp
Normal file
140
client/core/controllers/splitTunnelingController.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include "splitTunnelingController.h"
|
||||
#include "settings.h"
|
||||
|
||||
SplitTunnelingController::SplitTunnelingController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
// Apps split tunneling implementation
|
||||
bool SplitTunnelingController::addApp(const InstalledAppInfo &appInfo)
|
||||
{
|
||||
auto currentApps = m_settings->getVpnApps(getAppsRouteMode());
|
||||
|
||||
if (currentApps.contains(appInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentApps.append(appInfo);
|
||||
m_settings->setVpnApps(getAppsRouteMode(), currentApps);
|
||||
|
||||
emit appAdded(appInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SplitTunnelingController::removeApp(const InstalledAppInfo &appInfo)
|
||||
{
|
||||
auto currentApps = m_settings->getVpnApps(getAppsRouteMode());
|
||||
|
||||
if (!currentApps.contains(appInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentApps.removeAll(appInfo);
|
||||
m_settings->setVpnApps(getAppsRouteMode(), currentApps);
|
||||
|
||||
emit appRemoved(appInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<InstalledAppInfo> SplitTunnelingController::getApps(Settings::AppsRouteMode routeMode) const
|
||||
{
|
||||
return m_settings->getVpnApps(routeMode);
|
||||
}
|
||||
|
||||
Settings::AppsRouteMode SplitTunnelingController::getAppsRouteMode() const
|
||||
{
|
||||
return m_settings->getAppsRouteMode();
|
||||
}
|
||||
|
||||
void SplitTunnelingController::setAppsRouteMode(Settings::AppsRouteMode routeMode)
|
||||
{
|
||||
m_settings->setAppsRouteMode(routeMode);
|
||||
emit appsRouteModelChanged();
|
||||
}
|
||||
|
||||
bool SplitTunnelingController::isAppsSplitTunnelingEnabled() const
|
||||
{
|
||||
return m_settings->isAppsSplitTunnelingEnabled();
|
||||
}
|
||||
|
||||
void SplitTunnelingController::setAppsSplitTunnelingEnabled(bool enabled)
|
||||
{
|
||||
m_settings->setAppsSplitTunnelingEnabled(enabled);
|
||||
emit appsSplitTunnelingToggled();
|
||||
}
|
||||
|
||||
// Sites split tunneling implementation
|
||||
bool SplitTunnelingController::addSite(const QString &hostname, const QString &ip)
|
||||
{
|
||||
if (!m_settings->addVpnSite(getSitesRouteMode(), hostname, ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
emit siteAdded(hostname, ip);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SplitTunnelingController::addSites(const QMap<QString, QString> &sites, bool replaceExisting)
|
||||
{
|
||||
if (replaceExisting) {
|
||||
m_settings->removeAllVpnSites(getSitesRouteMode());
|
||||
}
|
||||
|
||||
m_settings->addVpnSites(getSitesRouteMode(), sites);
|
||||
|
||||
// Emit signals for each added site
|
||||
auto i = sites.constBegin();
|
||||
while (i != sites.constEnd()) {
|
||||
emit siteAdded(i.key(), i.value());
|
||||
++i;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SplitTunnelingController::removeSite(const QString &hostname)
|
||||
{
|
||||
if (!m_settings->removeVpnSite(getSitesRouteMode(), hostname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
emit siteRemoved(hostname);
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<QPair<QString, QString>> SplitTunnelingController::getSites(Settings::RouteMode routeMode) const
|
||||
{
|
||||
QVector<QPair<QString, QString>> sites;
|
||||
const QVariantMap &sitesMap = m_settings->vpnSites(routeMode);
|
||||
|
||||
auto i = sitesMap.constBegin();
|
||||
while (i != sitesMap.constEnd()) {
|
||||
sites.append(qMakePair(i.key(), i.value().toString()));
|
||||
++i;
|
||||
}
|
||||
|
||||
return sites;
|
||||
}
|
||||
|
||||
Settings::RouteMode SplitTunnelingController::getSitesRouteMode() const
|
||||
{
|
||||
return m_settings->routeMode();
|
||||
}
|
||||
|
||||
void SplitTunnelingController::setSitesRouteMode(Settings::RouteMode routeMode)
|
||||
{
|
||||
m_settings->setRouteMode(routeMode);
|
||||
emit sitesRouteModelChanged();
|
||||
}
|
||||
|
||||
bool SplitTunnelingController::isSitesSplitTunnelingEnabled() const
|
||||
{
|
||||
return m_settings->isSitesSplitTunnelingEnabled();
|
||||
}
|
||||
|
||||
void SplitTunnelingController::setSitesSplitTunnelingEnabled(bool enabled)
|
||||
{
|
||||
m_settings->setSitesSplitTunnelingEnabled(enabled);
|
||||
emit sitesSplitTunnelingToggled();
|
||||
}
|
||||
64
client/core/controllers/splitTunnelingController.h
Normal file
64
client/core/controllers/splitTunnelingController.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef SPLITTUNNELINGCONTROLLER_H
|
||||
#define SPLITTUNNELINGCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "settings.h"
|
||||
#include "core/defs.h"
|
||||
|
||||
struct InstalledAppInfo; // Forward declaration
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class SplitTunnelingController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SplitTunnelingController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
// Apps split tunneling
|
||||
bool addApp(const InstalledAppInfo &appInfo);
|
||||
bool removeApp(const InstalledAppInfo &appInfo);
|
||||
QVector<InstalledAppInfo> getApps(Settings::AppsRouteMode routeMode) const;
|
||||
|
||||
Settings::AppsRouteMode getAppsRouteMode() const;
|
||||
void setAppsRouteMode(Settings::AppsRouteMode routeMode);
|
||||
|
||||
bool isAppsSplitTunnelingEnabled() const;
|
||||
void setAppsSplitTunnelingEnabled(bool enabled);
|
||||
|
||||
// Sites split tunneling
|
||||
bool addSite(const QString &hostname, const QString &ip = QString());
|
||||
bool addSites(const QMap<QString, QString> &sites, bool replaceExisting = false);
|
||||
bool removeSite(const QString &hostname);
|
||||
QVector<QPair<QString, QString>> getSites(Settings::RouteMode routeMode) const;
|
||||
|
||||
Settings::RouteMode getSitesRouteMode() const;
|
||||
void setSitesRouteMode(Settings::RouteMode routeMode);
|
||||
|
||||
bool isSitesSplitTunnelingEnabled() const;
|
||||
void setSitesSplitTunnelingEnabled(bool enabled);
|
||||
|
||||
signals:
|
||||
// Apps signals
|
||||
void appsRouteModelChanged();
|
||||
void appsSplitTunnelingToggled();
|
||||
void appAdded(const InstalledAppInfo &appInfo);
|
||||
void appRemoved(const InstalledAppInfo &appInfo);
|
||||
|
||||
// Sites signals
|
||||
void sitesRouteModelChanged();
|
||||
void sitesSplitTunnelingToggled();
|
||||
void siteAdded(const QString &hostname, const QString &ip);
|
||||
void siteRemoved(const QString &hostname);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // SPLITTUNNELINGCONTROLLER_H
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "configurators/configurator_base.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
113
client/core/controllers/vpnConnectionController.cpp
Normal file
113
client/core/controllers/vpnConnectionController.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "vpnConnectionController.h"
|
||||
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "core/controllers/vpnConfigurationController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "settings.h"
|
||||
#include "logger.h"
|
||||
#include "utilities.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("VpnConnectionController");
|
||||
}
|
||||
|
||||
VpnConnectionController::VpnConnectionController(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QObject(parent), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
QFuture<QJsonObject> VpnConnectionController::prepareVpnConfiguration(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container, containerConfig]() -> QJsonObject {
|
||||
logger.info() << "Preparing VPN configuration for container" << ContainerProps::containerToString(container);
|
||||
|
||||
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
|
||||
VpnConfigurationsController vpnConfigurationController(m_settings, serverController);
|
||||
|
||||
// TODO: Extract DNS pair from serverConfig
|
||||
QPair<QString, QString> dns = qMakePair(QString(), QString());
|
||||
|
||||
auto vpnConfiguration = vpnConfigurationController.createVpnConfiguration(dns,
|
||||
serverConfig->toJson(),
|
||||
containerConfig,
|
||||
container);
|
||||
|
||||
emit configurationPrepared(vpnConfiguration);
|
||||
return vpnConfiguration;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<bool> VpnConnectionController::validateConnection(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container]() -> bool {
|
||||
logger.info() << "Validating connection for container" << ContainerProps::containerToString(container);
|
||||
|
||||
if (!isServerSupported(serverConfig, container)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Implement connection validation logic
|
||||
// Check if container is supported by current platform
|
||||
// Check if server is reachable
|
||||
// Check if container is properly configured
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> VpnConnectionController::establishConnection(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &vpnConfiguration)
|
||||
{
|
||||
return QtConcurrent::run([this, serverConfig, container, vpnConfiguration]() -> ErrorCode {
|
||||
logger.info() << "Establishing connection for container" << ContainerProps::containerToString(container);
|
||||
|
||||
// TODO: Implement connection establishment logic
|
||||
// This will delegate to VpnConnection or similar
|
||||
|
||||
emit connectionEstablished();
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
QFuture<ErrorCode> VpnConnectionController::terminateConnection()
|
||||
{
|
||||
return QtConcurrent::run([this]() -> ErrorCode {
|
||||
logger.info() << "Terminating VPN connection";
|
||||
|
||||
// TODO: Implement connection termination logic
|
||||
// This will delegate to VpnConnection or similar
|
||||
|
||||
emit connectionTerminated();
|
||||
return ErrorCode::NoError;
|
||||
});
|
||||
}
|
||||
|
||||
bool VpnConnectionController::isServerSupported(const QSharedPointer<ServerConfig> &serverConfig, DockerContainer container) const
|
||||
{
|
||||
// TODO: Implement server support validation
|
||||
// Check if container is supported by current platform
|
||||
Q_UNUSED(serverConfig)
|
||||
|
||||
return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||
}
|
||||
|
||||
QJsonObject VpnConnectionController::createVpnConfiguration(const QPair<QString, QString> &dns,
|
||||
const QJsonObject &serverConfig,
|
||||
const QJsonObject &containerConfig,
|
||||
DockerContainer container)
|
||||
{
|
||||
// TODO: Implement VPN configuration creation logic
|
||||
// This will be moved from existing code
|
||||
Q_UNUSED(dns)
|
||||
Q_UNUSED(serverConfig)
|
||||
Q_UNUSED(containerConfig)
|
||||
Q_UNUSED(container)
|
||||
|
||||
return QJsonObject();
|
||||
}
|
||||
57
client/core/controllers/vpnConnectionController.h
Normal file
57
client/core/controllers/vpnConnectionController.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef VPNCONNECTIONCONTROLLER_H
|
||||
#define VPNCONNECTIONCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFuture>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/servers/serverConfig.h"
|
||||
#include "protocols/vpnprotocol.h"
|
||||
|
||||
class Settings;
|
||||
class ServerController;
|
||||
class VpnConfigurationsController;
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class VpnConnectionController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VpnConnectionController(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
|
||||
QFuture<QJsonObject> prepareVpnConfiguration(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &containerConfig);
|
||||
|
||||
QFuture<bool> validateConnection(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container);
|
||||
|
||||
QFuture<ErrorCode> establishConnection(const QSharedPointer<ServerConfig> &serverConfig,
|
||||
DockerContainer container,
|
||||
const QJsonObject &vpnConfiguration);
|
||||
|
||||
QFuture<ErrorCode> terminateConnection();
|
||||
|
||||
bool isServerSupported(const QSharedPointer<ServerConfig> &serverConfig, DockerContainer container) const;
|
||||
|
||||
signals:
|
||||
void configurationPrepared(const QJsonObject &vpnConfiguration);
|
||||
void connectionEstablished();
|
||||
void connectionTerminated();
|
||||
void connectionError(ErrorCode errorCode);
|
||||
void connectionProgress(const QString &message);
|
||||
|
||||
private:
|
||||
QJsonObject createVpnConfiguration(const QPair<QString, QString> &dns,
|
||||
const QJsonObject &serverConfig,
|
||||
const QJsonObject &containerConfig,
|
||||
DockerContainer container);
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // VPNCONNECTIONCONTROLLER_H
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "apiV1ServerConfig.h"
|
||||
#include "apiV2ServerConfig.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <QLatin1String>
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
namespace amnezia {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define SERVER_DEFS_H
|
||||
|
||||
#include <QObject>
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
namespace amnezia {
|
||||
namespace server {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "openvpnovercloakprotocol.h"
|
||||
|
||||
#include "utilities.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "logger.h"
|
||||
#include "utilities.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QJsonDocument>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "openvpnprotocol.h"
|
||||
#include "QProcess"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
class ShadowSocksVpnProtocol : public OpenVpnProtocol
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "QProcess"
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "openvpnprotocol.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "core/networkUtilities.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "secure_qsettings.h"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "configurators/wireguard_configurator.h"
|
||||
#include "core/api/apiDefs.h"
|
||||
#include "core/api/apiUtils.h"
|
||||
#include "core/controllers/gatewayController.h"
|
||||
#include "core/controllers/api/gatewayController.h"
|
||||
#include "core/qrCodeUtils.h"
|
||||
#include "ui/controllers/systemController.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "core/api/apiDefs.h"
|
||||
#include "core/api/apiUtils.h"
|
||||
#include "core/controllers/gatewayController.h"
|
||||
#include "core/controllers/api/gatewayController.h"
|
||||
|
||||
ApiPremV1MigrationController::ApiPremV1MigrationController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/api/apiUtils.h"
|
||||
#include "core/controllers/gatewayController.h"
|
||||
#include "core/controllers/api/gatewayController.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CONNECTIONCONTROLLER_H
|
||||
|
||||
#include "protocols/vpnprotocol.h"
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/models/selfhosted/clientManagementModel.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
#include "vpnconnection.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/models/selfhosted/clientManagementModel.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "core/api/apiUtils.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/controllers/vpnConfigurationController.h"
|
||||
#include "core/models/servers/selfHostedServerConfig.h"
|
||||
#include "core/networkUtilities.h"
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/models/selfhosted/clientManagementModel.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/protocols_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
@@ -1,9 +1,23 @@
|
||||
#include "allowed_dns_model.h"
|
||||
#include "core/controllers/dnsController.h"
|
||||
|
||||
AllowedDnsModel::AllowedDnsModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QAbstractListModel(parent), m_settings(settings)
|
||||
AllowedDnsModel::AllowedDnsModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<DnsController> dnsController,
|
||||
QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_settings(settings),
|
||||
m_dnsController(dnsController)
|
||||
{
|
||||
fillDnsServers();
|
||||
// Connect to controller signals
|
||||
connect(m_dnsController.data(), &DnsController::dnsAdded,
|
||||
this, &AllowedDnsModel::onDnsAdded);
|
||||
connect(m_dnsController.data(), &DnsController::dnsListAdded,
|
||||
this, &AllowedDnsModel::onDnsListAdded);
|
||||
connect(m_dnsController.data(), &DnsController::dnsRemoved,
|
||||
this, &AllowedDnsModel::onDnsRemoved);
|
||||
|
||||
// Initialize data
|
||||
refreshData();
|
||||
}
|
||||
|
||||
int AllowedDnsModel::rowCount(const QModelIndex &parent) const
|
||||
@@ -27,33 +41,12 @@ QVariant AllowedDnsModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
bool AllowedDnsModel::addDns(const QString &ip)
|
||||
{
|
||||
if (m_dnsServers.contains(ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
m_dnsServers.append(ip);
|
||||
m_settings->setAllowedDnsServers(m_dnsServers);
|
||||
endInsertRows();
|
||||
return true;
|
||||
return m_dnsController->addDns(ip);
|
||||
}
|
||||
|
||||
void AllowedDnsModel::addDnsList(const QStringList &dnsServers, bool replaceExisting)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
if (replaceExisting) {
|
||||
m_dnsServers.clear();
|
||||
}
|
||||
|
||||
for (const QString &ip : dnsServers) {
|
||||
if (!m_dnsServers.contains(ip)) {
|
||||
m_dnsServers.append(ip);
|
||||
}
|
||||
}
|
||||
|
||||
m_settings->setAllowedDnsServers(m_dnsServers);
|
||||
endResetModel();
|
||||
m_dnsController->addDnsList(dnsServers, replaceExisting);
|
||||
}
|
||||
|
||||
void AllowedDnsModel::removeDns(QModelIndex index)
|
||||
@@ -62,10 +55,8 @@ void AllowedDnsModel::removeDns(QModelIndex index)
|
||||
return;
|
||||
}
|
||||
|
||||
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
||||
m_dnsServers.removeAt(index.row());
|
||||
m_settings->setAllowedDnsServers(m_dnsServers);
|
||||
endRemoveRows();
|
||||
const QString &ip = m_dnsServers.at(index.row());
|
||||
m_dnsController->removeDns(ip);
|
||||
}
|
||||
|
||||
QStringList AllowedDnsModel::getCurrentDnsServers()
|
||||
@@ -80,7 +71,31 @@ QHash<int, QByteArray> AllowedDnsModel::roleNames() const
|
||||
return roles;
|
||||
}
|
||||
|
||||
void AllowedDnsModel::fillDnsServers()
|
||||
void AllowedDnsModel::onDnsAdded(const QString &ip)
|
||||
{
|
||||
m_dnsServers = m_settings->allowedDnsServers();
|
||||
Q_UNUSED(ip)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void AllowedDnsModel::onDnsListAdded(const QStringList &dnsServers)
|
||||
{
|
||||
Q_UNUSED(dnsServers)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void AllowedDnsModel::onDnsRemoved(const QString &ip)
|
||||
{
|
||||
Q_UNUSED(ip)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void AllowedDnsModel::refreshData()
|
||||
{
|
||||
m_dnsServers = m_dnsController->getAllowedDnsServers();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <QAbstractListModel>
|
||||
#include "settings.h"
|
||||
|
||||
class DnsController;
|
||||
|
||||
class AllowedDnsModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -13,7 +15,9 @@ public:
|
||||
IpRole = Qt::UserRole + 1
|
||||
};
|
||||
|
||||
explicit AllowedDnsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
explicit AllowedDnsModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<DnsController> dnsController,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
@@ -27,10 +31,16 @@ public slots:
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private slots:
|
||||
void onDnsAdded(const QString &ip);
|
||||
void onDnsListAdded(const QStringList &dnsServers);
|
||||
void onDnsRemoved(const QString &ip);
|
||||
|
||||
private:
|
||||
void fillDnsServers();
|
||||
void refreshData();
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
QSharedPointer<DnsController> m_dnsController;
|
||||
QStringList m_dnsServers;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
#include "appSplitTunnelingModel.h"
|
||||
#include "core/controllers/splitTunnelingController.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
AppSplitTunnelingModel::AppSplitTunnelingModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QAbstractListModel(parent), m_settings(settings)
|
||||
AppSplitTunnelingModel::AppSplitTunnelingModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<SplitTunnelingController> splitTunnelingController,
|
||||
QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_settings(settings),
|
||||
m_splitTunnelingController(splitTunnelingController)
|
||||
{
|
||||
m_isSplitTunnelingEnabled = m_settings->isAppsSplitTunnelingEnabled();
|
||||
m_currentRouteMode = m_settings->getAppsRouteMode();
|
||||
if (m_currentRouteMode == Settings::VpnAllApps) { // for old split tunneling configs
|
||||
m_settings->setAppsRouteMode(static_cast<Settings::AppsRouteMode>(Settings::VpnAllExceptApps));
|
||||
m_currentRouteMode = Settings::VpnAllExceptApps;
|
||||
}
|
||||
m_apps = m_settings->getVpnApps(m_currentRouteMode);
|
||||
// Connect to controller signals
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::appAdded,
|
||||
this, &AppSplitTunnelingModel::onAppAdded);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::appRemoved,
|
||||
this, &AppSplitTunnelingModel::onAppRemoved);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::appsRouteModelChanged,
|
||||
this, &AppSplitTunnelingModel::onAppsRouteModelChanged);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::appsSplitTunnelingToggled,
|
||||
this, &AppSplitTunnelingModel::onAppsSplitTunnelingToggled);
|
||||
|
||||
// Initialize data
|
||||
refreshData();
|
||||
}
|
||||
|
||||
int AppSplitTunnelingModel::rowCount(const QModelIndex &parent) const
|
||||
@@ -39,51 +49,37 @@ QVariant AppSplitTunnelingModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
bool AppSplitTunnelingModel::addApp(const InstalledAppInfo &appInfo)
|
||||
{
|
||||
if (m_apps.contains(appInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
m_apps.append(appInfo);
|
||||
m_settings->setVpnApps(m_currentRouteMode, m_apps);
|
||||
endInsertRows();
|
||||
|
||||
return true;
|
||||
return m_splitTunnelingController->addApp(appInfo);
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::removeApp(QModelIndex index)
|
||||
{
|
||||
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
||||
m_apps.removeAt(index.row());
|
||||
m_settings->setVpnApps(m_currentRouteMode, m_apps);
|
||||
endRemoveRows();
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_apps.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const InstalledAppInfo &appInfo = m_apps.at(index.row());
|
||||
m_splitTunnelingController->removeApp(appInfo);
|
||||
}
|
||||
|
||||
int AppSplitTunnelingModel::getRouteMode()
|
||||
{
|
||||
return m_currentRouteMode;
|
||||
return static_cast<int>(m_splitTunnelingController->getAppsRouteMode());
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::setRouteMode(int routeMode)
|
||||
{
|
||||
beginResetModel();
|
||||
m_settings->setAppsRouteMode(static_cast<Settings::AppsRouteMode>(routeMode));
|
||||
m_currentRouteMode = m_settings->getAppsRouteMode();
|
||||
m_apps = m_settings->getVpnApps(m_currentRouteMode);
|
||||
endResetModel();
|
||||
emit routeModeChanged();
|
||||
m_splitTunnelingController->setAppsRouteMode(static_cast<Settings::AppsRouteMode>(routeMode));
|
||||
}
|
||||
|
||||
bool AppSplitTunnelingModel::isSplitTunnelingEnabled()
|
||||
{
|
||||
return m_isSplitTunnelingEnabled;
|
||||
return m_splitTunnelingController->isAppsSplitTunnelingEnabled();
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::toggleSplitTunneling(bool enabled)
|
||||
{
|
||||
m_settings->setAppsSplitTunnelingEnabled(enabled);
|
||||
m_isSplitTunnelingEnabled = enabled;
|
||||
emit splitTunnelingToggled();
|
||||
m_splitTunnelingController->setAppsSplitTunnelingEnabled(enabled);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> AppSplitTunnelingModel::roleNames() const
|
||||
@@ -92,3 +88,37 @@ QHash<int, QByteArray> AppSplitTunnelingModel::roleNames() const
|
||||
roles[AppPathRole] = "appPath";
|
||||
return roles;
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::onAppAdded(const InstalledAppInfo &appInfo)
|
||||
{
|
||||
Q_UNUSED(appInfo)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::onAppRemoved(const InstalledAppInfo &appInfo)
|
||||
{
|
||||
Q_UNUSED(appInfo)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::onAppsRouteModelChanged()
|
||||
{
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
emit routeModeChanged();
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::onAppsSplitTunnelingToggled()
|
||||
{
|
||||
emit splitTunnelingToggled();
|
||||
}
|
||||
|
||||
void AppSplitTunnelingModel::refreshData()
|
||||
{
|
||||
m_apps = m_splitTunnelingController->getApps(m_splitTunnelingController->getAppsRouteMode());
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "settings.h"
|
||||
#include "core/defs.h"
|
||||
|
||||
class SplitTunnelingController;
|
||||
|
||||
class AppSplitTunnelingModel: public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -17,13 +19,14 @@ public:
|
||||
PackageAppIconRole
|
||||
};
|
||||
|
||||
explicit AppSplitTunnelingModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
explicit AppSplitTunnelingModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<SplitTunnelingController> splitTunnelingController,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
Q_PROPERTY(int routeMode READ getRouteMode WRITE setRouteMode NOTIFY routeModeChanged)
|
||||
Q_PROPERTY(int routeMode READ getRouteMode NOTIFY routeModeChanged)
|
||||
Q_PROPERTY(bool isTunnelingEnabled READ isSplitTunnelingEnabled NOTIFY splitTunnelingToggled)
|
||||
|
||||
public slots:
|
||||
@@ -43,11 +46,17 @@ signals:
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
private slots:
|
||||
void onAppAdded(const InstalledAppInfo &appInfo);
|
||||
void onAppRemoved(const InstalledAppInfo &appInfo);
|
||||
void onAppsRouteModelChanged();
|
||||
void onAppsSplitTunnelingToggled();
|
||||
|
||||
bool m_isSplitTunnelingEnabled;
|
||||
Settings::AppsRouteMode m_currentRouteMode;
|
||||
private:
|
||||
void refreshData();
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
QSharedPointer<SplitTunnelingController> m_splitTunnelingController;
|
||||
|
||||
QVector<InstalledAppInfo> m_apps;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/containers/containerConfig.h"
|
||||
|
||||
class ContainersModel : public QAbstractListModel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
|
||||
namespace AwgConstant
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
||||
|
||||
class CloakConfigModel : public QAbstractListModel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
class Ikev2ConfigModel : public QAbstractListModel
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
||||
|
||||
class OpenVpnConfigModel : public QAbstractListModel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
||||
|
||||
class ShadowSocksConfigModel : public QAbstractListModel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/wireguardProtocolConfig.h"
|
||||
|
||||
class WireGuardConfigModel : public QAbstractListModel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
||||
|
||||
class XrayConfigModel : public QAbstractListModel
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "settings.h"
|
||||
|
||||
class ClientManagementModel : public QAbstractListModel
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "servers_model.h"
|
||||
|
||||
#include "core/api/apiDefs.h"
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/models/servers/apiV1ServerConfig.h"
|
||||
#include "core/models/servers/apiV2ServerConfig.h"
|
||||
#include "core/models/servers/selfHostedServerConfig.h"
|
||||
@@ -34,7 +34,11 @@ namespace
|
||||
|
||||
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
|
||||
{
|
||||
m_isAmneziaDnsEnabled = m_settings->useAmneziaDns();
|
||||
m_serverConfigController = std::make_shared<SelfhostedConfigController>(settings);
|
||||
m_installationController = std::make_shared<InstallationController>(settings);
|
||||
m_settingsConfigController = std::make_shared<SettingsConfigController>(settings);
|
||||
|
||||
m_isAmneziaDnsEnabled = m_settingsConfigController->isAmneziaDnsEnabled();
|
||||
|
||||
connect(this, &ServersModel::defaultServerIndexChanged, this, &ServersModel::defaultServerNameChanged);
|
||||
|
||||
@@ -45,6 +49,13 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
updateDefaultServerContainersModel();
|
||||
});
|
||||
|
||||
// Subscribe to controller signals
|
||||
connect(m_serverConfigController.get(), &SelfhostedConfigController::defaultServerChanged,
|
||||
this, [this](int serverIndex) {
|
||||
m_defaultServerIndex = serverIndex;
|
||||
emit defaultServerIndexChanged(m_defaultServerIndex);
|
||||
});
|
||||
|
||||
connect(this, &ServersModel::processedServerIndexChanged, this, &ServersModel::processedServerChanged);
|
||||
connect(this, &ServersModel::dataChanged, this, &ServersModel::processedServerChanged);
|
||||
}
|
||||
@@ -169,9 +180,7 @@ void ServersModel::resetModel()
|
||||
|
||||
void ServersModel::setDefaultServerIndex(const int index)
|
||||
{
|
||||
m_settings->setDefaultServer(index);
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
emit defaultServerIndexChanged(m_defaultServerIndex);
|
||||
m_serverConfigController->setDefaultServer(index);
|
||||
}
|
||||
|
||||
const int ServersModel::getDefaultServerIndex()
|
||||
@@ -305,19 +314,21 @@ bool ServersModel::isDefaultServerHasWriteAccess()
|
||||
|
||||
void ServersModel::addServer(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
m_serverConfigController->addServer(serverConfig);
|
||||
|
||||
beginResetModel();
|
||||
m_settings->addServer(serverConfig->toJson());
|
||||
m_servers1.clear();
|
||||
auto servers = m_settings->serversArray();
|
||||
for (auto server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(serverConfig);
|
||||
auto config = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(config);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ServersModel::editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex)
|
||||
{
|
||||
m_settings->editServer(serverIndex, serverConfig->toJson());
|
||||
m_serverConfigController->editServer(serverConfig, serverIndex);
|
||||
m_servers1[serverIndex] = serverConfig;
|
||||
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
||||
|
||||
@@ -339,12 +350,14 @@ void ServersModel::removeProcessedServer()
|
||||
|
||||
void ServersModel::removeServer(const int serverIndex)
|
||||
{
|
||||
m_serverConfigController->removeServer(serverIndex);
|
||||
|
||||
beginResetModel();
|
||||
m_settings->removeServer(serverIndex);
|
||||
m_servers1.clear();
|
||||
auto servers = m_settings->serversArray();
|
||||
for (auto server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(serverConfig);
|
||||
auto config = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(config);
|
||||
}
|
||||
|
||||
if (m_settings->defaultServerIndex() == serverIndex) {
|
||||
@@ -432,10 +445,13 @@ const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||
|
||||
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
||||
{
|
||||
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
||||
|
||||
Q_UNUSED(serverController)
|
||||
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
auto future = m_installationController->removeAllContainers(serverConfig);
|
||||
|
||||
ErrorCode errorCode = future.result();
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
serverConfig->containerConfigs.clear();
|
||||
editServer(serverConfig, m_processedServerIndex);
|
||||
}
|
||||
@@ -444,20 +460,24 @@ ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerControlle
|
||||
|
||||
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
||||
{
|
||||
ErrorCode errorCode = serverController->rebootServer(m_settings->serverCredentials(m_processedServerIndex));
|
||||
return errorCode;
|
||||
Q_UNUSED(serverController)
|
||||
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
auto future = m_installationController->rebootServer(serverConfig);
|
||||
return future.result();
|
||||
}
|
||||
|
||||
ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &serverController, const int containerIndex)
|
||||
{
|
||||
|
||||
auto credentials = m_settings->serverCredentials(m_processedServerIndex);
|
||||
Q_UNUSED(serverController)
|
||||
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
auto dockerContainer = static_cast<DockerContainer>(containerIndex);
|
||||
|
||||
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
||||
auto future = m_installationController->removeContainer(serverConfig, dockerContainer);
|
||||
ErrorCode errorCode = future.result();
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
serverConfig->containerConfigs.remove(ContainerProps::containerToString(dockerContainer));
|
||||
|
||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
@@ -550,30 +570,19 @@ QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
||||
|
||||
void ServersModel::toggleAmneziaDns(bool enabled)
|
||||
{
|
||||
m_settingsConfigController->toggleAmneziaDns(enabled);
|
||||
m_isAmneziaDnsEnabled = enabled;
|
||||
emit defaultServerDescriptionChanged();
|
||||
}
|
||||
|
||||
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||
{
|
||||
for (const auto &server : std::as_const(m_servers1)) {
|
||||
if (static_cast<quint16>(server->crc) == crc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return m_serverConfigController->isServerFromApiAlreadyExists(crc);
|
||||
}
|
||||
|
||||
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
||||
{
|
||||
for (const auto &serverConfig : std::as_const(m_servers1)) {
|
||||
const auto apiV2ServerConfig = qSharedPointerCast<ApiV2ServerConfig>(serverConfig);
|
||||
if (apiV2ServerConfig->apiConfig.userCountryCode == userCountryCode && apiV2ServerConfig->apiConfig.serviceType == serviceType
|
||||
&& apiV2ServerConfig->apiConfig.serviceProtocol == serviceProtocol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return m_serverConfigController->isServerFromApiAlreadyExists(userCountryCode, serviceType, serviceProtocol);
|
||||
}
|
||||
|
||||
bool ServersModel::serverHasInstalledContainers(const int serverIndex) const
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include "core/controllers/selfhosted/selfhostedConfigController.h"
|
||||
#include "core/controllers/selfhosted/installationController.h"
|
||||
#include "core/controllers/settingsConfigController.h"
|
||||
#include "core/models/servers/serverConfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
@@ -157,11 +160,14 @@ private:
|
||||
QVector<QSharedPointer<ServerConfig>> m_servers1;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
std::shared_ptr<SelfhostedConfigController> m_serverConfigController;
|
||||
std::shared_ptr<InstallationController> m_installationController;
|
||||
std::shared_ptr<SettingsConfigController> m_settingsConfigController;
|
||||
|
||||
int m_defaultServerIndex;
|
||||
int m_processedServerIndex;
|
||||
|
||||
bool m_isAmneziaDnsEnabled = m_settings->useAmneziaDns();
|
||||
bool m_isAmneziaDnsEnabled;
|
||||
};
|
||||
|
||||
#endif // SERVERSMODEL_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
class SftpConfigModel : public QAbstractListModel
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containers_defs.h"
|
||||
|
||||
class Socks5ProxyConfigModel : public QAbstractListModel
|
||||
{
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
#include "sites_model.h"
|
||||
#include "core/controllers/splitTunnelingController.h"
|
||||
|
||||
SitesModel::SitesModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: QAbstractListModel(parent), m_settings(settings)
|
||||
SitesModel::SitesModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<SplitTunnelingController> splitTunnelingController,
|
||||
QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_settings(settings),
|
||||
m_splitTunnelingController(splitTunnelingController)
|
||||
{
|
||||
m_isSplitTunnelingEnabled = m_settings->isSitesSplitTunnelingEnabled();
|
||||
m_currentRouteMode = m_settings->routeMode();
|
||||
if (m_currentRouteMode == Settings::VpnAllSites) { // for old split tunneling configs
|
||||
m_settings->setRouteMode(static_cast<Settings::RouteMode>(Settings::VpnOnlyForwardSites));
|
||||
m_currentRouteMode = Settings::VpnOnlyForwardSites;
|
||||
}
|
||||
fillSites();
|
||||
// Connect to controller signals
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::siteAdded,
|
||||
this, &SitesModel::onSiteAdded);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::siteRemoved,
|
||||
this, &SitesModel::onSiteRemoved);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::sitesRouteModelChanged,
|
||||
this, &SitesModel::onSitesRouteModelChanged);
|
||||
connect(m_splitTunnelingController.data(), &SplitTunnelingController::sitesSplitTunnelingToggled,
|
||||
this, &SitesModel::onSitesSplitTunnelingToggled);
|
||||
|
||||
// Initialize data
|
||||
refreshData();
|
||||
}
|
||||
|
||||
int SitesModel::rowCount(const QModelIndex &parent) const
|
||||
@@ -42,72 +52,42 @@ QVariant SitesModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
bool SitesModel::addSite(const QString &hostname, const QString &ip)
|
||||
{
|
||||
if (!m_settings->addVpnSite(m_currentRouteMode, hostname, ip)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_sites.size(); i++) {
|
||||
if (m_sites[i].first == hostname && (m_sites[i].second.isEmpty() && !ip.isEmpty())) {
|
||||
m_sites[i].second = ip;
|
||||
QModelIndex index = createIndex(i, i);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
} else if (m_sites[i].first == hostname && (m_sites[i].second == ip)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
m_sites.append(qMakePair(hostname, ip));
|
||||
endInsertRows();
|
||||
return true;
|
||||
return m_splitTunnelingController->addSite(hostname, ip);
|
||||
}
|
||||
|
||||
void SitesModel::addSites(const QMap<QString, QString> &sites, bool replaceExisting)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
if (replaceExisting) {
|
||||
m_settings->removeAllVpnSites(m_currentRouteMode);
|
||||
}
|
||||
m_settings->addVpnSites(m_currentRouteMode, sites);
|
||||
fillSites();
|
||||
|
||||
endResetModel();
|
||||
m_splitTunnelingController->addSites(sites, replaceExisting);
|
||||
}
|
||||
|
||||
void SitesModel::removeSite(QModelIndex index)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_sites.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto hostname = m_sites.at(index.row()).first;
|
||||
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
||||
m_settings->removeVpnSite(m_currentRouteMode, hostname);
|
||||
m_sites.removeAt(index.row());
|
||||
endRemoveRows();
|
||||
m_splitTunnelingController->removeSite(hostname);
|
||||
}
|
||||
|
||||
int SitesModel::getRouteMode()
|
||||
{
|
||||
return m_currentRouteMode;
|
||||
return static_cast<int>(m_splitTunnelingController->getSitesRouteMode());
|
||||
}
|
||||
|
||||
void SitesModel::setRouteMode(int routeMode)
|
||||
{
|
||||
beginResetModel();
|
||||
m_settings->setRouteMode(static_cast<Settings::RouteMode>(routeMode));
|
||||
m_currentRouteMode = m_settings->routeMode();
|
||||
fillSites();
|
||||
endResetModel();
|
||||
emit routeModeChanged();
|
||||
m_splitTunnelingController->setSitesRouteMode(static_cast<Settings::RouteMode>(routeMode));
|
||||
}
|
||||
|
||||
bool SitesModel::isSplitTunnelingEnabled()
|
||||
{
|
||||
return m_isSplitTunnelingEnabled;
|
||||
return m_splitTunnelingController->isSitesSplitTunnelingEnabled();
|
||||
}
|
||||
|
||||
void SitesModel::toggleSplitTunneling(bool enabled)
|
||||
{
|
||||
m_settings->setSitesSplitTunnelingEnabled(enabled);
|
||||
m_isSplitTunnelingEnabled = enabled;
|
||||
emit splitTunnelingToggled();
|
||||
m_splitTunnelingController->setSitesSplitTunnelingEnabled(enabled);
|
||||
}
|
||||
|
||||
QVector<QPair<QString, QString> > SitesModel::getCurrentSites()
|
||||
@@ -123,13 +103,37 @@ QHash<int, QByteArray> SitesModel::roleNames() const
|
||||
return roles;
|
||||
}
|
||||
|
||||
void SitesModel::fillSites()
|
||||
void SitesModel::onSiteAdded(const QString &hostname, const QString &ip)
|
||||
{
|
||||
m_sites.clear();
|
||||
const QVariantMap &sites = m_settings->vpnSites(m_currentRouteMode);
|
||||
auto i = sites.constBegin();
|
||||
while (i != sites.constEnd()) {
|
||||
m_sites.append(qMakePair(i.key(), i.value().toString()));
|
||||
++i;
|
||||
}
|
||||
Q_UNUSED(hostname)
|
||||
Q_UNUSED(ip)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SitesModel::onSiteRemoved(const QString &hostname)
|
||||
{
|
||||
Q_UNUSED(hostname)
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SitesModel::onSitesRouteModelChanged()
|
||||
{
|
||||
beginResetModel();
|
||||
refreshData();
|
||||
endResetModel();
|
||||
emit routeModeChanged();
|
||||
}
|
||||
|
||||
void SitesModel::onSitesSplitTunnelingToggled()
|
||||
{
|
||||
emit splitTunnelingToggled();
|
||||
}
|
||||
|
||||
void SitesModel::refreshData()
|
||||
{
|
||||
m_sites = m_splitTunnelingController->getSites(m_splitTunnelingController->getSitesRouteMode());
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
class SplitTunnelingController;
|
||||
|
||||
class SitesModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -15,13 +17,14 @@ public:
|
||||
IpRole
|
||||
};
|
||||
|
||||
explicit SitesModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
explicit SitesModel(std::shared_ptr<Settings> settings,
|
||||
QSharedPointer<SplitTunnelingController> splitTunnelingController,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
Q_PROPERTY(int routeMode READ getRouteMode WRITE setRouteMode NOTIFY routeModeChanged)
|
||||
Q_PROPERTY(int routeMode READ getRouteMode NOTIFY routeModeChanged)
|
||||
Q_PROPERTY(bool isTunnelingEnabled READ isSplitTunnelingEnabled NOTIFY splitTunnelingToggled)
|
||||
|
||||
public slots:
|
||||
@@ -44,13 +47,17 @@ signals:
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private slots:
|
||||
void onSiteAdded(const QString &hostname, const QString &ip);
|
||||
void onSiteRemoved(const QString &hostname);
|
||||
void onSitesRouteModelChanged();
|
||||
void onSitesSplitTunnelingToggled();
|
||||
|
||||
private:
|
||||
void fillSites();
|
||||
void refreshData();
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
||||
bool m_isSplitTunnelingEnabled;
|
||||
Settings::RouteMode m_currentRouteMode;
|
||||
QSharedPointer<SplitTunnelingController> m_splitTunnelingController;
|
||||
|
||||
QVector<QPair<QString, QString>> m_sites;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QHostInfo>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/controllers/serverController.h"
|
||||
#include "core/controllers/selfhosted/serverController.h"
|
||||
#include <configurators/cloak_configurator.h>
|
||||
#include <configurators/openvpn_configurator.h>
|
||||
#include <configurators/shadowsocks_configurator.h>
|
||||
|
||||
Reference in New Issue
Block a user