Files
amnezia-client/client/containers/containers_defs.cpp
T

252 lines
9.5 KiB
C++
Raw Normal View History

2021-09-09 20:15:44 +03:00
#include "containers_defs.h"
QDebug operator<<(QDebug debug, const amnezia::DockerContainer &c)
{
QDebugStateSaver saver(debug);
2021-09-20 21:51:28 +03:00
debug.nospace() << ContainerProps::containerToString(c);
2021-09-09 20:15:44 +03:00
return debug;
}
amnezia::DockerContainer ContainerProps::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 ContainerProps::containerToString(amnezia::DockerContainer c)
{
if (c == DockerContainer::None)
return "none";
if (c == DockerContainer::Cloak)
return "amnezia-openvpn-cloak";
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 ContainerProps::containerTypeToString(amnezia::DockerContainer c)
{
if (c == DockerContainer::None)
return "none";
if (c == DockerContainer::Ipsec)
return "ikev2";
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
QString containerKey = metaEnum.valueToKey(static_cast<int>(c));
return containerKey.toLower();
}
QVector<amnezia::Proto> ContainerProps::protocolsForContainer(amnezia::DockerContainer container)
2021-09-09 20:15:44 +03:00
{
switch (container) {
case DockerContainer::None: return {};
2021-09-28 02:36:38 +03:00
case DockerContainer::OpenVpn: return { Proto::OpenVpn };
2021-09-09 20:15:44 +03:00
case DockerContainer::ShadowSocks: return { Proto::OpenVpn, Proto::ShadowSocks };
2021-09-09 20:15:44 +03:00
case DockerContainer::Cloak: return { Proto::OpenVpn, Proto::ShadowSocks, Proto::Cloak };
2021-09-09 20:15:44 +03:00
case DockerContainer::Ipsec: return { Proto::Ikev2 /*, Protocol::L2tp */ };
2021-10-04 19:07:49 +03:00
case DockerContainer::Dns: return {};
2021-09-24 13:14:35 +03:00
case DockerContainer::Sftp: return { Proto::Sftp };
2021-11-17 23:42:17 +03:00
default: return { defaultProtocol(container) };
2021-09-09 20:15:44 +03:00
}
}
2021-09-20 21:51:28 +03:00
QList<DockerContainer> ContainerProps::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
}
2021-09-20 21:51:28 +03:00
QMap<DockerContainer, QString> ContainerProps::containerHumanNames()
2021-09-09 20:15:44 +03:00
{
return { { DockerContainer::None, "Not installed" },
{ DockerContainer::OpenVpn, "OpenVPN" },
2023-08-20 13:36:54 +05:00
{ DockerContainer::ShadowSocks, "ShadowSocks" },
{ DockerContainer::Cloak, "OpenVPN over Cloak" },
{ DockerContainer::WireGuard, "WireGuard" },
{ DockerContainer::Ipsec, QObject::tr("IPsec") },
{ DockerContainer::TorWebSite, QObject::tr("Web site in Tor network") },
{ DockerContainer::Dns, QObject::tr("Amnezia DNS") },
//{DockerContainer::FileShare, QObject::tr("SMB file sharing service")},
{ DockerContainer::Sftp, QObject::tr("Sftp file sharing service") } };
2021-09-09 20:15:44 +03:00
}
2021-09-20 21:51:28 +03:00
QMap<DockerContainer, QString> ContainerProps::containerDescriptions()
2023-08-20 13:36:54 +05:00
{
return { { DockerContainer::OpenVpn,
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.") },
{ DockerContainer::ShadowSocks,
QObject::tr("ShadowSocks - masks VPN traffic, making it similar to normal web traffic, but is "
"recognised by analysis systems in some highly censored regions.") },
{ DockerContainer::Cloak,
QObject::tr("OpenVPN over Cloak - OpenVPN with VPN masquerading as web traffic and protection against "
"active-probbing detection. Ideal for bypassing blocking in regions with the highest levels "
"of censorship.") },
{ DockerContainer::WireGuard,
QObject::tr("WireGuard - New popular VPN protocol with high performance, high speed and low power "
"consumption. Recommended for regions with low levels of censorship.") },
{ DockerContainer::Ipsec,
QObject::tr("IKEv2 - Modern stable protocol, a bit faster than others, restores connection after "
"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::FileShare, QObject::tr("SMB file sharing service - is Window file sharing protocol")},
{ DockerContainer::Sftp,
QObject::tr("Creates a file vault on your server to securely store and transfer files.") } };
}
QMap<DockerContainer, QString> ContainerProps::containerDetailedDescriptions()
2021-09-09 20:15:44 +03:00
{
return { { DockerContainer::OpenVpn, QObject::tr("OpenVPN container") },
{ DockerContainer::ShadowSocks, QObject::tr("Container with OpenVpn and ShadowSocks") },
{ DockerContainer::Cloak,
QObject::tr("Container with OpenVpn and ShadowSocks protocols "
"configured with traffic masking by Cloak plugin") },
{ DockerContainer::WireGuard, QObject::tr("WireGuard container") },
{ DockerContainer::Ipsec, QObject::tr("IPsec container") },
{ DockerContainer::TorWebSite, QObject::tr("Web site in Tor network") },
{ DockerContainer::Dns, QObject::tr("DNS Service") },
//{DockerContainer::FileShare, QObject::tr("SMB file sharing service - is Window file sharing protocol")},
{ DockerContainer::Sftp, QObject::tr("Sftp file sharing service - is secure FTP service") } };
2021-09-09 20:15:44 +03:00
}
2021-09-20 21:51:28 +03:00
amnezia::ServiceType ContainerProps::containerService(DockerContainer c)
2021-09-09 20:15:44 +03:00
{
switch (c) {
case DockerContainer::None: return ServiceType::None;
case DockerContainer::OpenVpn: return ServiceType::Vpn;
case DockerContainer::Cloak: return ServiceType::Vpn;
case DockerContainer::ShadowSocks: return ServiceType::Vpn;
case DockerContainer::WireGuard: return ServiceType::Vpn;
case DockerContainer::Ipsec: return ServiceType::Vpn;
case DockerContainer::TorWebSite: return ServiceType::Other;
case DockerContainer::Dns: return ServiceType::Other;
// case DockerContainer::FileShare : return ServiceType::Other;
case DockerContainer::Sftp: return ServiceType::Other;
default: return ServiceType::Other;
2021-09-09 20:15:44 +03:00
}
}
2021-09-20 21:51:28 +03:00
Proto ContainerProps::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::Any;
case DockerContainer::OpenVpn: return Proto::OpenVpn;
case DockerContainer::Cloak: return Proto::Cloak;
case DockerContainer::ShadowSocks: return Proto::ShadowSocks;
case DockerContainer::WireGuard: return Proto::WireGuard;
case DockerContainer::Ipsec: return Proto::Ikev2;
case DockerContainer::TorWebSite: return Proto::TorWebSite;
case DockerContainer::Dns: return Proto::Dns;
// case DockerContainer::FileShare : return Protocol::FileShare;
case DockerContainer::Sftp: return Proto::Sftp;
default: return Proto::Any;
2021-10-04 19:07:49 +03:00
}
2021-09-20 21:51:28 +03:00
}
bool ContainerProps::isSupportedByCurrentPlatform(DockerContainer c)
2021-12-04 16:13:34 +03:00
{
#ifdef Q_OS_WINDOWS
return true;
#elif defined(Q_OS_IOS)
2021-12-04 16:13:34 +03:00
switch (c) {
case DockerContainer::WireGuard: return true;
case DockerContainer::OpenVpn: return true;
case DockerContainer::Cloak:
return true;
// case DockerContainer::ShadowSocks: return true;
2021-12-04 16:13:34 +03:00
default: return false;
}
#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;
2022-04-01 10:05:58 +05:30
case DockerContainer::ShadowSocks: return true;
case DockerContainer::Cloak: 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::WireGuard: return true;
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 ContainerProps::fixedPortsForContainer(DockerContainer c)
{
switch (c) {
case DockerContainer::Ipsec: return QStringList { "500", "4500" };
default: return {};
}
}
bool ContainerProps::isEasySetupContainer(DockerContainer container)
{
switch (container) {
case DockerContainer::OpenVpn: return true;
case DockerContainer::Cloak: return true;
case DockerContainer::ShadowSocks: return true;
default: return false;
}
}
QString ContainerProps::easySetupHeader(DockerContainer container)
{
switch (container) {
case DockerContainer::OpenVpn: return tr("Low");
case DockerContainer::Cloak: return tr("High");
case DockerContainer::ShadowSocks: return tr("Medium");
default: return "";
}
}
QString ContainerProps::easySetupDescription(DockerContainer container)
{
switch (container) {
case DockerContainer::OpenVpn: return tr("I just want to increase the level of privacy");
2023-08-13 11:28:32 +05:00
case DockerContainer::Cloak: return tr("Many foreign websites and VPN providers are blocked");
case DockerContainer::ShadowSocks: return tr("Some foreign sites are blocked, but VPN providers are not blocked");
default: return "";
}
}