From d6b9a28b58a4a7fede852eca3220bad110897837 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 7 Jan 2017 19:10:12 +0100 Subject: [PATCH 1/3] new type API --- lam/lib/account.inc | 9 +++++---- lam/lib/pdfstruct.inc | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 8043a6bb..ec489529 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -672,13 +672,14 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes elseif (sizeof($filterParts) > 1) { $filter = '(& ' . implode(' ', $filterParts) . ')'; } - $activeTypes = $_SESSION['config']->get_ActiveTypes(); - for ($s = 0; $s < sizeof($scopes); $s++) { - if (!in_array($scopes[$s], $activeTypes)) { + $typeManager = new \LAM\TYPES\TypeManager(); + $activeTypes = $typeManager->getConfiguredTypes(); + foreach ($activeTypes as $type) { + if (!in_array($type->getScope(), $scopes)) { continue; // skip non-active account types } // search LDAP - $entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])), + $entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), $filter, $attributes, 0, $_SESSION['config']->get_searchLimit()); if (ldap_errno($_SESSION['ldap']->server()) == 4) { logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.'); diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index c2bb59ce..580f92c2 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -8,7 +8,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2003 - 2006 Michael Duergner - 2011 - 2016 Roland Gruber + 2011 - 2017 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,19 +40,20 @@ include_once("ldap.inc"); /** * This function will return all available PDF structure definitions for the submitted - * account scope. + * account type. * - * @param string $scope The account scope the PDF structure definitions should be - * returned. + * @param string $typeId the account type * @param string $profile server profile name * - * @return array $scope All available PDF structure definitions for the submitted account + * @return array All available PDF structure definitions for the submitted account * scope. Each entry is a string being the filename that may be passed to the * createModulePDF() function as second argument. */ -function getPDFStructures($scope = "user", $profile = null) { +function getPDFStructures($typeId, $profile = null) { $return = array(); - + if (!preg_match('/[a-zA-Z]+/', $typeId)) { + return null; + } if (!isset($profile)) { $profile = $_SESSION['config']->getName(); } @@ -61,7 +62,7 @@ function getPDFStructures($scope = "user", $profile = null) { $dirHandle = opendir($path); while($file = readdir($dirHandle)) { $struct_file = explode('.',$file); - if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && (sizeof($struct_file) == 3) && ($struct_file[1] == $scope) && ($struct_file[2] == 'xml')) { + if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && (sizeof($struct_file) == 3) && ($struct_file[1] == $typeId) && ($struct_file[2] == 'xml')) { array_push($return, $struct_file[0]); } } @@ -292,14 +293,15 @@ function deletePDFLogo($name) { return new htmlStatusMessage('ERROR', _('File does not exist.'), htmlspecialchars($name)); } // check if still in use - $activeTypes = $_SESSION['config']->get_ActiveTypes(); + $typeManager = new \LAM\TYPES\TypeManager(); + $activeTypes = $typeManager->getConfiguredTypes(); foreach ($activeTypes as $type) { - $structures = getPDFStructures($type); + $structures = getPDFStructures($type->getId()); foreach ($structures as $structure) { - $data = loadPDFStructure($type, $structure); + $data = loadPDFStructure($type->getId(), $structure); if ($data['page_definitions']['filename'] == $name) { return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), - sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, \LAM\TYPES\getTypeAlias($type))); + sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, $type->getAlias())); } } } From 7d60eba628b9bbaf96041f63cd0c48a6591174aa Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 7 Jan 2017 19:10:33 +0100 Subject: [PATCH 2/3] removed obsolete code --- lam/lib/modules/inetOrgPerson.inc | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index 4bf5ef80..4589a067 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2003 - 2006 Tilo Lutz - 2005 - 2016 Roland Gruber + 2005 - 2017 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,8 +37,6 @@ $Id$ */ class inetOrgPerson extends baseModule implements passwordService { - /** caches the list of possible managers */ - private $cachedManagers = null; /** clear text password */ private $clearTextPassword = null; /** cache for departments */ @@ -3495,28 +3493,6 @@ class inetOrgPerson extends baseModule implements passwordService { return array(); } - /** - * Returns a list of possible managers. - * - * @return array list of format array(abstract DN => DN) - */ - private function getManagers() { - if ($this->cachedManagers != null) { - return $this->cachedManagers; - } - $dnUsers = searchLDAPByAttribute(null, null, 'inetOrgPerson', array('dn'), array('user')); - for ($i = 0; $i < sizeof($dnUsers); $i++) { - $dnUsers[$i] = $dnUsers[$i]['dn']; - } - usort($dnUsers, 'compareDN'); - array_unshift($dnUsers, '-'); - $this->cachedManagers = array(); - for ($i = 0; $i < sizeof($dnUsers); $i++) { - $this->cachedManagers[getAbstractDN($dnUsers[$i])] = $dnUsers[$i]; - } - return $this->cachedManagers; - } - /** * Loads cached data from LDAP such as departmets etc. */ From 6b643729d058ba2353ac39963cb60e027b39751d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 7 Jan 2017 19:14:29 +0100 Subject: [PATCH 3/3] new type API --- lam/lib/account.inc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index ec489529..e725e90f 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2003 - 2006 Tilo Lutz - 2009 - 2016 Roland Gruber + 2009 - 2017 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -704,9 +704,14 @@ function searchLDAPByFilter($filter, $attributes, $scopes, $attrsOnly = false) { if ($attrsOnly) { $readAttributesOnly = 1; } - for ($s = 0; $s < sizeof($scopes); $s++) { + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + foreach ($types as $type) { + if (!in_array($type->getScope(), $scopes)) { + continue; + } // search LDAP - $entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])), + $entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), $filter, $attributes, $readAttributesOnly, $_SESSION['config']->get_searchLimit()); if (ldap_errno($_SESSION['ldap']->server()) == 4) { logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.');