2020-12-26 15:03:51 +03:00
|
|
|
#ifndef OPENVPNPROTOCOL_H
|
|
|
|
|
#define OPENVPNPROTOCOL_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
#include "managementserver.h"
|
|
|
|
|
#include "vpnprotocol.h"
|
|
|
|
|
|
2021-02-02 01:47:40 +03:00
|
|
|
#include "core/ipcclient.h"
|
|
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
class OpenVpnProtocol : public VpnProtocol
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2021-02-18 15:00:41 +03:00
|
|
|
explicit OpenVpnProtocol(const QJsonObject& configuration, QObject* parent = nullptr);
|
2021-01-15 23:36:35 +03:00
|
|
|
virtual ~OpenVpnProtocol() override;
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
ErrorCode start() override;
|
2020-12-26 15:03:51 +03:00
|
|
|
void stop() override;
|
|
|
|
|
|
2021-10-04 19:07:49 +03:00
|
|
|
ErrorCode prepare() override;
|
2021-06-12 11:59:36 +03:00
|
|
|
static QString defaultConfigFileName();
|
|
|
|
|
static QString defaultConfigPath();
|
2021-02-18 15:00:41 +03:00
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
protected slots:
|
|
|
|
|
void onReadyReadDataFromManagementServer();
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
private:
|
2020-12-26 15:03:51 +03:00
|
|
|
QString configPath() const;
|
|
|
|
|
bool openVpnProcessIsRunning() const;
|
|
|
|
|
bool sendTermSignal();
|
2021-02-18 15:00:41 +03:00
|
|
|
void readOpenVpnConfiguration(const QJsonObject &configuration);
|
2020-12-26 15:03:51 +03:00
|
|
|
void disconnectFromManagementServer();
|
|
|
|
|
void killOpenVpnProcess();
|
|
|
|
|
void sendByteCount();
|
|
|
|
|
void sendInitialData();
|
2021-02-18 15:00:41 +03:00
|
|
|
void sendManagementCommand(const QString& command);
|
2020-12-26 15:03:51 +03:00
|
|
|
|
|
|
|
|
const QString m_managementHost = "127.0.0.1";
|
|
|
|
|
const unsigned int m_managementPort = 57775;
|
|
|
|
|
|
|
|
|
|
ManagementServer m_managementServer;
|
|
|
|
|
QString m_configFileName;
|
2021-02-18 15:00:41 +03:00
|
|
|
QTemporaryFile m_configFile;
|
2021-01-26 15:01:15 +03:00
|
|
|
|
2022-08-29 02:58:23 +03:00
|
|
|
uint selectMgmtPort();
|
|
|
|
|
|
2021-01-26 15:01:15 +03:00
|
|
|
private:
|
|
|
|
|
void updateRouteGateway(QString line);
|
2021-02-21 09:44:53 -08:00
|
|
|
void updateVpnGateway(const QString &line);
|
2021-02-03 15:42:36 +03:00
|
|
|
|
2021-11-19 19:02:39 +03:00
|
|
|
QSharedPointer<PrivilegedProcess> m_openVpnProcess;
|
2020-12-26 15:03:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // OPENVPNPROTOCOL_H
|