summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-06-19 13:39:47 +0200
committerSimon Rettberg2024-06-19 13:39:47 +0200
commit13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14 (patch)
treefab02c0fec059ef66aa16f599f99340c1117a776
parentFix reading UTF8 strings from settings (diff)
downloadslxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.tar.gz
slxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.tar.xz
slxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.zip
Add allowed-shibboleth-domains config option to inject in website
This will inject a piece of JS code on page load that sets slxIdpFilter to this value, to be used by the IdP selector to filter the list.
-rw-r--r--src/settings.h2
-rw-r--r--src/webview.cpp30
-rw-r--r--src/webview.h5
3 files changed, 30 insertions, 7 deletions
diff --git a/src/settings.h b/src/settings.h
index 4d8f04b..a218e3b 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -3,6 +3,7 @@
#include <QSettings>
#include <QDir>
+#include <QTextCodec>
#define CONFIG_FILE "/etc/lightdm/qt-lightdm-greeter.conf"
#define CONFIG_FOLDER "/etc/lightdm/qt-lightdm-greeter.conf.d"
@@ -59,6 +60,7 @@ public:
static QString guestSessionButtonText() { return s_settings->value("guest-session-button-text").toString(); }
static QString guestSessionStartText() { return s_settings->value("guest-session-start-text").toString(); }
static QString guestSessionStartButtonText() { return s_settings->value("guest-session-start-button-text").toString(); }
+ static QString allowedShibbolethDomains() { return s_settings->value("allowed-shibboleth-domains").toString(); }
static int resetForm() { return s_settings->value("reset-timeout", "30").toInt(); }
static int rpcPort() { return s_settings->value("rpc-port", "0").toInt(); }
};
diff --git a/src/webview.cpp b/src/webview.cpp
index 9ebc1ba..4fb8511 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -1,6 +1,7 @@
#include "webview.h"
#include "nam.h"
#include "global.h"
+#include "settings.h"
#include <QWebFrame>
#include <QNetworkReply>
@@ -14,6 +15,7 @@
#include <QWebElement>
#include <QRegularExpression>
#include <QWebPage>
+#include <QWebFrame>
static QRegularExpression urlListToRegExp(const QStringList &list);
@@ -32,13 +34,21 @@ QRegularExpression UaWebPage::re("(\\S+)$");
WebView::WebView(QWidget* parent)
: QWebView(parent),
- _timerAbortMessage(new QTimer(this)),
- _abortedDownload(false),
- _inErrorState(false),
- _timerReset(new QTimer(this)),
- _firstLoad(false)
+ _timerAbortMessage(new QTimer(this)),
+ _abortedDownload(false),
+ _inErrorState(false),
+ _timerReset(new QTimer(this)),
+ _firstLoad(false)
{
- this->setPage(new UaWebPage);
+ auto p = new UaWebPage;
+ if (!Settings::allowedShibbolethDomains().trimmed().isEmpty()) {
+ QObject::connect(p, &UaWebPage::frameCreated, [this](QWebFrame *frame) {
+ QObject::connect(frame, &QWebFrame::javaScriptWindowObjectCleared, [this, frame]() {
+ this->jsInjector(frame);
+ });
+ });
+ }
+ this->setPage(p);
_timerAbortMessage->setSingleShot(true);
_timerReset->setSingleShot(true);
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
@@ -60,6 +70,14 @@ WebView::WebView(QWidget* parent)
connect(this, &QWebView::loadFinished, this, &WebView::onLoadFinished);
}
+void WebView::jsInjector(QWebFrame *frame)
+{
+ QString str = Settings::allowedShibbolethDomains().replace(
+ QRegularExpression("[^\\w. -]", QRegularExpression::UseUnicodePropertiesOption),
+ QStringLiteral(""));
+ frame->evaluateJavaScript(QStringLiteral("var slxIdpFilter ='") + str + QStringLiteral("'"));
+}
+
void WebView::windowCloseRequested()
{
// If we have an old URL stored on the stack, navigate back to it, otherwise we return and nothing happens
diff --git a/src/webview.h b/src/webview.h
index 98c596d..27ab2f7 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -7,6 +7,7 @@
class QNetworkReply;
class QTimer;
+class QWebFrame;
/**
* Make sure pages that want to load in a new tab are actually loaded in the same page,
@@ -17,7 +18,7 @@ class WebView : public QWebView
Q_OBJECT
public:
WebView(QWidget* parent = NULL);
- void reset(const QString baseUrl);
+ void reset(const QString baseUrl);
protected:
QWebView *createWindow(QWebPage::WebWindowType) override;
@@ -27,6 +28,8 @@ protected:
void resetTimeout();
+ void jsInjector(QWebFrame *frame);
+
signals:
void triggerReset(const QString &message);
void startAuthentication(const QString &user, const QString &pass);