Merge pull request #22 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2017-01-07 19:16:24 +01:00 committed by GitHub
commit 841306c00c
3 changed files with 28 additions and 44 deletions

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz 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 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 it under the terms of the GNU General Public License as published by
@ -672,13 +672,14 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes
elseif (sizeof($filterParts) > 1) { elseif (sizeof($filterParts) > 1) {
$filter = '(& ' . implode(' ', $filterParts) . ')'; $filter = '(& ' . implode(' ', $filterParts) . ')';
} }
$activeTypes = $_SESSION['config']->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager();
for ($s = 0; $s < sizeof($scopes); $s++) { $activeTypes = $typeManager->getConfiguredTypes();
if (!in_array($scopes[$s], $activeTypes)) { foreach ($activeTypes as $type) {
if (!in_array($type->getScope(), $scopes)) {
continue; // skip non-active account types continue; // skip non-active account types
} }
// search LDAP // 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()); $filter, $attributes, 0, $_SESSION['config']->get_searchLimit());
if (ldap_errno($_SESSION['ldap']->server()) == 4) { if (ldap_errno($_SESSION['ldap']->server()) == 4) {
logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.'); logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.');
@ -703,9 +704,14 @@ function searchLDAPByFilter($filter, $attributes, $scopes, $attrsOnly = false) {
if ($attrsOnly) { if ($attrsOnly) {
$readAttributesOnly = 1; $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 // 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()); $filter, $attributes, $readAttributesOnly, $_SESSION['config']->get_searchLimit());
if (ldap_errno($_SESSION['ldap']->server()) == 4) { if (ldap_errno($_SESSION['ldap']->server()) == 4) {
logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.'); logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.');

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz 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 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 it under the terms of the GNU General Public License as published by
@ -37,8 +37,6 @@ $Id$
*/ */
class inetOrgPerson extends baseModule implements passwordService { class inetOrgPerson extends baseModule implements passwordService {
/** caches the list of possible managers */
private $cachedManagers = null;
/** clear text password */ /** clear text password */
private $clearTextPassword = null; private $clearTextPassword = null;
/** cache for departments */ /** cache for departments */
@ -3495,28 +3493,6 @@ class inetOrgPerson extends baseModule implements passwordService {
return array(); 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. * Loads cached data from LDAP such as departmets etc.
*/ */

View File

@ -8,7 +8,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner 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 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 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 * 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 * @param string $typeId the account type
* returned.
* @param string $profile server profile name * @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 * scope. Each entry is a string being the filename that may be passed to the
* createModulePDF() function as second argument. * createModulePDF() function as second argument.
*/ */
function getPDFStructures($scope = "user", $profile = null) { function getPDFStructures($typeId, $profile = null) {
$return = array(); $return = array();
if (!preg_match('/[a-zA-Z]+/', $typeId)) {
return null;
}
if (!isset($profile)) { if (!isset($profile)) {
$profile = $_SESSION['config']->getName(); $profile = $_SESSION['config']->getName();
} }
@ -61,7 +62,7 @@ function getPDFStructures($scope = "user", $profile = null) {
$dirHandle = opendir($path); $dirHandle = opendir($path);
while($file = readdir($dirHandle)) { while($file = readdir($dirHandle)) {
$struct_file = explode('.',$file); $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]); array_push($return, $struct_file[0]);
} }
} }
@ -292,14 +293,15 @@ function deletePDFLogo($name) {
return new htmlStatusMessage('ERROR', _('File does not exist.'), htmlspecialchars($name)); return new htmlStatusMessage('ERROR', _('File does not exist.'), htmlspecialchars($name));
} }
// check if still in use // check if still in use
$activeTypes = $_SESSION['config']->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager();
$activeTypes = $typeManager->getConfiguredTypes();
foreach ($activeTypes as $type) { foreach ($activeTypes as $type) {
$structures = getPDFStructures($type); $structures = getPDFStructures($type->getId());
foreach ($structures as $structure) { foreach ($structures as $structure) {
$data = loadPDFStructure($type, $structure); $data = loadPDFStructure($type->getId(), $structure);
if ($data['page_definitions']['filename'] == $name) { if ($data['page_definitions']['filename'] == $name) {
return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), 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()));
} }
} }
} }