Merge branch 'dev' of github.com:amnezia-vpn/desktop-client into feature/qt6-libssh-support
This commit is contained in:
commit
f6ca22ecdd
9 changed files with 144 additions and 31 deletions
|
@ -670,6 +670,10 @@ QString ServerController::replaceVars(const QString &script, const Vars &vars)
|
||||||
|
|
||||||
ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config)
|
ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config)
|
||||||
{
|
{
|
||||||
|
if (container == DockerContainer::Dns) {
|
||||||
|
return ErrorCode::NoError;
|
||||||
|
}
|
||||||
|
|
||||||
QString stdOut;
|
QString stdOut;
|
||||||
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
||||||
stdOut += data + "\n";
|
stdOut += data + "\n";
|
||||||
|
@ -688,13 +692,16 @@ ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credential
|
||||||
QString port = containerConfig.value(config_key::port).toString(protocols::openvpn::defaultPort);
|
QString port = containerConfig.value(config_key::port).toString(protocols::openvpn::defaultPort);
|
||||||
QString transportProto = containerConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
QString transportProto = containerConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
||||||
|
|
||||||
QString script = QString("sudo lsof -i -P -n | grep -E ':%1").arg(port);
|
QString script = QString("sudo lsof -i -P -n | grep -E ':%1 ").arg(port);
|
||||||
for (auto &port : fixedPorts) {
|
for (auto &port : fixedPorts) {
|
||||||
script = script.append("|:%1").arg(port);
|
script = script.append("|:%1").arg(port);
|
||||||
}
|
}
|
||||||
script = script.append("' | grep -i %1").arg(transportProto);
|
script = script.append("' | grep -i %1").arg(transportProto);
|
||||||
runScript(credentials,
|
ErrorCode errorCode = runScript(credentials,
|
||||||
replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr);
|
replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr);
|
||||||
|
if (errorCode != ErrorCode::NoError) {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
if (!stdOut.isEmpty()) {
|
if (!stdOut.isEmpty()) {
|
||||||
return ErrorCode::ServerPortAlreadyAllocatedError;
|
return ErrorCode::ServerPortAlreadyAllocatedError;
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
#include "wireguardprotocol.h"
|
#include "wireguardprotocol.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject* parent) :
|
WireguardProtocol::WireguardProtocol(const QJsonObject &configuration, QObject* parent) : VpnProtocol(configuration, parent)
|
||||||
VpnProtocol(configuration, parent)
|
|
||||||
{
|
{
|
||||||
m_configFile.setFileName(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
|
m_configFile.setFileName(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
|
||||||
writeWireguardConfiguration(configuration);
|
writeWireguardConfiguration(configuration);
|
||||||
|
@ -47,11 +46,8 @@ void WireguardProtocol::stop()
|
||||||
|
|
||||||
m_wireguardStopProcess->setProgram(PermittedProcess::Wireguard);
|
m_wireguardStopProcess->setProgram(PermittedProcess::Wireguard);
|
||||||
|
|
||||||
|
m_wireguardStopProcess->setArguments(stopArgs());
|
||||||
QStringList arguments({"--remove", configPath()});
|
qDebug() << stopArgs().join(" ");
|
||||||
m_wireguardStopProcess->setArguments(arguments);
|
|
||||||
|
|
||||||
qDebug() << arguments.join(" ");
|
|
||||||
|
|
||||||
connect(m_wireguardStopProcess.data(), &PrivilegedProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
|
connect(m_wireguardStopProcess.data(), &PrivilegedProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
|
||||||
qDebug() << "WireguardProtocol::WireguardProtocol Stop errorOccurred" << error;
|
qDebug() << "WireguardProtocol::WireguardProtocol Stop errorOccurred" << error;
|
||||||
|
@ -62,12 +58,25 @@ void WireguardProtocol::stop()
|
||||||
qDebug() << "WireguardProtocol::WireguardProtocol Stop stateChanged" << newState;
|
qDebug() << "WireguardProtocol::WireguardProtocol Stop stateChanged" << newState;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
if (IpcClient::Interface()) {
|
||||||
|
QRemoteObjectPendingReply<bool> result = IpcClient::Interface()->isWireguardRunning();
|
||||||
|
if (result.returnValue()) {
|
||||||
|
setConnectionState(VpnProtocol::Disconnected);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "IPC client not initialized";
|
||||||
|
setConnectionState(VpnProtocol::Disconnected);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
m_wireguardStopProcess->start();
|
m_wireguardStopProcess->start();
|
||||||
m_wireguardStopProcess->waitForFinished(10000);
|
m_wireguardStopProcess->waitForFinished(10000);
|
||||||
|
|
||||||
setConnectionState(VpnProtocol::Disconnected);
|
setConnectionState(VpnProtocol::Disconnected);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WireguardProtocol::writeWireguardConfiguration(const QJsonObject &configuration)
|
void WireguardProtocol::writeWireguardConfiguration(const QJsonObject &configuration)
|
||||||
|
@ -79,13 +88,28 @@ void WireguardProtocol::writeWireguardConfiguration(const QJsonObject &configura
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isConfigLoaded = true;
|
|
||||||
|
|
||||||
m_configFile.write(jConfig.value(config_key::config).toString().toUtf8());
|
m_configFile.write(jConfig.value(config_key::config).toString().toUtf8());
|
||||||
m_configFile.close();
|
m_configFile.close();
|
||||||
m_configFileName = m_configFile.fileName();
|
|
||||||
|
|
||||||
qDebug().noquote() << QString("Set config data") << m_configFileName;
|
#ifdef Q_OS_LINUX
|
||||||
|
if (IpcClient::Interface()) {
|
||||||
|
QRemoteObjectPendingReply<bool> result = IpcClient::Interface()->copyWireguardConfig(m_configFile.fileName());
|
||||||
|
if (result.returnValue()) {
|
||||||
|
qCritical() << "Failed to copy wireguard config";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "IPC client not initialized";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_configFileName = "/etc/wireguard/wg99.conf";
|
||||||
|
#else
|
||||||
|
m_configFileName = m_configFile.fileName();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_isConfigLoaded = true;
|
||||||
|
|
||||||
|
qDebug().noquote() << QString("Set config data") << configPath();
|
||||||
qDebug().noquote() << QString("Set config data") << configuration.value(ProtocolProps::key_proto_config_data(Proto::WireGuard)).toString().toUtf8();
|
qDebug().noquote() << QString("Set config data") << configuration.value(ProtocolProps::key_proto_config_data(Proto::WireGuard)).toString().toUtf8();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,8 +144,15 @@ ErrorCode WireguardProtocol::start()
|
||||||
return lastError();
|
return lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!QFileInfo::exists(configPath())) {
|
if (IpcClient::Interface()) {
|
||||||
setLastError(ErrorCode::ConfigMissing);
|
QRemoteObjectPendingReply<bool> result = IpcClient::Interface()->isWireguardConfigExists(configPath());
|
||||||
|
if (result.returnValue()) {
|
||||||
|
setLastError(ErrorCode::ConfigMissing);
|
||||||
|
return lastError();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "IPC client not initialized";
|
||||||
|
setLastError(ErrorCode::InternalError);
|
||||||
return lastError();
|
return lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,11 +174,8 @@ ErrorCode WireguardProtocol::start()
|
||||||
|
|
||||||
m_wireguardStartProcess->setProgram(PermittedProcess::Wireguard);
|
m_wireguardStartProcess->setProgram(PermittedProcess::Wireguard);
|
||||||
|
|
||||||
|
m_wireguardStartProcess->setArguments(startArgs());
|
||||||
QStringList arguments({"--add", configPath()});
|
qDebug() << startArgs().join(" ");
|
||||||
m_wireguardStartProcess->setArguments(arguments);
|
|
||||||
|
|
||||||
qDebug() << arguments.join(" ");
|
|
||||||
|
|
||||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
|
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
|
||||||
qDebug() << "WireguardProtocol::WireguardProtocol errorOccurred" << error;
|
qDebug() << "WireguardProtocol::WireguardProtocol errorOccurred" << error;
|
||||||
|
@ -176,7 +204,7 @@ ErrorCode WireguardProtocol::start()
|
||||||
|
|
||||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyReadStandardError, this, [this]() {
|
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyReadStandardError, this, [this]() {
|
||||||
QRemoteObjectPendingReply<QByteArray> reply = m_wireguardStartProcess->readAllStandardError();
|
QRemoteObjectPendingReply<QByteArray> reply = m_wireguardStartProcess->readAllStandardError();
|
||||||
reply.waitForFinished(1000);
|
reply.waitForFinished(10);
|
||||||
qDebug() << "WireguardProtocol::WireguardProtocol readAllStandardError" << reply.returnValue();
|
qDebug() << "WireguardProtocol::WireguardProtocol readAllStandardError" << reply.returnValue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -204,10 +232,33 @@ void WireguardProtocol::updateVpnGateway(const QString &line)
|
||||||
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WireguardProtocol::serviceName() const
|
QString WireguardProtocol::serviceName() const
|
||||||
{
|
{
|
||||||
return "AmneziaVPN.WireGuard0";
|
return "AmneziaVPN.WireGuard0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList WireguardProtocol::stopArgs()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
return {"--remove", configPath()};
|
||||||
|
#elif defined Q_OS_LINUX
|
||||||
|
return {"down", "wg99"};
|
||||||
|
#else
|
||||||
|
return {"--remove", configPath()};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList WireguardProtocol::startArgs()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
return {"--add", configPath()};
|
||||||
|
#elif defined Q_OS_LINUX
|
||||||
|
return {"up", "wg99"};
|
||||||
|
#else
|
||||||
|
return {"--add", configPath()};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ private:
|
||||||
void updateRouteGateway(QString line);
|
void updateRouteGateway(QString line);
|
||||||
void updateVpnGateway(const QString &line);
|
void updateVpnGateway(const QString &line);
|
||||||
QString serviceName() const;
|
QString serviceName() const;
|
||||||
|
QStringList stopArgs();
|
||||||
|
QStringList startArgs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_configFileName;
|
QString m_configFileName;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
sudo docker ps | grep amnezia | awk '{print $1}' | xargs sudo docker stop
|
sudo docker ps -a | grep amnezia | awk '{print $1}' | xargs sudo docker stop
|
||||||
sudo docker ps | grep amnezia | awk '{print $1}' | xargs sudo docker rm
|
sudo docker ps -a | grep amnezia | awk '{print $1}' | xargs sudo docker rm
|
||||||
sudo docker images -a | grep amnezia | awk '{print $3}' | xargs sudo docker rmi
|
sudo docker images -a | grep amnezia | awk '{print $3}' | xargs sudo docker rmi
|
||||||
|
|
|
@ -231,7 +231,7 @@ QString Utils::wireguardExecPath()
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
return Utils::executable("wireguard/wireguard-service", true);
|
return Utils::executable("wireguard/wireguard-service", true);
|
||||||
#elif defined Q_OS_LINUX
|
#elif defined Q_OS_LINUX
|
||||||
return Utils::usrExecutable("wg");
|
return Utils::usrExecutable("wg-quick");
|
||||||
#else
|
#else
|
||||||
return Utils::executable("/wireguard", true);
|
return Utils::executable("/wireguard", true);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,13 +20,12 @@ inline QString permittedProcessPath(PermittedProcess pid)
|
||||||
{
|
{
|
||||||
if (pid == PermittedProcess::OpenVPN) {
|
if (pid == PermittedProcess::OpenVPN) {
|
||||||
return Utils::openVpnExecPath();
|
return Utils::openVpnExecPath();
|
||||||
}
|
} else if (pid == PermittedProcess::Wireguard) {
|
||||||
if (pid == PermittedProcess::Wireguard) {
|
|
||||||
return Utils::wireguardExecPath();
|
return Utils::wireguardExecPath();
|
||||||
}
|
} else if (pid == PermittedProcess::CertUtil) {
|
||||||
else if (pid == PermittedProcess::CertUtil) {
|
|
||||||
return Utils::certUtilPath();
|
return Utils::certUtilPath();
|
||||||
}
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,9 @@ class IpcInterface
|
||||||
|
|
||||||
SLOT( void cleanUp() );
|
SLOT( void cleanUp() );
|
||||||
SLOT( void setLogsEnabled(bool enabled) );
|
SLOT( void setLogsEnabled(bool enabled) );
|
||||||
|
|
||||||
|
SLOT( bool copyWireguardConfig(const QString &sourcePath) );
|
||||||
|
SLOT( bool isWireguardRunning() );
|
||||||
|
SLOT( bool isWireguardConfigExists(const QString &configPath) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
@ -124,3 +125,50 @@ void IpcServer::setLogsEnabled(bool enabled)
|
||||||
Logger::deinit();
|
Logger::deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IpcServer::copyWireguardConfig(const QString &sourcePath)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
const QString wireguardConfigPath = "/etc/wireguard/wg99.conf";
|
||||||
|
if (QFile::exists(wireguardConfigPath))
|
||||||
|
{
|
||||||
|
QFile::remove(wireguardConfigPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!QFile::copy(sourcePath, wireguardConfigPath)) {
|
||||||
|
qDebug() << "WireguardProtocol::WireguardProtocol error occured while copying wireguard config:";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IpcServer::isWireguardRunning()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QProcess checkWireguardStatusProcess;
|
||||||
|
|
||||||
|
connect(&checkWireguardStatusProcess, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
|
||||||
|
qDebug() << "WireguardProtocol::WireguardProtocol error occured while checking wireguard status: " << error;
|
||||||
|
});
|
||||||
|
|
||||||
|
checkWireguardStatusProcess.setProgram("/bin/wg");
|
||||||
|
checkWireguardStatusProcess.setArguments(QStringList{"show"});
|
||||||
|
checkWireguardStatusProcess.start();
|
||||||
|
checkWireguardStatusProcess.waitForFinished(10000);
|
||||||
|
QString output = checkWireguardStatusProcess.readAllStandardOutput();
|
||||||
|
if (!output.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IpcServer::isWireguardConfigExists(const QString &configPath)
|
||||||
|
{
|
||||||
|
return QFileInfo::exists(configPath);
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ public:
|
||||||
virtual QStringList getTapList() override;
|
virtual QStringList getTapList() override;
|
||||||
virtual void cleanUp() override;
|
virtual void cleanUp() override;
|
||||||
virtual void setLogsEnabled(bool enabled) override;
|
virtual void setLogsEnabled(bool enabled) override;
|
||||||
|
virtual bool copyWireguardConfig(const QString &sourcePath) override;
|
||||||
|
virtual bool isWireguardRunning() override;
|
||||||
|
virtual bool isWireguardConfigExists(const QString &configPath) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_localpid = 0;
|
int m_localpid = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue