From b78bf39767a975f897729cdacdca30076864c4a2 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Fri, 13 Oct 2023 15:45:06 +0500 Subject: [PATCH] added split tunneling to the config --- client/protocols/protocols_defs.h | 4 ++++ client/translations/amneziavpn_ru.ts | 20 +++++++++++++++++--- client/translations/amneziavpn_zh_CN.ts | 20 +++++++++++++++++--- client/ui/controllers/importController.cpp | 7 +++++++ client/vpnconnection.cpp | 16 ++++++++++++++++ client/vpnconnection.h | 2 ++ 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/client/protocols/protocols_defs.h b/client/protocols/protocols_defs.h index d6af132b..a6840e8c 100644 --- a/client/protocols/protocols_defs.h +++ b/client/protocols/protocols_defs.h @@ -43,6 +43,7 @@ namespace amnezia constexpr char server_priv_key[] = "server_priv_key"; constexpr char server_pub_key[] = "server_pub_key"; constexpr char psk_key[] = "psk_key"; + constexpr char allowed_ips[] = "allowed_ips"; constexpr char client_ip[] = "client_ip"; // internal ip address @@ -78,6 +79,9 @@ namespace amnezia constexpr char sftp[] = "sftp"; constexpr char awg[] = "awg"; + constexpr char splitTunnelSites[] = "splitTunnelSites"; + constexpr char splitTunnelType[] = "splitTunnelType"; + } namespace protocols diff --git a/client/translations/amneziavpn_ru.ts b/client/translations/amneziavpn_ru.ts index ac099552..d3c2657e 100644 --- a/client/translations/amneziavpn_ru.ts +++ b/client/translations/amneziavpn_ru.ts @@ -130,7 +130,7 @@ ImportController - + Scanned %1 of %2. @@ -2413,10 +2413,14 @@ It's okay as long as it's from someone you trust. - WireGuard - New popular VPN protocol with high performance, high speed and low power consumption. Recommended for regions with low levels of censorship. + + + AmneziaWG - Special protocol from Amnezia, based on WireGuard. It's fast like WireGuard, but very resistant to blockages. Recommended for regions with high levels of censorship. + + 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. @@ -2537,6 +2541,16 @@ It's okay as long as it's from someone you trust. error 0x%1: %2 + + + WireGuard Configuration Highlighter + + + + + &Randomize colors + + SelectLanguageDrawer @@ -2704,7 +2718,7 @@ It's okay as long as it's from someone you trust. VpnConnection - + Mbps diff --git a/client/translations/amneziavpn_zh_CN.ts b/client/translations/amneziavpn_zh_CN.ts index 7a08682c..88e13f04 100644 --- a/client/translations/amneziavpn_zh_CN.ts +++ b/client/translations/amneziavpn_zh_CN.ts @@ -130,7 +130,7 @@ ImportController - + Scanned %1 of %2. 扫描 %1 of %2. @@ -2520,10 +2520,14 @@ It's okay as long as it's from someone you trust. - WireGuard - New popular VPN protocol with high performance, high speed and low power consumption. Recommended for regions with low levels of censorship. WireGuard - 新型流行的VPN协议,具有高性能、高速度和低功耗。建议用于审查力度较低的地区 + + + AmneziaWG - Special protocol from Amnezia, based on WireGuard. It's fast like WireGuard, but very resistant to blockages. Recommended for regions with high levels of censorship. + + 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. @@ -2644,6 +2648,16 @@ It's okay as long as it's from someone you trust. error 0x%1: %2 错误 0x%1: %2 + + + WireGuard Configuration Highlighter + + + + + &Randomize colors + + SelectLanguageDrawer @@ -2815,7 +2829,7 @@ It's okay as long as it's from someone you trust. VpnConnection - + Mbps diff --git a/client/ui/controllers/importController.cpp b/client/ui/controllers/importController.cpp index 08b662ec..044ddb37 100644 --- a/client/ui/controllers/importController.cpp +++ b/client/ui/controllers/importController.cpp @@ -263,6 +263,13 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data) // return QJsonObject(); // } + auto allowedIps = configMap.value("AllowedIPs").split(","); + QJsonArray allowedIpsJsonArray; + for (const auto &allowedIp : allowedIps) { + allowedIpsJsonArray.append(allowedIp); + } + lastConfig[config_key::allowed_ips] = allowedIpsJsonArray; + QString protocolName = "wireguard"; if (!configMap.value(config_key::junkPacketCount).isEmpty() && !configMap.value(config_key::junkPacketMinSize).isEmpty() diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 46e8be60..c73df444 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -329,6 +329,8 @@ void VpnConnection::connectToVpn(int serverIndex, const ServerCredentials &crede return; } + appendSplitTunnelingConfig(); + #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) m_vpnProtocol.reset(VpnProtocol::factory(container, m_vpnConfiguration)); if (!m_vpnProtocol) { @@ -363,6 +365,20 @@ void VpnConnection::createProtocolConnections() connect(m_vpnProtocol.data(), SIGNAL(bytesChanged(quint64, quint64)), this, SLOT(onBytesChanged(quint64, quint64))); } +void VpnConnection::appendSplitTunnelingConfig() +{ + auto routeMode = m_settings->routeMode(); + auto sites = m_settings->getVpnIps(routeMode); + + QJsonArray sitesJsonArray; + for (const auto &site : sites) { + sitesJsonArray.append(site); + } + + m_vpnConfiguration.insert(config_key::splitTunnelType, routeMode); + m_vpnConfiguration.insert(config_key::splitTunnelSites, sitesJsonArray); +} + #ifdef Q_OS_ANDROID void VpnConnection::restoreConnection() { diff --git a/client/vpnconnection.h b/client/vpnconnection.h index f6b2343c..45582de5 100644 --- a/client/vpnconnection.h +++ b/client/vpnconnection.h @@ -112,6 +112,8 @@ private: #endif void createProtocolConnections(); + + void appendSplitTunnelingConfig(); }; #endif // VPNCONNECTION_H