mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
check the openconnect version
This commit is contained in:
parent
51cff7cbac
commit
c84a2abb14
@ -1,10 +1,12 @@
|
|||||||
#include "gpservice.h"
|
#include "gpservice.h"
|
||||||
#include "gpserviceadaptor.h"
|
#include "gpserviceadaptor.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
#include <QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtCore/QRegularExpression>
|
||||||
|
#include <QtCore/QRegularExpressionMatch>
|
||||||
|
|
||||||
GPService::GPService(QObject *parent)
|
GPService::GPService(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@ -104,6 +106,10 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isValidVersion(bin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << QCoreApplication::arguments().mid(1)
|
args << QCoreApplication::arguments().mid(1)
|
||||||
<< "--protocol=gp"
|
<< "--protocol=gp"
|
||||||
@ -117,6 +123,30 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin
|
|||||||
openconnect->start(bin, args);
|
openconnect->start(bin, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GPService::isValidVersion(QString &bin) {
|
||||||
|
QProcess p;
|
||||||
|
p.start(bin, QStringList("--version"));
|
||||||
|
p.waitForFinished();
|
||||||
|
QString output = p.readAllStandardOutput();
|
||||||
|
|
||||||
|
QRegularExpression re("v(\\d+).*?\\n");
|
||||||
|
QRegularExpressionMatch match = re.match(output);
|
||||||
|
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
QString fullVersion = match.captured(0);
|
||||||
|
QString majorVersion = match.captured(1);
|
||||||
|
|
||||||
|
if (majorVersion.toInt() < 8) {
|
||||||
|
emit error("The OpenConnect version must greater than v8.0.0, but got " + fullVersion);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log("Failed to parse the OpenConnect version from " + output);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GPService::disconnect()
|
void GPService::disconnect()
|
||||||
{
|
{
|
||||||
if (openconnect->state() != QProcess::NotRunning) {
|
if (openconnect->state() != QProcess::NotRunning) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef GLOBALPROTECTSERVICE_H
|
#ifndef GLOBALPROTECTSERVICE_H
|
||||||
#define GLOBALPROTECTSERVICE_H
|
#define GLOBALPROTECTSERVICE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QProcess>
|
#include <QtCore/QProcess>
|
||||||
|
|
||||||
static const QString binaryPaths[] {
|
static const QString binaryPaths[] {
|
||||||
"/usr/local/bin/openconnect",
|
"/usr/local/bin/openconnect",
|
||||||
@ -54,6 +54,7 @@ private:
|
|||||||
int vpnStatus = GPService::VpnNotConnected;
|
int vpnStatus = GPService::VpnNotConnected;
|
||||||
|
|
||||||
void log(QString msg);
|
void log(QString msg);
|
||||||
|
bool isValidVersion(QString &bin);
|
||||||
static QString findBinary();
|
static QString findBinary();
|
||||||
static QStringList splitCommand(QString command);
|
static QStringList splitCommand(QString command);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user