mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fix: fixes after merge with dev
This commit is contained in:
@@ -512,39 +512,42 @@ ImportController::ImportResult ImportController::importLink(const QUrl &url)
|
||||
return result;
|
||||
}
|
||||
|
||||
ImportController::ImportResult ImportController::editServerConfigWithData(QString data, int serverIndex, const QJsonObject& uiConfig)
|
||||
ImportController::ImportResult ImportController::editServerConfigWithData(const QString &serverId, QString data, const QJsonObject& uiConfig)
|
||||
{
|
||||
ImportResult result = extractConfigFromData(data);
|
||||
|
||||
if (result.errorCode != ErrorCode::NoError)
|
||||
return result;
|
||||
|
||||
const QJsonObject currentConfig = m_serversRepository->server(serverIndex).toJson();
|
||||
QJsonObject editedConfig = result.config;
|
||||
|
||||
for (auto it = uiConfig.begin(); it != uiConfig.end(); ++it) {
|
||||
editedConfig.insert(it.key(), it.value());
|
||||
}
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
if (!cfg.has_value()) {
|
||||
result.errorCode = ErrorCode::ImportInvalidConfigError;
|
||||
break;
|
||||
}
|
||||
|
||||
QJsonObject currentConfig = cfg->toJson();
|
||||
|
||||
for (auto it = uiConfig.begin(); it != uiConfig.end(); ++it) {
|
||||
editedConfig.insert(it.key(), it.value());
|
||||
}
|
||||
|
||||
if (currentConfig.contains(configKey::description)) {
|
||||
editedConfig.insert(configKey::description, currentConfig.value(configKey::description));
|
||||
}
|
||||
|
||||
if (currentConfig.contains(configKey::xraySubscriptionConfig)) {
|
||||
editedConfig.insert(configKey::xraySubscriptionConfig, currentConfig.value(configKey::xraySubscriptionConfig));
|
||||
}
|
||||
|
||||
if (currentConfig.contains(configKey::xraySubscriptionConfigName)) {
|
||||
editedConfig.insert(configKey::xraySubscriptionConfigName, currentConfig.value(configKey::xraySubscriptionConfigName));
|
||||
}
|
||||
|
||||
if (currentConfig.contains(configKey::xraySubscriptionConfigCurrent)) {
|
||||
editedConfig.insert(configKey::xraySubscriptionConfigCurrent, currentConfig.value(configKey::xraySubscriptionConfigCurrent));
|
||||
|
||||
m_serversRepository->editServer(serverId, editedConfig, kind);
|
||||
|
||||
break;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default: result.errorCode = ErrorCode::ImportInvalidConfigError;
|
||||
}
|
||||
|
||||
const ServerConfig finalServerConfig = ServerConfig::fromJson(editedConfig);
|
||||
|
||||
m_serversRepository->editServer(serverIndex, finalServerConfig);
|
||||
|
||||
result.config = editedConfig;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
int qrChunksTotal() const;
|
||||
|
||||
ImportResult importLink(const QUrl &url);
|
||||
ImportResult editServerConfigWithData(QString data, int serverIndex, const QJsonObject &uiConfig);
|
||||
ImportResult editServerConfigWithData(const QString &serverId, QString data, const QJsonObject &uiConfig);
|
||||
bool isValidBase64(const QByteArray &input);
|
||||
|
||||
void importConfig(const QJsonObject &config);
|
||||
|
||||
@@ -61,6 +61,13 @@ bool ServersController::renameServer(const QString &serverId, const QString &nam
|
||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
||||
return true;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
if (!cfg.has_value()) return false;
|
||||
cfg->description = name;
|
||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
||||
return true;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::AmneziaPremiumV2:
|
||||
case serverConfigUtils::ConfigType::AmneziaFreeV3:
|
||||
case serverConfigUtils::ConfigType::ExternalPremium: {
|
||||
@@ -114,6 +121,13 @@ void ServersController::setDefaultContainer(const QString &serverId, DockerConta
|
||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
||||
return;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
if (!cfg.has_value()) return;
|
||||
cfg->defaultContainer = container;
|
||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
||||
return;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::AmneziaPremiumV2:
|
||||
case serverConfigUtils::ConfigType::AmneziaFreeV3:
|
||||
case serverConfigUtils::ConfigType::ExternalPremium: {
|
||||
@@ -131,6 +145,75 @@ void ServersController::setDefaultContainer(const QString &serverId, DockerConta
|
||||
}
|
||||
}
|
||||
|
||||
void ServersController::setCurrentConfigIndex(const QString &serverId, const int index)
|
||||
{
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
if (!cfg.has_value()) return;
|
||||
cfg->currentConfig = index;
|
||||
m_serversRepository->editServer(serverId, cfg->toJson(), kind);
|
||||
return;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
int ServersController::getCurrentConfigIndex(const QString &serverId) const
|
||||
{
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->currentConfig : int();
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default: return int();
|
||||
}
|
||||
}
|
||||
|
||||
QString ServersController::getConfigString(const QString &serverId, const int index) const
|
||||
{
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->configString.at(index).toString() : QString();
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
QString ServersController::getConfigName(const QString &serverId, const int index) const
|
||||
{
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->configName.at(index).toString() : QString();
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default: return QString();
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray ServersController::getConfigNames(const QString &serverId) const
|
||||
{
|
||||
const serverConfigUtils::ConfigType kind = m_serversRepository->serverKind(serverId);
|
||||
switch (kind) {
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->configName : QJsonArray();
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default: return QJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<ServerDescription> ServersController::buildServerDescriptions(bool isAmneziaDnsEnabled) const
|
||||
{
|
||||
QVector<ServerDescription> out;
|
||||
@@ -166,6 +249,14 @@ QVector<ServerDescription> ServersController::buildServerDescriptions(bool isAmn
|
||||
d = buildServerDescription(*cfg, isAmneziaDnsEnabled);
|
||||
break;
|
||||
}
|
||||
case Kind::XRaySubscription: {
|
||||
const auto cfg = m_serversRepository->xraySubscriptionConfig(id);
|
||||
if (!cfg) {
|
||||
continue;
|
||||
}
|
||||
d = buildServerDescription(*cfg, isAmneziaDnsEnabled);
|
||||
break;
|
||||
}
|
||||
case Kind::AmneziaPremiumV2:
|
||||
case Kind::AmneziaFreeV3:
|
||||
case Kind::ExternalPremium: {
|
||||
@@ -197,60 +288,37 @@ QVector<ServerDescription> ServersController::buildServerDescriptions(bool isAmn
|
||||
}
|
||||
|
||||
QMap<DockerContainer, ContainerConfig> ServersController::getServerContainersMap(const QString &serverId) const
|
||||
void ServersController::setCurrentConfigIndex(const int serverIndex, const int index)
|
||||
{
|
||||
m_serversRepository->setCurrentConfigIndex(serverIndex, index);
|
||||
}
|
||||
|
||||
int ServersController::getCurrentConfigIndex(const int serverIndex) const
|
||||
{
|
||||
return m_serversRepository->getCurrentConfigIndex(serverIndex);
|
||||
}
|
||||
|
||||
QString ServersController::getConfigString(const int serverIndex, const int index) const
|
||||
{
|
||||
return m_serversRepository->getConfigString(serverIndex, index);
|
||||
}
|
||||
|
||||
QString ServersController::getConfigName(const int serverIndex, const int index) const
|
||||
{
|
||||
return m_serversRepository->getConfigName(serverIndex, index);
|
||||
}
|
||||
|
||||
QJsonArray ServersController::getConfigNames(const int serverIndex) const
|
||||
{
|
||||
return m_serversRepository->getConfigNames(serverIndex);
|
||||
}
|
||||
|
||||
QJsonArray ServersController::getServersArray() const
|
||||
{
|
||||
switch (m_serversRepository->serverKind(serverId)) {
|
||||
case serverConfigUtils::ConfigType::SelfHostedAdmin: {
|
||||
const auto cfg = m_serversRepository->selfHostedAdminConfig(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig>{};
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::SelfHostedUser: {
|
||||
const auto cfg = m_serversRepository->selfHostedUserConfig(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig>{};
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Native: {
|
||||
const auto cfg = m_serversRepository->nativeConfig(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig>{};
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
const auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::AmneziaPremiumV2:
|
||||
case serverConfigUtils::ConfigType::AmneziaFreeV3:
|
||||
case serverConfigUtils::ConfigType::ExternalPremium: {
|
||||
const auto cfg = m_serversRepository->apiV2Config(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig>{};
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::AmneziaPremiumV1:
|
||||
case serverConfigUtils::ConfigType::AmneziaFreeV2: {
|
||||
const auto cfg = m_serversRepository->legacyApiConfig(serverId);
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig>{};
|
||||
return cfg.has_value() ? cfg->containers : QMap<DockerContainer, ContainerConfig> {};
|
||||
}
|
||||
case serverConfigUtils::ConfigType::Invalid:
|
||||
default:
|
||||
return {};
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +337,10 @@ DockerContainer ServersController::getDefaultContainer(const QString &serverId)
|
||||
const auto cfg = m_serversRepository->nativeConfig(serverId);
|
||||
return cfg.has_value() ? cfg->defaultContainer : DockerContainer::None;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::XRaySubscription: {
|
||||
const auto cfg = m_serversRepository->xraySubscriptionConfig(serverId);
|
||||
return cfg.has_value() ? cfg->defaultContainer : DockerContainer::None;
|
||||
}
|
||||
case serverConfigUtils::ConfigType::AmneziaPremiumV2:
|
||||
case serverConfigUtils::ConfigType::AmneziaFreeV3:
|
||||
case serverConfigUtils::ConfigType::ExternalPremium: {
|
||||
@@ -348,6 +420,14 @@ QString ServersController::notificationDisplayName(const QString &serverId) cons
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Kind::XRaySubscription: {
|
||||
if (const auto cfg = m_serversRepository->xraySubscriptionConfig(serverId)) {
|
||||
if (!cfg->displayName.isEmpty()) {
|
||||
return cfg->displayName;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Kind::AmneziaPremiumV2:
|
||||
case Kind::AmneziaFreeV3:
|
||||
case Kind::ExternalPremium: {
|
||||
|
||||
@@ -44,11 +44,11 @@ public:
|
||||
void setDefaultContainer(const QString &serverId, DockerContainer container);
|
||||
|
||||
// XRay subscription config getters/setters
|
||||
void setCurrentConfigIndex(const int serverIndex, int index);
|
||||
int getCurrentConfigIndex(const int serverIndex) const;
|
||||
QString getConfigString(const int serverIndex, const int index) const;
|
||||
QString getConfigName(const int serverIndex, const int index) const;
|
||||
QJsonArray getConfigNames(const int serverIndex) const;
|
||||
void setCurrentConfigIndex(const QString &serverId, int index);
|
||||
int getCurrentConfigIndex(const QString &serverId) const;
|
||||
QString getConfigString(const QString &serverId, const int index) const;
|
||||
QString getConfigName(const QString &serverId, const int index) const;
|
||||
QJsonArray getConfigNames(const QString &serverId) const;
|
||||
|
||||
// Getters
|
||||
QVector<ServerDescription> buildServerDescriptions(bool isAmneziaDnsEnabled) const;
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace amnezia
|
||||
if (!description.isEmpty()) {
|
||||
obj[configKey::description] = this->description;
|
||||
}
|
||||
if (!displayName.isEmpty()) {
|
||||
obj[configKey::displayName] = displayName;
|
||||
}
|
||||
if (!hostName.isEmpty()) {
|
||||
obj[configKey::hostName] = hostName;
|
||||
}
|
||||
@@ -76,6 +79,7 @@ namespace amnezia
|
||||
XRaySubscriptionConfig config;
|
||||
|
||||
config.description = json.value(configKey::description).toString();
|
||||
config.displayName = json.value(configKey::displayName).toString();
|
||||
config.hostName = json.value(configKey::hostName).toString();
|
||||
|
||||
QJsonArray containersArray = json.value(configKey::containers).toArray();
|
||||
@@ -95,6 +99,10 @@ namespace amnezia
|
||||
config.dns1 = json.value(configKey::dns1).toString();
|
||||
config.dns2 = json.value(configKey::dns2).toString();
|
||||
|
||||
if (config.displayName.isEmpty()) {
|
||||
config.displayName = config.description.isEmpty() ? config.hostName : config.description;
|
||||
}
|
||||
|
||||
config.configString = json.value(configKey::xraySubscriptionConfig).toArray();
|
||||
config.configName = json.value(configKey::xraySubscriptionConfigName).toArray();
|
||||
config.currentConfig = json.value(configKey::xraySubscriptionConfigCurrent).toInt();
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace amnezia
|
||||
struct XRaySubscriptionConfig
|
||||
{
|
||||
QString description;
|
||||
QString displayName;
|
||||
QString hostName;
|
||||
QMap<DockerContainer, ContainerConfig> containers;
|
||||
DockerContainer defaultContainer;
|
||||
|
||||
@@ -130,6 +130,20 @@ ServerDescription buildServerDescription(const NativeServerConfig &server, bool
|
||||
return row;
|
||||
}
|
||||
|
||||
ServerDescription buildServerDescription(const XRaySubscriptionConfig &server, bool isAmneziaDnsEnabled)
|
||||
{
|
||||
ServerDescription row = buildBaseDescription(server);
|
||||
row.hasWriteAccess = false;
|
||||
row.isXRaySubscription = true;
|
||||
|
||||
row.serverName = server.displayName;
|
||||
row.baseDescription = getBaseDescription(server.containers, isAmneziaDnsEnabled, row.hasWriteAccess, row.primaryDnsIsAmnezia);
|
||||
|
||||
row.expandedServerDescription = row.baseDescription + server.configName.at(server.currentConfig).toString();
|
||||
row.collapsedServerDescription = row.baseDescription + server.configName.at(server.currentConfig).toString();
|
||||
return row;
|
||||
}
|
||||
|
||||
ServerDescription buildServerDescription(const LegacyApiServerConfig &server, bool /*isAmneziaDnsEnabled*/)
|
||||
{
|
||||
ServerDescription row = buildBaseDescription(server);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "core/models/selfhosted/selfHostedAdminServerConfig.h"
|
||||
#include "core/models/selfhosted/selfHostedUserServerConfig.h"
|
||||
#include "core/models/selfhosted/nativeServerConfig.h"
|
||||
#include "core/models/selfhosted/xraySubscriptionConfig.h"
|
||||
#include "core/models/api/legacyApiServerConfig.h"
|
||||
#include "core/models/api/apiV2ServerConfig.h"
|
||||
|
||||
@@ -32,6 +33,8 @@ struct ServerDescription
|
||||
DockerContainer defaultContainer = DockerContainer::None;
|
||||
bool hasInstalledVpnContainers = false;
|
||||
|
||||
bool isXRaySubscription = false;
|
||||
|
||||
bool isApiV1 = false;
|
||||
bool isApiV2 = false;
|
||||
bool isServerFromGatewayApi = false;
|
||||
@@ -56,6 +59,7 @@ struct ServerDescription
|
||||
ServerDescription buildServerDescription(const SelfHostedAdminServerConfig &server, bool isAmneziaDnsEnabled);
|
||||
ServerDescription buildServerDescription(const SelfHostedUserServerConfig &server, bool isAmneziaDnsEnabled);
|
||||
ServerDescription buildServerDescription(const NativeServerConfig &server, bool isAmneziaDnsEnabled);
|
||||
ServerDescription buildServerDescription(const XRaySubscriptionConfig &server, bool isAmneziaDnsEnabled);
|
||||
ServerDescription buildServerDescription(const LegacyApiServerConfig &server, bool isAmneziaDnsEnabled);
|
||||
ServerDescription buildServerDescription(const ApiV2ServerConfig &server, bool isAmneziaDnsEnabled);
|
||||
|
||||
|
||||
@@ -286,6 +286,19 @@ std::optional<NativeServerConfig> SecureServersRepository::nativeConfig(const QS
|
||||
return NativeServerConfig::fromJson(strippedJson);
|
||||
}
|
||||
|
||||
std::optional<XRaySubscriptionConfig> SecureServersRepository::xraySubscriptionConfig(const QString &serverId) const
|
||||
{
|
||||
const auto it = m_serverJsonById.constFind(serverId);
|
||||
if (it == m_serverJsonById.constEnd()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const QJsonObject strippedJson = withoutStorageServerId(it.value());
|
||||
if (serverConfigUtils::configTypeFromJson(strippedJson) != serverConfigUtils::ConfigType::XRaySubscription) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return XRaySubscriptionConfig::fromJson(strippedJson);
|
||||
}
|
||||
|
||||
std::optional<ApiV2ServerConfig> SecureServersRepository::apiV2Config(const QString &serverId) const
|
||||
{
|
||||
const auto it = m_serverJsonById.constFind(serverId);
|
||||
@@ -299,65 +312,6 @@ std::optional<ApiV2ServerConfig> SecureServersRepository::apiV2Config(const QStr
|
||||
return ApiV2ServerConfig::fromJson(strippedJson);
|
||||
}
|
||||
|
||||
void SecureServersRepository::setCurrentConfigIndex(const int serverIndex, const int index)
|
||||
{
|
||||
ServerConfig serverConfig = server(serverIndex);
|
||||
|
||||
if (serverConfig.isXRayConfig()) {
|
||||
XRaySubscriptionConfig* xrayConfig = serverConfig.as<XRaySubscriptionConfig>();
|
||||
if (xrayConfig && xrayConfig->currentConfig != index) {
|
||||
xrayConfig->currentConfig = index;
|
||||
editServer(serverIndex, serverConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SecureServersRepository::getCurrentConfigIndex(const int serverIndex) const
|
||||
{
|
||||
ServerConfig serverConfig = server(serverIndex);
|
||||
if (!serverConfig.isXRayConfig())
|
||||
return int();
|
||||
|
||||
const XRaySubscriptionConfig* xrayConfig = serverConfig.as<XRaySubscriptionConfig>();
|
||||
if (xrayConfig->currentConfig < 0)
|
||||
return int();
|
||||
|
||||
return xrayConfig->currentConfig;
|
||||
}
|
||||
|
||||
QString SecureServersRepository::getConfigString(const int serverIndex, const int index) const
|
||||
{
|
||||
ServerConfig serverConfig = server(serverIndex);
|
||||
if (!serverConfig.isXRayConfig())
|
||||
return QString();
|
||||
|
||||
const XRaySubscriptionConfig* xrayConfig = serverConfig.as<XRaySubscriptionConfig>();
|
||||
if (xrayConfig->configString.isEmpty())
|
||||
return QString();
|
||||
|
||||
return xrayConfig->configString.at(index).toString();
|
||||
}
|
||||
|
||||
QString SecureServersRepository::getConfigName(const int serverIndex, const int index) const
|
||||
{
|
||||
QJsonArray names = getConfigNames(serverIndex);
|
||||
return names.at(index).toString();
|
||||
}
|
||||
|
||||
QJsonArray SecureServersRepository::getConfigNames(const int serverIndex) const
|
||||
{
|
||||
ServerConfig serverConfig = server(serverIndex);
|
||||
if (!serverConfig.isXRayConfig())
|
||||
return QJsonArray();
|
||||
|
||||
const XRaySubscriptionConfig* xrayConfig = serverConfig.as<XRaySubscriptionConfig>();
|
||||
if (xrayConfig->configName.isEmpty())
|
||||
return QJsonArray();
|
||||
|
||||
return xrayConfig->configName;
|
||||
}
|
||||
|
||||
ServerCredentials SecureServersRepository::serverCredentials(int index) const
|
||||
std::optional<LegacyApiServerConfig> SecureServersRepository::legacyApiConfig(const QString &serverId) const
|
||||
{
|
||||
const auto it = m_serverJsonById.constFind(serverId);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "core/models/selfhosted/selfHostedAdminServerConfig.h"
|
||||
#include "core/models/selfhosted/selfHostedUserServerConfig.h"
|
||||
#include "core/models/selfhosted/nativeServerConfig.h"
|
||||
#include "core/models/selfhosted/xraySubscriptionConfig.h"
|
||||
#include "core/models/api/apiV2ServerConfig.h"
|
||||
#include "core/models/api/legacyApiServerConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
@@ -34,6 +35,7 @@ public:
|
||||
std::optional<SelfHostedAdminServerConfig> selfHostedAdminConfig(const QString &serverId) const;
|
||||
std::optional<SelfHostedUserServerConfig> selfHostedUserConfig(const QString &serverId) const;
|
||||
std::optional<NativeServerConfig> nativeConfig(const QString &serverId) const;
|
||||
std::optional<XRaySubscriptionConfig> xraySubscriptionConfig(const QString &serverId) const;
|
||||
std::optional<ApiV2ServerConfig> apiV2Config(const QString &serverId) const;
|
||||
std::optional<LegacyApiServerConfig> legacyApiConfig(const QString &serverId) const;
|
||||
|
||||
@@ -47,22 +49,6 @@ public:
|
||||
void setDefaultServer(const QString &serverId);
|
||||
|
||||
void clearServers();
|
||||
void setDefaultContainer(int serverIndex, DockerContainer container);
|
||||
ContainerConfig containerConfig(int serverIndex, DockerContainer container) const;
|
||||
void setContainerConfig(int serverIndex, DockerContainer container, const ContainerConfig &config);
|
||||
void clearLastConnectionConfig(int serverIndex, DockerContainer container);
|
||||
|
||||
void setCurrentConfigIndex(const int serverIndex, int index);
|
||||
int getCurrentConfigIndex(const int serverIndex) const;
|
||||
QString getConfigString(const int serverIndex, const int index) const;
|
||||
QString getConfigName(const int serverIndex, const int index) const;
|
||||
QJsonArray getConfigNames(const int serverIndex) const;
|
||||
|
||||
ServerCredentials serverCredentials(int index) const;
|
||||
bool hasServerWithVpnKey(const QString &vpnKey) const;
|
||||
bool hasServerWithCrc(quint16 crc) const;
|
||||
|
||||
void setServersArray(const QJsonArray &servers);
|
||||
|
||||
void invalidateCache();
|
||||
|
||||
|
||||
@@ -29,6 +29,12 @@ bool hasThirdPartyConfig(const QJsonObject &json)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasXrayConfigs(const QJsonObject &json)
|
||||
{
|
||||
const QJsonArray configsArray = json.value(amnezia::configKey::xraySubscriptionConfig).toArray();
|
||||
return !configsArray.isEmpty();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace serverConfigUtils
|
||||
@@ -93,6 +99,10 @@ ConfigType configTypeFromJson(const QJsonObject &serverConfigObject)
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasXrayConfigs(serverConfigObject)) {
|
||||
return ConfigType::XRaySubscription;
|
||||
}
|
||||
|
||||
if (hasThirdPartyConfig(serverConfigObject)) {
|
||||
return ConfigType::Native;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ enum ConfigType {
|
||||
SelfHostedAdmin = 8,
|
||||
SelfHostedUser,
|
||||
Native,
|
||||
XRaySubscription,
|
||||
Invalid
|
||||
};
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ bool ImportUiController::importLink(const QUrl &url)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImportUiController::editServerConfigWithData(QString data, int serverIndex)
|
||||
bool ImportUiController::editServerConfigWithData(const QString &serverId, QString data)
|
||||
{
|
||||
auto result = m_importController->editServerConfigWithData(data, serverIndex, m_config);
|
||||
auto result = m_importController->editServerConfigWithData(serverId, data, m_config);
|
||||
|
||||
if (result.errorCode != ErrorCode::NoError) {
|
||||
emit importErrorOccurred(result.errorCode, false);
|
||||
|
||||
@@ -21,7 +21,7 @@ public slots:
|
||||
void importConfig();
|
||||
void clearConfigFileName();
|
||||
bool importLink(const QUrl &url);
|
||||
bool editServerConfigWithData(QString data, int serverIndex);
|
||||
bool editServerConfigWithData(const QString &serverId, QString data);
|
||||
bool extractConfigFromFile(const QString &fileName);
|
||||
bool extractConfigFromData(QString data);
|
||||
bool extractConfigFromQr(const QByteArray &data);
|
||||
|
||||
@@ -234,12 +234,6 @@ QString ServersUiController::getDefaultServerDescriptionExpanded() const
|
||||
return description.expandedServerDescription;
|
||||
}
|
||||
}
|
||||
|
||||
if (server.isXRayConfig()) {
|
||||
return getConfigName(getCurrentConfigIndex());
|
||||
}
|
||||
|
||||
return description + server.hostName();
|
||||
return QString();
|
||||
}
|
||||
|
||||
@@ -301,6 +295,17 @@ bool ServersUiController::isDefaultServerFromApi() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServersUiController::isDefaultServerContainXRayConfigs() const
|
||||
{
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.isXRaySubscription;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ServersUiController::getProcessedContainerIndex() const
|
||||
{
|
||||
return m_processedContainerIndex;
|
||||
@@ -480,27 +485,27 @@ int ServersUiController::getServerIndexById(const QString &serverId) const
|
||||
|
||||
void ServersUiController::setCurrentConfigIndex(const int index)
|
||||
{
|
||||
m_serversController->setCurrentConfigIndex(m_processedServerIndex, index);
|
||||
m_serversController->setCurrentConfigIndex(m_processedServerId, index);
|
||||
}
|
||||
|
||||
int ServersUiController::getCurrentConfigIndex() const
|
||||
{
|
||||
return m_serversController->getCurrentConfigIndex(m_processedServerIndex);
|
||||
return m_serversController->getCurrentConfigIndex(m_processedServerId);
|
||||
}
|
||||
|
||||
QString ServersUiController::getConfigString(const int index) const
|
||||
{
|
||||
return m_serversController->getConfigString(m_processedServerIndex, index);
|
||||
return m_serversController->getConfigString(m_processedServerId, index);
|
||||
}
|
||||
|
||||
QString ServersUiController::getConfigName(const int index) const
|
||||
{
|
||||
return m_serversController->getConfigName(m_processedServerIndex, index);
|
||||
return m_serversController->getConfigName(m_processedServerId, index);
|
||||
}
|
||||
|
||||
QJsonArray ServersUiController::getConfigNames() const
|
||||
{
|
||||
return m_serversController->getConfigNames(m_processedServerIndex);
|
||||
return m_serversController->getConfigNames(m_processedServerId);
|
||||
}
|
||||
|
||||
void ServersUiController::updateContainersModel()
|
||||
|
||||
@@ -106,89 +106,8 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
||||
return row.isSubscriptionExpired;
|
||||
case IsSubscriptionExpiringSoonRole:
|
||||
return row.isSubscriptionExpiringSoon;
|
||||
}
|
||||
case ApiAvailableCountriesRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.availableCountries;
|
||||
}
|
||||
return QJsonArray();
|
||||
}
|
||||
case ApiServerCountryCodeRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serverCountryCode;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
case HasAmneziaDns: {
|
||||
QString primaryDns = server.dns1();
|
||||
return primaryDns == protocols::dns::amneziaDnsIp;
|
||||
}
|
||||
case IsAdVisibleRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serviceInfo.isAdVisible;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case AdHeaderRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serviceInfo.adHeader;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
case AdDescriptionRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serviceInfo.adDescription;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
case AdEndpointRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serviceInfo.adEndpoint;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
case IsRenewalAvailableRole: {
|
||||
if (server.isApiV2()) {
|
||||
return server.as<ApiV2ServerConfig>()->apiConfig.serviceInfo.isRenewalAvailable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case IsSubscriptionExpiredRole: {
|
||||
if (!server.isApiV2()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const ApiConfig &apiConfig = server.as<ApiV2ServerConfig>()->apiConfig;
|
||||
if (apiConfig.isInAppPurchase) {
|
||||
return false;
|
||||
}
|
||||
if (apiConfig.subscriptionExpiredByServer) {
|
||||
return true;
|
||||
}
|
||||
if (apiConfig.subscription.endDate.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return apiUtils::isSubscriptionExpired(apiConfig.subscription.endDate);
|
||||
}
|
||||
case IsSubscriptionExpiringSoonRole: {
|
||||
if (!server.isApiV2()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const ApiConfig &apiConfig = server.as<ApiV2ServerConfig>()->apiConfig;
|
||||
if (apiConfig.isInAppPurchase) {
|
||||
return false;
|
||||
}
|
||||
if (apiConfig.subscription.endDate.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return apiUtils::isSubscriptionExpiringSoon(apiConfig.subscription.endDate);
|
||||
}
|
||||
case IsXRayConfigSelectionAvailableRole: {
|
||||
if (server.isXRayConfig()) {
|
||||
return !server.as<XRaySubscriptionConfig>()->configString.isEmpty();
|
||||
}
|
||||
}
|
||||
case IsXRayConfigSelectionAvailableRole:
|
||||
return row.isXRaySubscription;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
||||
@@ -123,7 +123,7 @@ PageType {
|
||||
if (index !== ServersUiController.getCurrentConfigIndex()) {
|
||||
PageController.showBusyIndicator(true)
|
||||
ServersUiController.setCurrentConfigIndex(index)
|
||||
ImportController.editServerConfigWithData(ServersUiController.getConfigString(index), ServersUiController.getProcessedServerIndex())
|
||||
ImportController.editServerConfigWithData(ServersUiController.getProcessedServerId(), ServersUiController.getConfigString(index))
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ PageType {
|
||||
PageController.showNotificationMessage(qsTr("Cannot reload config during active connection"))
|
||||
} else {
|
||||
PageController.showBusyIndicator(true)
|
||||
InstallController.rebootProcessedServer()
|
||||
InstallController.rebootProcessedServer(ServersUiController.getProcessedServerId())
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ PageType {
|
||||
PageController.showNotificationMessage(qsTr("Cannot remove server during active connection"))
|
||||
} else {
|
||||
PageController.showBusyIndicator(true)
|
||||
InstallController.removeServer(ServersUiController.getProcessedServerIndex())
|
||||
InstallController.removeServer(ServersUiController.getProcessedServerId())
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user