refactoring: replaced part of the code to work with new config classes
This commit is contained in:
parent
2d22a74b22
commit
65f60ab922
22 changed files with 637 additions and 595 deletions
|
@ -2,8 +2,7 @@
|
|||
|
||||
#include <QJsonArray>
|
||||
|
||||
ContainersModel::ContainersModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
ContainersModel::ContainersModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,7 +36,7 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
|||
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
||||
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
||||
case EasySetupOrderRole: return ContainerProps::easySetupOrder(container);
|
||||
case IsInstalledRole: return m_containers.contains(container);
|
||||
case IsInstalledRole: return m_containerConfigs.contains(ContainerProps::containerToString(container));
|
||||
case IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_processedContainerIndex);
|
||||
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||
case IsShareableRole: return ContainerProps::isShareable(container);
|
||||
|
@ -53,14 +52,10 @@ QVariant ContainersModel::data(const int index, int role) const
|
|||
return data(modelIndex, role);
|
||||
}
|
||||
|
||||
void ContainersModel::updateModel(const QJsonArray &containers)
|
||||
void ContainersModel::updateModel(const QMap<QString, ContainerConfig> &containerConfigs)
|
||||
{
|
||||
beginResetModel();
|
||||
m_containers.clear();
|
||||
for (const QJsonValue &val : containers) {
|
||||
m_containers.insert(ContainerProps::containerFromString(val.toObject().value(config_key::container).toString()),
|
||||
val.toObject());
|
||||
}
|
||||
m_containerConfigs = containerConfigs;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
@ -96,8 +91,8 @@ bool ContainersModel::isServiceContainer(const int containerIndex)
|
|||
|
||||
bool ContainersModel::hasInstalledServices()
|
||||
{
|
||||
for (const auto &container : m_containers.keys()) {
|
||||
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
||||
for (const auto &containerName : m_containerConfigs.keys()) {
|
||||
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Other) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -106,8 +101,8 @@ bool ContainersModel::hasInstalledServices()
|
|||
|
||||
bool ContainersModel::hasInstalledProtocols()
|
||||
{
|
||||
for (const auto &container : m_containers.keys()) {
|
||||
if (ContainerProps::containerService(container) == ServiceType::Vpn) {
|
||||
for (const auto &containerName : m_containerConfigs.keys()) {
|
||||
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Vpn) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/models/containers/containerConfig.h"
|
||||
|
||||
class ContainersModel : public QAbstractListModel
|
||||
{
|
||||
|
@ -42,7 +41,7 @@ public:
|
|||
QVariant data(const int index, int role) const;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonArray &containers);
|
||||
void updateModel(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||
|
||||
void setProcessedContainerIndex(int containerIndex);
|
||||
int getProcessedContainerIndex();
|
||||
|
@ -64,7 +63,7 @@ signals:
|
|||
void containersModelUpdated();
|
||||
|
||||
private:
|
||||
QMap<DockerContainer, QJsonObject> m_containers;
|
||||
QMap<QString, ContainerConfig> m_containerConfigs;
|
||||
|
||||
int m_processedContainerIndex;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
AwgConfigModel::AwgConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||
AwgConfigModel::AwgConfigModel(QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_newAwgProtocolConfig(ProtocolProps::protoToString(Proto::Awg)),
|
||||
m_oldAwgProtocolConfig(ProtocolProps::protoToString(Proto::Awg))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -21,30 +24,42 @@ bool AwgConfigModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::SubnetAddressRole: m_serverProtocolConfig.insert(config_key::subnet_address, value.toString()); break;
|
||||
case Roles::PortRole: m_serverProtocolConfig.insert(config_key::port, value.toString()); break;
|
||||
case Roles::SubnetAddressRole: m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress = value.toString(); break;
|
||||
case Roles::PortRole: m_newAwgProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
||||
|
||||
case Roles::ClientMtuRole: m_clientProtocolConfig.insert(config_key::mtu, value.toString()); break;
|
||||
case Roles::ClientJunkPacketCountRole: m_clientProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
||||
case Roles::ClientJunkPacketMinSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
||||
case Roles::ClientJunkPacketMaxSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
||||
|
||||
case Roles::ServerJunkPacketCountRole: m_serverProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
||||
case Roles::ServerJunkPacketMinSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
||||
case Roles::ServerJunkPacketMaxSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
||||
case Roles::ServerInitPacketJunkSizeRole: m_serverProtocolConfig.insert(config_key::initPacketJunkSize, value.toString()); break;
|
||||
case Roles::ServerResponsePacketJunkSizeRole:
|
||||
m_serverProtocolConfig.insert(config_key::responsePacketJunkSize, value.toString());
|
||||
case Roles::ClientMtuRole: m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu = value.toString(); break;
|
||||
case Roles::ClientJunkPacketCountRole: m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
||||
case Roles::ClientJunkPacketMinSizeRole:
|
||||
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize = value.toString();
|
||||
break;
|
||||
case Roles::ClientJunkPacketMaxSizeRole:
|
||||
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize = value.toString();
|
||||
break;
|
||||
|
||||
case Roles::ServerJunkPacketCountRole: m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
||||
case Roles::ServerJunkPacketMinSizeRole:
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMinSize = value.toString();
|
||||
break;
|
||||
case Roles::ServerJunkPacketMaxSizeRole:
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMaxSize = value.toString();
|
||||
break;
|
||||
case Roles::ServerInitPacketJunkSizeRole:
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketJunkSize = value.toString();
|
||||
break;
|
||||
case Roles::ServerResponsePacketJunkSizeRole:
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketJunkSize = value.toString();
|
||||
break;
|
||||
case Roles::ServerInitPacketMagicHeaderRole:
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketMagicHeader = value.toString();
|
||||
break;
|
||||
case Roles::ServerInitPacketMagicHeaderRole: m_serverProtocolConfig.insert(config_key::initPacketMagicHeader, value.toString()); break;
|
||||
case Roles::ServerResponsePacketMagicHeaderRole:
|
||||
m_serverProtocolConfig.insert(config_key::responsePacketMagicHeader, value.toString());
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader = value.toString();
|
||||
break;
|
||||
case Roles::ServerUnderloadPacketMagicHeaderRole:
|
||||
m_serverProtocolConfig.insert(config_key::underloadPacketMagicHeader, value.toString());
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader = value.toString();
|
||||
break;
|
||||
case Roles::ServerTransportPacketMagicHeaderRole:
|
||||
m_serverProtocolConfig.insert(config_key::transportPacketMagicHeader, value.toString());
|
||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader = value.toString();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -59,94 +74,42 @@ QVariant AwgConfigModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
|
||||
switch (role) {
|
||||
case Roles::SubnetAddressRole: return m_serverProtocolConfig.value(config_key::subnet_address).toString();
|
||||
case Roles::PortRole: return m_serverProtocolConfig.value(config_key::port).toString();
|
||||
case Roles::SubnetAddressRole: return m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress;
|
||||
case Roles::PortRole: return m_newAwgProtocolConfig.serverProtocolConfig.port;
|
||||
|
||||
case Roles::ClientMtuRole: return m_clientProtocolConfig.value(config_key::mtu);
|
||||
case Roles::ClientJunkPacketCountRole: return m_clientProtocolConfig.value(config_key::junkPacketCount);
|
||||
case Roles::ClientJunkPacketMinSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMinSize);
|
||||
case Roles::ClientJunkPacketMaxSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMaxSize);
|
||||
case Roles::ClientMtuRole: return m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu;
|
||||
case Roles::ClientJunkPacketCountRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount;
|
||||
case Roles::ClientJunkPacketMinSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize;
|
||||
case Roles::ClientJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize;
|
||||
|
||||
case Roles::ServerJunkPacketCountRole: return m_serverProtocolConfig.value(config_key::junkPacketCount);
|
||||
case Roles::ServerJunkPacketMinSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMinSize);
|
||||
case Roles::ServerJunkPacketMaxSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMaxSize);
|
||||
case Roles::ServerInitPacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::initPacketJunkSize);
|
||||
case Roles::ServerResponsePacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::responsePacketJunkSize);
|
||||
case Roles::ServerInitPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::initPacketMagicHeader);
|
||||
case Roles::ServerResponsePacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::responsePacketMagicHeader);
|
||||
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::underloadPacketMagicHeader);
|
||||
case Roles::ServerTransportPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::transportPacketMagicHeader);
|
||||
case Roles::ServerJunkPacketCountRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount;
|
||||
case Roles::ServerJunkPacketMinSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMinSize;
|
||||
case Roles::ServerJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMaxSize;
|
||||
case Roles::ServerInitPacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketJunkSize;
|
||||
case Roles::ServerResponsePacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketJunkSize;
|
||||
case Roles::ServerInitPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketMagicHeader;
|
||||
case Roles::ServerResponsePacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader;
|
||||
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader;
|
||||
case Roles::ServerTransportPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void AwgConfigModel::updateModel(const QJsonObject &config)
|
||||
void AwgConfigModel::updateModel(const AwgProtocolConfig awgProtocolConfig)
|
||||
{
|
||||
beginResetModel();
|
||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||
|
||||
m_fullConfig = config;
|
||||
|
||||
QJsonObject serverProtocolConfig = config.value(config_key::awg).toObject();
|
||||
|
||||
auto defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::Awg), Proto::Awg);
|
||||
m_serverProtocolConfig.insert(config_key::transport_proto,
|
||||
serverProtocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||
m_serverProtocolConfig[config_key::last_config] = serverProtocolConfig.value(config_key::last_config);
|
||||
m_serverProtocolConfig[config_key::subnet_address] = serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||
m_serverProtocolConfig[config_key::port] = serverProtocolConfig.value(config_key::port).toString(protocols::awg::defaultPort);
|
||||
m_serverProtocolConfig[config_key::junkPacketCount] =
|
||||
serverProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||
m_serverProtocolConfig[config_key::junkPacketMinSize] =
|
||||
serverProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||
m_serverProtocolConfig[config_key::junkPacketMaxSize] =
|
||||
serverProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||
m_serverProtocolConfig[config_key::initPacketJunkSize] =
|
||||
serverProtocolConfig.value(config_key::initPacketJunkSize).toString(protocols::awg::defaultInitPacketJunkSize);
|
||||
m_serverProtocolConfig[config_key::responsePacketJunkSize] =
|
||||
serverProtocolConfig.value(config_key::responsePacketJunkSize).toString(protocols::awg::defaultResponsePacketJunkSize);
|
||||
m_serverProtocolConfig[config_key::initPacketMagicHeader] =
|
||||
serverProtocolConfig.value(config_key::initPacketMagicHeader).toString(protocols::awg::defaultInitPacketMagicHeader);
|
||||
m_serverProtocolConfig[config_key::responsePacketMagicHeader] =
|
||||
serverProtocolConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader);
|
||||
m_serverProtocolConfig[config_key::underloadPacketMagicHeader] =
|
||||
serverProtocolConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader);
|
||||
m_serverProtocolConfig[config_key::transportPacketMagicHeader] =
|
||||
serverProtocolConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader);
|
||||
|
||||
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||
m_clientProtocolConfig[config_key::mtu] = clientProtocolConfig[config_key::mtu].toString(protocols::awg::defaultMtu);
|
||||
m_clientProtocolConfig[config_key::junkPacketCount] =
|
||||
clientProtocolConfig.value(config_key::junkPacketCount).toString(m_serverProtocolConfig[config_key::junkPacketCount].toString());
|
||||
m_clientProtocolConfig[config_key::junkPacketMinSize] =
|
||||
clientProtocolConfig.value(config_key::junkPacketMinSize).toString(m_serverProtocolConfig[config_key::junkPacketMinSize].toString());
|
||||
m_clientProtocolConfig[config_key::junkPacketMaxSize] =
|
||||
clientProtocolConfig.value(config_key::junkPacketMaxSize).toString(m_serverProtocolConfig[config_key::junkPacketMaxSize].toString());
|
||||
m_newAwgProtocolConfig = awgProtocolConfig;
|
||||
m_oldAwgProtocolConfig = awgProtocolConfig;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject AwgConfigModel::getConfig()
|
||||
QSharedPointer<ProtocolConfig> AwgConfigModel::getConfig()
|
||||
{
|
||||
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
||||
const AwgConfig newConfig(m_serverProtocolConfig);
|
||||
|
||||
if (!oldConfig.hasEqualServerSettings(newConfig)) {
|
||||
m_serverProtocolConfig.remove(config_key::last_config);
|
||||
} else {
|
||||
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||
QJsonObject jsonConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||
jsonConfig[config_key::mtu] = m_clientProtocolConfig[config_key::mtu];
|
||||
jsonConfig[config_key::junkPacketCount] = m_clientProtocolConfig[config_key::junkPacketCount];
|
||||
jsonConfig[config_key::junkPacketMinSize] = m_clientProtocolConfig[config_key::junkPacketMinSize];
|
||||
jsonConfig[config_key::junkPacketMaxSize] = m_clientProtocolConfig[config_key::junkPacketMaxSize];
|
||||
|
||||
m_serverProtocolConfig[config_key::last_config] = QString(QJsonDocument(jsonConfig).toJson());
|
||||
if (m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig)) {
|
||||
m_newAwgProtocolConfig.clearClientSettings();
|
||||
}
|
||||
|
||||
m_fullConfig.insert(config_key::awg, m_serverProtocolConfig);
|
||||
return m_fullConfig;
|
||||
return QSharedPointer<AwgProtocolConfig>::create(m_newAwgProtocolConfig);
|
||||
}
|
||||
|
||||
bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4)
|
||||
|
@ -156,15 +119,12 @@ bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const
|
|||
|
||||
bool AwgConfigModel::isPacketSizeEqual(const int s1, const int s2)
|
||||
{
|
||||
return (AwgConstant::messageInitiationSize + s1 == AwgConstant::messageResponseSize + s2);
|
||||
return (awg::messageInitiationSize + s1 == awg::messageResponseSize + s2);
|
||||
}
|
||||
|
||||
bool AwgConfigModel::isServerSettingsEqual()
|
||||
{
|
||||
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
||||
const AwgConfig newConfig(m_serverProtocolConfig);
|
||||
|
||||
return oldConfig.hasEqualServerSettings(newConfig);
|
||||
return m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||
|
@ -191,53 +151,3 @@ QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
|||
|
||||
return roles;
|
||||
}
|
||||
|
||||
AwgConfig::AwgConfig(const QJsonObject &serverProtocolConfig)
|
||||
{
|
||||
auto lastConfig = serverProtocolConfig.value(config_key::last_config).toString();
|
||||
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||
clientMtu = clientProtocolConfig[config_key::mtu].toString(protocols::awg::defaultMtu);
|
||||
clientJunkPacketCount = clientProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||
clientJunkPacketMinSize = clientProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||
clientJunkPacketMaxSize = clientProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||
|
||||
subnetAddress = serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||
port = serverProtocolConfig.value(config_key::port).toString(protocols::awg::defaultPort);
|
||||
serverJunkPacketCount = serverProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||
serverJunkPacketMinSize = serverProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||
serverJunkPacketMaxSize = serverProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||
serverInitPacketJunkSize = serverProtocolConfig.value(config_key::initPacketJunkSize).toString(protocols::awg::defaultInitPacketJunkSize);
|
||||
serverResponsePacketJunkSize =
|
||||
serverProtocolConfig.value(config_key::responsePacketJunkSize).toString(protocols::awg::defaultResponsePacketJunkSize);
|
||||
serverInitPacketMagicHeader =
|
||||
serverProtocolConfig.value(config_key::initPacketMagicHeader).toString(protocols::awg::defaultInitPacketMagicHeader);
|
||||
serverResponsePacketMagicHeader =
|
||||
serverProtocolConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader);
|
||||
serverUnderloadPacketMagicHeader =
|
||||
serverProtocolConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader);
|
||||
serverTransportPacketMagicHeader =
|
||||
serverProtocolConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader);
|
||||
}
|
||||
|
||||
bool AwgConfig::hasEqualServerSettings(const AwgConfig &other) const
|
||||
{
|
||||
if (subnetAddress != other.subnetAddress || port != other.port || serverJunkPacketCount != other.serverJunkPacketCount
|
||||
|| serverJunkPacketMinSize != other.serverJunkPacketMinSize || serverJunkPacketMaxSize != other.serverJunkPacketMaxSize
|
||||
|| serverInitPacketJunkSize != other.serverInitPacketJunkSize || serverResponsePacketJunkSize != other.serverResponsePacketJunkSize
|
||||
|| serverInitPacketMagicHeader != other.serverInitPacketMagicHeader
|
||||
|| serverResponsePacketMagicHeader != other.serverResponsePacketMagicHeader
|
||||
|| serverUnderloadPacketMagicHeader != other.serverUnderloadPacketMagicHeader
|
||||
|| serverTransportPacketMagicHeader != other.serverTransportPacketMagicHeader) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AwgConfig::hasEqualClientSettings(const AwgConfig &other) const
|
||||
{
|
||||
if (clientMtu != other.clientMtu || clientJunkPacketCount != other.clientJunkPacketCount
|
||||
|| clientJunkPacketMinSize != other.clientJunkPacketMinSize || clientJunkPacketMaxSize != other.clientJunkPacketMaxSize) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,38 +5,7 @@
|
|||
#include <QJsonObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
namespace AwgConstant {
|
||||
const int messageInitiationSize = 148;
|
||||
const int messageResponseSize = 92;
|
||||
}
|
||||
|
||||
struct AwgConfig
|
||||
{
|
||||
AwgConfig(const QJsonObject &jsonConfig);
|
||||
|
||||
QString subnetAddress;
|
||||
QString port;
|
||||
|
||||
QString clientMtu;
|
||||
QString clientJunkPacketCount;
|
||||
QString clientJunkPacketMinSize;
|
||||
QString clientJunkPacketMaxSize;
|
||||
|
||||
QString serverJunkPacketCount;
|
||||
QString serverJunkPacketMinSize;
|
||||
QString serverJunkPacketMaxSize;
|
||||
QString serverInitPacketJunkSize;
|
||||
QString serverResponsePacketJunkSize;
|
||||
QString serverInitPacketMagicHeader;
|
||||
QString serverResponsePacketMagicHeader;
|
||||
QString serverUnderloadPacketMagicHeader;
|
||||
QString serverTransportPacketMagicHeader;
|
||||
|
||||
bool hasEqualServerSettings(const AwgConfig &other) const;
|
||||
bool hasEqualClientSettings(const AwgConfig &other) const;
|
||||
|
||||
};
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
|
||||
class AwgConfigModel : public QAbstractListModel
|
||||
{
|
||||
|
@ -71,8 +40,8 @@ public:
|
|||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &config);
|
||||
QJsonObject getConfig();
|
||||
void updateModel(const AwgProtocolConfig awgProtocolConfig);
|
||||
QSharedPointer<ProtocolConfig> getConfig();
|
||||
|
||||
bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4);
|
||||
bool isPacketSizeEqual(const int s1, const int s2);
|
||||
|
@ -83,10 +52,8 @@ protected:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_serverProtocolConfig;
|
||||
QJsonObject m_clientProtocolConfig;
|
||||
QJsonObject m_fullConfig;
|
||||
AwgProtocolConfig m_newAwgProtocolConfig;
|
||||
AwgProtocolConfig m_oldAwgProtocolConfig;
|
||||
};
|
||||
|
||||
#endif // AWGCONFIGMODEL_H
|
||||
|
|
|
@ -1,14 +1,41 @@
|
|||
#include "protocols_model.h"
|
||||
|
||||
ProtocolsModel::ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: m_settings(settings), QAbstractListModel(parent)
|
||||
#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"
|
||||
|
||||
ProtocolsModel::ProtocolsModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ProtocolsModel::ProtocolsModel(const QSharedPointer<OpenVpnConfigModel> &openVpnConfigModel,
|
||||
const QSharedPointer<ShadowSocksConfigModel> &shadowSocksConfigModel,
|
||||
const QSharedPointer<CloakConfigModel> &cloakConfigModel,
|
||||
const QSharedPointer<WireGuardConfigModel> &wireGuardConfigModel,
|
||||
const QSharedPointer<AwgConfigModel> &awgConfigModel, const QSharedPointer<XrayConfigModel> &xrayConfigModel,
|
||||
const QSharedPointer<Ikev2ConfigModel> &ikev2ConfigModel,
|
||||
const QSharedPointer<SftpConfigModel> &sftpConfigModel,
|
||||
const QSharedPointer<Socks5ProxyConfigModel> &socks5ProxyConfigModel, QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_openVpnConfigModel(openVpnConfigModel),
|
||||
m_shadowSocksConfigModel(shadowSocksConfigModel),
|
||||
m_cloakConfigModel(cloakConfigModel),
|
||||
m_wireGuardConfigModel(wireGuardConfigModel),
|
||||
m_awgConfigModel(awgConfigModel),
|
||||
m_xrayConfigModel(xrayConfigModel),
|
||||
m_ikev2ConfigModel(ikev2ConfigModel),
|
||||
m_sftpConfigModel(sftpConfigModel),
|
||||
m_socks5ProxyConfigModel(socks5ProxyConfigModel)
|
||||
{
|
||||
}
|
||||
|
||||
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return m_content.size();
|
||||
return m_protocolConfigs.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
||||
|
@ -27,60 +54,102 @@ QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
|||
|
||||
QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_content.size()) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_protocolConfigs.size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto protocolConfig = m_protocolConfigs.at(index.row());
|
||||
amnezia::Proto protocol = ProtocolProps::protoFromString(protocolConfig->protocolName);
|
||||
|
||||
switch (role) {
|
||||
case ProtocolNameRole: {
|
||||
amnezia::Proto proto = ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||
return ProtocolProps::protocolHumanNames().value(proto);
|
||||
return ProtocolProps::protocolHumanNames().value(protocol);
|
||||
}
|
||||
case ServerProtocolPageRole:
|
||||
return static_cast<int>(serverProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||
case ClientProtocolPageRole:
|
||||
return static_cast<int>(clientProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||
case ProtocolIndexRole: return ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||
case RawConfigRole: {
|
||||
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||
auto lastConfigJsonDoc =
|
||||
QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||
auto lastConfigJson = lastConfigJsonDoc.object();
|
||||
case ServerProtocolPageRole: return static_cast<int>(serverProtocolPage(protocol));
|
||||
case ClientProtocolPageRole: return static_cast<int>(clientProtocolPage(protocol));
|
||||
case ProtocolIndexRole: return protocol;
|
||||
// case RawConfigRole: {
|
||||
// auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||
// auto lastConfigJsonDoc = QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||
// auto lastConfigJson = lastConfigJsonDoc.object();
|
||||
|
||||
QString rawConfig;
|
||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||
for (const QString &l : lines) {
|
||||
rawConfig.append(l + "\n");
|
||||
}
|
||||
return rawConfig;
|
||||
}
|
||||
// QString rawConfig;
|
||||
// QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||
// for (const QString &l : lines) {
|
||||
// rawConfig.append(l + "\n");
|
||||
// }
|
||||
// return rawConfig;
|
||||
// }
|
||||
case IsClientProtocolExistsRole: {
|
||||
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||
auto lastConfigJsonDoc =
|
||||
QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||
auto lastConfigJson = lastConfigJsonDoc.object();
|
||||
|
||||
auto configString = lastConfigJson.value(config_key::config).toString();
|
||||
return !configString.isEmpty();
|
||||
auto protocolVariant = ProtocolConfig::getProtocolConfigVariant(protocolConfig);
|
||||
return std::visit([](const auto &ptr) -> bool { return ptr->clientProtocolConfig.isEmpty; }, protocolVariant);
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ProtocolsModel::updateModel(const QJsonObject &content)
|
||||
void ProtocolsModel::updateModel(const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs)
|
||||
{
|
||||
m_container = ContainerProps::containerFromString(content.value(config_key::container).toString());
|
||||
|
||||
m_content = content;
|
||||
m_content.remove(config_key::container);
|
||||
beginResetModel();
|
||||
m_protocolConfigs.clear();
|
||||
for (const auto &protocolConfig : protocolConfigs) {
|
||||
m_protocolConfigs.push_back(protocolConfig);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject ProtocolsModel::getConfig()
|
||||
void ProtocolsModel::updateProtocolModel(amnezia::Proto protocol)
|
||||
{
|
||||
QJsonObject config = m_content;
|
||||
config.insert(config_key::container, ContainerProps::containerToString(m_container));
|
||||
return config;
|
||||
QSharedPointer<ProtocolConfig> protocolConfig;
|
||||
|
||||
for (const auto &config : m_protocolConfigs) {
|
||||
if (ProtocolProps::protoFromString(config->protocolName) == protocol) {
|
||||
protocolConfig = config;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (protocol) {
|
||||
case Proto::OpenVpn: m_openVpnConfigModel->updateModel(config); break;
|
||||
case Proto::ShadowSocks: m_shadowSocksConfigModel->updateModel(config); break;
|
||||
case Proto::Cloak: m_cloakConfigModel->updateModel(config); break;
|
||||
case Proto::WireGuard: m_wireGuardConfigModel->updateModel(config); break;
|
||||
case Proto::Awg: m_awgConfigModel->updateModel(config); break;
|
||||
case Proto::Xray: m_xrayConfigModel->updateModel(config); break;
|
||||
#ifdef Q_OS_WINDOWS
|
||||
case Proto::Ikev2:
|
||||
case Proto::L2tp: m_ikev2ConfigModel->updateModel(config); break;
|
||||
#endif
|
||||
case Proto::Sftp: m_sftpConfigModel->updateModel(config); break;
|
||||
case Proto::Socks5Proxy: m_socks5ProxyConfigModel->updateModel(config); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> ProtocolsModel::getProtocolConfigs()
|
||||
{
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> protocolConfigs;
|
||||
|
||||
for (const auto &config : m_protocolConfigs) {
|
||||
switch (ProtocolProps::protoFromString(config->protocolName)) {
|
||||
case Proto::OpenVpn: protocolConfigs.insert(config->protocolName, m_openVpnConfigModel->getConfig()); break;
|
||||
case Proto::ShadowSocks: m_shadowSocksConfigModel->updateModel(config); break;
|
||||
case Proto::Cloak: m_cloakConfigModel->updateModel(config); break;
|
||||
case Proto::WireGuard: m_wireGuardConfigModel->updateModel(config); break;
|
||||
case Proto::Awg: protocolConfigs.insert(config->protocolName, m_awgConfigModel->getConfig()); break;
|
||||
case Proto::Xray: m_xrayConfigModel->updateModel(config); break;
|
||||
#ifdef Q_OS_WINDOWS
|
||||
case Proto::Ikev2:
|
||||
case Proto::L2tp: m_ikev2ConfigModel->updateModel(config); break;
|
||||
#endif
|
||||
case Proto::Sftp: m_sftpConfigModel->updateModel(config); break;
|
||||
case Proto::Socks5Proxy: m_socks5ProxyConfigModel->updateModel(config); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return protocolConfigs;
|
||||
}
|
||||
|
||||
PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
|
||||
|
@ -94,7 +163,7 @@ PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
|
|||
case Proto::Ikev2: return PageLoader::PageEnum::PageProtocolIKev2Settings;
|
||||
case Proto::L2tp: return PageLoader::PageEnum::PageProtocolIKev2Settings;
|
||||
case Proto::Xray: return PageLoader::PageEnum::PageProtocolXraySettings;
|
||||
|
||||
|
||||
// non-vpn
|
||||
case Proto::TorWebSite: return PageLoader::PageEnum::PageServiceTorWebsiteSettings;
|
||||
case Proto::Dns: return PageLoader::PageEnum::PageServiceDnsSettings;
|
||||
|
|
|
@ -4,8 +4,19 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "../controllers/pageController.h"
|
||||
#include "settings.h"
|
||||
#include "core/models/protocols/protocolConfig.h"
|
||||
#include "ui/controllers/pageController.h"
|
||||
#include "ui/models/protocols/awgConfigModel.h"
|
||||
#include "ui/models/protocols/cloakConfigModel.h"
|
||||
#include "ui/models/protocols/openvpnConfigModel.h"
|
||||
#include "ui/models/protocols/shadowsocksConfigModel.h"
|
||||
#include "ui/models/protocols/wireguardConfigModel.h"
|
||||
#include "ui/models/protocols/xrayConfigModel.h"
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include "ui/models/protocols/ikev2ConfigModel.h"
|
||||
#endif
|
||||
#include "ui/models/services/sftpConfigModel.h"
|
||||
#include "ui/models/services/socks5ProxyConfigModel.h"
|
||||
|
||||
class ProtocolsModel : public QAbstractListModel
|
||||
{
|
||||
|
@ -20,16 +31,26 @@ public:
|
|||
IsClientProtocolExistsRole
|
||||
};
|
||||
|
||||
ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||
ProtocolsModel(QObject *parent = nullptr);
|
||||
ProtocolsModel(const QSharedPointer<OpenVpnConfigModel> &openVpnConfigModel,
|
||||
const QSharedPointer<ShadowSocksConfigModel> &shadowSocksConfigModel,
|
||||
const QSharedPointer<CloakConfigModel> &cloakConfigModel, const QSharedPointer<WireGuardConfigModel> &wireGuardConfigModel,
|
||||
const QSharedPointer<AwgConfigModel> &awgConfigModel, const QSharedPointer<XrayConfigModel> &xrayConfigModel,
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const QSharedPointer<Ikev2ConfigModel> &ikev2ConfigModel,
|
||||
#endif
|
||||
const QSharedPointer<SftpConfigModel> &sftpConfigModel,
|
||||
const QSharedPointer<Socks5ProxyConfigModel> &socks5ProxyConfigModel, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
public slots:
|
||||
void updateModel(const QJsonObject &content);
|
||||
void updateModel(const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs);
|
||||
void updateProtocolModel(amnezia::Proto protocol);
|
||||
|
||||
QJsonObject getConfig();
|
||||
QMap<QString, QSharedPointer<ProtocolConfig>> getProtocolConfigs();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
@ -38,10 +59,19 @@ private:
|
|||
PageLoader::PageEnum serverProtocolPage(Proto protocol) const;
|
||||
PageLoader::PageEnum clientProtocolPage(Proto protocol) const;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
QVector<QSharedPointer<ProtocolConfig>> m_protocolConfigs;
|
||||
|
||||
DockerContainer m_container;
|
||||
QJsonObject m_content;
|
||||
QSharedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
||||
QSharedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
||||
QSharedPointer<CloakConfigModel> m_cloakConfigModel;
|
||||
QSharedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
||||
QSharedPointer<AwgConfigModel> m_awgConfigModel;
|
||||
QSharedPointer<XrayConfigModel> m_xrayConfigModel;
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QSharedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
||||
#endif
|
||||
QSharedPointer<SftpConfigModel> m_sftpConfigModel;
|
||||
QSharedPointer<Socks5ProxyConfigModel> m_socks5ProxyConfigModel;
|
||||
};
|
||||
|
||||
#endif // PROTOCOLS_MODEL_H
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "core/models/servers/apiV1ServerConfig.h"
|
||||
#include "core/models/servers/apiV2ServerConfig.h"
|
||||
#include "core/models/servers/selfHostedServerConfig.h"
|
||||
#include "core/models/servers/serverConfig.h"
|
||||
#include "core/networkUtilities.h"
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
|
@ -27,9 +28,6 @@ namespace
|
|||
constexpr char publicKeyInfo[] = "public_key";
|
||||
constexpr char expiresAt[] = "expires_at";
|
||||
}
|
||||
|
||||
using ServerConfigVariant =
|
||||
std::variant<QSharedPointer<SelfHostedServerConfig>, QSharedPointer<ApiV1ServerConfig>, QSharedPointer<ApiV2ServerConfig> >;
|
||||
}
|
||||
|
||||
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
|
||||
|
@ -39,8 +37,7 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
|||
connect(this, &ServersModel::defaultServerIndexChanged, this, &ServersModel::defaultServerNameChanged);
|
||||
|
||||
connect(this, &ServersModel::defaultServerIndexChanged, this, [this](const int serverIndex) {
|
||||
auto defaultContainer =
|
||||
ContainerProps::containerFromString(m_servers.at(serverIndex).toObject().value(config_key::defaultContainer).toString());
|
||||
auto defaultContainer = ContainerProps::containerFromString(m_servers1.at(serverIndex)->defaultContainer);
|
||||
emit ServersModel::defaultServerDefaultContainerChanged(defaultContainer);
|
||||
emit ServersModel::defaultServerNameChanged();
|
||||
updateDefaultServerContainersModel();
|
||||
|
@ -53,28 +50,25 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
|||
int ServersModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return static_cast<int>(m_servers.size());
|
||||
return static_cast<int>(m_servers1.size());
|
||||
}
|
||||
|
||||
bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers.size())) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers1.size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject server = m_servers.at(index.row()).toObject();
|
||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
||||
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
||||
|
||||
switch (role) {
|
||||
case NameRole: {
|
||||
if (configVersion) {
|
||||
server.insert(config_key::name, value.toString());
|
||||
} else {
|
||||
server.insert(config_key::description, value.toString());
|
||||
}
|
||||
server.insert(config_key::nameOverriddenByUser, true);
|
||||
m_settings->editServer(index.row(), server);
|
||||
m_servers.replace(index.row(), server);
|
||||
std::visit([&value](const auto &ptr) -> void { ptr->name = value.toString(); }, variant);
|
||||
serverConfig->nameOverriddenByUser = true;
|
||||
|
||||
m_settings->editServer(index.row(), serverConfig->toJson());
|
||||
m_servers1.replace(index.row(), serverConfig);
|
||||
if (index.row() == m_defaultServerIndex) {
|
||||
emit defaultServerNameChanged();
|
||||
}
|
||||
|
@ -102,12 +96,7 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
|
||||
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
||||
ServerConfigVariant variant;
|
||||
switch (serverConfig->type) {
|
||||
case amnezia::ServerConfigType::SelfHosted: variant = qSharedPointerCast<SelfHostedServerConfig>(serverConfig); break;
|
||||
case amnezia::ServerConfigType::ApiV1: variant = qSharedPointerCast<ApiV1ServerConfig>(serverConfig); break;
|
||||
case amnezia::ServerConfigType::ApiV2: variant = qSharedPointerCast<ApiV2ServerConfig>(serverConfig); break;
|
||||
}
|
||||
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
||||
|
||||
switch (role) {
|
||||
case NameRole: {
|
||||
|
@ -163,26 +152,13 @@ QVariant ServersModel::data(const int index, int role) const
|
|||
void ServersModel::resetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
m_servers = m_settings->serversArray();
|
||||
auto servers = m_settings->serversArray();
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
m_processedServerIndex = m_defaultServerIndex;
|
||||
|
||||
for (auto server : m_servers) {
|
||||
for (auto server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(serverConfig);
|
||||
qDebug() << "333";
|
||||
qDebug() << server.toObject();
|
||||
qDebug() << "333";
|
||||
|
||||
ServerConfigVariant variant;
|
||||
switch (serverConfig->type) {
|
||||
case amnezia::ServerConfigType::SelfHosted: variant = qSharedPointerCast<SelfHostedServerConfig>(serverConfig); break;
|
||||
case amnezia::ServerConfigType::ApiV1: variant = qSharedPointerCast<ApiV1ServerConfig>(serverConfig); break;
|
||||
case amnezia::ServerConfigType::ApiV2: variant = qSharedPointerCast<ApiV2ServerConfig>(serverConfig); break;
|
||||
}
|
||||
qDebug() << "123";
|
||||
qDebug() << std::visit([](const auto &ptr) -> QJsonObject { return ptr->toJson(); }, variant);
|
||||
qDebug() << "123";
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
@ -237,33 +213,33 @@ QString ServersModel::getServerDescription(const int index) const
|
|||
|
||||
const QString ServersModel::getDefaultServerDescriptionCollapsed()
|
||||
{
|
||||
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||
auto description = getServerDescription(m_defaultServerIndex);
|
||||
if (configVersion) {
|
||||
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
|
||||
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
||||
return description;
|
||||
}
|
||||
|
||||
auto container = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||
|
||||
return description += ContainerProps::containerHumanNames().value(container) + " | " + server.value(config_key::hostName).toString();
|
||||
return description += ContainerProps::containerHumanNames().value(containerName) + " | " + serverConfig->hostName;
|
||||
}
|
||||
|
||||
const QString ServersModel::getDefaultServerDescriptionExpanded()
|
||||
{
|
||||
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||
auto description = getServerDescription(m_defaultServerIndex);
|
||||
if (configVersion) {
|
||||
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
|
||||
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
||||
return description;
|
||||
}
|
||||
|
||||
return description += server.value(config_key::hostName).toString();
|
||||
return description += serverConfig->hostName;
|
||||
}
|
||||
|
||||
const int ServersModel::getServersCount()
|
||||
{
|
||||
return m_servers.count();
|
||||
return m_servers1.count();
|
||||
}
|
||||
|
||||
bool ServersModel::hasServerWithWriteAccess()
|
||||
|
@ -325,18 +301,22 @@ bool ServersModel::isDefaultServerHasWriteAccess()
|
|||
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
||||
}
|
||||
|
||||
void ServersModel::addServer(const QJsonObject &server)
|
||||
void ServersModel::addServer(const QSharedPointer<ServerConfig> &serverConfig)
|
||||
{
|
||||
beginResetModel();
|
||||
m_settings->addServer(server);
|
||||
m_servers = m_settings->serversArray();
|
||||
m_settings->addServer(serverConfig->toJson());
|
||||
auto servers = m_settings->serversArray();
|
||||
for (auto server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(serverConfig);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ServersModel::editServer(const QJsonObject &server, const int serverIndex)
|
||||
void ServersModel::editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex)
|
||||
{
|
||||
m_settings->editServer(serverIndex, server);
|
||||
m_servers.replace(serverIndex, m_settings->serversArray().at(serverIndex));
|
||||
m_settings->editServer(serverIndex, serverConfig->toJson());
|
||||
m_servers1[serverIndex] = serverConfig;
|
||||
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
||||
|
||||
if (serverIndex == m_defaultServerIndex) {
|
||||
|
@ -350,30 +330,20 @@ void ServersModel::editServer(const QJsonObject &server, const int serverIndex)
|
|||
}
|
||||
}
|
||||
|
||||
void ServersModel::removeServer()
|
||||
void ServersModel::removeProcessedServer()
|
||||
{
|
||||
beginResetModel();
|
||||
m_settings->removeServer(m_processedServerIndex);
|
||||
m_servers = m_settings->serversArray();
|
||||
|
||||
if (m_settings->defaultServerIndex() == m_processedServerIndex) {
|
||||
setDefaultServerIndex(0);
|
||||
} else if (m_settings->defaultServerIndex() > m_processedServerIndex) {
|
||||
setDefaultServerIndex(m_settings->defaultServerIndex() - 1);
|
||||
}
|
||||
|
||||
if (m_settings->serversCount() == 0) {
|
||||
setDefaultServerIndex(-1);
|
||||
}
|
||||
setProcessedServerIndex(m_defaultServerIndex);
|
||||
endResetModel();
|
||||
removeServer(m_processedServerIndex);
|
||||
}
|
||||
|
||||
void ServersModel::removeServer(const int serverIndex)
|
||||
{
|
||||
beginResetModel();
|
||||
m_settings->removeServer(serverIndex);
|
||||
m_servers = m_settings->serversArray();
|
||||
auto servers = m_settings->serversArray();
|
||||
for (auto server : servers) {
|
||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||
m_servers1.push_back(serverConfig);
|
||||
}
|
||||
|
||||
if (m_settings->defaultServerIndex() == serverIndex) {
|
||||
setDefaultServerIndex(0);
|
||||
|
@ -429,84 +399,27 @@ ServerCredentials ServersModel::serverCredentials(int index) const
|
|||
|
||||
void ServersModel::updateContainersModel()
|
||||
{
|
||||
auto containers = m_servers.at(m_processedServerIndex).toObject().value(config_key::containers).toArray();
|
||||
emit containersUpdated(containers);
|
||||
auto containerConfigs = m_servers1.at(m_processedServerIndex)->containerConfigs;
|
||||
emit containersUpdated(containerConfigs);
|
||||
}
|
||||
|
||||
void ServersModel::updateDefaultServerContainersModel()
|
||||
{
|
||||
auto containers = m_servers.at(m_defaultServerIndex).toObject().value(config_key::containers).toArray();
|
||||
emit defaultServerContainersUpdated(containers);
|
||||
auto containerConfigs = m_servers1.at(m_defaultServerIndex)->containerConfigs;
|
||||
emit defaultServerContainersUpdated(containerConfigs);
|
||||
}
|
||||
|
||||
QJsonObject ServersModel::getServerConfig(const int serverIndex)
|
||||
QSharedPointer<const ServerConfig> ServersModel::getServerConfig(const int serverIndex)
|
||||
{
|
||||
return m_servers.at(serverIndex).toObject();
|
||||
}
|
||||
|
||||
void ServersModel::reloadDefaultServerContainerConfig()
|
||||
{
|
||||
QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
auto container = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
|
||||
auto config = m_settings->containerConfig(m_defaultServerIndex, container);
|
||||
for (auto i = 0; i < containers.size(); i++) {
|
||||
auto c = ContainerProps::containerFromString(containers.at(i).toObject().value(config_key::container).toString());
|
||||
if (c == container) {
|
||||
containers.replace(i, config);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
server.insert(config_key::containers, containers);
|
||||
editServer(server, m_defaultServerIndex);
|
||||
}
|
||||
|
||||
void ServersModel::updateContainerConfig(const int containerIndex, const QJsonObject config)
|
||||
{
|
||||
auto container = static_cast<DockerContainer>(containerIndex);
|
||||
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
for (auto i = 0; i < containers.size(); i++) {
|
||||
auto c = ContainerProps::containerFromString(containers.at(i).toObject().value(config_key::container).toString());
|
||||
if (c == container) {
|
||||
containers.replace(i, config);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
server.insert(config_key::containers, containers);
|
||||
editServer(server, m_processedServerIndex);
|
||||
}
|
||||
|
||||
void ServersModel::addContainerConfig(const int containerIndex, const QJsonObject config)
|
||||
{
|
||||
auto container = static_cast<DockerContainer>(containerIndex);
|
||||
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
containers.push_back(config);
|
||||
|
||||
server.insert(config_key::containers, containers);
|
||||
|
||||
auto defaultContainer = server.value(config_key::defaultContainer).toString();
|
||||
if (ContainerProps::containerFromString(defaultContainer) == DockerContainer::None
|
||||
&& ContainerProps::containerService(container) != ServiceType::Other && ContainerProps::isSupportedByCurrentPlatform(container)) {
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
||||
}
|
||||
|
||||
editServer(server, m_processedServerIndex);
|
||||
return m_servers1.at(serverIndex);
|
||||
}
|
||||
|
||||
void ServersModel::setDefaultContainer(const int serverIndex, const int containerIndex)
|
||||
{
|
||||
auto container = static_cast<DockerContainer>(containerIndex);
|
||||
QJsonObject s = m_servers.at(serverIndex).toObject();
|
||||
s.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
||||
editServer(s, serverIndex); // check
|
||||
auto serverConfig = m_servers1.at(serverIndex);
|
||||
serverConfig->defaultContainer = ContainerProps::containerToString(container);
|
||||
editServer(serverConfig, serverIndex);
|
||||
}
|
||||
|
||||
const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||
|
@ -517,25 +430,19 @@ const QString ServersModel::getDefaultServerDefaultContainerName()
|
|||
|
||||
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
||||
{
|
||||
|
||||
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
QJsonObject s = m_servers.at(m_processedServerIndex).toObject();
|
||||
s.insert(config_key::containers, {});
|
||||
s.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
||||
|
||||
editServer(s, m_processedServerIndex);
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
serverConfig->containerConfigs.clear();
|
||||
editServer(serverConfig, m_processedServerIndex);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
||||
{
|
||||
|
||||
auto credentials = m_settings->serverCredentials(m_processedServerIndex);
|
||||
|
||||
ErrorCode errorCode = serverController->rebootServer(credentials);
|
||||
ErrorCode errorCode = serverController->rebootServer(m_settings->serverCredentials(m_processedServerIndex));
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
@ -548,30 +455,19 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
|||
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||
serverConfig->containerConfigs.remove(ContainerProps::containerToString(dockerContainer));
|
||||
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||
if (it->toObject().value(config_key::container).toString() == ContainerProps::containerToString(dockerContainer)) {
|
||||
containers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
server.insert(config_key::containers, containers);
|
||||
|
||||
auto defaultContainer = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
if (defaultContainer == containerIndex) {
|
||||
if (containers.empty()) {
|
||||
defaultContainer = DockerContainer::None;
|
||||
if (serverConfig->containerConfigs.empty()) {
|
||||
serverConfig->defaultContainer = ContainerProps::containerToString(DockerContainer::None);
|
||||
} else {
|
||||
defaultContainer =
|
||||
ContainerProps::containerFromString(containers.begin()->toObject().value(config_key::container).toString());
|
||||
serverConfig->defaultContainer = serverConfig->containerConfigs.begin()->containerName;
|
||||
}
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(defaultContainer));
|
||||
}
|
||||
|
||||
editServer(server, m_processedServerIndex);
|
||||
editServer(serverConfig, m_processedServerIndex);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
@ -579,7 +475,9 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
|||
void ServersModel::clearCachedProfile(const DockerContainer container)
|
||||
{
|
||||
m_settings->clearLastConnectionConfig(m_processedServerIndex, container);
|
||||
m_servers.replace(m_processedServerIndex, m_settings->server(m_processedServerIndex));
|
||||
auto serverConfig = ServerConfig::createServerConfig(m_settings->server(m_processedServerIndex));
|
||||
|
||||
m_servers1.replace(m_processedServerIndex, serverConfig);
|
||||
if (m_processedServerIndex == m_defaultServerIndex) {
|
||||
updateDefaultServerContainersModel();
|
||||
}
|
||||
|
@ -588,10 +486,9 @@ void ServersModel::clearCachedProfile(const DockerContainer container)
|
|||
|
||||
bool ServersModel::isAmneziaDnsContainerInstalled(const int serverIndex) const
|
||||
{
|
||||
QJsonObject server = m_servers.at(serverIndex).toObject();
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||
if (it->toObject().value(config_key::container).toString() == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||
auto serverConfig = m_servers1.at(serverIndex);
|
||||
for (const auto &container : serverConfig->containerConfigs) {
|
||||
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -602,17 +499,16 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
|||
{
|
||||
QPair<QString, QString> dns;
|
||||
|
||||
const QJsonObject &server = m_servers.at(m_processedServerIndex).toObject();
|
||||
const auto containers = server.value(config_key::containers).toArray();
|
||||
auto serverConfig = m_servers1.at(serverIndex);
|
||||
bool isDnsContainerInstalled = false;
|
||||
for (const QJsonValue &container : containers) {
|
||||
if (ContainerProps::containerFromString(container.toObject().value(config_key::container).toString()) == DockerContainer::Dns) {
|
||||
for (const auto &container : serverConfig->containerConfigs) {
|
||||
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||
isDnsContainerInstalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
dns.first = server.value(config_key::dns1).toString();
|
||||
dns.second = server.value(config_key::dns2).toString();
|
||||
dns.first = serverConfig->dns1;
|
||||
dns.second = serverConfig->dns2;
|
||||
|
||||
if (dns.first.isEmpty() || !NetworkUtilities::checkIPv4Format(dns.first)) {
|
||||
if (m_isAmneziaDnsEnabled && isDnsContainerInstalled) {
|
||||
|
@ -631,18 +527,17 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
|||
QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
||||
{
|
||||
QStringList servicesName;
|
||||
QJsonObject server = m_servers.at(serverIndex).toObject();
|
||||
const auto containers = server.value(config_key::containers).toArray();
|
||||
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||
auto container = ContainerProps::containerFromString(it->toObject().value(config_key::container).toString());
|
||||
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
||||
if (container == DockerContainer::Dns) {
|
||||
auto serverConfig = m_servers1.at(serverIndex);
|
||||
for (const auto &container : serverConfig->containerConfigs) {
|
||||
auto containerType = ContainerProps::containerFromString(container.containerName);
|
||||
if (ContainerProps::containerService(containerType) == ServiceType::Other) {
|
||||
if (containerType == DockerContainer::Dns) {
|
||||
servicesName.append("DNS");
|
||||
} else if (container == DockerContainer::Sftp) {
|
||||
} else if (containerType == DockerContainer::Sftp) {
|
||||
servicesName.append("SFTP");
|
||||
} else if (container == DockerContainer::TorWebSite) {
|
||||
} else if (containerType == DockerContainer::TorWebSite) {
|
||||
servicesName.append("TOR");
|
||||
} else if (container == DockerContainer::Socks5Proxy) {
|
||||
} else if (containerType == DockerContainer::Socks5Proxy) {
|
||||
servicesName.append("SOCKS5");
|
||||
}
|
||||
}
|
||||
|
@ -659,8 +554,8 @@ void ServersModel::toggleAmneziaDns(bool enabled)
|
|||
|
||||
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||
{
|
||||
for (const auto &server : std::as_const(m_servers)) {
|
||||
if (static_cast<quint16>(server.toObject().value(config_key::crc).toInt()) == crc) {
|
||||
for (const auto &server : std::as_const(m_servers1)) {
|
||||
if (static_cast<quint16>(server->crc) == crc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -669,11 +564,10 @@ bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
|||
|
||||
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
||||
{
|
||||
for (const auto &server : std::as_const(m_servers)) {
|
||||
const auto apiConfig = server.toObject().value(configKey::apiConfig).toObject();
|
||||
if (apiConfig.value(configKey::userCountryCode).toString() == userCountryCode
|
||||
&& apiConfig.value(configKey::serviceType).toString() == serviceType
|
||||
&& apiConfig.value(configKey::serviceProtocol).toString() == 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;
|
||||
}
|
||||
}
|
||||
|
@ -734,27 +628,46 @@ bool ServersModel::setProcessedServerData(const QString &roleString, const QVari
|
|||
|
||||
bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling()
|
||||
{
|
||||
auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
auto defaultContainer = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||
|
||||
auto containers = server.value(config_key::containers).toArray();
|
||||
for (auto i = 0; i < containers.size(); i++) {
|
||||
auto container = containers.at(i).toObject();
|
||||
if (container.value(config_key::container).toString() != ContainerProps::containerToString(defaultContainer)) {
|
||||
for (const auto &container : serverConfig->containerConfigs) {
|
||||
if (container.containerName != serverConfig->defaultContainer) {
|
||||
continue;
|
||||
}
|
||||
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
||||
QJsonObject serverProtocolConfig = container.value(ContainerProps::containerTypeToString(defaultContainer)).toObject();
|
||||
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
||||
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(clientProtocolConfigString.toUtf8()).object();
|
||||
return (clientProtocolConfigString.contains("AllowedIPs") && !clientProtocolConfigString.contains("AllowedIPs = 0.0.0.0/0, ::/0"))
|
||||
|| (!clientProtocolConfig.value(config_key::allowed_ips).toArray().isEmpty()
|
||||
&& !clientProtocolConfig.value(config_key::allowed_ips).toArray().contains("0.0.0.0/0"));
|
||||
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(container.protocolConfigs[serverConfig->defaultContainer]);
|
||||
return std::visit(
|
||||
[](const auto &ptr) -> bool {
|
||||
if constexpr (requires {
|
||||
ptr->clientProtocolConfig;
|
||||
ptr->clientProtocolConfig.wireGuardData;
|
||||
}) {
|
||||
const auto nativeConfig = ptr->clientProtocolConfig.nativeConfig;
|
||||
const auto allowedIps = ptr->clientProtocolConfig.wireGuardData.allowedIps;
|
||||
|
||||
return (nativeConfig.contains("AllowedIPs") && !nativeConfig.contains("AllowedIPs = 0.0.0.0/0, ::/0"))
|
||||
|| (!allowedIps.isEmpty() && !allowedIps.contains("0.0.0.0/0"));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
protocolConfigVariant);
|
||||
} else if (defaultContainer == DockerContainer::Cloak || defaultContainer == DockerContainer::OpenVpn
|
||||
|| defaultContainer == DockerContainer::ShadowSocks) {
|
||||
auto serverProtocolConfig = container.value(ContainerProps::containerTypeToString(DockerContainer::OpenVpn)).toObject();
|
||||
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
||||
return !clientProtocolConfigString.isEmpty() && !clientProtocolConfigString.contains("redirect-gateway");
|
||||
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(
|
||||
container.protocolConfigs[ContainerProps::containerTypeToString(DockerContainer::OpenVpn)]);
|
||||
return std::visit(
|
||||
[](const auto &ptr) -> bool {
|
||||
if constexpr (requires { ptr->clientProtocolConfig; }) {
|
||||
const auto nativeConfig = ptr->clientProtocolConfig.nativeConfig;
|
||||
|
||||
return (!nativeConfig.isEmpty() && !nativeConfig.contains("redirect-gateway"));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
protocolConfigVariant);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -767,62 +680,62 @@ bool ServersModel::isServerFromApi(const int serverIndex)
|
|||
|
||||
bool ServersModel::isApiKeyExpired(const int serverIndex)
|
||||
{
|
||||
auto serverConfig = m_servers.at(serverIndex).toObject();
|
||||
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||
// auto serverConfig = m_servers1.at(serverIndex);
|
||||
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||
|
||||
auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
||||
const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
||||
if (expiresAt.isEmpty()) {
|
||||
publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
||||
apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
||||
serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||
editServer(serverConfig, serverIndex);
|
||||
// auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
||||
// const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
||||
// if (expiresAt.isEmpty()) {
|
||||
// publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
||||
// apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
||||
// serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||
// editServer(serverConfig, serverIndex);
|
||||
|
||||
return false;
|
||||
}
|
||||
// return false;
|
||||
// }
|
||||
|
||||
auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
||||
if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
||||
// if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
void ServersModel::removeApiConfig(const int serverIndex)
|
||||
{
|
||||
auto serverConfig = getServerConfig(serverIndex);
|
||||
// auto serverConfig = m_servers1.at(serverIndex);
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
QString vpncName = QString("%1 (%2) %3")
|
||||
.arg(serverConfig[config_key::description].toString())
|
||||
.arg(serverConfig[config_key::hostName].toString())
|
||||
.arg(serverConfig[config_key::vpnproto].toString());
|
||||
// #ifdef Q_OS_IOS
|
||||
// QString vpncName = QString("%1 (%2) %3")
|
||||
// .arg(serverConfig[config_key::description].toString())
|
||||
// .arg(serverConfig[config_key::hostName].toString())
|
||||
// .arg(serverConfig[config_key::vpnproto].toString());
|
||||
|
||||
AmneziaVPN::removeVPNC(vpncName.toStdString());
|
||||
#endif
|
||||
// AmneziaVPN::removeVPNC(vpncName.toStdString());
|
||||
// #endif
|
||||
|
||||
serverConfig.remove(config_key::dns1);
|
||||
serverConfig.remove(config_key::dns2);
|
||||
serverConfig.remove(config_key::containers);
|
||||
serverConfig.remove(config_key::hostName);
|
||||
// serverConfig.remove(config_key::dns1);
|
||||
// serverConfig.remove(config_key::dns2);
|
||||
// serverConfig.remove(config_key::containers);
|
||||
// serverConfig.remove(config_key::hostName);
|
||||
|
||||
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||
apiConfig.remove(configKey::publicKeyInfo);
|
||||
serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||
// apiConfig.remove(configKey::publicKeyInfo);
|
||||
// serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||
|
||||
serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
||||
// serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
||||
|
||||
editServer(serverConfig, serverIndex);
|
||||
// editServer(serverConfig, serverIndex);
|
||||
}
|
||||
|
||||
const QString ServersModel::getDefaultServerImagePathCollapsed()
|
||||
{
|
||||
const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||
const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
||||
// const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||
// const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||
// const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
||||
|
||||
if (countryCode.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
||||
// if (countryCode.isEmpty()) {
|
||||
// return "";
|
||||
// }
|
||||
// return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
||||
}
|
||||
|
|
|
@ -86,16 +86,12 @@ public slots:
|
|||
const ServerCredentials getProcessedServerCredentials();
|
||||
const ServerCredentials getServerCredentials(const int index);
|
||||
|
||||
void addServer(const QJsonObject &server);
|
||||
void editServer(const QJsonObject &server, const int serverIndex);
|
||||
void removeServer();
|
||||
void addServer(const QSharedPointer<ServerConfig> &serverConfig);
|
||||
void editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex);
|
||||
void removeProcessedServer();
|
||||
void removeServer(const int serverIndex);
|
||||
|
||||
QJsonObject getServerConfig(const int serverIndex);
|
||||
|
||||
void reloadDefaultServerContainerConfig();
|
||||
void updateContainerConfig(const int containerIndex, const QJsonObject config);
|
||||
void addContainerConfig(const int containerIndex, const QJsonObject config);
|
||||
QSharedPointer<const ServerConfig> getServerConfig(const int serverIndex);
|
||||
|
||||
void clearCachedProfile(const DockerContainer container);
|
||||
|
||||
|
@ -136,8 +132,8 @@ signals:
|
|||
void defaultServerNameChanged();
|
||||
void defaultServerDescriptionChanged();
|
||||
|
||||
void containersUpdated(const QJsonArray &containers);
|
||||
void defaultServerContainersUpdated(const QJsonArray &containers);
|
||||
void containersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||
void defaultServerContainersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||
void defaultServerDefaultContainerChanged(const int containerIndex);
|
||||
|
||||
void updateApiCountryModel();
|
||||
|
@ -155,7 +151,6 @@ private:
|
|||
|
||||
bool serverHasInstalledContainers(const int serverIndex) const;
|
||||
|
||||
QJsonArray m_servers;
|
||||
QVector<QSharedPointer<ServerConfig>> m_servers1;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue