diff --git a/GPClient/GPClient.pro b/GPClient/GPClient.pro
index 57b6da9..9755d1e 100644
--- a/GPClient/GPClient.pro
+++ b/GPClient/GPClient.pro
@@ -54,3 +54,6 @@ desktop_icon.path = /usr/share/pixmaps/
desktop_icon.files = com.yuezk.qt.GPClient.svg
INSTALLS += desktop_entry desktop_icon
+
+RESOURCES += \
+ resources.qrc
diff --git a/GPClient/com.yuezk.qt.GPClient.svg b/GPClient/com.yuezk.qt.GPClient.svg
index c6a0609..ee0ebd3 100644
--- a/GPClient/com.yuezk.qt.GPClient.svg
+++ b/GPClient/com.yuezk.qt.GPClient.svg
@@ -16,11 +16,11 @@
viewBox="0 0 96 96"
style="enable-background:new 0 0 96 96;"
xml:space="preserve"
- sodipodi:docname="logo.svg"
+ sodipodi:docname="com.yuezk.qt.GPClient.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14">image/svg+xml
\ No newline at end of file
+ d="m 50.35,48.2 c 0,-1 -0.8,-1.8 -1.8,-1.8 -1,0 -1.8,0.8 -1.8,1.8 0,0.7 0.4,1.3 1,1.6 l -1,5.2 h 3.6 l -1,-5.2 c 0.6,-0.3 1,-0.9 1,-1.6 z" />
\ No newline at end of file
diff --git a/GPClient/connected.png b/GPClient/connected.png
new file mode 100644
index 0000000..e6e4e50
Binary files /dev/null and b/GPClient/connected.png differ
diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp
index f760764..7f61b2b 100644
--- a/GPClient/gpclient.cpp
+++ b/GPClient/gpclient.cpp
@@ -3,23 +3,26 @@
#include "samlloginwindow.h"
#include
+#include
+#include
+#include
+#include
+#include
GPClient::GPClient(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::GPClient)
{
ui->setupUi(this);
-
setFixedSize(width(), height());
moveCenter();
+ // Restore portal from the previous settings
settings = new QSettings("com.yuezk.qt", "GPClient");
ui->portalInput->setText(settings->value("portal", "").toString());
QObject::connect(this, &GPClient::connectFailed, [this]() {
- ui->connectButton->setDisabled(false);
- ui->connectButton->setText("Connect");
- ui->statusLabel->setText("Not Connected");
+ updateConnectionStatus("not_connected");
});
// QNetworkAccessManager setup
@@ -38,8 +41,7 @@ GPClient::GPClient(QWidget *parent)
int status = vpn->status();
if (status != 0) {
- ui->statusLabel->setText("Connected");
- ui->connectButton->setText("Disconnect");
+ updateConnectionStatus("connected");
}
}
@@ -61,15 +63,19 @@ void GPClient::on_connectButton_clicked()
QString portal = ui->portalInput->text();
settings->setValue("portal", portal);
ui->statusLabel->setText("Authenticating...");
- ui->connectButton->setDisabled(true);
+ updateConnectionStatus("pending");
samlLogin(portal);
} else if (btnText == "Cancel") {
ui->statusLabel->setText("Canceling...");
- ui->connectButton->setDisabled(true);
+ updateConnectionStatus("pending");
+
+ if (reply->isRunning()) {
+ reply->abort();
+ }
vpn->disconnect();
} else {
ui->statusLabel->setText("Disconnecting...");
- ui->connectButton->setDisabled(true);
+ updateConnectionStatus("pending");
vpn->disconnect();
}
}
@@ -118,7 +124,6 @@ void GPClient::preloginResultFinished()
loginWindow->login(samlRequest);
loginWindow->exec();
}
- delete reply;
}
void GPClient::onLoginSuccess(QJsonObject loginResult)
@@ -141,27 +146,38 @@ void GPClient::onLoginSuccess(QJsonObject loginResult)
}
QString host = QString("https://%1/%2:%3").arg(loginResult.value("server").toString(), shortpath, cookieName);
- qDebug() << "Server:" << host << ", User:" << user << "Cookie:" << cookieValue;
- qDebug() << "openconnect --protocol=gp -u" << user << "--passwd-on-stdin" << host;
-
- ui->statusLabel->setText("Connecting...");
- ui->connectButton->setText("Cancel");
- ui->connectButton->setDisabled(false);
vpn->connect(host, user, cookieValue);
+ ui->statusLabel->setText("Connecting...");
+ updateConnectionStatus("pending");
+}
+
+void GPClient::updateConnectionStatus(QString status)
+{
+ if (status == "not_connected") {
+ ui->statusLabel->setText("Not Connected");
+ ui->statusImage->setStyleSheet("image: url(:/images/not_connected.png); padding: 15;");
+ ui->connectButton->setText("Connect");
+ ui->connectButton->setDisabled(false);
+ } else if (status == "pending") {
+ ui->statusImage->setStyleSheet("image: url(:/images/pending.png); padding: 15;");
+ ui->connectButton->setText("Cancel");
+ ui->connectButton->setDisabled(false);
+ } else if (status == "connected") {
+ ui->statusLabel->setText("Connected");
+ ui->statusImage->setStyleSheet("image: url(:/images/connected.png); padding: 15;");
+ ui->connectButton->setText("Disconnect");
+ ui->connectButton->setDisabled(false);
+ }
}
void GPClient::onVPNConnected()
{
- ui->statusLabel->setText("Connected");
- ui->connectButton->setText("Disconnect");
- ui->connectButton->setDisabled(false);
+ updateConnectionStatus("connected");
}
void GPClient::onVPNDisconnected()
{
- ui->statusLabel->setText("Not Connected");
- ui->connectButton->setText("Connect");
- ui->connectButton->setDisabled(false);
+ updateConnectionStatus("not_connected");
}
void GPClient::onVPNLogAvailable(QString log)
diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h
index f7d5264..d8f79d0 100644
--- a/GPClient/gpclient.h
+++ b/GPClient/gpclient.h
@@ -41,6 +41,7 @@ private:
QSettings *settings;
void moveCenter();
+ void updateConnectionStatus(QString status);
void samlLogin(const QString portal);
};
#endif // GPCLIENT_H
diff --git a/GPClient/gpclient.ui b/GPClient/gpclient.ui
index 02f07e7..ad50a25 100644
--- a/GPClient/gpclient.ui
+++ b/GPClient/gpclient.ui
@@ -7,15 +7,18 @@
0
0
260
- 300
+ 338
GP VPN Client
-
- com.yuezk.qt.GPClient.svgcom.yuezk.qt.GPClient.svg
+
+ :/images/logo.svg:/images/logo.svg
+
+
+
@@ -47,12 +50,28 @@
15
-
-
+
+
+ 15
+
+
-
+
+
+ #statusImage {
+ image: url(:/images/not_connected.png);
+ padding: 15
+}
+
+
+
+
+
+
-
- 18
+ 14
50
false
false
@@ -101,6 +120,8 @@
-
+
+
+
diff --git a/GPClient/not_connected.png b/GPClient/not_connected.png
new file mode 100644
index 0000000..99adc1b
Binary files /dev/null and b/GPClient/not_connected.png differ
diff --git a/GPClient/pending.png b/GPClient/pending.png
new file mode 100644
index 0000000..2130be7
Binary files /dev/null and b/GPClient/pending.png differ
diff --git a/GPClient/resources.qrc b/GPClient/resources.qrc
new file mode 100644
index 0000000..262af01
--- /dev/null
+++ b/GPClient/resources.qrc
@@ -0,0 +1,11 @@
+
+
+ com.yuezk.qt.GPClient.svg
+ connected.png
+ pending.png
+ not_connected.png
+
+
+ styles.css
+
+
diff --git a/GPClient/styles.css b/GPClient/styles.css
new file mode 100644
index 0000000..e69de29
diff --git a/GPService/systemd/gpservice.service b/GPService/systemd/gpservice.service
index e811c96..9574461 100644
--- a/GPService/systemd/gpservice.service
+++ b/GPService/systemd/gpservice.service
@@ -6,4 +6,4 @@ Wants=network.target
[Service]
Type=dbus
BusName=com.yuezk.qt.GPService
-ExecStart=/usr/local/bin/gpservice --no-dtls -U nm-openconnect
+ExecStart=/usr/local/bin/gpservice