Compare commits

...

5 Commits

Author SHA1 Message Date
Roberto Metere
4d4605439a
Merge 99342372d27e6232f80bc172e26fc548481c3e2b into edc13ed14d55f63d4dfa598377df389c4b2c98ed 2023-11-13 18:05:24 +08:00
Kevin Yue
edc13ed14d
Merge pull request #265 from fftmp/master
fix link in Readme
2023-11-13 18:04:46 +08:00
fftmp
dd737bc8c5 fix link in Readme 2023-11-10 22:58:40 +04:00
Roberto Metere
99342372d2 autofill password field 2023-10-14 13:17:47 +01:00
Roberto Metere
cd8d794655 load credentials from ini file
portal is the section name in the ini file
2023-10-14 12:53:04 +01:00
6 changed files with 37 additions and 5 deletions

View File

@ -96,6 +96,7 @@ target_link_libraries(gpclient
Qt5::DBus
QtSignals
${QTKEYCHAIN_LIBRARIES}
inih
)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0 AND CMAKE_BUILD_TYPE STREQUAL Release)

View File

@ -151,7 +151,7 @@ void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QSt
{
LOGI << "Trying to perform SAML login with saml-method " << samlMethod;
auto *loginWindow = new SAMLLoginWindow;
auto *loginWindow = new SAMLLoginWindow(gateway);
connect(loginWindow, &SAMLLoginWindow::success, [this, loginWindow](const QMap<QString, QString> &samlResult) {
this->onSAMLLoginSuccess(samlResult);

View File

@ -118,7 +118,7 @@ void PortalAuthenticator::samlAuth()
{
LOGI << "Trying to perform SAML login with saml-method " << preloginResponse.samlMethod();
auto *loginWindow = new SAMLLoginWindow;
auto *loginWindow = new SAMLLoginWindow(this->portal);
connect(loginWindow, &SAMLLoginWindow::success, [this, loginWindow](const QMap<QString, QString> samlResult) {
this->onSAMLLoginSuccess(samlResult);

View File

@ -4,9 +4,10 @@
#include <QWebEngineCookieStore>
#include <plog/Log.h>
#include "INIReader.h"
#include "samlloginwindow.h"
SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
SAMLLoginWindow::SAMLLoginWindow(QString portal, QWidget *parent)
: QDialog(parent)
, webView(new EnhancedWebView(this))
{
@ -23,6 +24,9 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
connect(webView, &EnhancedWebView::loadFinished, this, &SAMLLoginWindow::onLoadFinished);
// Portal
this->portal = portal;
// Show the login window automatically when exceeds the MAX_WAIT_TIME
QTimer::singleShot(MAX_WAIT_TIME, this, [this]() {
if (failed) {
@ -108,6 +112,9 @@ void SAMLLoginWindow::onLoadFinished()
{
LOGI << "Load finished " << webView->page()->url().toString();
webView->page()->toHtml([this] (const QString &html) { this->handleHtml(html); });
QMap<QString, QString> credentials = this->loadCredentials();
webView->page()->runJavaScript("document.getElementById('username').value='" + credentials["username"] + "';");
webView->page()->runJavaScript("document.getElementById('password').value='" + credentials["password"] + "';");
}
void SAMLLoginWindow::handleHtml(const QString &html)
@ -134,3 +141,25 @@ QString SAMLLoginWindow::parseTag(const QString &tag, const QString &html) {
const QRegularExpression expression(QString("<%1>(.*)</%1>").arg(tag));
return expression.match(html).captured(1);
}
QMap<QString, QString> SAMLLoginWindow::loadCredentials()
{
std::string home = getenv("HOME");
std::string iniFile = home + "/.gpclient-credentials";
INIReader reader(iniFile);
QMap<QString, QString> credentials;
if (reader.ParseError() < 0) {
LOGE << "File '" << iniFile << "' not found.";
return credentials;
}
if (reader.HasSection(this->portal.toStdString())) {
credentials.insert(QString("username"), QString::fromStdString(reader.Get(this->portal.toStdString(), "username", "")));
credentials.insert(QString("password"), QString::fromStdString(reader.Get(this->portal.toStdString(), "password", "")));
} else {
LOGE << "No credentials found for '" << this->portal.toStdString() << "' in '" << iniFile << "'";
}
return credentials;
}

View File

@ -12,9 +12,10 @@ class SAMLLoginWindow : public QDialog
Q_OBJECT
public:
explicit SAMLLoginWindow(QWidget *parent = nullptr);
explicit SAMLLoginWindow(QString portal, QWidget *parent = nullptr);
void login(const QString samlMethod, const QString samlRequest, const QString preloginUrl);
QMap<QString, QString> loadCredentials();
signals:
void success(QMap<QString, QString> samlResult);
@ -31,6 +32,7 @@ private:
bool failed { false };
EnhancedWebView *webView { nullptr };
QMap<QString, QString> samlResult;
QString portal;
void closeEvent(QCloseEvent *event);
void handleHtml(const QString &html);

View File

@ -23,7 +23,7 @@ A GlobalProtect VPN client (GUI) for Linux based on Openconnect and built with Q
|OS|Stable version | Development version|
|---|--------------|--------------------|
|Linux Mint, Ubuntu 18.04 or later|[ppa:yuezk/globalprotect-openconnect](https://launchpad.net/~yuezk/+archive/ubuntu/globalprotect-openconnect)|[ppa:yuezk/globalprotect-openconnect-snapshot](https://launchpad.net/~yuezk/+archive/ubuntu/globalprotect-openconnect-snapshot)|
|Arch, Manjaro|[globalprotect-openconnect](https://archlinux.org/packages/community/x86_64/globalprotect-openconnect/)|[AUR: globalprotect-openconnect-git](https://aur.archlinux.org/packages/globalprotect-openconnect-git/)|
|Arch, Manjaro|[globalprotect-openconnect](https://archlinux.org/packages/extra/x86_64/globalprotect-openconnect/)|[AUR: globalprotect-openconnect-git](https://aur.archlinux.org/packages/globalprotect-openconnect-git/)|
|Fedora|[copr: yuezk/globalprotect-openconnect](https://copr.fedorainfracloud.org/coprs/yuezk/globalprotect-openconnect/)|[copr: yuezk/globalprotect-openconnect](https://copr.fedorainfracloud.org/coprs/yuezk/globalprotect-openconnect/)|
|openSUSE, CentOS 8|[OBS: globalprotect-openconnect](https://build.opensuse.org/package/show/home:yuezk/globalprotect-openconnect)|[OBS: globalprotect-openconnect-snapshot](https://build.opensuse.org/package/show/home:yuezk/globalprotect-openconnect-snapshot)|