Merge branch 'dev' of github.com:amnezia-vpn/amnezia-client into feature/new-gui

This commit is contained in:
vladimir.kuznetsov 2023-07-18 05:36:17 +03:00
commit 5b8a0881b7
180 changed files with 5446 additions and 3661 deletions

View file

@ -547,7 +547,8 @@ void IOSVpnProtocol::launchWireguardTunnel(const QJsonObject &rawConfig)
void IOSVpnProtocol::launchCloakTunnel(const QJsonObject &rawConfig)
{
{
//TODO move to OpenVpnConfigurator
QJsonObject ovpn = rawConfig["openvpn_config_data"].toObject();
QString ovpnConfig = ovpn["config"].toString();
@ -555,12 +556,17 @@ void IOSVpnProtocol::launchCloakTunnel(const QJsonObject &rawConfig)
if(rawConfig["protocol"].toString() == "cloak"){
QJsonObject cloak = rawConfig["cloak_config_data"].toObject();
cloak["NumConn"] = 1;
cloak["RemoteHost"] = cloak["remote"].toString();
cloak["RemotePort"] = cloak["port"].toString();
if (cloak.contains("remote")) {
cloak["RemoteHost"] = cloak["remote"].toString();
}
if (cloak.contains("port")) {
cloak["RemotePort"] = cloak["port"].toString();
}
cloak.remove("remote");
cloak.remove("port");
cloak.remove("transport_proto");
// Convert JSONObject to JSONDocument
QJsonObject jsonObject {};
foreach(const QString& key, cloak.keys()) {

View file

@ -53,16 +53,6 @@ QString ProtocolProps::transportProtoToString(TransportProto proto, Proto p)
QMetaEnum metaEnum = QMetaEnum::fromType<TransportProto>();
QString protoKey = metaEnum.valueToKey(static_cast<int>(proto));
return protoKey.toLower();
// if (p == Protocol::OpenVpn){
// return protoKey.toLower();
// }
// else if (p == Protocol::ShadowSocks) {
// return protoKey.toUpper();
// }
// else {
// return protoKey.toLower();
// }
}

View file

@ -3,7 +3,7 @@
#include <QDebug>
#include <QObject>
#include <QQmlEngine>
#include <QMetaEnum>
namespace amnezia
{
@ -207,19 +207,6 @@ namespace amnezia
Q_INVOKABLE static QString key_proto_config_data(Proto p);
Q_INVOKABLE static QString key_proto_config_path(Proto p);
};
static void declareQmlProtocolEnum()
{
qmlRegisterUncreatableMetaObject(ProtocolEnumNS::staticMetaObject, "ProtocolEnum", 1, 0, "ProtocolEnum",
"Error: only enums");
qmlRegisterUncreatableMetaObject(ProtocolEnumNS::staticMetaObject, "ProtocolEnum", 1, 0, "TransportProto",
"Error: only enums");
qmlRegisterUncreatableMetaObject(ProtocolEnumNS::staticMetaObject, "ProtocolEnum", 1, 0, "ServiceType",
"Error: only enums");
}
} // namespace amnezia
QDebug operator<<(QDebug debug, const amnezia::Proto &p);

View file

@ -0,0 +1,44 @@
#ifndef QML_REGISTER_PROTOCOLS_H
#define QML_REGISTER_PROTOCOLS_H
#include "protocols_defs.h"
#include <QObject>
#include <QDebug>
#include <QQmlEngine>
namespace amnezia {
using namespace amnezia::ProtocolEnumNS;
void declareQmlProtocolEnum() {
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"ProtocolEnum",
"Error: only enums"
);
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"TransportProto",
"Error: only enums"
);
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"ServiceType",
"Error: only enums"
);
}
} // namespace amnezia
QDebug operator<<(QDebug debug, const amnezia::Proto &p);
#endif // QML_REGISTER_PROTOCOLS_H

View file

@ -8,10 +8,26 @@
#include "wireguardprotocol.h"
#include "utilities.h"
#include "mozilla/localsocketcontroller.h"
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject* parent) : VpnProtocol(configuration, parent)
{
m_configFile.setFileName(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
writeWireguardConfiguration(configuration);
// MZ
#if defined(MZ_LINUX)
//m_impl.reset(new LinuxController());
#elif defined(MZ_MACOS) // || defined(MZ_WINDOWS)
m_impl.reset(new LocalSocketController());
connect(m_impl.get(), &ControllerImpl::connected, this, [this](const QString& pubkey, const QDateTime& connectionTimestamp) {
emit connectionStateChanged(VpnProtocol::Connected);
});
connect(m_impl.get(), &ControllerImpl::disconnected, this, [this](){
emit connectionStateChanged(VpnProtocol::Disconnected);
});
m_impl->initialize(nullptr, nullptr);
#endif
}
WireguardProtocol::~WireguardProtocol()
@ -22,7 +38,11 @@ WireguardProtocol::~WireguardProtocol()
void WireguardProtocol::stop()
{
#ifndef Q_OS_IOS
#ifdef Q_OS_MAC
stopMzImpl();
return;
#endif
if (!QFileInfo::exists(Utils::wireguardExecPath())) {
qCritical() << "Wireguard executable missing!";
setLastError(ErrorCode::ExecutableMissing);
@ -76,9 +96,22 @@ void WireguardProtocol::stop()
m_wireguardStopProcess->waitForFinished(10000);
setConnectionState(Vpn::ConnectionState::Disconnected);
#endif
}
#ifdef Q_OS_MAC
ErrorCode WireguardProtocol::startMzImpl()
{
m_impl->activate(m_rawConfig);
return ErrorCode::NoError;
}
ErrorCode WireguardProtocol::stopMzImpl()
{
m_impl->deactivate();
return ErrorCode::NoError;
}
#endif
void WireguardProtocol::writeWireguardConfiguration(const QJsonObject &configuration)
{
QJsonObject jConfig = configuration.value(ProtocolProps::key_proto_config_data(Proto::WireGuard)).toObject();
@ -131,13 +164,14 @@ void WireguardProtocol::updateRouteGateway(QString line)
ErrorCode WireguardProtocol::start()
{
#ifndef Q_OS_IOS
if (!m_isConfigLoaded) {
setLastError(ErrorCode::ConfigMissing);
return lastError();
}
WireguardProtocol::stop();
#ifdef Q_OS_MAC
return startMzImpl();
#endif
if (!QFileInfo::exists(Utils::wireguardExecPath())) {
setLastError(ErrorCode::ExecutableMissing);
@ -212,27 +246,11 @@ ErrorCode WireguardProtocol::start()
m_wireguardStartProcess->waitForFinished(10000);
return ErrorCode::NoError;
#else
return ErrorCode::NotImplementedError;
#endif
}
void WireguardProtocol::updateVpnGateway(const QString &line)
{
// // line looks like
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
// QStringList params = line.split(",");
// for (const QString &l : params) {
// if (l.contains("ifconfig")) {
// if (l.split(" ").size() == 3) {
// m_vpnLocalAddress = l.split(" ").at(1);
// m_vpnGateway = l.split(" ").at(2);
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
// }
// }
// }
}
QString WireguardProtocol::serviceName() const
@ -247,7 +265,7 @@ QStringList WireguardProtocol::stopArgs()
#elif defined Q_OS_LINUX
return {"down", "wg99"};
#else
return {"--remove", configPath()};
return {};
#endif
}
@ -258,7 +276,7 @@ QStringList WireguardProtocol::startArgs()
#elif defined Q_OS_LINUX
return {"up", "wg99"};
#else
return {"--add", configPath()};
return {};
#endif
}

View file

@ -10,6 +10,8 @@
#include "vpnprotocol.h"
#include "core/ipcclient.h"
#include "mozilla/controllerimpl.h"
class WireguardProtocol : public VpnProtocol
{
Q_OBJECT
@ -21,6 +23,11 @@ public:
ErrorCode start() override;
void stop() override;
#ifdef Q_OS_MAC
ErrorCode startMzImpl();
ErrorCode stopMzImpl();
#endif
private:
QString configPath() const;
void writeWireguardConfiguration(const QJsonObject &configuration);
@ -40,6 +47,9 @@ private:
bool m_isConfigLoaded = false;
#ifdef Q_OS_MAC
QScopedPointer<ControllerImpl> m_impl;
#endif
};
#endif // WIREGUARDPROTOCOL_H