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
|
@ -54,38 +54,43 @@ void CoreController::initModels()
|
||||||
m_appSplitTunnelingModel.reset(new AppSplitTunnelingModel(m_settings, this));
|
m_appSplitTunnelingModel.reset(new AppSplitTunnelingModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("AppSplitTunnelingModel", m_appSplitTunnelingModel.get());
|
m_engine->rootContext()->setContextProperty("AppSplitTunnelingModel", m_appSplitTunnelingModel.get());
|
||||||
|
|
||||||
m_protocolsModel.reset(new ProtocolsModel(m_settings, this));
|
m_openVpnConfigModel = QSharedPointer<OpenVpnConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
|
||||||
|
|
||||||
m_openVpnConfigModel.reset(new OpenVpnConfigModel(this));
|
|
||||||
m_engine->rootContext()->setContextProperty("OpenVpnConfigModel", m_openVpnConfigModel.get());
|
m_engine->rootContext()->setContextProperty("OpenVpnConfigModel", m_openVpnConfigModel.get());
|
||||||
|
|
||||||
m_shadowSocksConfigModel.reset(new ShadowSocksConfigModel(this));
|
m_shadowSocksConfigModel = QSharedPointer<ShadowSocksConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel", m_shadowSocksConfigModel.get());
|
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel", m_shadowSocksConfigModel.get());
|
||||||
|
|
||||||
m_cloakConfigModel.reset(new CloakConfigModel(this));
|
m_cloakConfigModel = QSharedPointer<CloakConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("CloakConfigModel", m_cloakConfigModel.get());
|
m_engine->rootContext()->setContextProperty("CloakConfigModel", m_cloakConfigModel.get());
|
||||||
|
|
||||||
m_wireGuardConfigModel.reset(new WireGuardConfigModel(this));
|
m_wireGuardConfigModel = QSharedPointer<WireGuardConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("WireGuardConfigModel", m_wireGuardConfigModel.get());
|
m_engine->rootContext()->setContextProperty("WireGuardConfigModel", m_wireGuardConfigModel.get());
|
||||||
|
|
||||||
m_awgConfigModel.reset(new AwgConfigModel(this));
|
m_awgConfigModel = QSharedPointer<AwgConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("AwgConfigModel", m_awgConfigModel.get());
|
m_engine->rootContext()->setContextProperty("AwgConfigModel", m_awgConfigModel.get());
|
||||||
|
|
||||||
m_xrayConfigModel.reset(new XrayConfigModel(this));
|
m_xrayConfigModel = QSharedPointer<XrayConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("XrayConfigModel", m_xrayConfigModel.get());
|
m_engine->rootContext()->setContextProperty("XrayConfigModel", m_xrayConfigModel.get());
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
m_ikev2ConfigModel.reset(new Ikev2ConfigModel(this));
|
m_ikev2ConfigModel = QSharedPointer<Ikev2ConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("Ikev2ConfigModel", m_ikev2ConfigModel.get());
|
m_engine->rootContext()->setContextProperty("Ikev2ConfigModel", m_ikev2ConfigModel.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_sftpConfigModel.reset(new SftpConfigModel(this));
|
m_sftpConfigModel = QSharedPointer<SftpConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("SftpConfigModel", m_sftpConfigModel.get());
|
m_engine->rootContext()->setContextProperty("SftpConfigModel", m_sftpConfigModel.get());
|
||||||
|
|
||||||
m_socks5ConfigModel.reset(new Socks5ProxyConfigModel(this));
|
m_socks5ConfigModel = QSharedPointer<Socks5ProxyConfigModel>::create(this);
|
||||||
m_engine->rootContext()->setContextProperty("Socks5ProxyConfigModel", m_socks5ConfigModel.get());
|
m_engine->rootContext()->setContextProperty("Socks5ProxyConfigModel", m_socks5ConfigModel.get());
|
||||||
|
|
||||||
|
m_protocolsModel.reset(new ProtocolsModel(m_openVpnConfigModel, m_shadowSocksConfigModel, m_cloakConfigModel, m_wireGuardConfigModel,
|
||||||
|
m_awgConfigModel, m_xrayConfigModel,
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
m_ikev2ConfigModel,
|
||||||
|
#endif
|
||||||
|
m_sftpConfigModel, m_socks5ConfigModel, this));
|
||||||
|
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
||||||
|
|
||||||
m_clientManagementModel.reset(new ClientManagementModel(m_settings, this));
|
m_clientManagementModel.reset(new ClientManagementModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("ClientManagementModel", m_clientManagementModel.get());
|
m_engine->rootContext()->setContextProperty("ClientManagementModel", m_clientManagementModel.get());
|
||||||
|
|
||||||
|
|
|
@ -129,17 +129,17 @@ private:
|
||||||
QSharedPointer<ApiAccountInfoModel> m_apiAccountInfoModel;
|
QSharedPointer<ApiAccountInfoModel> m_apiAccountInfoModel;
|
||||||
QSharedPointer<ApiDevicesModel> m_apiDevicesModel;
|
QSharedPointer<ApiDevicesModel> m_apiDevicesModel;
|
||||||
|
|
||||||
QScopedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
QSharedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
||||||
QScopedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
QSharedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
||||||
QScopedPointer<CloakConfigModel> m_cloakConfigModel;
|
QSharedPointer<CloakConfigModel> m_cloakConfigModel;
|
||||||
QScopedPointer<XrayConfigModel> m_xrayConfigModel;
|
QSharedPointer<XrayConfigModel> m_xrayConfigModel;
|
||||||
QScopedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
QSharedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
||||||
QScopedPointer<AwgConfigModel> m_awgConfigModel;
|
QSharedPointer<AwgConfigModel> m_awgConfigModel;
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
QScopedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
QSharedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
||||||
#endif
|
#endif
|
||||||
QScopedPointer<SftpConfigModel> m_sftpConfigModel;
|
QSharedPointer<SftpConfigModel> m_sftpConfigModel;
|
||||||
QScopedPointer<Socks5ProxyConfigModel> m_socks5ConfigModel;
|
QSharedPointer<Socks5ProxyConfigModel> m_socks5ConfigModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CORECONTROLLER_H
|
#endif // CORECONTROLLER_H
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
using namespace amnezia;
|
using namespace amnezia;
|
||||||
|
|
||||||
|
AwgProtocolConfig::AwgProtocolConfig(const QString &protocolName) : ProtocolConfig(protocolName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AwgProtocolConfig::AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
AwgProtocolConfig::AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
||||||
{
|
{
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
||||||
|
@ -68,6 +72,12 @@ AwgProtocolConfig::AwgProtocolConfig(const QJsonObject &protocolConfigObject, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AwgProtocolConfig::AwgProtocolConfig(const AwgProtocolConfig &other) : ProtocolConfig(other.protocolName)
|
||||||
|
{
|
||||||
|
serverProtocolConfig = other.serverProtocolConfig;
|
||||||
|
clientProtocolConfig = other.clientProtocolConfig;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject AwgProtocolConfig::toJson() const
|
QJsonObject AwgProtocolConfig::toJson() const
|
||||||
{
|
{
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
|
@ -196,3 +206,37 @@ QJsonObject AwgProtocolConfig::toJson() const
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AwgProtocolConfig::hasEqualServerSettings(const AwgProtocolConfig &other) const
|
||||||
|
{
|
||||||
|
if (serverProtocolConfig.subnetAddress != other.serverProtocolConfig.subnetAddress
|
||||||
|
|| serverProtocolConfig.port != other.serverProtocolConfig.port
|
||||||
|
|| serverProtocolConfig.awgData.junkPacketCount != other.serverProtocolConfig.awgData.junkPacketCount
|
||||||
|
|| serverProtocolConfig.awgData.junkPacketMinSize != other.serverProtocolConfig.awgData.junkPacketMinSize
|
||||||
|
|| serverProtocolConfig.awgData.junkPacketMaxSize != other.serverProtocolConfig.awgData.junkPacketMaxSize
|
||||||
|
|| serverProtocolConfig.awgData.initPacketJunkSize != other.serverProtocolConfig.awgData.initPacketJunkSize
|
||||||
|
|| serverProtocolConfig.awgData.responsePacketJunkSize != other.serverProtocolConfig.awgData.responsePacketJunkSize
|
||||||
|
|| serverProtocolConfig.awgData.initPacketMagicHeader != other.serverProtocolConfig.awgData.initPacketMagicHeader
|
||||||
|
|| serverProtocolConfig.awgData.responsePacketMagicHeader != other.serverProtocolConfig.awgData.responsePacketMagicHeader
|
||||||
|
|| serverProtocolConfig.awgData.underloadPacketMagicHeader != other.serverProtocolConfig.awgData.underloadPacketMagicHeader
|
||||||
|
|| serverProtocolConfig.awgData.transportPacketMagicHeader != other.serverProtocolConfig.awgData.transportPacketMagicHeader) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AwgProtocolConfig::hasEqualClientSettings(const AwgProtocolConfig &other) const
|
||||||
|
{
|
||||||
|
if (clientProtocolConfig.wireGuardData.mtu != other.clientProtocolConfig.wireGuardData.mtu
|
||||||
|
|| clientProtocolConfig.awgData.junkPacketCount != other.clientProtocolConfig.awgData.junkPacketCount
|
||||||
|
|| clientProtocolConfig.awgData.junkPacketMinSize != other.clientProtocolConfig.awgData.junkPacketMinSize
|
||||||
|
|| clientProtocolConfig.awgData.junkPacketMaxSize != other.clientProtocolConfig.awgData.junkPacketMaxSize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AwgProtocolConfig::clearClientSettings()
|
||||||
|
{
|
||||||
|
clientProtocolConfig = awg::ClientProtocolConfig();
|
||||||
|
}
|
||||||
|
|
|
@ -49,15 +49,24 @@ namespace awg
|
||||||
|
|
||||||
QString nativeConfig;
|
QString nativeConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int messageInitiationSize = 148;
|
||||||
|
const int messageResponseSize = 92;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AwgProtocolConfig : public ProtocolConfig
|
class AwgProtocolConfig : public ProtocolConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
AwgProtocolConfig(const QString &protocolName);
|
||||||
AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
||||||
|
AwgProtocolConfig(const AwgProtocolConfig &other);
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
QJsonObject toJson() const override;
|
||||||
|
|
||||||
|
bool hasEqualServerSettings(const AwgProtocolConfig &other) const;
|
||||||
|
bool hasEqualClientSettings(const AwgProtocolConfig &other) const;
|
||||||
|
void clearClientSettings();
|
||||||
|
|
||||||
awg::ServerProtocolConfig serverProtocolConfig;
|
awg::ServerProtocolConfig serverProtocolConfig;
|
||||||
awg::ClientProtocolConfig clientProtocolConfig;
|
awg::ClientProtocolConfig clientProtocolConfig;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,74 @@
|
||||||
#include "protocolConfig.h"
|
#include "protocolConfig.h"
|
||||||
|
|
||||||
#include <QJsonObject>
|
#include "core/models/protocols/awgProtocolConfig.h"
|
||||||
|
#include "core/models/protocols/cloakProtocolConfig.h"
|
||||||
|
#include "core/models/protocols/openvpnProtocolConfig.h"
|
||||||
|
#include "core/models/protocols/protocolConfig.h"
|
||||||
|
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
||||||
|
#include "core/models/protocols/xrayProtocolConfig.h"
|
||||||
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
|
using namespace amnezia;
|
||||||
|
|
||||||
ProtocolConfig::ProtocolConfig(const QString &protocolName) : protocolName(protocolName)
|
ProtocolConfig::ProtocolConfig(const QString &protocolName) : protocolName(protocolName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProtocolConfigVariant ProtocolConfig::getProtocolConfigVariant(const QSharedPointer<ProtocolConfig> &protocolConfig)
|
||||||
|
{
|
||||||
|
ProtocolConfigVariant variant;
|
||||||
|
auto proto = ProtocolProps::protoFromString(protocolConfig->protocolName);
|
||||||
|
switch (proto) {
|
||||||
|
case Proto::OpenVpn: variant = qSharedPointerCast<OpenVpnProtocolConfig>(protocolConfig); break;
|
||||||
|
case Proto::WireGuard: variant = qSharedPointerCast<WireGuardProtocolConfig>(protocolConfig); break;
|
||||||
|
case Proto::ShadowSocks: variant = qSharedPointerCast<ShadowsocksProtocolConfig>(protocolConfig); break;
|
||||||
|
case Proto::Cloak: variant = qSharedPointerCast<CloakProtocolConfig>(protocolConfig); break;
|
||||||
|
case Proto::Xray: variant = qSharedPointerCast<XrayProtocolConfig>(protocolConfig); break;
|
||||||
|
case Proto::Awg: variant = qSharedPointerCast<AwgProtocolConfig>(protocolConfig); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProtocolConfig::isServerSettingsEqual(const QSharedPointer<ProtocolConfig> &other)
|
||||||
|
{
|
||||||
|
auto proto = ProtocolProps::protoFromString(protocolName);
|
||||||
|
|
||||||
|
switch (proto) {
|
||||||
|
case Proto::OpenVpn: {
|
||||||
|
auto thisConfig = qSharedPointerCast<OpenVpnProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<OpenVpnProtocolConfig>(other);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Proto::WireGuard: {
|
||||||
|
auto thisConfig = qSharedPointerCast<WireGuardProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<WireGuardProtocolConfig>(other);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Proto::ShadowSocks: {
|
||||||
|
auto thisConfig = qSharedPointerCast<ShadowsocksProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<ShadowsocksProtocolConfig>(other);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Proto::Cloak: {
|
||||||
|
auto thisConfig = qSharedPointerCast<CloakProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<CloakProtocolConfig>(other);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Proto::Xray: {
|
||||||
|
auto thisConfig = qSharedPointerCast<XrayProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<XrayProtocolConfig>(other);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Proto::Awg: {
|
||||||
|
auto thisConfig = qSharedPointerCast<AwgProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
||||||
|
auto otherConfig = qSharedPointerCast<AwgProtocolConfig>(other);
|
||||||
|
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
||||||
|
}
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject ProtocolConfig::toJson() const
|
QJsonObject ProtocolConfig::toJson() const
|
||||||
{
|
{
|
||||||
return QJsonObject();
|
return QJsonObject();
|
||||||
|
|
|
@ -2,15 +2,30 @@
|
||||||
#define PROTOCOLCONFIG_H
|
#define PROTOCOLCONFIG_H
|
||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
class OpenVpnProtocolConfig;
|
||||||
|
class WireGuardProtocolConfig;
|
||||||
|
class ShadowsocksProtocolConfig;
|
||||||
|
class CloakProtocolConfig;
|
||||||
|
class XrayProtocolConfig;
|
||||||
|
class AwgProtocolConfig;
|
||||||
|
|
||||||
|
using ProtocolConfigVariant =
|
||||||
|
std::variant<QSharedPointer<OpenVpnProtocolConfig>, QSharedPointer<WireGuardProtocolConfig>, QSharedPointer<ShadowsocksProtocolConfig>,
|
||||||
|
QSharedPointer<CloakProtocolConfig>, QSharedPointer<XrayProtocolConfig>, QSharedPointer<AwgProtocolConfig> >;
|
||||||
|
|
||||||
class ProtocolConfig
|
class ProtocolConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProtocolConfig(const QString &protocolName);
|
ProtocolConfig(const QString &protocolName);
|
||||||
|
virtual QJsonObject toJson() const;
|
||||||
|
|
||||||
|
static ProtocolConfigVariant getProtocolConfigVariant(const QSharedPointer<ProtocolConfig> &protocolConfig);
|
||||||
|
bool isServerSettingsEqual(const QSharedPointer<ProtocolConfig> &protocolConfig);
|
||||||
|
|
||||||
QString protocolName;
|
QString protocolName;
|
||||||
|
|
||||||
virtual QJsonObject toJson() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROTOCOLCONFIG_H
|
#endif // PROTOCOLCONFIG_H
|
||||||
|
|
|
@ -15,10 +15,8 @@ ApiV1ServerConfig::ApiV1ServerConfig(const QJsonObject &serverConfigObject) : Se
|
||||||
|
|
||||||
QJsonObject ApiV1ServerConfig::toJson() const
|
QJsonObject ApiV1ServerConfig::toJson() const
|
||||||
{
|
{
|
||||||
// Сначала вызываем родительскую функцию для сериализации базовых полей
|
|
||||||
QJsonObject json = ServerConfig::toJson();
|
QJsonObject json = ServerConfig::toJson();
|
||||||
|
|
||||||
// Добавляем свои поля только если они не пустые
|
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
json[config_key::name] = name;
|
json[config_key::name] = name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,14 +38,15 @@ ApiV2ServerConfig::ApiV2ServerConfig(const QJsonObject &serverConfigObject) : Se
|
||||||
apiConfig.userCountryCode = apiConfigObject.value("user_country_code").toString();
|
apiConfig.userCountryCode = apiConfigObject.value("user_country_code").toString();
|
||||||
|
|
||||||
apiConfig.vpnKey = apiConfigObject.value("vpn_key").toString();
|
apiConfig.vpnKey = apiConfigObject.value("vpn_key").toString();
|
||||||
|
|
||||||
|
auto authDataObject = serverConfigObject.value("auth_data").toObject();
|
||||||
|
apiConfig.authData.apiKey = authDataObject.value("api_key").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ApiV2ServerConfig::toJson() const
|
QJsonObject ApiV2ServerConfig::toJson() const
|
||||||
{
|
{
|
||||||
// Сначала вызываем родительскую функцию для сериализации базовых полей
|
|
||||||
QJsonObject json = ServerConfig::toJson();
|
QJsonObject json = ServerConfig::toJson();
|
||||||
|
|
||||||
// Добавляем свои поля только если они не пустые
|
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
json[config_key::name] = name;
|
json[config_key::name] = name;
|
||||||
}
|
}
|
||||||
|
@ -53,10 +54,8 @@ QJsonObject ApiV2ServerConfig::toJson() const
|
||||||
json[config_key::description] = description;
|
json[config_key::description] = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация API конфигурации
|
|
||||||
QJsonObject apiConfigJson;
|
QJsonObject apiConfigJson;
|
||||||
|
|
||||||
// Сериализация доступных стран только если массив не пустой
|
|
||||||
if (!apiConfig.availableCountries.isEmpty()) {
|
if (!apiConfig.availableCountries.isEmpty()) {
|
||||||
QJsonArray availableCountriesArray;
|
QJsonArray availableCountriesArray;
|
||||||
for (const auto &country : apiConfig.availableCountries) {
|
for (const auto &country : apiConfig.availableCountries) {
|
||||||
|
@ -76,21 +75,18 @@ QJsonObject ApiV2ServerConfig::toJson() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация подписки только если есть данные
|
|
||||||
if (!apiConfig.subscription.end_date.isEmpty()) {
|
if (!apiConfig.subscription.end_date.isEmpty()) {
|
||||||
QJsonObject subscriptionObject;
|
QJsonObject subscriptionObject;
|
||||||
subscriptionObject["end_date"] = apiConfig.subscription.end_date;
|
subscriptionObject["end_date"] = apiConfig.subscription.end_date;
|
||||||
apiConfigJson["subscription"] = subscriptionObject;
|
apiConfigJson["subscription"] = subscriptionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация публичного ключа только если есть данные
|
|
||||||
if (!apiConfig.publicKey.expiresAt.isEmpty()) {
|
if (!apiConfig.publicKey.expiresAt.isEmpty()) {
|
||||||
QJsonObject publicKeyObject;
|
QJsonObject publicKeyObject;
|
||||||
publicKeyObject["expires_at"] = apiConfig.publicKey.expiresAt;
|
publicKeyObject["expires_at"] = apiConfig.publicKey.expiresAt;
|
||||||
apiConfigJson["public_key"] = publicKeyObject;
|
apiConfigJson["public_key"] = publicKeyObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация информации о сервере только если не пустая
|
|
||||||
if (!apiConfig.serverCountryCode.isEmpty()) {
|
if (!apiConfig.serverCountryCode.isEmpty()) {
|
||||||
apiConfigJson["server_country_code"] = apiConfig.serverCountryCode;
|
apiConfigJson["server_country_code"] = apiConfig.serverCountryCode;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +94,6 @@ QJsonObject ApiV2ServerConfig::toJson() const
|
||||||
apiConfigJson["server_country_name"] = apiConfig.serverCountryName;
|
apiConfigJson["server_country_name"] = apiConfig.serverCountryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация информации о сервисе только если не пустая
|
|
||||||
if (!apiConfig.serviceProtocol.isEmpty()) {
|
if (!apiConfig.serviceProtocol.isEmpty()) {
|
||||||
apiConfigJson["service_protocol"] = apiConfig.serviceProtocol;
|
apiConfigJson["service_protocol"] = apiConfig.serviceProtocol;
|
||||||
}
|
}
|
||||||
|
@ -106,17 +101,22 @@ QJsonObject ApiV2ServerConfig::toJson() const
|
||||||
apiConfigJson["service_type"] = apiConfig.serviceType;
|
apiConfigJson["service_type"] = apiConfig.serviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация информации о пользователе только если не пустая
|
|
||||||
if (!apiConfig.userCountryCode.isEmpty()) {
|
if (!apiConfig.userCountryCode.isEmpty()) {
|
||||||
apiConfigJson["user_country_code"] = apiConfig.userCountryCode;
|
apiConfigJson["user_country_code"] = apiConfig.userCountryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сериализация VPN ключа только если не пустой
|
|
||||||
if (!apiConfig.vpnKey.isEmpty()) {
|
if (!apiConfig.vpnKey.isEmpty()) {
|
||||||
apiConfigJson["vpn_key"] = apiConfig.vpnKey;
|
apiConfigJson["vpn_key"] = apiConfig.vpnKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Добавляем API конфигурацию в основной JSON только если есть данные
|
QJsonObject authDataJson;
|
||||||
|
if (!apiConfig.authData.apiKey.isEmpty()) {
|
||||||
|
authDataJson["api_key"] = apiConfig.authData.apiKey;
|
||||||
|
}
|
||||||
|
if (!authDataJson.isEmpty()) {
|
||||||
|
apiConfigJson["auth_data"] = authDataJson;
|
||||||
|
}
|
||||||
|
|
||||||
if (!apiConfigJson.isEmpty()) {
|
if (!apiConfigJson.isEmpty()) {
|
||||||
json["api_config"] = apiConfigJson;
|
json["api_config"] = apiConfigJson;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,19 @@ namespace apiv2
|
||||||
QString end_date;
|
QString end_date;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AuthData
|
||||||
|
{
|
||||||
|
QString apiKey;
|
||||||
|
};
|
||||||
|
|
||||||
struct ApiConfig {
|
struct ApiConfig {
|
||||||
QVector<Country> availableCountries;
|
QVector<Country> availableCountries;
|
||||||
|
|
||||||
Subscription subscription;
|
Subscription subscription;
|
||||||
PublicKey publicKey;
|
PublicKey publicKey;
|
||||||
|
|
||||||
|
AuthData authData;
|
||||||
|
|
||||||
QString serverCountryCode;
|
QString serverCountryCode;
|
||||||
QString serverCountryName;
|
QString serverCountryName;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,9 @@ ServerConfig::ServerConfig(const QJsonObject &serverConfigObject)
|
||||||
|
|
||||||
defaultContainer = serverConfigObject.value(config_key::defaultContainer).toString();
|
defaultContainer = serverConfigObject.value(config_key::defaultContainer).toString();
|
||||||
|
|
||||||
|
crc = serverConfigObject.value(config_key::crc).toInt(0);
|
||||||
|
nameOverriddenByUser = serverConfigObject.value(config_key::nameOverriddenByUser).toBool(false);
|
||||||
|
|
||||||
auto containers = serverConfigObject.value(config_key::containers).toArray();
|
auto containers = serverConfigObject.value(config_key::containers).toArray();
|
||||||
for (const auto &container : std::as_const(containers)) {
|
for (const auto &container : std::as_const(containers)) {
|
||||||
auto containerObject = container.toObject();
|
auto containerObject = container.toObject();
|
||||||
|
@ -98,6 +101,17 @@ QSharedPointer<ServerConfig> ServerConfig::createServerConfig(const QJsonObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerConfigVariant ServerConfig::getServerConfigVariant(const QSharedPointer<ServerConfig> &serverConfig)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject ServerConfig::toJson() const
|
QJsonObject ServerConfig::toJson() const
|
||||||
{
|
{
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
|
@ -143,3 +157,11 @@ QJsonObject ServerConfig::toJson() const
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerConfig::updateProtocolConfig(const QString &containerName, const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs)
|
||||||
|
{
|
||||||
|
if (containerConfigs.contains(containerName)) {
|
||||||
|
ContainerConfig &containerConfig = containerConfigs[containerName];
|
||||||
|
containerConfig.protocolConfigs = protocolConfigs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,13 @@
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/models/containers/containerConfig.h"
|
#include "core/models/containers/containerConfig.h"
|
||||||
|
|
||||||
|
class SelfHostedServerConfig;
|
||||||
|
class ApiV1ServerConfig;
|
||||||
|
class ApiV2ServerConfig;
|
||||||
|
|
||||||
|
using ServerConfigVariant =
|
||||||
|
std::variant<QSharedPointer<SelfHostedServerConfig>, QSharedPointer<ApiV1ServerConfig>, QSharedPointer<ApiV2ServerConfig> >;
|
||||||
|
|
||||||
class ServerConfig
|
class ServerConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -16,6 +23,9 @@ public:
|
||||||
virtual QJsonObject toJson() const;
|
virtual QJsonObject toJson() const;
|
||||||
|
|
||||||
static QSharedPointer<ServerConfig> createServerConfig(const QJsonObject &serverConfigObject);
|
static QSharedPointer<ServerConfig> createServerConfig(const QJsonObject &serverConfigObject);
|
||||||
|
static ServerConfigVariant getServerConfigVariant(const QSharedPointer<ServerConfig> &serverConfig);
|
||||||
|
|
||||||
|
void updateProtocolConfig(const QString &containerName, const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs);
|
||||||
|
|
||||||
amnezia::ServerConfigType type;
|
amnezia::ServerConfigType type;
|
||||||
|
|
||||||
|
@ -26,6 +36,9 @@ public:
|
||||||
|
|
||||||
QString defaultContainer;
|
QString defaultContainer;
|
||||||
|
|
||||||
|
bool nameOverriddenByUser;
|
||||||
|
int crc; // TODO it makes sense to add for all server types or move it to the api
|
||||||
|
|
||||||
QMap<QString, ContainerConfig> containerConfigs;
|
QMap<QString, ContainerConfig> containerConfigs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,15 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
|
#include "core/api/apiUtils.h"
|
||||||
#include "core/controllers/serverController.h"
|
#include "core/controllers/serverController.h"
|
||||||
#include "core/controllers/vpnConfigurationController.h"
|
#include "core/controllers/vpnConfigurationController.h"
|
||||||
|
#include "core/models/servers/selfHostedServerConfig.h"
|
||||||
#include "core/networkUtilities.h"
|
#include "core/networkUtilities.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "ui/models/protocols/awgConfigModel.h"
|
#include "ui/models/protocols/awgConfigModel.h"
|
||||||
#include "ui/models/protocols/wireguardConfigModel.h"
|
#include "ui/models/protocols/wireguardConfigModel.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "core/api/apiUtils.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -552,28 +553,34 @@ ErrorCode InstallController::getAlreadyInstalledContainers(const ServerCredentia
|
||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallController::updateContainer(QJsonObject config)
|
void InstallController::updateContainer()
|
||||||
{
|
{
|
||||||
int serverIndex = m_serversModel->getProcessedServerIndex();
|
int serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
ServerCredentials serverCredentials =
|
auto oldServerConfig = m_serversModel->getServerConfig(serverIndex);
|
||||||
qvariant_cast<ServerCredentials>(m_serversModel->data(serverIndex, ServersModel::Roles::CredentialsRole));
|
auto newServerConfig = QSharedPointer<SelfHostedServerConfig>::create(oldServerConfig);
|
||||||
|
|
||||||
|
const DockerContainer container = static_cast<DockerContainer>(m_containersModel->getProcessedContainerIndex());
|
||||||
|
const QString containerName = m_containersModel->getProcessedContainerName();
|
||||||
|
auto protocolConfigs = m_protocolModel->getProtocolConfigs();
|
||||||
|
newServerConfig->updateProtocolConfig(containerName, protocolConfigs);
|
||||||
|
|
||||||
|
auto oldProtocolConfigs = oldServerConfig->containerConfigs[containerName].protocolConfigs;
|
||||||
|
auto newProtocolConfigs = newServerConfig->containerConfigs[containerName].protocolConfigs;
|
||||||
|
|
||||||
const DockerContainer container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
|
||||||
QJsonObject oldContainerConfig = m_containersModel->getContainerConfig(container);
|
|
||||||
ErrorCode errorCode = ErrorCode::NoError;
|
ErrorCode errorCode = ErrorCode::NoError;
|
||||||
|
|
||||||
if (isUpdateDockerContainerRequired(container, oldContainerConfig, config)) {
|
if (isUpdateDockerContainerRequired(container, oldProtocolConfigs, newProtocolConfigs)) {
|
||||||
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
|
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
|
||||||
connect(serverController.get(), &ServerController::serverIsBusy, this, &InstallController::serverIsBusy);
|
connect(serverController.get(), &ServerController::serverIsBusy, this, &InstallController::serverIsBusy);
|
||||||
connect(this, &InstallController::cancelInstallation, serverController.get(), &ServerController::cancelInstallation);
|
connect(this, &InstallController::cancelInstallation, serverController.get(), &ServerController::cancelInstallation);
|
||||||
|
|
||||||
errorCode = serverController->updateContainer(serverCredentials, container, oldContainerConfig, config);
|
errorCode = serverController->updateContainer(newServerConfig->serverCredentials, container, oldContainerConfig, config);
|
||||||
clearCachedProfile(serverController);
|
clearCachedProfile(serverController);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
m_serversModel->updateContainerConfig(container, config);
|
m_serversModel->editServer(newServerConfig, serverIndex);
|
||||||
m_protocolModel->updateModel(config);
|
m_protocolModel->updateModel(protocolConfigs);
|
||||||
|
|
||||||
auto defaultContainer = qvariant_cast<DockerContainer>(m_serversModel->data(serverIndex, ServersModel::Roles::DefaultContainerRole));
|
auto defaultContainer = qvariant_cast<DockerContainer>(m_serversModel->data(serverIndex, ServersModel::Roles::DefaultContainerRole));
|
||||||
if ((serverIndex == m_serversModel->getDefaultServerIndex()) && (container == defaultContainer)) {
|
if ((serverIndex == m_serversModel->getDefaultServerIndex()) && (container == defaultContainer)) {
|
||||||
|
@ -607,7 +614,7 @@ void InstallController::removeProcessedServer()
|
||||||
int serverIndex = m_serversModel->getProcessedServerIndex();
|
int serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||||
|
|
||||||
m_serversModel->removeServer();
|
m_serversModel->removeProcessedServer();
|
||||||
emit removeProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
|
emit removeProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,29 +920,21 @@ bool InstallController::isConfigValid()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InstallController::isUpdateDockerContainerRequired(const DockerContainer container, const QJsonObject &oldConfig,
|
bool InstallController::isUpdateDockerContainerRequired(const DockerContainer container,
|
||||||
const QJsonObject &newConfig)
|
const QMap<QString, QSharedPointer<ProtocolConfig>> &oldProtocolConfigs,
|
||||||
|
const QMap<QString, QSharedPointer<ProtocolConfig>> &newProtocolConfigs)
|
||||||
{
|
{
|
||||||
Proto mainProto = ContainerProps::defaultProtocol(container);
|
Proto mainProto = ContainerProps::defaultProtocol(container);
|
||||||
|
|
||||||
const QJsonObject &oldProtoConfig = oldConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
const auto oldProtoConfig = oldProtocolConfigs.value(ProtocolProps::protoToString(mainProto));
|
||||||
const QJsonObject &newProtoConfig = newConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
const auto newProtoConfig = newProtocolConfigs.value(ProtocolProps::protoToString(mainProto));
|
||||||
|
|
||||||
if (container == DockerContainer::Awg) {
|
switch (mainProto) {
|
||||||
const AwgConfig oldConfig(oldProtoConfig);
|
case Proto::Awg: {
|
||||||
const AwgConfig newConfig(newProtoConfig);
|
auto newConfig = qSharedPointerCast<AwgProtocolConfig>(oldProtoConfig);
|
||||||
|
auto oldConfig = qSharedPointerCast<AwgProtocolConfig>(newProtoConfig);
|
||||||
if (oldConfig.hasEqualServerSettings(newConfig)) {
|
return !newConfig->hasEqualServerSettings(*oldConfig.data());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (container == DockerContainer::WireGuard) {
|
default: return true;
|
||||||
const WgConfig oldConfig(oldProtoConfig);
|
|
||||||
const WgConfig newConfig(newProtoConfig);
|
|
||||||
|
|
||||||
if (oldConfig.hasEqualServerSettings(newConfig)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public slots:
|
||||||
|
|
||||||
void scanServerForInstalledContainers();
|
void scanServerForInstalledContainers();
|
||||||
|
|
||||||
void updateContainer(QJsonObject config);
|
void updateContainer();
|
||||||
|
|
||||||
void removeProcessedServer();
|
void removeProcessedServer();
|
||||||
void rebootProcessedServer();
|
void rebootProcessedServer();
|
||||||
|
@ -94,7 +94,9 @@ private:
|
||||||
|
|
||||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, const QSharedPointer<ServerController> &serverController,
|
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, const QSharedPointer<ServerController> &serverController,
|
||||||
QMap<DockerContainer, QJsonObject> &installedContainers);
|
QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||||
bool isUpdateDockerContainerRequired(const DockerContainer container, const QJsonObject &oldConfig, const QJsonObject &newConfig);
|
bool isUpdateDockerContainerRequired(const DockerContainer container,
|
||||||
|
const QMap<QString, QSharedPointer<ProtocolConfig>> &oldProtocolConfigs,
|
||||||
|
const QMap<QString, QSharedPointer<ProtocolConfig>> &newProtocolConfigs);
|
||||||
|
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
QSharedPointer<ContainersModel> m_containersModel;
|
QSharedPointer<ContainersModel> m_containersModel;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
ContainersModel::ContainersModel(QObject *parent)
|
ContainersModel::ContainersModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
||||||
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
||||||
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
||||||
case EasySetupOrderRole: return ContainerProps::easySetupOrder(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 IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_processedContainerIndex);
|
||||||
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||||
case IsShareableRole: return ContainerProps::isShareable(container);
|
case IsShareableRole: return ContainerProps::isShareable(container);
|
||||||
|
@ -53,14 +52,10 @@ QVariant ContainersModel::data(const int index, int role) const
|
||||||
return data(modelIndex, role);
|
return data(modelIndex, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainersModel::updateModel(const QJsonArray &containers)
|
void ContainersModel::updateModel(const QMap<QString, ContainerConfig> &containerConfigs)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_containers.clear();
|
m_containerConfigs = containerConfigs;
|
||||||
for (const QJsonValue &val : containers) {
|
|
||||||
m_containers.insert(ContainerProps::containerFromString(val.toObject().value(config_key::container).toString()),
|
|
||||||
val.toObject());
|
|
||||||
}
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +91,8 @@ bool ContainersModel::isServiceContainer(const int containerIndex)
|
||||||
|
|
||||||
bool ContainersModel::hasInstalledServices()
|
bool ContainersModel::hasInstalledServices()
|
||||||
{
|
{
|
||||||
for (const auto &container : m_containers.keys()) {
|
for (const auto &containerName : m_containerConfigs.keys()) {
|
||||||
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,8 +101,8 @@ bool ContainersModel::hasInstalledServices()
|
||||||
|
|
||||||
bool ContainersModel::hasInstalledProtocols()
|
bool ContainersModel::hasInstalledProtocols()
|
||||||
{
|
{
|
||||||
for (const auto &container : m_containers.keys()) {
|
for (const auto &containerName : m_containerConfigs.keys()) {
|
||||||
if (ContainerProps::containerService(container) == ServiceType::Vpn) {
|
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Vpn) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
|
#include "core/models/containers/containerConfig.h"
|
||||||
|
|
||||||
class ContainersModel : public QAbstractListModel
|
class ContainersModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -42,7 +41,7 @@ public:
|
||||||
QVariant data(const int index, int role) const;
|
QVariant data(const int index, int role) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const QJsonArray &containers);
|
void updateModel(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||||
|
|
||||||
void setProcessedContainerIndex(int containerIndex);
|
void setProcessedContainerIndex(int containerIndex);
|
||||||
int getProcessedContainerIndex();
|
int getProcessedContainerIndex();
|
||||||
|
@ -64,7 +63,7 @@ signals:
|
||||||
void containersModelUpdated();
|
void containersModelUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<DockerContainer, QJsonObject> m_containers;
|
QMap<QString, ContainerConfig> m_containerConfigs;
|
||||||
|
|
||||||
int m_processedContainerIndex;
|
int m_processedContainerIndex;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#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) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: m_serverProtocolConfig.insert(config_key::subnet_address, value.toString()); break;
|
case Roles::SubnetAddressRole: m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress = value.toString(); break;
|
||||||
case Roles::PortRole: m_serverProtocolConfig.insert(config_key::port, 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::ClientMtuRole: m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu = value.toString(); break;
|
||||||
case Roles::ClientJunkPacketCountRole: m_clientProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
case Roles::ClientJunkPacketCountRole: m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
||||||
case Roles::ClientJunkPacketMinSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
case Roles::ClientJunkPacketMinSizeRole:
|
||||||
case Roles::ClientJunkPacketMaxSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize = value.toString();
|
||||||
|
break;
|
||||||
case Roles::ServerJunkPacketCountRole: m_serverProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
case Roles::ClientJunkPacketMaxSizeRole:
|
||||||
case Roles::ServerJunkPacketMinSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize = value.toString();
|
||||||
case Roles::ServerJunkPacketMaxSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
break;
|
||||||
case Roles::ServerInitPacketJunkSizeRole: m_serverProtocolConfig.insert(config_key::initPacketJunkSize, value.toString()); break;
|
|
||||||
case Roles::ServerResponsePacketJunkSizeRole:
|
case Roles::ServerJunkPacketCountRole: m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
||||||
m_serverProtocolConfig.insert(config_key::responsePacketJunkSize, value.toString());
|
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;
|
break;
|
||||||
case Roles::ServerInitPacketMagicHeaderRole: m_serverProtocolConfig.insert(config_key::initPacketMagicHeader, value.toString()); break;
|
|
||||||
case Roles::ServerResponsePacketMagicHeaderRole:
|
case Roles::ServerResponsePacketMagicHeaderRole:
|
||||||
m_serverProtocolConfig.insert(config_key::responsePacketMagicHeader, value.toString());
|
m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader = value.toString();
|
||||||
break;
|
break;
|
||||||
case Roles::ServerUnderloadPacketMagicHeaderRole:
|
case Roles::ServerUnderloadPacketMagicHeaderRole:
|
||||||
m_serverProtocolConfig.insert(config_key::underloadPacketMagicHeader, value.toString());
|
m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader = value.toString();
|
||||||
break;
|
break;
|
||||||
case Roles::ServerTransportPacketMagicHeaderRole:
|
case Roles::ServerTransportPacketMagicHeaderRole:
|
||||||
m_serverProtocolConfig.insert(config_key::transportPacketMagicHeader, value.toString());
|
m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader = value.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,94 +74,42 @@ QVariant AwgConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: return m_serverProtocolConfig.value(config_key::subnet_address).toString();
|
case Roles::SubnetAddressRole: return m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress;
|
||||||
case Roles::PortRole: return m_serverProtocolConfig.value(config_key::port).toString();
|
case Roles::PortRole: return m_newAwgProtocolConfig.serverProtocolConfig.port;
|
||||||
|
|
||||||
case Roles::ClientMtuRole: return m_clientProtocolConfig.value(config_key::mtu);
|
case Roles::ClientMtuRole: return m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu;
|
||||||
case Roles::ClientJunkPacketCountRole: return m_clientProtocolConfig.value(config_key::junkPacketCount);
|
case Roles::ClientJunkPacketCountRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount;
|
||||||
case Roles::ClientJunkPacketMinSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMinSize);
|
case Roles::ClientJunkPacketMinSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize;
|
||||||
case Roles::ClientJunkPacketMaxSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMaxSize);
|
case Roles::ClientJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize;
|
||||||
|
|
||||||
case Roles::ServerJunkPacketCountRole: return m_serverProtocolConfig.value(config_key::junkPacketCount);
|
case Roles::ServerJunkPacketCountRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount;
|
||||||
case Roles::ServerJunkPacketMinSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMinSize);
|
case Roles::ServerJunkPacketMinSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMinSize;
|
||||||
case Roles::ServerJunkPacketMaxSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMaxSize);
|
case Roles::ServerJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMaxSize;
|
||||||
case Roles::ServerInitPacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::initPacketJunkSize);
|
case Roles::ServerInitPacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketJunkSize;
|
||||||
case Roles::ServerResponsePacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::responsePacketJunkSize);
|
case Roles::ServerResponsePacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketJunkSize;
|
||||||
case Roles::ServerInitPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::initPacketMagicHeader);
|
case Roles::ServerInitPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketMagicHeader;
|
||||||
case Roles::ServerResponsePacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::responsePacketMagicHeader);
|
case Roles::ServerResponsePacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader;
|
||||||
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::underloadPacketMagicHeader);
|
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader;
|
||||||
case Roles::ServerTransportPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::transportPacketMagicHeader);
|
case Roles::ServerTransportPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AwgConfigModel::updateModel(const QJsonObject &config)
|
void AwgConfigModel::updateModel(const AwgProtocolConfig awgProtocolConfig)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
m_newAwgProtocolConfig = awgProtocolConfig;
|
||||||
|
m_oldAwgProtocolConfig = awgProtocolConfig;
|
||||||
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());
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject AwgConfigModel::getConfig()
|
QSharedPointer<ProtocolConfig> AwgConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
if (m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig)) {
|
||||||
const AwgConfig newConfig(m_serverProtocolConfig);
|
m_newAwgProtocolConfig.clearClientSettings();
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
return QSharedPointer<AwgProtocolConfig>::create(m_newAwgProtocolConfig);
|
||||||
m_fullConfig.insert(config_key::awg, m_serverProtocolConfig);
|
|
||||||
return m_fullConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4)
|
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)
|
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()
|
bool AwgConfigModel::isServerSettingsEqual()
|
||||||
{
|
{
|
||||||
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
return m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig);
|
||||||
const AwgConfig newConfig(m_serverProtocolConfig);
|
|
||||||
|
|
||||||
return oldConfig.hasEqualServerSettings(newConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||||
|
@ -191,53 +151,3 @@ QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
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 <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
|
#include "core/models/protocols/awgProtocolConfig.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;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class AwgConfigModel : public QAbstractListModel
|
class AwgConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -71,8 +40,8 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const QJsonObject &config);
|
void updateModel(const AwgProtocolConfig awgProtocolConfig);
|
||||||
QJsonObject getConfig();
|
QSharedPointer<ProtocolConfig> getConfig();
|
||||||
|
|
||||||
bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4);
|
bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4);
|
||||||
bool isPacketSizeEqual(const int s1, const int s2);
|
bool isPacketSizeEqual(const int s1, const int s2);
|
||||||
|
@ -83,10 +52,8 @@ protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DockerContainer m_container;
|
AwgProtocolConfig m_newAwgProtocolConfig;
|
||||||
QJsonObject m_serverProtocolConfig;
|
AwgProtocolConfig m_oldAwgProtocolConfig;
|
||||||
QJsonObject m_clientProtocolConfig;
|
|
||||||
QJsonObject m_fullConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AWGCONFIGMODEL_H
|
#endif // AWGCONFIGMODEL_H
|
||||||
|
|
|
@ -1,14 +1,41 @@
|
||||||
#include "protocols_model.h"
|
#include "protocols_model.h"
|
||||||
|
|
||||||
ProtocolsModel::ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent)
|
#include "core/models/protocols/awgProtocolConfig.h"
|
||||||
: m_settings(settings), QAbstractListModel(parent)
|
#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
|
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return m_content.size();
|
return m_protocolConfigs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
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
|
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();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto protocolConfig = m_protocolConfigs.at(index.row());
|
||||||
|
amnezia::Proto protocol = ProtocolProps::protoFromString(protocolConfig->protocolName);
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case ProtocolNameRole: {
|
case ProtocolNameRole: {
|
||||||
amnezia::Proto proto = ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
return ProtocolProps::protocolHumanNames().value(protocol);
|
||||||
return ProtocolProps::protocolHumanNames().value(proto);
|
|
||||||
}
|
}
|
||||||
case ServerProtocolPageRole:
|
case ServerProtocolPageRole: return static_cast<int>(serverProtocolPage(protocol));
|
||||||
return static_cast<int>(serverProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
case ClientProtocolPageRole: return static_cast<int>(clientProtocolPage(protocol));
|
||||||
case ClientProtocolPageRole:
|
case ProtocolIndexRole: return protocol;
|
||||||
return static_cast<int>(clientProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
// case RawConfigRole: {
|
||||||
case ProtocolIndexRole: return ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
// auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||||
case RawConfigRole: {
|
// auto lastConfigJsonDoc = QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||||
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
// auto lastConfigJson = lastConfigJsonDoc.object();
|
||||||
auto lastConfigJsonDoc =
|
|
||||||
QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
|
||||||
auto lastConfigJson = lastConfigJsonDoc.object();
|
|
||||||
|
|
||||||
QString rawConfig;
|
// QString rawConfig;
|
||||||
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
// QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||||
for (const QString &l : lines) {
|
// for (const QString &l : lines) {
|
||||||
rawConfig.append(l + "\n");
|
// rawConfig.append(l + "\n");
|
||||||
}
|
// }
|
||||||
return rawConfig;
|
// return rawConfig;
|
||||||
}
|
// }
|
||||||
case IsClientProtocolExistsRole: {
|
case IsClientProtocolExistsRole: {
|
||||||
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
auto protocolVariant = ProtocolConfig::getProtocolConfigVariant(protocolConfig);
|
||||||
auto lastConfigJsonDoc =
|
return std::visit([](const auto &ptr) -> bool { return ptr->clientProtocolConfig.isEmpty; }, protocolVariant);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
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());
|
beginResetModel();
|
||||||
|
m_protocolConfigs.clear();
|
||||||
m_content = content;
|
for (const auto &protocolConfig : protocolConfigs) {
|
||||||
m_content.remove(config_key::container);
|
m_protocolConfigs.push_back(protocolConfig);
|
||||||
|
}
|
||||||
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ProtocolsModel::getConfig()
|
void ProtocolsModel::updateProtocolModel(amnezia::Proto protocol)
|
||||||
{
|
{
|
||||||
QJsonObject config = m_content;
|
QSharedPointer<ProtocolConfig> protocolConfig;
|
||||||
config.insert(config_key::container, ContainerProps::containerToString(m_container));
|
|
||||||
return config;
|
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
|
PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
|
||||||
|
|
|
@ -4,8 +4,19 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "../controllers/pageController.h"
|
#include "core/models/protocols/protocolConfig.h"
|
||||||
#include "settings.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
|
class ProtocolsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -20,16 +31,26 @@ public:
|
||||||
IsClientProtocolExistsRole
|
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;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
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:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
@ -38,10 +59,19 @@ private:
|
||||||
PageLoader::PageEnum serverProtocolPage(Proto protocol) const;
|
PageLoader::PageEnum serverProtocolPage(Proto protocol) const;
|
||||||
PageLoader::PageEnum clientProtocolPage(Proto protocol) const;
|
PageLoader::PageEnum clientProtocolPage(Proto protocol) const;
|
||||||
|
|
||||||
std::shared_ptr<Settings> m_settings;
|
QVector<QSharedPointer<ProtocolConfig>> m_protocolConfigs;
|
||||||
|
|
||||||
DockerContainer m_container;
|
QSharedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
||||||
QJsonObject m_content;
|
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
|
#endif // PROTOCOLS_MODEL_H
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "core/models/servers/apiV1ServerConfig.h"
|
#include "core/models/servers/apiV1ServerConfig.h"
|
||||||
#include "core/models/servers/apiV2ServerConfig.h"
|
#include "core/models/servers/apiV2ServerConfig.h"
|
||||||
#include "core/models/servers/selfHostedServerConfig.h"
|
#include "core/models/servers/selfHostedServerConfig.h"
|
||||||
|
#include "core/models/servers/serverConfig.h"
|
||||||
#include "core/networkUtilities.h"
|
#include "core/networkUtilities.h"
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
|
@ -27,9 +28,6 @@ namespace
|
||||||
constexpr char publicKeyInfo[] = "public_key";
|
constexpr char publicKeyInfo[] = "public_key";
|
||||||
constexpr char expiresAt[] = "expires_at";
|
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)
|
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, &ServersModel::defaultServerNameChanged);
|
||||||
|
|
||||||
connect(this, &ServersModel::defaultServerIndexChanged, this, [this](const int serverIndex) {
|
connect(this, &ServersModel::defaultServerIndexChanged, this, [this](const int serverIndex) {
|
||||||
auto defaultContainer =
|
auto defaultContainer = ContainerProps::containerFromString(m_servers1.at(serverIndex)->defaultContainer);
|
||||||
ContainerProps::containerFromString(m_servers.at(serverIndex).toObject().value(config_key::defaultContainer).toString());
|
|
||||||
emit ServersModel::defaultServerDefaultContainerChanged(defaultContainer);
|
emit ServersModel::defaultServerDefaultContainerChanged(defaultContainer);
|
||||||
emit ServersModel::defaultServerNameChanged();
|
emit ServersModel::defaultServerNameChanged();
|
||||||
updateDefaultServerContainersModel();
|
updateDefaultServerContainersModel();
|
||||||
|
@ -53,28 +50,25 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||||
int ServersModel::rowCount(const QModelIndex &parent) const
|
int ServersModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
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)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject server = m_servers.at(index.row()).toObject();
|
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
||||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case NameRole: {
|
case NameRole: {
|
||||||
if (configVersion) {
|
std::visit([&value](const auto &ptr) -> void { ptr->name = value.toString(); }, variant);
|
||||||
server.insert(config_key::name, value.toString());
|
serverConfig->nameOverriddenByUser = true;
|
||||||
} else {
|
|
||||||
server.insert(config_key::description, value.toString());
|
m_settings->editServer(index.row(), serverConfig->toJson());
|
||||||
}
|
m_servers1.replace(index.row(), serverConfig);
|
||||||
server.insert(config_key::nameOverriddenByUser, true);
|
|
||||||
m_settings->editServer(index.row(), server);
|
|
||||||
m_servers.replace(index.row(), server);
|
|
||||||
if (index.row() == m_defaultServerIndex) {
|
if (index.row() == m_defaultServerIndex) {
|
||||||
emit defaultServerNameChanged();
|
emit defaultServerNameChanged();
|
||||||
}
|
}
|
||||||
|
@ -102,12 +96,7 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
||||||
ServerConfigVariant variant;
|
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case NameRole: {
|
case NameRole: {
|
||||||
|
@ -163,26 +152,13 @@ QVariant ServersModel::data(const int index, int role) const
|
||||||
void ServersModel::resetModel()
|
void ServersModel::resetModel()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_servers = m_settings->serversArray();
|
auto servers = m_settings->serversArray();
|
||||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||||
m_processedServerIndex = m_defaultServerIndex;
|
m_processedServerIndex = m_defaultServerIndex;
|
||||||
|
|
||||||
for (auto server : m_servers) {
|
for (auto server : servers) {
|
||||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
||||||
m_servers1.push_back(serverConfig);
|
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();
|
endResetModel();
|
||||||
|
@ -237,33 +213,33 @@ QString ServersModel::getServerDescription(const int index) const
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDescriptionCollapsed()
|
const QString ServersModel::getDefaultServerDescriptionCollapsed()
|
||||||
{
|
{
|
||||||
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
|
||||||
auto description = getServerDescription(m_defaultServerIndex);
|
auto description = getServerDescription(m_defaultServerIndex);
|
||||||
if (configVersion) {
|
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||||
|
|
||||||
|
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto container = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
return description += ContainerProps::containerHumanNames().value(containerName) + " | " + serverConfig->hostName;
|
||||||
|
|
||||||
return description += ContainerProps::containerHumanNames().value(container) + " | " + server.value(config_key::hostName).toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDescriptionExpanded()
|
const QString ServersModel::getDefaultServerDescriptionExpanded()
|
||||||
{
|
{
|
||||||
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||||
const auto configVersion = server.value(config_key::configVersion).toInt();
|
|
||||||
auto description = getServerDescription(m_defaultServerIndex);
|
auto description = getServerDescription(m_defaultServerIndex);
|
||||||
if (configVersion) {
|
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||||
|
|
||||||
|
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return description += server.value(config_key::hostName).toString();
|
return description += serverConfig->hostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ServersModel::getServersCount()
|
const int ServersModel::getServersCount()
|
||||||
{
|
{
|
||||||
return m_servers.count();
|
return m_servers1.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServersModel::hasServerWithWriteAccess()
|
bool ServersModel::hasServerWithWriteAccess()
|
||||||
|
@ -325,18 +301,22 @@ bool ServersModel::isDefaultServerHasWriteAccess()
|
||||||
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::addServer(const QJsonObject &server)
|
void ServersModel::addServer(const QSharedPointer<ServerConfig> &serverConfig)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_settings->addServer(server);
|
m_settings->addServer(serverConfig->toJson());
|
||||||
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);
|
||||||
|
}
|
||||||
endResetModel();
|
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_settings->editServer(serverIndex, serverConfig->toJson());
|
||||||
m_servers.replace(serverIndex, m_settings->serversArray().at(serverIndex));
|
m_servers1[serverIndex] = serverConfig;
|
||||||
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
||||||
|
|
||||||
if (serverIndex == m_defaultServerIndex) {
|
if (serverIndex == m_defaultServerIndex) {
|
||||||
|
@ -350,30 +330,20 @@ void ServersModel::editServer(const QJsonObject &server, const int serverIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeServer()
|
void ServersModel::removeProcessedServer()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
removeServer(m_processedServerIndex);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeServer(const int serverIndex)
|
void ServersModel::removeServer(const int serverIndex)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_settings->removeServer(serverIndex);
|
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) {
|
if (m_settings->defaultServerIndex() == serverIndex) {
|
||||||
setDefaultServerIndex(0);
|
setDefaultServerIndex(0);
|
||||||
|
@ -429,84 +399,27 @@ ServerCredentials ServersModel::serverCredentials(int index) const
|
||||||
|
|
||||||
void ServersModel::updateContainersModel()
|
void ServersModel::updateContainersModel()
|
||||||
{
|
{
|
||||||
auto containers = m_servers.at(m_processedServerIndex).toObject().value(config_key::containers).toArray();
|
auto containerConfigs = m_servers1.at(m_processedServerIndex)->containerConfigs;
|
||||||
emit containersUpdated(containers);
|
emit containersUpdated(containerConfigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::updateDefaultServerContainersModel()
|
void ServersModel::updateDefaultServerContainersModel()
|
||||||
{
|
{
|
||||||
auto containers = m_servers.at(m_defaultServerIndex).toObject().value(config_key::containers).toArray();
|
auto containerConfigs = m_servers1.at(m_defaultServerIndex)->containerConfigs;
|
||||||
emit defaultServerContainersUpdated(containers);
|
emit defaultServerContainersUpdated(containerConfigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ServersModel::getServerConfig(const int serverIndex)
|
QSharedPointer<const ServerConfig> ServersModel::getServerConfig(const int serverIndex)
|
||||||
{
|
{
|
||||||
return m_servers.at(serverIndex).toObject();
|
return m_servers1.at(serverIndex);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::setDefaultContainer(const int serverIndex, const int containerIndex)
|
void ServersModel::setDefaultContainer(const int serverIndex, const int containerIndex)
|
||||||
{
|
{
|
||||||
auto container = static_cast<DockerContainer>(containerIndex);
|
auto container = static_cast<DockerContainer>(containerIndex);
|
||||||
QJsonObject s = m_servers.at(serverIndex).toObject();
|
auto serverConfig = m_servers1.at(serverIndex);
|
||||||
s.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
serverConfig->defaultContainer = ContainerProps::containerToString(container);
|
||||||
editServer(s, serverIndex); // check
|
editServer(serverConfig, serverIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDefaultContainerName()
|
const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||||
|
@ -517,25 +430,19 @@ const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||||
|
|
||||||
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
||||||
{
|
{
|
||||||
|
|
||||||
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
QJsonObject s = m_servers.at(m_processedServerIndex).toObject();
|
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
||||||
s.insert(config_key::containers, {});
|
serverConfig->containerConfigs.clear();
|
||||||
s.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
editServer(serverConfig, m_processedServerIndex);
|
||||||
|
|
||||||
editServer(s, m_processedServerIndex);
|
|
||||||
}
|
}
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
||||||
{
|
{
|
||||||
|
ErrorCode errorCode = serverController->rebootServer(m_settings->serverCredentials(m_processedServerIndex));
|
||||||
auto credentials = m_settings->serverCredentials(m_processedServerIndex);
|
|
||||||
|
|
||||||
ErrorCode errorCode = serverController->rebootServer(credentials);
|
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,30 +455,19 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
||||||
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
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();
|
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||||
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());
|
|
||||||
if (defaultContainer == containerIndex) {
|
if (defaultContainer == containerIndex) {
|
||||||
if (containers.empty()) {
|
if (serverConfig->containerConfigs.empty()) {
|
||||||
defaultContainer = DockerContainer::None;
|
serverConfig->defaultContainer = ContainerProps::containerToString(DockerContainer::None);
|
||||||
} else {
|
} else {
|
||||||
defaultContainer =
|
serverConfig->defaultContainer = serverConfig->containerConfigs.begin()->containerName;
|
||||||
ContainerProps::containerFromString(containers.begin()->toObject().value(config_key::container).toString());
|
|
||||||
}
|
}
|
||||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(defaultContainer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
editServer(server, m_processedServerIndex);
|
editServer(serverConfig, m_processedServerIndex);
|
||||||
}
|
}
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
@ -579,7 +475,9 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
||||||
void ServersModel::clearCachedProfile(const DockerContainer container)
|
void ServersModel::clearCachedProfile(const DockerContainer container)
|
||||||
{
|
{
|
||||||
m_settings->clearLastConnectionConfig(m_processedServerIndex, 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) {
|
if (m_processedServerIndex == m_defaultServerIndex) {
|
||||||
updateDefaultServerContainersModel();
|
updateDefaultServerContainersModel();
|
||||||
}
|
}
|
||||||
|
@ -588,10 +486,9 @@ void ServersModel::clearCachedProfile(const DockerContainer container)
|
||||||
|
|
||||||
bool ServersModel::isAmneziaDnsContainerInstalled(const int serverIndex) const
|
bool ServersModel::isAmneziaDnsContainerInstalled(const int serverIndex) const
|
||||||
{
|
{
|
||||||
QJsonObject server = m_servers.at(serverIndex).toObject();
|
auto serverConfig = m_servers1.at(serverIndex);
|
||||||
auto containers = server.value(config_key::containers).toArray();
|
for (const auto &container : serverConfig->containerConfigs) {
|
||||||
for (auto it = containers.begin(); it != containers.end(); it++) {
|
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||||
if (it->toObject().value(config_key::container).toString() == ContainerProps::containerToString(DockerContainer::Dns)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,17 +499,16 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
||||||
{
|
{
|
||||||
QPair<QString, QString> dns;
|
QPair<QString, QString> dns;
|
||||||
|
|
||||||
const QJsonObject &server = m_servers.at(m_processedServerIndex).toObject();
|
auto serverConfig = m_servers1.at(serverIndex);
|
||||||
const auto containers = server.value(config_key::containers).toArray();
|
|
||||||
bool isDnsContainerInstalled = false;
|
bool isDnsContainerInstalled = false;
|
||||||
for (const QJsonValue &container : containers) {
|
for (const auto &container : serverConfig->containerConfigs) {
|
||||||
if (ContainerProps::containerFromString(container.toObject().value(config_key::container).toString()) == DockerContainer::Dns) {
|
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||||
isDnsContainerInstalled = true;
|
isDnsContainerInstalled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dns.first = server.value(config_key::dns1).toString();
|
dns.first = serverConfig->dns1;
|
||||||
dns.second = server.value(config_key::dns2).toString();
|
dns.second = serverConfig->dns2;
|
||||||
|
|
||||||
if (dns.first.isEmpty() || !NetworkUtilities::checkIPv4Format(dns.first)) {
|
if (dns.first.isEmpty() || !NetworkUtilities::checkIPv4Format(dns.first)) {
|
||||||
if (m_isAmneziaDnsEnabled && isDnsContainerInstalled) {
|
if (m_isAmneziaDnsEnabled && isDnsContainerInstalled) {
|
||||||
|
@ -631,18 +527,17 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
||||||
QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
||||||
{
|
{
|
||||||
QStringList servicesName;
|
QStringList servicesName;
|
||||||
QJsonObject server = m_servers.at(serverIndex).toObject();
|
auto serverConfig = m_servers1.at(serverIndex);
|
||||||
const auto containers = server.value(config_key::containers).toArray();
|
for (const auto &container : serverConfig->containerConfigs) {
|
||||||
for (auto it = containers.begin(); it != containers.end(); it++) {
|
auto containerType = ContainerProps::containerFromString(container.containerName);
|
||||||
auto container = ContainerProps::containerFromString(it->toObject().value(config_key::container).toString());
|
if (ContainerProps::containerService(containerType) == ServiceType::Other) {
|
||||||
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
if (containerType == DockerContainer::Dns) {
|
||||||
if (container == DockerContainer::Dns) {
|
|
||||||
servicesName.append("DNS");
|
servicesName.append("DNS");
|
||||||
} else if (container == DockerContainer::Sftp) {
|
} else if (containerType == DockerContainer::Sftp) {
|
||||||
servicesName.append("SFTP");
|
servicesName.append("SFTP");
|
||||||
} else if (container == DockerContainer::TorWebSite) {
|
} else if (containerType == DockerContainer::TorWebSite) {
|
||||||
servicesName.append("TOR");
|
servicesName.append("TOR");
|
||||||
} else if (container == DockerContainer::Socks5Proxy) {
|
} else if (containerType == DockerContainer::Socks5Proxy) {
|
||||||
servicesName.append("SOCKS5");
|
servicesName.append("SOCKS5");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -659,8 +554,8 @@ void ServersModel::toggleAmneziaDns(bool enabled)
|
||||||
|
|
||||||
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||||
{
|
{
|
||||||
for (const auto &server : std::as_const(m_servers)) {
|
for (const auto &server : std::as_const(m_servers1)) {
|
||||||
if (static_cast<quint16>(server.toObject().value(config_key::crc).toInt()) == crc) {
|
if (static_cast<quint16>(server->crc) == crc) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -669,11 +564,10 @@ bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||||
|
|
||||||
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
||||||
{
|
{
|
||||||
for (const auto &server : std::as_const(m_servers)) {
|
for (const auto &serverConfig : std::as_const(m_servers1)) {
|
||||||
const auto apiConfig = server.toObject().value(configKey::apiConfig).toObject();
|
const auto apiV2ServerConfig = qSharedPointerCast<ApiV2ServerConfig>(serverConfig);
|
||||||
if (apiConfig.value(configKey::userCountryCode).toString() == userCountryCode
|
if (apiV2ServerConfig->apiConfig.userCountryCode == userCountryCode && apiV2ServerConfig->apiConfig.serviceType == serviceType
|
||||||
&& apiConfig.value(configKey::serviceType).toString() == serviceType
|
&& apiV2ServerConfig->apiConfig.serviceProtocol == serviceProtocol) {
|
||||||
&& apiConfig.value(configKey::serviceProtocol).toString() == serviceProtocol) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -734,27 +628,46 @@ bool ServersModel::setProcessedServerData(const QString &roleString, const QVari
|
||||||
|
|
||||||
bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling()
|
bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling()
|
||||||
{
|
{
|
||||||
auto server = m_servers.at(m_defaultServerIndex).toObject();
|
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
||||||
auto defaultContainer = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
||||||
|
|
||||||
auto containers = server.value(config_key::containers).toArray();
|
for (const auto &container : serverConfig->containerConfigs) {
|
||||||
for (auto i = 0; i < containers.size(); i++) {
|
if (container.containerName != serverConfig->defaultContainer) {
|
||||||
auto container = containers.at(i).toObject();
|
|
||||||
if (container.value(config_key::container).toString() != ContainerProps::containerToString(defaultContainer)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
||||||
QJsonObject serverProtocolConfig = container.value(ContainerProps::containerTypeToString(defaultContainer)).toObject();
|
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(container.protocolConfigs[serverConfig->defaultContainer]);
|
||||||
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
return std::visit(
|
||||||
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(clientProtocolConfigString.toUtf8()).object();
|
[](const auto &ptr) -> bool {
|
||||||
return (clientProtocolConfigString.contains("AllowedIPs") && !clientProtocolConfigString.contains("AllowedIPs = 0.0.0.0/0, ::/0"))
|
if constexpr (requires {
|
||||||
|| (!clientProtocolConfig.value(config_key::allowed_ips).toArray().isEmpty()
|
ptr->clientProtocolConfig;
|
||||||
&& !clientProtocolConfig.value(config_key::allowed_ips).toArray().contains("0.0.0.0/0"));
|
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
|
} else if (defaultContainer == DockerContainer::Cloak || defaultContainer == DockerContainer::OpenVpn
|
||||||
|| defaultContainer == DockerContainer::ShadowSocks) {
|
|| defaultContainer == DockerContainer::ShadowSocks) {
|
||||||
auto serverProtocolConfig = container.value(ContainerProps::containerTypeToString(DockerContainer::OpenVpn)).toObject();
|
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(
|
||||||
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
container.protocolConfigs[ContainerProps::containerTypeToString(DockerContainer::OpenVpn)]);
|
||||||
return !clientProtocolConfigString.isEmpty() && !clientProtocolConfigString.contains("redirect-gateway");
|
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;
|
return false;
|
||||||
|
@ -767,62 +680,62 @@ bool ServersModel::isServerFromApi(const int serverIndex)
|
||||||
|
|
||||||
bool ServersModel::isApiKeyExpired(const int serverIndex)
|
bool ServersModel::isApiKeyExpired(const int serverIndex)
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers.at(serverIndex).toObject();
|
// auto serverConfig = m_servers1.at(serverIndex);
|
||||||
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
|
|
||||||
auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
// auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
||||||
const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
// const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
||||||
if (expiresAt.isEmpty()) {
|
// if (expiresAt.isEmpty()) {
|
||||||
publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
// publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
||||||
apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
// apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
||||||
serverConfig.insert(configKey::apiConfig, apiConfig);
|
// serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||||
editServer(serverConfig, serverIndex);
|
// editServer(serverConfig, serverIndex);
|
||||||
|
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
// auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
||||||
if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
// if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeApiConfig(const int serverIndex)
|
void ServersModel::removeApiConfig(const int serverIndex)
|
||||||
{
|
{
|
||||||
auto serverConfig = getServerConfig(serverIndex);
|
// auto serverConfig = m_servers1.at(serverIndex);
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
// #ifdef Q_OS_IOS
|
||||||
QString vpncName = QString("%1 (%2) %3")
|
// QString vpncName = QString("%1 (%2) %3")
|
||||||
.arg(serverConfig[config_key::description].toString())
|
// .arg(serverConfig[config_key::description].toString())
|
||||||
.arg(serverConfig[config_key::hostName].toString())
|
// .arg(serverConfig[config_key::hostName].toString())
|
||||||
.arg(serverConfig[config_key::vpnproto].toString());
|
// .arg(serverConfig[config_key::vpnproto].toString());
|
||||||
|
|
||||||
AmneziaVPN::removeVPNC(vpncName.toStdString());
|
// AmneziaVPN::removeVPNC(vpncName.toStdString());
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
serverConfig.remove(config_key::dns1);
|
// serverConfig.remove(config_key::dns1);
|
||||||
serverConfig.remove(config_key::dns2);
|
// serverConfig.remove(config_key::dns2);
|
||||||
serverConfig.remove(config_key::containers);
|
// serverConfig.remove(config_key::containers);
|
||||||
serverConfig.remove(config_key::hostName);
|
// serverConfig.remove(config_key::hostName);
|
||||||
|
|
||||||
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
apiConfig.remove(configKey::publicKeyInfo);
|
// apiConfig.remove(configKey::publicKeyInfo);
|
||||||
serverConfig.insert(configKey::apiConfig, apiConfig);
|
// 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 QString ServersModel::getDefaultServerImagePathCollapsed()
|
||||||
{
|
{
|
||||||
const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
// const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
// const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||||
const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
// const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
||||||
|
|
||||||
if (countryCode.isEmpty()) {
|
// if (countryCode.isEmpty()) {
|
||||||
return "";
|
// return "";
|
||||||
}
|
// }
|
||||||
return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
// return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,16 +86,12 @@ public slots:
|
||||||
const ServerCredentials getProcessedServerCredentials();
|
const ServerCredentials getProcessedServerCredentials();
|
||||||
const ServerCredentials getServerCredentials(const int index);
|
const ServerCredentials getServerCredentials(const int index);
|
||||||
|
|
||||||
void addServer(const QJsonObject &server);
|
void addServer(const QSharedPointer<ServerConfig> &serverConfig);
|
||||||
void editServer(const QJsonObject &server, const int serverIndex);
|
void editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex);
|
||||||
void removeServer();
|
void removeProcessedServer();
|
||||||
void removeServer(const int serverIndex);
|
void removeServer(const int serverIndex);
|
||||||
|
|
||||||
QJsonObject getServerConfig(const int serverIndex);
|
QSharedPointer<const ServerConfig> getServerConfig(const int serverIndex);
|
||||||
|
|
||||||
void reloadDefaultServerContainerConfig();
|
|
||||||
void updateContainerConfig(const int containerIndex, const QJsonObject config);
|
|
||||||
void addContainerConfig(const int containerIndex, const QJsonObject config);
|
|
||||||
|
|
||||||
void clearCachedProfile(const DockerContainer container);
|
void clearCachedProfile(const DockerContainer container);
|
||||||
|
|
||||||
|
@ -136,8 +132,8 @@ signals:
|
||||||
void defaultServerNameChanged();
|
void defaultServerNameChanged();
|
||||||
void defaultServerDescriptionChanged();
|
void defaultServerDescriptionChanged();
|
||||||
|
|
||||||
void containersUpdated(const QJsonArray &containers);
|
void containersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||||
void defaultServerContainersUpdated(const QJsonArray &containers);
|
void defaultServerContainersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
||||||
void defaultServerDefaultContainerChanged(const int containerIndex);
|
void defaultServerDefaultContainerChanged(const int containerIndex);
|
||||||
|
|
||||||
void updateApiCountryModel();
|
void updateApiCountryModel();
|
||||||
|
@ -155,7 +151,6 @@ private:
|
||||||
|
|
||||||
bool serverHasInstalledContainers(const int serverIndex) const;
|
bool serverHasInstalledContainers(const int serverIndex) const;
|
||||||
|
|
||||||
QJsonArray m_servers;
|
|
||||||
QVector<QSharedPointer<ServerConfig>> m_servers1;
|
QVector<QSharedPointer<ServerConfig>> m_servers1;
|
||||||
|
|
||||||
std::shared_ptr<Settings> m_settings;
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
|
@ -101,10 +101,7 @@ PageType {
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
if (isClientProtocolExists) {
|
if (isClientProtocolExists) {
|
||||||
switch (protocolIndex) {
|
ProtocolsModel.updateProtocolModel(protocolIndex)
|
||||||
case ProtocolEnum.WireGuard: WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Awg: AwgConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
}
|
|
||||||
PageController.goToPage(clientProtocolPage);
|
PageController.goToPage(clientProtocolPage);
|
||||||
} else {
|
} else {
|
||||||
PageController.showNotificationMessage(qsTr("Click the \"connect\" button to create a connection configuration"))
|
PageController.showNotificationMessage(qsTr("Click the \"connect\" button to create a connection configuration"))
|
||||||
|
@ -132,17 +129,7 @@ PageType {
|
||||||
visible: delegateContent.isServerSettingsVisible
|
visible: delegateContent.isServerSettingsVisible
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
switch (protocolIndex) {
|
ProtocolsModel.updateProtocolModel(protocolIndex)
|
||||||
case ProtocolEnum.OpenVpn: OpenVpnConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.ShadowSocks: ShadowSocksConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Cloak: CloakConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.WireGuard: WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Awg: AwgConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Xray: XrayConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Sftp: SftpConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Ipsec: Ikev2ConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
case ProtocolEnum.Socks5Proxy: Socks5ProxyConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
|
||||||
}
|
|
||||||
PageController.goToPage(serverProtocolPage);
|
PageController.goToPage(serverProtocolPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue