From fb9bcbcad0b522b131682ebbffb78ff87abd0bdd Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 18 Jun 2018 11:10:41 +0200 Subject: Add support for filtering by LDAP values from file This is a temporary solution until we can do server-side filtering. --- src/vsession.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/vsession.cpp') diff --git a/src/vsession.cpp b/src/vsession.cpp index 05b84a1..04d0ac2 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -14,6 +14,7 @@ #include "globals.h" #include "vsession.h" #include "sessionsiconholder.h" +#include "userldapdata.h" static QProcess _process; @@ -43,7 +44,7 @@ void VSession::addNodeWithAttribute(const QString& nodeName, QIcon VSession::icon() const { QString icon(getAttribute("icon")); SessionsIconHolder *iconHolder = SessionsIconHolder::get(); - if (icon.startsWith("http://")) { + if (icon.startsWith("http://") || icon.startsWith("https://")) { // try to load icon from url QIcon url_icon(iconHolder->getIcon(QUrl(icon))); if (!url_icon.isNull()) { @@ -169,11 +170,13 @@ ImgType VSession::imgtype() const { bool VSession::isActive() const { QString value(getAttribute("active")); - + // Is disabled completely if (value.compare("false") == 0) { if (g_debugMode) qDebug() << "'" << shortDescription() << "' not active. Reason: active == false"; return false; - } else if (value.count("/") == 1) { + } + // Check for date range + if (value.count("/") == 1) { // try to interpret value as date range // [YYYY-MM-DD]/[YYYY-MM-DD] // eg. "1970-01-01/1971-01-01" from Jan 1st 1970 till Jan 1st 1971 @@ -202,7 +205,7 @@ bool VSession::isActive() const { return false; } } - + // Filtering by pool name if (!g_currentPoolName.isEmpty()) { QStringList pools = getAttribute("pools").split("\\s*,\\s*"); if (!pools.isEmpty() && !pools.contains(g_currentPoolName)) { @@ -211,6 +214,19 @@ bool VSession::isActive() const { return false; } } + // Filter by LDAP data + if (!UserLdapData::isEmpty()) { + QDomNode keywordsNode = eintrag_.namedItem("filters"); + for (QDomElement el(keywordsNode.firstChildElement("filter")); + !el.isNull(); + el = el.nextSiblingElement("filter")) { + if (el.attribute("type") != "LDAP") + continue; + if (UserLdapData::isAllowed(el.firstChildElement("key").text(), el.firstChildElement("value").text())) + return true; + } + return false; + } return true; } @@ -337,6 +353,8 @@ QList VSession::readXmlFile(const QString& filepath) { } } + UserLdapData::init(); + QDomElement settingsNode = doc.firstChildElement("settings"); for (QDomElement el(settingsNode.firstChildElement("eintrag")); !el.isNull(); -- cgit v1.2.3-55-g7522