added wireguard connection implementation for Linux

This commit is contained in:
vladimir.kuznetsov 2023-02-28 17:16:38 +03:00
parent 1dd79d9e31
commit caad670dbf
7 changed files with 133 additions and 37 deletions

View file

@ -20,13 +20,12 @@ inline QString permittedProcessPath(PermittedProcess pid)
{
if (pid == PermittedProcess::OpenVPN) {
return Utils::openVpnExecPath();
}
if (pid == PermittedProcess::Wireguard) {
} else if (pid == PermittedProcess::Wireguard) {
return Utils::wireguardExecPath();
}
else if (pid == PermittedProcess::CertUtil) {
} else if (pid == PermittedProcess::CertUtil) {
return Utils::certUtilPath();
}
return "";
}

View file

@ -18,5 +18,8 @@ class IpcInterface
SLOT( void cleanUp() );
SLOT( void setLogsEnabled(bool enabled) );
SLOT( bool copyWireguardConfig(const QString &sourcePath) );
SLOT( bool isWireguardRunning() );
};

View file

@ -124,3 +124,48 @@ void IpcServer::setLogsEnabled(bool enabled)
Logger::deinit();
}
}
bool IpcServer::copyWireguardConfig(const QString &sourcePath)
{
#ifdef Q_OS_LINUX
QProcess copyWireguardConfigProcess;
bool errorOccurred = false;
connect(&copyWireguardConfigProcess, &QProcess::errorOccurred, this, [&errorOccurred](QProcess::ProcessError error) {
qDebug() << "WireguardProtocol::WireguardProtocol error occured while copying wireguard config: " << error;
errorOccurred = true;
});
copyWireguardConfigProcess.setProgram("/bin/cp");
copyWireguardConfigProcess.setArguments(QStringList{sourcePath, "/etc/wireguard/wg99.conf"});
copyWireguardConfigProcess.start();
copyWireguardConfigProcess.waitForFinished(10000);
return errorOccurred;
#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
}

View file

@ -25,6 +25,8 @@ public:
virtual QStringList getTapList() override;
virtual void cleanUp() override;
virtual void setLogsEnabled(bool enabled) override;
virtual bool copyWireguardConfig(const QString &sourcePath) override;
virtual bool isWireguardRunning() override;
private:
int m_localpid = 0;