mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-11-20 03:23:35 +09:00
* server-side container stack * core model, enums and install pipeline * settings UI and setup wizard * fix workers * remove debug logs * address review findings * fix validate email * update docker * remove write port & add default port 443/80
78 lines
2.9 KiB
C++
78 lines
2.9 KiB
C++
#include "tProxyProtocolConfig.h"
|
|
|
|
#include "core/utils/constants/configKeys.h"
|
|
#include "core/utils/constants/protocolConstants.h"
|
|
|
|
using namespace amnezia;
|
|
|
|
QJsonObject TProxyProtocolConfig::toJson() const
|
|
{
|
|
QJsonObject obj;
|
|
if (!port.isEmpty()) {
|
|
obj[QString(configKey::port)] = port;
|
|
}
|
|
if (!httpPort.isEmpty()) {
|
|
obj[protocols::tProxy::httpPortKey] = httpPort;
|
|
}
|
|
if (!secret.isEmpty()) {
|
|
obj[protocols::tProxy::secretKey] = secret;
|
|
}
|
|
if (!hostname.isEmpty()) {
|
|
obj[protocols::tProxy::hostnameKey] = hostname;
|
|
}
|
|
if (!acmeEmail.isEmpty()) {
|
|
obj[protocols::tProxy::acmeEmailKey] = acmeEmail;
|
|
}
|
|
if (!carrierMode.isEmpty()) {
|
|
obj[protocols::tProxy::carrierModeKey] = carrierMode;
|
|
}
|
|
if (!workers.isEmpty()) {
|
|
obj[protocols::tProxy::workersKey] = workers;
|
|
}
|
|
if (!tgLink.isEmpty()) {
|
|
obj[protocols::tProxy::tgLinkKey] = tgLink;
|
|
}
|
|
if (!tmeLink.isEmpty()) {
|
|
obj[protocols::tProxy::tmeLinkKey] = tmeLink;
|
|
}
|
|
obj[protocols::tProxy::isEnabledKey] = isEnabled;
|
|
return obj;
|
|
}
|
|
|
|
TProxyProtocolConfig TProxyProtocolConfig::fromJson(const QJsonObject &json)
|
|
{
|
|
TProxyProtocolConfig c;
|
|
c.port = json.value(QString(configKey::port)).toString();
|
|
c.httpPort = json.value(protocols::tProxy::httpPortKey).toString();
|
|
c.secret = json.value(protocols::tProxy::secretKey).toString();
|
|
c.hostname = json.value(protocols::tProxy::hostnameKey).toString();
|
|
c.acmeEmail = json.value(protocols::tProxy::acmeEmailKey).toString();
|
|
c.carrierMode = json.value(protocols::tProxy::carrierModeKey).toString();
|
|
c.workers = json.value(protocols::tProxy::workersKey).toString();
|
|
c.tgLink = json.value(protocols::tProxy::tgLinkKey).toString();
|
|
c.tmeLink = json.value(protocols::tProxy::tmeLinkKey).toString();
|
|
c.isEnabled = json.value(protocols::tProxy::isEnabledKey).toBool(true);
|
|
return c;
|
|
}
|
|
|
|
bool TProxyProtocolConfig::equalsDockerDeploymentSettings(const TProxyProtocolConfig &other) const
|
|
{
|
|
const auto normCarrier = [](const QString &m) {
|
|
return m.isEmpty() ? QString(protocols::tProxy::carrierModeHttps) : m;
|
|
};
|
|
const auto normWorkers = [](const QString &w) {
|
|
return w.isEmpty() ? QString(protocols::tProxy::defaultWorkers) : w;
|
|
};
|
|
|
|
const auto normPort = [](const QString &p, const char *defaultPort) {
|
|
return p.isEmpty() ? QString(defaultPort) : p;
|
|
};
|
|
|
|
return hostname == other.hostname && secret == other.secret && acmeEmail == other.acmeEmail
|
|
&& normPort(port, protocols::tProxy::defaultPort) == normPort(other.port, protocols::tProxy::defaultPort)
|
|
&& normPort(httpPort, protocols::tProxy::defaultHttpPort)
|
|
== normPort(other.httpPort, protocols::tProxy::defaultHttpPort)
|
|
&& normCarrier(carrierMode) == normCarrier(other.carrierMode)
|
|
&& normWorkers(workers) == normWorkers(other.workers) && isEnabled == other.isEnabled;
|
|
}
|