Files
amnezia-client/client/core/utils/containers/containerUtils.cpp
T

405 lines
17 KiB
C++
Raw Normal View History

#include "containerUtils.h"
2021-09-09 20:15:44 +03:00
#include <QMetaEnum>
#include <QObject>
#include <QJsonDocument>
using namespace amnezia;
2021-09-09 20:15:44 +03:00
DockerContainer ContainerUtils::containerFromString(const QString &container)
{
2021-09-20 21:51:28 +03:00
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
for (int i = 0; i < metaEnum.keyCount(); ++i) {
DockerContainer c = static_cast<DockerContainer>(i);
if (container == containerToString(c))
return c;
2021-09-20 21:51:28 +03:00
}
2021-09-09 20:15:44 +03:00
return DockerContainer::None;
}
QString ContainerUtils::containerToString(DockerContainer c)
{
if (c == DockerContainer::None)
return "none";
2026-06-04 15:45:53 +01:00
if (c == DockerContainer::Cloak)
return "amnezia-openvpn-cloak";
2025-12-11 15:18:36 +08:00
if (c == DockerContainer::Awg)
return "amnezia-awg";
if (c == DockerContainer::Awg2)
return "amnezia-awg2";
2021-09-20 21:51:28 +03:00
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
QString containerKey = metaEnum.valueToKey(static_cast<int>(c));
2021-09-28 02:36:38 +03:00
2021-09-20 21:51:28 +03:00
return "amnezia-" + containerKey.toLower();
2021-09-09 20:15:44 +03:00
}
QString ContainerUtils::containerTypeToString(DockerContainer c)
{
if (c == DockerContainer::None)
return "none";
if (c == DockerContainer::Ipsec)
return "ikev2";
2025-12-11 15:18:36 +08:00
if (c == DockerContainer::Awg)
return "awg";
if (c == DockerContainer::Awg2)
return "awg";
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
QString containerKey = metaEnum.valueToKey(static_cast<int>(c));
return containerKey.toLower();
}
QList<DockerContainer> ContainerUtils::allContainers()
2021-09-09 20:15:44 +03:00
{
2021-09-20 21:51:28 +03:00
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
QList<DockerContainer> all;
for (int i = 0; i < metaEnum.keyCount(); ++i) {
all.append(static_cast<DockerContainer>(i));
}
return all;
2021-09-09 20:15:44 +03:00
}
QMap<DockerContainer, QString> ContainerUtils::containerHumanNames()
2021-09-09 20:15:44 +03:00
{
return { { DockerContainer::None, "Not installed" },
{ DockerContainer::OpenVpn, "OpenVPN" },
2026-06-04 15:45:53 +01:00
{ DockerContainer::ShadowSocks, "OpenVPN over SS" },
{ DockerContainer::Cloak, "OpenVPN over Cloak" },
{ DockerContainer::WireGuard, "WireGuard" },
2023-10-09 23:18:24 +05:00
{ DockerContainer::Awg, "AmneziaWG" },
{ DockerContainer::Awg2, "AmneziaWG" },
2024-03-27 11:02:34 +00:00
{ DockerContainer::Xray, "XRay" },
{ DockerContainer::Ipsec, QObject::tr("IPsec") },
2024-07-27 20:42:11 +03:00
{ DockerContainer::SSXray, "Shadowsocks"},
{ DockerContainer::TorWebSite, QObject::tr("Website in Tor network") },
2024-06-19 02:14:22 +03:00
{ DockerContainer::Dns, QObject::tr("AmneziaDNS") },
2024-06-19 02:31:04 +03:00
{ DockerContainer::Sftp, QObject::tr("SFTP file sharing service") },
2026-05-18 14:52:58 +03:00
{ DockerContainer::Socks5Proxy, QObject::tr("SOCKS5 proxy server") },
{ DockerContainer::MtProxy, QObject::tr("MTProxy (Telegram)") },
2026-05-18 15:01:09 +03:00
{ DockerContainer::Telemt, QObject::tr("Telemt (Telegram)") },
2026-05-18 14:52:58 +03:00
};
2021-09-09 20:15:44 +03:00
}
QMap<DockerContainer, QString> ContainerUtils::containerDescriptions()
2023-08-20 13:36:54 +05:00
{
return { { DockerContainer::OpenVpn,
2023-08-20 13:36:54 +05:00
QObject::tr("OpenVPN is the most popular VPN protocol, with flexible configuration options. It uses its "
"own security protocol with SSL/TLS for key exchange.") },
2026-06-04 15:45:53 +01:00
{ DockerContainer::ShadowSocks,
QObject::tr("This protocol is no longer supported.") },
{ DockerContainer::Cloak,
QObject::tr("This protocol is no longer supported.") },
2023-08-20 13:36:54 +05:00
{ DockerContainer::WireGuard,
2025-02-04 15:53:40 +00:00
QObject::tr("WireGuard - popular VPN protocol with high performance, high speed and low power "
"consumption.") },
2023-10-14 18:21:49 +05:00
{ DockerContainer::Awg,
2026-01-15 15:48:48 +08:00
QObject::tr("AmneziaWG is a special protocol from Amnezia based on WireGuard. "
"It provides high connection speed and ensures stable operation even in the most challenging network conditions.") },
{ DockerContainer::Awg2,
2025-02-04 15:53:40 +00:00
QObject::tr("AmneziaWG is a special protocol from Amnezia based on WireGuard. "
2025-02-05 23:11:21 +00:00
"It provides high connection speed and ensures stable operation even in the most challenging network conditions.") },
2024-03-27 11:02:34 +00:00
{ DockerContainer::Xray,
2025-02-04 15:53:40 +00:00
QObject::tr("XRay with REALITY masks VPN traffic as web traffic and protects against active probing. "
2025-02-05 23:11:21 +00:00
"It is highly resistant to detection and offers high speed.") },
2023-08-20 13:36:54 +05:00
{ DockerContainer::Ipsec,
2024-06-19 02:14:22 +03:00
QObject::tr("IKEv2/IPsec - Modern stable protocol, a bit faster than others, restores connection after "
2023-08-20 13:36:54 +05:00
"signal loss. It has native support on the latest versions of Android and iOS.") },
{ DockerContainer::TorWebSite, QObject::tr("Deploy a WordPress site on the Tor network in two clicks.") },
{ DockerContainer::Dns,
QObject::tr("Replace the current DNS server with your own. This will increase your privacy level.") },
{ DockerContainer::Sftp,
2024-06-10 18:35:24 +07:00
QObject::tr("Create a file vault on your server to securely store and transfer files.") },
{ DockerContainer::Socks5Proxy,
2026-05-18 14:52:58 +03:00
QObject::tr("") },
{ DockerContainer::MtProxy,
QObject::tr("Telegram MTProto proxy server") },
2026-05-18 15:01:09 +03:00
{ DockerContainer::Telemt,
QObject::tr("Telegram MTProto proxy (Telemt, Rust)") },
2026-05-18 14:52:58 +03:00
};
2023-08-20 13:36:54 +05:00
}
QMap<DockerContainer, QString> ContainerUtils::containerDetailedDescriptions()
2021-09-09 20:15:44 +03:00
{
2023-10-14 18:21:49 +05:00
return {
{ DockerContainer::OpenVpn,
QObject::tr("OpenVPN is one of the most popular and reliable VPN protocols. "
"It uses SSL/TLS encryption, supports a wide variety of devices and operating systems, "
"and is continuously improved by the community due to its open-source nature. "
"It provides a good balance between speed and security but is easily recognized by DPI systems, "
"making it susceptible to blocking.\n"
"\nFeatures:\n"
"* Available on all AmneziaVPN platforms\n"
"* Normal battery consumption on mobile devices\n"
"* Flexible customization for various devices and OS\n"
"* Operates over both TCP and UDP protocols") },
2023-10-14 18:21:49 +05:00
{ DockerContainer::WireGuard,
QObject::tr("WireGuard is a modern, streamlined VPN protocol offering stable connectivity and excellent performance across all devices. "
"It uses fixed encryption settings, delivering lower latency and higher data transfer speeds compared to OpenVPN. "
"However, WireGuard is easily identifiable by DPI systems due to its distinctive packet signatures, making it susceptible to blocking.\n"
"\nFeatures:\n"
"* Available on all AmneziaVPN platforms\n"
"* Low power consumption on mobile devices\n"
"* Minimal configuration required\n"
"* Easily detected by DPI systems (susceptible to blocking)\n"
"* Operates over UDP protocol") },
2025-12-11 15:18:36 +08:00
{ DockerContainer::Awg2,
QObject::tr("AmneziaWG is a modern VPN protocol based on WireGuard, "
"combining simplified architecture with high performance across all devices. "
"It addresses WireGuard's main vulnerability (easy detection by DPI systems) through advanced obfuscation techniques, "
"making VPN traffic indistinguishable from regular internet traffic.\n"
"\nAmneziaWG is an excellent choice for those seeking a fast, stealthy VPN connection.\n"
"\nFeatures:\n"
"* Available on all AmneziaVPN platforms\n"
"* Low battery consumption on mobile devices\n"
"* Minimal settings required\n"
"* Undetectable by traffic analysis systems (DPI)\n"
"* Operates over UDP protocol") },
2024-03-27 11:02:34 +00:00
{ DockerContainer::Xray,
QObject::tr("REALITY is an innovative protocol developed by the creators of XRay, designed specifically to combat high levels of internet censorship. "
"REALITY identifies censorship systems during the TLS handshake, "
"redirecting suspicious traffic seamlessly to legitimate websites like google.com while providing genuine TLS certificates. "
"This allows VPN traffic to blend indistinguishably with regular web traffic without special configuration."
"\nUnlike older protocols such as VMess, VLESS, and XTLS-Vision, REALITY incorporates an advanced built-in \"friend-or-foe\" detection mechanism, "
"effectively protecting against DPI and other traffic analysis methods.\n"
"\nFeatures:\n"
"* Resistant to active probing and DPI detection\n"
"* No special configuration required to disguise traffic\n"
"* Highly effective in heavily censored regions\n"
"* Minimal battery consumption on devices\n"
"* Operates over TCP protocol") },
2023-10-14 18:21:49 +05:00
{ DockerContainer::Ipsec,
QObject::tr("IKEv2, combined with IPSec encryption, is a modern and reliable VPN protocol. "
"It reconnects quickly when switching networks or devices, making it ideal for dynamic network environments. "
"While it provides good security and speed, it's easily recognized by DPI systems and susceptible to blocking.\n"
"\nFeatures:\n"
"* Available in AmneziaVPN only on Windows\n"
"* Low battery consumption on mobile devices\n"
"* Minimal configuration required\n"
"* Detectable by DPI analysis systems(easily blocked)\n"
"* Operates over UDP protocol(ports 500 and 4500)") },
2023-10-14 18:21:49 +05:00
{ DockerContainer::TorWebSite, QObject::tr("Website in Tor network") },
{ DockerContainer::Dns, QObject::tr("DNS Service") },
2024-03-26 20:05:04 +02:00
{ DockerContainer::Sftp,
QObject::tr("After installation, Amnezia will create a\n\n file storage on your server. "
"You will be able to access it using\n FileZilla or other SFTP clients, "
"as well as mount the disk on your device to access\n it directly from your device.\n\n"
2024-06-10 18:35:24 +07:00
"For more detailed information, you can\n find it in the support section under \"Create SFTP file storage.\" ") },
2026-05-18 14:52:58 +03:00
{ DockerContainer::Socks5Proxy, QObject::tr("SOCKS5 proxy server") },
{ DockerContainer::MtProxy,
QObject::tr("Telegram MTProto proxy server. "
"Allows Telegram clients to connect through your server "
"using the MTProto protocol. Supports FakeTLS mode for "
"bypassing DPI-based blocking.") },
2026-05-18 15:01:09 +03:00
{ DockerContainer::Telemt,
QObject::tr("Telegram MTProto proxy powered by Telemt (Rust). "
"Supports secure and TLS fronting modes with optional traffic masking.") },
2023-10-14 18:21:49 +05:00
};
2021-09-09 20:15:44 +03:00
}
ServiceType ContainerUtils::containerService(DockerContainer c)
2021-09-09 20:15:44 +03:00
{
2026-06-04 15:45:53 +01:00
if (isUnsupportedContainer(c)) {
return ServiceType::Vpn;
}
return ProtocolUtils::protocolService(defaultProtocol(c));
2021-09-09 20:15:44 +03:00
}
2021-09-20 21:51:28 +03:00
Proto ContainerUtils::defaultProtocol(DockerContainer c)
2021-09-20 21:51:28 +03:00
{
2021-10-04 19:07:49 +03:00
switch (c) {
case DockerContainer::None: return Proto::Unknown;
case DockerContainer::OpenVpn: return Proto::OpenVpn;
2026-06-04 15:45:53 +01:00
case DockerContainer::Cloak:
case DockerContainer::ShadowSocks: return Proto::Unknown;
case DockerContainer::WireGuard: return Proto::WireGuard;
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return Proto::Awg;
2023-10-06 17:19:44 +05:00
case DockerContainer::Awg: return Proto::Awg;
2024-03-27 11:02:34 +00:00
case DockerContainer::Xray: return Proto::Xray;
case DockerContainer::Ipsec: return Proto::Ikev2;
case DockerContainer::SSXray: return Proto::SSXray;
case DockerContainer::TorWebSite: return Proto::TorWebSite;
case DockerContainer::Dns: return Proto::Dns;
case DockerContainer::Sftp: return Proto::Sftp;
2024-06-10 18:35:24 +07:00
case DockerContainer::Socks5Proxy: return Proto::Socks5Proxy;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy: return Proto::MtProxy;
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt: return Proto::Telemt;
default: return Proto::Unknown;
2021-10-04 19:07:49 +03:00
}
2021-09-20 21:51:28 +03:00
}
QString ContainerUtils::containerTypeToProtocolString(DockerContainer c)
2025-12-11 15:18:36 +08:00
{
if (c == DockerContainer::None)
return "none";
Proto p = defaultProtocol(c);
return ProtocolUtils::protoToString(p);
2025-12-11 15:18:36 +08:00
}
bool ContainerUtils::isSupportedByCurrentPlatform(DockerContainer c)
2021-12-04 16:13:34 +03:00
{
#ifdef Q_OS_WINDOWS
return true;
#elif defined(Q_OS_IOS)
// Standard iOS build (without Network Extension limitations)
2021-12-04 16:13:34 +03:00
switch (c) {
case DockerContainer::WireGuard: return true;
case DockerContainer::OpenVpn: return true;
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return true;
2023-10-06 17:19:44 +05:00
case DockerContainer::Awg: return true;
2024-06-30 12:19:38 +03:00
case DockerContainer::Xray: return true;
2024-07-09 14:56:39 +07:00
case DockerContainer::SSXray: return true;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy: return true;
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt: return true;
default:
return false;
}
#elif defined(MACOS_NE)
2026-04-08 07:37:52 +03:00
// macOS build using Network Extension allow OpenVPN for parity with iOS.
switch (c) {
2026-04-08 07:37:52 +03:00
case DockerContainer::OpenVpn: return true;
2026-06-04 15:45:53 +01:00
case DockerContainer::Cloak: return false;
case DockerContainer::ShadowSocks: return false;
case DockerContainer::WireGuard: return true;
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return true;
case DockerContainer::Awg: return true;
case DockerContainer::Xray: return true;
case DockerContainer::SSXray: return true;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy: return true;
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt: return true;
default:
return false;
2021-12-04 16:13:34 +03:00
}
#elif defined(Q_OS_MAC)
2022-01-23 15:25:53 -08:00
switch (c) {
2023-07-15 14:19:48 -07:00
case DockerContainer::WireGuard: return true;
2022-01-23 15:25:53 -08:00
case DockerContainer::Ipsec: return false;
default: return true;
}
2021-12-04 05:24:11 -08:00
#elif defined(Q_OS_ANDROID)
2021-12-04 16:13:34 +03:00
switch (c) {
case DockerContainer::WireGuard: return true;
case DockerContainer::OpenVpn: return true;
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return true;
2023-10-07 09:01:29 -04:00
case DockerContainer::Awg: return true;
2024-06-18 20:46:21 +03:00
case DockerContainer::Xray: return true;
2024-07-06 18:44:34 +03:00
case DockerContainer::SSXray: return true;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy: return true;
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt: return true;
2021-12-04 16:13:34 +03:00
default: return false;
}
#elif defined(Q_OS_LINUX)
2023-07-15 14:19:48 -07:00
switch (c) {
case DockerContainer::Ipsec: return false;
default: return true;
}
2021-12-04 16:13:34 +03:00
#else
return false;
2021-12-04 16:13:34 +03:00
#endif
}
QStringList ContainerUtils::fixedPortsForContainer(DockerContainer c)
{
switch (c) {
case DockerContainer::Ipsec: return QStringList { "500", "4500" };
default: return {};
}
}
bool ContainerUtils::isEasySetupContainer(DockerContainer container)
{
switch (container) {
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return true;
default: return false;
}
}
QString ContainerUtils::easySetupHeader(DockerContainer container)
{
switch (container) {
case DockerContainer::Awg2: return QObject::tr("Automatic");
default: return "";
}
}
QString ContainerUtils::easySetupDescription(DockerContainer container)
{
switch (container) {
case DockerContainer::Awg2: return QObject::tr("AmneziaWG protocol will be installed. "
2025-02-05 23:11:21 +00:00
"It provides high connection speed and ensures stable operation even in the most challenging network conditions.");
default: return "";
}
}
2023-08-22 14:37:29 +05:00
int ContainerUtils::easySetupOrder(DockerContainer container)
2023-09-18 21:06:10 +05:00
{
switch (container) {
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return 1;
2023-09-18 21:06:10 +05:00
default: return 0;
}
}
bool ContainerUtils::isShareable(DockerContainer container)
2023-08-22 14:37:29 +05:00
{
2026-06-04 15:45:53 +01:00
if (isUnsupportedContainer(container)) {
return false;
}
2023-08-22 14:37:29 +05:00
switch (container) {
case DockerContainer::TorWebSite: return false;
case DockerContainer::Dns: return false;
case DockerContainer::Sftp: return false;
2024-06-10 18:35:24 +07:00
case DockerContainer::Socks5Proxy: return false;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy: return false;
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt: return false;
2023-08-22 14:37:29 +05:00
default: return true;
}
}
bool ContainerUtils::isAwgContainer(DockerContainer container)
2025-12-11 15:18:36 +08:00
{
return container == DockerContainer::Awg || container == DockerContainer::Awg2;
2025-12-11 15:18:36 +08:00
}
2026-06-04 15:45:53 +01:00
bool ContainerUtils::isUnsupportedContainer(DockerContainer container)
{
return container == DockerContainer::Cloak || container == DockerContainer::ShadowSocks;
}
QJsonObject ContainerUtils::getProtocolConfigFromContainer(const Proto protocol, const QJsonObject &containerConfig)
{
QString protocolConfigString = containerConfig.value(ProtocolUtils::protoToString(protocol))
2025-02-04 15:53:40 +00:00
.toObject()
.value(configKey::lastConfig)
2025-02-04 15:53:40 +00:00
.toString();
return QJsonDocument::fromJson(protocolConfigString.toUtf8()).object();
}
int ContainerUtils::installPageOrder(DockerContainer container)
{
switch (container) {
case DockerContainer::OpenVpn: return 4;
case DockerContainer::WireGuard: return 2;
2025-12-11 15:18:36 +08:00
case DockerContainer::Awg2: return 1;
case DockerContainer::Xray: return 3;
case DockerContainer::Ipsec: return 7;
case DockerContainer::SSXray: return 8;
2026-05-18 14:52:58 +03:00
case DockerContainer::MtProxy:
2026-05-18 15:01:09 +03:00
case DockerContainer::Telemt:
2026-05-18 14:52:58 +03:00
return 20;
default: return 0;
}
}