diff --git a/.gitignore b/.gitignore index fb6b006..9db7613 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ gpservice *_adaptor.cpp *_adaptor.h +gpservice_interface.* + # C++ objects and libs *.slo *.lo diff --git a/GPClient/GPClient.pro b/GPClient/GPClient.pro index 7d38d2c..0be925e 100644 --- a/GPClient/GPClient.pro +++ b/GPClient/GPClient.pro @@ -35,7 +35,8 @@ SOURCES += \ portalconfigresponse.cpp \ preloginresponse.cpp \ samlloginwindow.cpp \ - gpclient.cpp + gpclient.cpp \ + settingsdialog.cpp HEADERS += \ cdpcommand.h \ @@ -50,11 +51,13 @@ HEADERS += \ portalconfigresponse.h \ preloginresponse.h \ samlloginwindow.h \ - gpclient.h + gpclient.h \ + settingsdialog.h FORMS += \ gpclient.ui \ - normalloginwindow.ui + normalloginwindow.ui \ + settingsdialog.ui DBUS_INTERFACES += ../GPService/gpservice.xml diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp index 4b2d079..89d36cd 100644 --- a/GPClient/gpclient.cpp +++ b/GPClient/gpclient.cpp @@ -3,6 +3,7 @@ #include "ui_gpclient.h" #include "portalauthenticator.h" #include "gatewayauthenticator.h" +#include "settingsdialog.h" #include #include @@ -12,12 +13,16 @@ using namespace gpclient::helper; GPClient::GPClient(QWidget *parent) : QMainWindow(parent) , ui(new Ui::GPClient) + , settingsDialog(new SettingsDialog(this)) { ui->setupUi(this); + setWindowTitle("GlobalProtect"); setFixedSize(width(), height()); gpclient::helper::moveCenter(this); + setupSettings(); + // Restore portal from the previous settings ui->portalInput->setText(settings::get("portal", "").toString()); @@ -36,6 +41,37 @@ GPClient::~GPClient() { delete ui; delete vpn; + delete settingsDialog; + delete settingsButton; +} + +void GPClient::setupSettings() +{ + settingsButton = new QPushButton(this); + settingsButton->setIcon(QIcon(":/images/settings_icon.svg")); + settingsButton->setFixedSize(QSize(28, 28)); + + QRect rect = this->geometry(); + settingsButton->setGeometry( + rect.width() - settingsButton->width() - 15, + 15, + settingsButton->geometry().width(), + settingsButton->geometry().height() + ); + + connect(settingsButton, &QPushButton::clicked, this, &GPClient::onSettingsButtonClicked); + connect(settingsDialog, &QDialog::accepted, this, &GPClient::onSettingsAccepted); +} + +void GPClient::onSettingsButtonClicked() +{ + settingsDialog->setExtraArgs(settings::get("extraArgs", "").toString()); + settingsDialog->show(); +} + +void GPClient::onSettingsAccepted() +{ + settings::save("extraArgs", settingsDialog->extraArgs()); } void GPClient::on_connectButton_clicked() @@ -330,7 +366,7 @@ void GPClient::onGatewaySuccess(const QString &authCookie) PLOGI << "Gateway login succeeded, got the cookie " << authCookie; isQuickConnect = false; - vpn->connect(currentGateway().address(), portalConfig.username(), authCookie); + vpn->connect(currentGateway().address(), portalConfig.username(), authCookie, settings::get("extraArgs", "").toString()); ui->statusLabel->setText("Connecting..."); updateConnectionStatus(VpnStatus::pending); } diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index f3a15d0..a993a19 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -3,10 +3,12 @@ #include "gpservice_interface.h" #include "portalconfigresponse.h" +#include "settingsdialog.h" #include #include #include +#include QT_BEGIN_NAMESPACE namespace Ui { class GPClient; } @@ -23,6 +25,9 @@ public: void activate(); private slots: + void onSettingsButtonClicked(); + void onSettingsAccepted(); + void on_connectButton_clicked(); void on_portalInput_returnPressed(); void on_portalInput_editingFinished(); @@ -62,10 +67,15 @@ private: QAction *clearAction; QAction *quitAction; + SettingsDialog *settingsDialog; + QPushButton *settingsButton; + bool isQuickConnect { false }; bool isSwitchingGateway { false }; PortalConfigResponse portalConfig; + void setupSettings(); + void initSystemTrayIcon(); void initVpnStatus(); void populateGatewayMenu(); diff --git a/GPClient/resources.qrc b/GPClient/resources.qrc index 88130b8..f6ee3f6 100644 --- a/GPClient/resources.qrc +++ b/GPClient/resources.qrc @@ -6,5 +6,6 @@ not_connected.png radio_unselected.png radio_selected.png + settings_icon.svg diff --git a/GPClient/settings_icon.svg b/GPClient/settings_icon.svg new file mode 100644 index 0000000..7a6140a --- /dev/null +++ b/GPClient/settings_icon.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/GPClient/settingsdialog.cpp b/GPClient/settingsdialog.cpp new file mode 100644 index 0000000..b36a729 --- /dev/null +++ b/GPClient/settingsdialog.cpp @@ -0,0 +1,26 @@ +#include "settingsdialog.h" +#include "ui_settingsdialog.h" + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + + ui->extraArgsInput->setPlaceholderText("e.g. --name=value"); +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +void SettingsDialog::setExtraArgs(QString args) +{ + ui->extraArgsInput->setPlainText(args); +} + +QString SettingsDialog::extraArgs() +{ + return ui->extraArgsInput->toPlainText().trimmed(); +} diff --git a/GPClient/settingsdialog.h b/GPClient/settingsdialog.h new file mode 100644 index 0000000..9208a9c --- /dev/null +++ b/GPClient/settingsdialog.h @@ -0,0 +1,25 @@ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include + +namespace Ui { +class SettingsDialog; +} + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsDialog(QWidget *parent = nullptr); + ~SettingsDialog(); + + void setExtraArgs(QString); + QString extraArgs(); + +private: + Ui::SettingsDialog *ui; +}; + +#endif // SETTINGSDIALOG_H diff --git a/GPClient/settingsdialog.ui b/GPClient/settingsdialog.ui new file mode 100644 index 0000000..b601d9e --- /dev/null +++ b/GPClient/settingsdialog.ui @@ -0,0 +1,86 @@ + + + SettingsDialog + + + + 0 + 0 + 470 + 183 + + + + + 0 + 0 + + + + Settings + + + + :/images/connected.png:/images/connected.png + + + + + + Custom Parameters: + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/GPService/gpservice.cpp b/GPService/gpservice.cpp index 5426d59..b3f72d6 100644 --- a/GPService/gpservice.cpp +++ b/GPService/gpservice.cpp @@ -49,7 +49,7 @@ void GPService::quit() } } -void GPService::connect(QString server, QString username, QString passwd) +void GPService::connect(QString server, QString username, QString passwd, QString extraArgs) { if (vpnStatus != GPService::VpnNotConnected) { log("VPN status is: " + QVariant::fromValue(vpnStatus).toString()); @@ -65,10 +65,13 @@ void GPService::connect(QString server, QString username, QString passwd) QStringList args; args << QCoreApplication::arguments().mid(1) << "--protocol=gp" + << QProcess::splitCommand(extraArgs) << "-u" << username << "-C" << passwd << server; + log("Start process with arugments: " + args.join(" ")); + openconnect->start(bin, args); } diff --git a/GPService/gpservice.h b/GPService/gpservice.h index 0d1e536..ce753a8 100644 --- a/GPService/gpservice.h +++ b/GPService/gpservice.h @@ -34,7 +34,7 @@ signals: void logAvailable(QString log); public slots: - void connect(QString server, QString username, QString passwd); + void connect(QString server, QString username, QString passwd, QString extraArgs); void disconnect(); int status(); void quit(); diff --git a/GPService/gpservice.xml b/GPService/gpservice.xml index de8b11d..202573d 100644 --- a/GPService/gpservice.xml +++ b/GPService/gpservice.xml @@ -12,6 +12,7 @@ + diff --git a/README.md b/README.md index 5d4985b..1e25bd8 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ A GlobalProtect VPN client (GUI) for Linux based on Openconnect and built with Q - Supports automatically selecting the preferred gateway from the multiple gateways. - Supports switching gateway from the system tray menu manually. +## Passing the Custom Parameters to `OpenConnect` CLI + +Custom parameters can be appended to the `OpenConnect` CLI with the following settings. +

+ +

+ ## Prerequisites - Openconnect v8.x