mirror of
				https://github.com/yuezk/GlobalProtect-openconnect.git
				synced 2025-05-20 07:26:58 -04:00 
			
		
		
		
	Add User Agent Override to SAML Authentication
Adds "samlUserAgent" key to settings dialog. If left blank, prior behavior is unchanged. If provided, the WebView Profile is adjusted with ::setHttpUserAgent() before opening the portal's SAML page.
This commit is contained in:
		| @@ -62,6 +62,7 @@ void GPClient::onSettingsButtonClicked() | ||||
| { | ||||
|     settingsDialog->setClientos(settings::get("clientos", "Linux").toString()); | ||||
|     settingsDialog->setOsVersion(settings::get("os-version", QSysInfo::prettyProductName()).toString()); | ||||
|     settingsDialog->setSamlUserAgent(settings::get("samlUserAgent", "").toString()); | ||||
|     settingsDialog->show(); | ||||
| } | ||||
|  | ||||
| @@ -69,6 +70,7 @@ void GPClient::onSettingsAccepted() | ||||
| { | ||||
|     settings::save("clientos", settingsDialog->clientos()); | ||||
|     settings::save("os-version", settingsDialog->osVersion()); | ||||
|     settings::save("samlUserAgent", settingsDialog->samlUserAgent()); | ||||
| } | ||||
|  | ||||
| void GPClient::on_connectButton_clicked() | ||||
|   | ||||
| @@ -31,7 +31,7 @@ namespace gpclient { | ||||
|         namespace settings { | ||||
|  | ||||
|             extern QSettings *_settings; | ||||
|             static const QStringList reservedKeys {"extraArgs", "clientos"}; | ||||
|             static const QStringList reservedKeys {"extraArgs", "clientos", "samlUserAgent"}; | ||||
|  | ||||
|             QVariant get(const QString &key, const QVariant &defaultValue = QVariant()); | ||||
|             QStringList get_all(const QString &key, const QVariant &defaultValue = QVariant()); | ||||
|   | ||||
| @@ -4,8 +4,11 @@ | ||||
| #include <QWebEngineCookieStore> | ||||
| #include <plog/Log.h> | ||||
|  | ||||
| #include "gphelper.h" | ||||
| #include "samlloginwindow.h" | ||||
|  | ||||
| using namespace gpclient::helper; | ||||
|  | ||||
| SAMLLoginWindow::SAMLLoginWindow(QWidget *parent) | ||||
|     : QDialog(parent) | ||||
|     , webView(new EnhancedWebView(this)) | ||||
| @@ -42,6 +45,9 @@ void SAMLLoginWindow::closeEvent(QCloseEvent *event) | ||||
| void SAMLLoginWindow::login(const QString samlMethod, const QString samlRequest, const QString preloginUrl) | ||||
| { | ||||
|     webView->page()->profile()->cookieStore()->deleteSessionCookies(); | ||||
|     const QString&  ua = settings::get("samlUserAgent", "").toString(); | ||||
|     if (!ua.isEmpty()) | ||||
|         webView->page()->profile()->setHttpUserAgent(ua); | ||||
|  | ||||
|     if (samlMethod == "POST") { | ||||
|         webView->setHtml(samlRequest, preloginUrl); | ||||
|   | ||||
| @@ -40,3 +40,11 @@ void SettingsDialog::setOsVersion(QString osVersion) { | ||||
| QString SettingsDialog::osVersion() { | ||||
|     return ui->osVersionInput->text(); | ||||
| } | ||||
|  | ||||
| void SettingsDialog::setSamlUserAgent(QString samlUserAgent) { | ||||
|     ui->samlUserAgentInput->setText(samlUserAgent); | ||||
| } | ||||
|  | ||||
| QString SettingsDialog::samlUserAgent() { | ||||
|     return ui->samlUserAgentInput->text(); | ||||
| } | ||||
| @@ -24,6 +24,9 @@ public: | ||||
|     void setOsVersion(QString osVersion); | ||||
|     QString osVersion(); | ||||
|  | ||||
|     void setSamlUserAgent(QString samlUserAgent); | ||||
|     QString samlUserAgent(); | ||||
|  | ||||
| private: | ||||
|     Ui::SettingsDialog *ui; | ||||
| }; | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>488</width> | ||||
|     <height>220</height> | ||||
|     <height>328</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="sizePolicy"> | ||||
| @@ -55,7 +55,17 @@ | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item row="3" column="1"> | ||||
|    <item row="2" column="0"> | ||||
|     <widget class="QLabel" name="label_3"> | ||||
|      <property name="text"> | ||||
|       <string>os-version:</string> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item row="2" column="1"> | ||||
|     <widget class="QLineEdit" name="osVersionInput"/> | ||||
|    </item> | ||||
|    <item row="4" column="1"> | ||||
|     <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|      <property name="orientation"> | ||||
|       <enum>Qt::Horizontal</enum> | ||||
| @@ -65,13 +75,13 @@ | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item row="2" column="1"> | ||||
|     <widget class="QLineEdit" name="osVersionInput"/> | ||||
|    <item row="3" column="1"> | ||||
|     <widget class="QLineEdit" name="samlUserAgentInput"/> | ||||
|    </item> | ||||
|    <item row="2" column="0"> | ||||
|     <widget class="QLabel" name="label_3"> | ||||
|    <item row="3" column="0"> | ||||
|     <widget class="QLabel" name="label_4"> | ||||
|      <property name="text"> | ||||
|       <string>os-version:</string> | ||||
|       <string>saml-user-agent:</string> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user