mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-09 20:04:31 +03:00
* fix: AUTOMOC and AUTOUIC added * update: native exports test * update: export test * update: vless serialization/deserialization test added * update: language model and controller test * update: sites UiController and Model test * update: sites test * update: app ui model and controller test * update: allowed dns ui model and controller test * update: env vars and removed some lines * update: news ui model and controller test (incomplete) * update: api services ui model and controller test (incompleted) * update: job for tests (Linux) * update: job for tests (Windows) * update: proper artifact names * update: added envs * update: added 'get sources' and changed steps order * update: tests jobs remake * update: 'get sources' step and windows shell * update: using ctest * search for exe files * changed path to run tests * update: 'Build' step * update: changed path to deploy qt dependencies * update: dependencies only for tests executables * update: ctest dir * update: include ctest * update: set dir for tests exe * update: qt path * update: serialization test * update: removed api tests from cmake * update: changed tests dir * added ctest to client cmake * update: installing msvc and additional checks * removed mcvs install * update: path to ssh.dll * fixed issue with ssh path * update: removed unneccessary step and line * update: linux job step 'Run tests' * update: linux 'Install dependencies' * update: modified qtest include * update: changed QVERIFY to QVERIFY2 * update: some qverify2 messages * update: linux additional dependencies * update: offscreen for linux tests * update: MacOS tests job * update: Android tests job * update: rewrited env's, qtest include and clear clients in some tests * update: added local vars file for tests * proper path for some vars * some fixes due merge * update: windows tests deploy * python and conan installation to tests jobs * chore: minor fixes after merge with dev * chore: move selfhosted admin tests to separate folder * refactor: some rename * chore: fixes after merge * refactor: moved tests to separate repo * refactor: remove tests from core controller * chore: add more protected getters to core controller * chore: add more protected getters * chore: remove ctest * chore: return xray model default values --------- Co-authored-by: vkamn <vk@amnezia.org>
113 lines
3.2 KiB
C++
113 lines
3.2 KiB
C++
#include "nativeServerConfig.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include "core/utils/containerEnum.h"
|
|
#include "core/utils/containers/containerUtils.h"
|
|
#include "core/utils/protocolEnum.h"
|
|
#include "core/utils/protocolEnum.h"
|
|
#include "core/protocols/protocolUtils.h"
|
|
#include "core/utils/constants/configKeys.h"
|
|
#include "core/utils/constants/protocolConstants.h"
|
|
#include "core/utils/networkUtilities.h"
|
|
|
|
namespace amnezia
|
|
{
|
|
|
|
using namespace ContainerEnumNS;
|
|
|
|
bool NativeServerConfig::hasContainers() const
|
|
{
|
|
return !containers.isEmpty();
|
|
}
|
|
|
|
ContainerConfig NativeServerConfig::containerConfig(DockerContainer container) const
|
|
{
|
|
if (!containers.contains(container)) {
|
|
return ContainerConfig{};
|
|
}
|
|
return containers.value(container);
|
|
}
|
|
|
|
QPair<QString, QString> NativeServerConfig::getDnsPair(const QString &primaryDns, const QString &secondaryDns) const
|
|
{
|
|
QString d1 = dns1;
|
|
QString d2 = dns2;
|
|
|
|
if (d1.isEmpty() || !NetworkUtilities::checkIPv4Format(d1)) {
|
|
d1 = primaryDns;
|
|
}
|
|
if (d2.isEmpty() || !NetworkUtilities::checkIPv4Format(d2)) {
|
|
d2 = secondaryDns;
|
|
}
|
|
return { d1, d2 };
|
|
}
|
|
|
|
QJsonObject NativeServerConfig::toJson() const
|
|
{
|
|
QJsonObject obj;
|
|
|
|
if (!description.isEmpty()) {
|
|
obj[configKey::description] = this->description;
|
|
}
|
|
if (!hostName.isEmpty()) {
|
|
obj[configKey::hostName] = hostName;
|
|
}
|
|
|
|
QJsonArray containersArray;
|
|
for (auto it = containers.begin(); it != containers.end(); ++it) {
|
|
QJsonObject containerObj = it.value().toJson();
|
|
containersArray.append(containerObj);
|
|
}
|
|
if (!containersArray.isEmpty()) {
|
|
obj[configKey::containers] = containersArray;
|
|
}
|
|
|
|
if (defaultContainer != DockerContainer::None) {
|
|
obj[configKey::defaultContainer] = ContainerUtils::containerToString(defaultContainer);
|
|
}
|
|
|
|
if (!dns1.isEmpty()) {
|
|
obj[configKey::dns1] = dns1;
|
|
}
|
|
if (!dns2.isEmpty()) {
|
|
obj[configKey::dns2] = dns2;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
NativeServerConfig NativeServerConfig::fromJson(const QJsonObject& json)
|
|
{
|
|
NativeServerConfig config;
|
|
|
|
config.description = json.value(configKey::description).toString();
|
|
config.hostName = json.value(configKey::hostName).toString();
|
|
|
|
QJsonArray containersArray = json.value(configKey::containers).toArray();
|
|
for (const QJsonValue& val : containersArray) {
|
|
QJsonObject containerObj = val.toObject();
|
|
ContainerConfig containerConfig = ContainerConfig::fromJson(containerObj);
|
|
|
|
QString containerStr = containerObj.value(configKey::container).toString();
|
|
DockerContainer container = ContainerUtils::containerFromString(containerStr);
|
|
|
|
config.containers.insert(container, containerConfig);
|
|
}
|
|
|
|
QString defaultContainerStr = json.value(configKey::defaultContainer).toString();
|
|
config.defaultContainer = ContainerUtils::containerFromString(defaultContainerStr);
|
|
|
|
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;
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
} // namespace amnezia
|
|
|