fixed conflicts after merge
This commit is contained in:
parent
36a2482165
commit
8f6aa950cd
6 changed files with 140 additions and 104 deletions
|
@ -108,6 +108,9 @@ void AmneziaApplication::init()
|
|||
&ImportController::extractConfigFromData);
|
||||
connect(AndroidController::instance(), &AndroidController::importConfigFromOutside, m_pageController.get(),
|
||||
&PageController::goToPageViewConfig);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
IosController::Instance()->initialize();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
#ifdef Q_OS_IOS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
#include "fileUtilites.h"
|
||||
|
||||
namespace
|
||||
|
@ -88,6 +91,18 @@ void ImportController::extractConfigFromFile()
|
|||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
|
||||
"*.vpn *.ovpn *.conf");
|
||||
QFile file(fileName);
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault,
|
||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||
kCFURLPOSIXPathStyle, 0);
|
||||
|
||||
if (!CFURLStartAccessingSecurityScopedResource(url)) {
|
||||
qDebug() << "Could not access path " << QUrl::fromLocalFile(fileName).toString();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QString data = file.readAll();
|
||||
|
||||
|
|
|
@ -95,6 +95,18 @@ void SettingsController::restoreAppConfig()
|
|||
}
|
||||
|
||||
QFile file(fileName);
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault,
|
||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||
kCFURLPOSIXPathStyle, 0);
|
||||
|
||||
if (!CFURLStartAccessingSecurityScopedResource(url)) {
|
||||
qDebug() << "Could not access path " << QUrl::fromLocalFile(fileName).toString();
|
||||
}
|
||||
#endif
|
||||
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
|
||||
|
|
|
@ -90,6 +90,18 @@ void SitesController::importSites(bool replaceExisting)
|
|||
}
|
||||
|
||||
QFile file(fileName);
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault,
|
||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||
kCFURLPOSIXPathStyle, 0);
|
||||
|
||||
if (!CFURLStartAccessingSecurityScopedResource(url)) {
|
||||
qDebug() << "Could not access path " << QUrl::fromLocalFile(fileName).toString();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
emit errorOccurred(tr("Can't open file: ") + fileName);
|
||||
return;
|
||||
|
|
|
@ -22,14 +22,7 @@
|
|||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
enum class ConfigTypes {
|
||||
Amnezia,
|
||||
OpenVpn,
|
||||
WireGuard
|
||||
};
|
||||
|
||||
ConfigTypes checkConfigFormat(const QString &config)
|
||||
namespace
|
||||
{
|
||||
enum class ConfigTypes {
|
||||
Amnezia,
|
||||
|
@ -203,8 +196,8 @@ void StartPageLogic::onPushButtonImportOpenFile()
|
|||
|
||||
#ifdef Q_OS_IOS
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()),
|
||||
fileName.length()),
|
||||
kCFAllocatorDefault,
|
||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||
kCFURLPOSIXPathStyle, 0);
|
||||
|
||||
if (!CFURLStartAccessingSecurityScopedResource(url)) {
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
#include <QHostInfo>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <configurators/openvpn_configurator.h>
|
||||
#include <configurators/cloak_configurator.h>
|
||||
#include <configurators/openvpn_configurator.h>
|
||||
#include <configurators/shadowsocks_configurator.h>
|
||||
#include <configurators/wireguard_configurator.h>
|
||||
#include <configurators/vpn_configurator.h>
|
||||
#include <configurators/wireguard_configurator.h>
|
||||
#include <core/servercontroller.h>
|
||||
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
#include "ipc.h"
|
||||
#include "core/ipcclient.h"
|
||||
#include "ipc.h"
|
||||
#include <protocols/wireguardprotocol.h>
|
||||
#endif
|
||||
|
||||
|
@ -29,15 +29,14 @@
|
|||
#include "utilities.h"
|
||||
#include "vpnconnection.h"
|
||||
|
||||
VpnConnection::VpnConnection(std::shared_ptr<Settings> settings,
|
||||
std::shared_ptr<VpnConfigurator> configurator, QObject* parent) : QObject(parent),
|
||||
m_settings(settings),
|
||||
m_configurator(configurator),
|
||||
m_checkTimer(new QTimer(this))
|
||||
VpnConnection::VpnConnection(std::shared_ptr<Settings> settings, std::shared_ptr<VpnConfigurator> configurator,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_settings(settings), m_configurator(configurator), m_checkTimer(new QTimer(this))
|
||||
{
|
||||
m_checkTimer.setInterval(1000);
|
||||
#ifdef Q_OS_IOS
|
||||
connect(IosController::Instance(), &IosController::connectionStateChanged, this, &VpnConnection::onConnectionStateChanged);
|
||||
connect(IosController::Instance(), &IosController::connectionStateChanged, this,
|
||||
&VpnConnection::onConnectionStateChanged);
|
||||
connect(IosController::Instance(), &IosController::bytesChanged, this, &VpnConnection::onBytesChanged);
|
||||
|
||||
#endif
|
||||
|
@ -71,16 +70,12 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state)
|
|||
QString dns1 = m_vpnConfiguration.value(config_key::dns1).toString();
|
||||
QString dns2 = m_vpnConfiguration.value(config_key::dns1).toString();
|
||||
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(),
|
||||
QStringList() << dns1 << dns2);
|
||||
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), QStringList() << dns1 << dns2);
|
||||
|
||||
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
||||
QTimer::singleShot(1000, m_vpnProtocol.data(), [this](){
|
||||
addSitesRoutes(m_vpnProtocol->vpnGateway(), m_settings->routeMode());
|
||||
});
|
||||
}
|
||||
else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
QTimer::singleShot(1000, m_vpnProtocol.data(),
|
||||
[this]() { addSitesRoutes(m_vpnProtocol->vpnGateway(), m_settings->routeMode()); });
|
||||
} else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), QStringList() << "0.0.0.0/1");
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), QStringList() << "128.0.0.0/1");
|
||||
|
||||
|
@ -88,9 +83,7 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state)
|
|||
addSitesRoutes(m_vpnProtocol->routeGateway(), m_settings->routeMode());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (state == Vpn::ConnectionState::Error) {
|
||||
} else if (state == Vpn::ConnectionState::Error) {
|
||||
IpcClient::Interface()->flushDns();
|
||||
|
||||
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
||||
|
@ -103,8 +96,7 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state)
|
|||
#ifdef Q_OS_IOS
|
||||
if (state == Vpn::ConnectionState::Connected) {
|
||||
m_checkTimer.start();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
m_checkTimer.stop();
|
||||
}
|
||||
#endif
|
||||
|
@ -125,8 +117,7 @@ void VpnConnection::addSitesRoutes(const QString &gw, Settings::RouteMode mode)
|
|||
for (auto i = m.constBegin(); i != m.constEnd(); ++i) {
|
||||
if (Utils::checkIpSubnetFormat(i.key())) {
|
||||
ips.append(i.key());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (Utils::checkIpSubnetFormat(i.value().toString())) {
|
||||
ips.append(i.value().toString());
|
||||
}
|
||||
|
@ -172,8 +163,7 @@ void VpnConnection::addRoutes(const QStringList &ips)
|
|||
if (connectionState() == Vpn::ConnectionState::Connected && IpcClient::Interface()) {
|
||||
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->vpnGateway(), ips);
|
||||
}
|
||||
else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
} else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
IpcClient::Interface()->routeAddList(m_vpnProtocol->routeGateway(), ips);
|
||||
}
|
||||
}
|
||||
|
@ -186,8 +176,7 @@ void VpnConnection::deleteRoutes(const QStringList &ips)
|
|||
if (connectionState() == Vpn::ConnectionState::Connected && IpcClient::Interface()) {
|
||||
if (m_settings->routeMode() == Settings::VpnOnlyForwardSites) {
|
||||
IpcClient::Interface()->routeDeleteList(vpnProtocol()->vpnGateway(), ips);
|
||||
}
|
||||
else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
} else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
|
||||
IpcClient::Interface()->routeDeleteList(m_vpnProtocol->routeGateway(), ips);
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +186,8 @@ void VpnConnection::deleteRoutes(const QStringList &ips)
|
|||
void VpnConnection::flushDns()
|
||||
{
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
if (IpcClient::Interface()) IpcClient::Interface()->flushDns();
|
||||
if (IpcClient::Interface())
|
||||
IpcClient::Interface()->flushDns();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -215,16 +205,20 @@ QMap<Proto, QString> VpnConnection::getLastVpnConfig(const QJsonObject &containe
|
|||
QMap<Proto, QString> configs;
|
||||
for (Proto proto : ProtocolProps::allProtocols()) {
|
||||
|
||||
QString cfg = containerConfig.value(ProtocolProps::protoToString(proto)).toObject().value(config_key::last_config).toString();
|
||||
QString cfg = containerConfig.value(ProtocolProps::protoToString(proto))
|
||||
.toObject()
|
||||
.value(config_key::last_config)
|
||||
.toString();
|
||||
|
||||
if (!cfg.isEmpty()) configs.insert(proto, cfg);
|
||||
if (!cfg.isEmpty())
|
||||
configs.insert(proto, cfg);
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
||||
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig, Proto proto,
|
||||
ErrorCode *errorCode)
|
||||
QString VpnConnection::createVpnConfigurationForProto(int serverIndex, const ServerCredentials &credentials,
|
||||
DockerContainer container, const QJsonObject &containerConfig,
|
||||
Proto proto, ErrorCode *errorCode)
|
||||
{
|
||||
QMap<Proto, QString> lastVpnConfig = getLastVpnConfig(containerConfig);
|
||||
|
||||
|
@ -232,10 +226,8 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
|||
if (lastVpnConfig.contains(proto)) {
|
||||
configData = lastVpnConfig.value(proto);
|
||||
configData = m_configurator->processConfigWithLocalSettings(serverIndex, container, proto, configData);
|
||||
}
|
||||
else {
|
||||
configData = m_configurator->genVpnProtocolConfig(credentials,
|
||||
container, containerConfig, proto, errorCode);
|
||||
} else {
|
||||
configData = m_configurator->genVpnProtocolConfig(credentials, container, containerConfig, proto, errorCode);
|
||||
|
||||
if (errorCode && *errorCode) {
|
||||
return "";
|
||||
|
@ -246,7 +238,8 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
|||
configData = m_configurator->processConfigWithLocalSettings(serverIndex, container, proto, configData);
|
||||
|
||||
if (serverIndex >= 0) {
|
||||
qDebug() << "VpnConnection::createVpnConfiguration: saving config for server #" << serverIndex << container << proto;
|
||||
qDebug() << "VpnConnection::createVpnConfiguration: saving config for server #" << serverIndex << container
|
||||
<< proto;
|
||||
QJsonObject protoObject = m_settings->protocolConfig(serverIndex, container, proto);
|
||||
protoObject.insert(config_key::last_config, configDataBeforeLocalProcessing);
|
||||
m_settings->setProtocolConfig(serverIndex, container, proto, protoObject);
|
||||
|
@ -256,17 +249,18 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
|||
return configData;
|
||||
}
|
||||
|
||||
QJsonObject VpnConnection::createVpnConfiguration(int serverIndex,
|
||||
const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &containerConfig, ErrorCode *errorCode)
|
||||
QJsonObject VpnConnection::createVpnConfiguration(int serverIndex, const ServerCredentials &credentials,
|
||||
DockerContainer container, const QJsonObject &containerConfig,
|
||||
ErrorCode *errorCode)
|
||||
{
|
||||
QJsonObject vpnConfiguration;
|
||||
|
||||
for (ProtocolEnumNS::Proto proto : ContainerProps::protocolsForContainer(container)) {
|
||||
QJsonObject vpnConfigData = QJsonDocument::fromJson(
|
||||
createVpnConfigurationForProto(
|
||||
serverIndex, credentials, container, containerConfig, proto, errorCode).toUtf8()).
|
||||
object();
|
||||
QJsonObject vpnConfigData =
|
||||
QJsonDocument::fromJson(createVpnConfigurationForProto(serverIndex, credentials, container,
|
||||
containerConfig, proto, errorCode)
|
||||
.toUtf8())
|
||||
.object();
|
||||
|
||||
if (errorCode && *errorCode) {
|
||||
return {};
|
||||
|
@ -293,11 +287,13 @@ QJsonObject VpnConnection::createVpnConfiguration(int serverIndex,
|
|||
return vpnConfiguration;
|
||||
}
|
||||
|
||||
void VpnConnection::connectToVpn(int serverIndex,
|
||||
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig)
|
||||
void VpnConnection::connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &containerConfig)
|
||||
{
|
||||
qDebug() << QString("ConnectToVpn, Server index is %1, container is %2, route mode is")
|
||||
.arg(serverIndex).arg(ContainerProps::containerToString(container)) << m_settings->routeMode();
|
||||
.arg(serverIndex)
|
||||
.arg(ContainerProps::containerToString(container))
|
||||
<< m_settings->routeMode();
|
||||
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
||||
if (!m_IpcClient) {
|
||||
m_IpcClient = new IpcClient(this);
|
||||
|
@ -354,17 +350,21 @@ void VpnConnection::connectToVpn(int serverIndex,
|
|||
createProtocolConnections();
|
||||
|
||||
e = m_vpnProtocol.data()->start();
|
||||
if (e) emit connectionStateChanged(Vpn::ConnectionState::Error);
|
||||
if (e)
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Error);
|
||||
}
|
||||
|
||||
void VpnConnection::createProtocolConnections() {
|
||||
void VpnConnection::createProtocolConnections()
|
||||
{
|
||||
connect(m_vpnProtocol.data(), &VpnProtocol::protocolError, this, &VpnConnection::vpnProtocolError);
|
||||
connect(m_vpnProtocol.data(), SIGNAL(connectionStateChanged(Vpn::ConnectionState)), this, SLOT(onConnectionStateChanged(Vpn::ConnectionState)));
|
||||
connect(m_vpnProtocol.data(), SIGNAL(connectionStateChanged(Vpn::ConnectionState)), this,
|
||||
SLOT(onConnectionStateChanged(Vpn::ConnectionState)));
|
||||
connect(m_vpnProtocol.data(), SIGNAL(bytesChanged(quint64, quint64)), this, SLOT(onBytesChanged(quint64, quint64)));
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
void VpnConnection::restoreConnection() {
|
||||
void VpnConnection::restoreConnection()
|
||||
{
|
||||
createAndroidConnections();
|
||||
|
||||
m_vpnProtocol.reset(androidVpnProtocol);
|
||||
|
@ -384,8 +384,10 @@ void VpnConnection::createAndroidConnections(DockerContainer container)
|
|||
{
|
||||
androidVpnProtocol = createDefaultAndroidVpnProtocol(container);
|
||||
|
||||
connect(AndroidController::instance(), &AndroidController::connectionStateChanged, androidVpnProtocol, &AndroidVpnProtocol::setConnectionState);
|
||||
connect(AndroidController::instance(), &AndroidController::statusUpdated, androidVpnProtocol, &AndroidVpnProtocol::connectionDataUpdated);
|
||||
connect(AndroidController::instance(), &AndroidController::connectionStateChanged, androidVpnProtocol,
|
||||
&AndroidVpnProtocol::setConnectionState);
|
||||
connect(AndroidController::instance(), &AndroidController::statusUpdated, androidVpnProtocol,
|
||||
&AndroidVpnProtocol::connectionDataUpdated);
|
||||
}
|
||||
|
||||
AndroidVpnProtocol *VpnConnection::createDefaultAndroidVpnProtocol(DockerContainer container)
|
||||
|
@ -415,8 +417,6 @@ void VpnConnection::disconnectFromVpn()
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!m_vpnProtocol.data()) {
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||
#ifdef Q_OS_ANDROID
|
||||
AndroidController::instance()->stop();
|
||||
#endif
|
||||
|
@ -427,7 +427,7 @@ void VpnConnection::disconnectFromVpn()
|
|||
#endif
|
||||
|
||||
if (!m_vpnProtocol.data()) {
|
||||
emit connectionStateChanged(VpnProtocol::Disconnected);
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -439,7 +439,8 @@ void VpnConnection::disconnectFromVpn()
|
|||
|
||||
Vpn::ConnectionState VpnConnection::connectionState()
|
||||
{
|
||||
if (!m_vpnProtocol) return Vpn::ConnectionState::Disconnected;
|
||||
if (!m_vpnProtocol)
|
||||
return Vpn::ConnectionState::Disconnected;
|
||||
return m_vpnProtocol->connectionState();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue