new type API

This commit is contained in:
Roland Gruber 2016-12-29 20:12:15 +01:00
parent 23c1251009
commit a6330b41e2
2 changed files with 35 additions and 24 deletions

View File

@ -90,18 +90,24 @@ function is_base_module($name, $scope) {
/** /**
* Returns the LDAP filter used by the account lists * Returns the LDAP filter used by the account lists
* *
* @param string $scope the account type ("user", "group", "host") * @param string $typeId the account type ("user", "group", "host")
* @return string LDAP filter * @return string LDAP filter
*/ */
function get_ldap_filter($scope) { function get_ldap_filter($typeId) {
$mods = $_SESSION['config']->get_AccountModules($scope); $typeManager = new \LAM\TYPES\TypeManager();
$filters = array(); $type = $typeManager->getConfiguredType($typeId);
$mods = $_SESSION['config']->get_AccountModules($typeId);
$filters = array('or' => array(), 'and' => array());
$orFilter = ''; $orFilter = '';
for ($i = 0; $i < sizeof($mods); $i++) { for ($i = 0; $i < sizeof($mods); $i++) {
$module = moduleCache::getModule($mods[$i], $scope); $module = moduleCache::getModule($mods[$i], $type->getScope());
$modinfo = $module->get_ldap_filter(); $modinfo = $module->get_ldap_filter();
if (isset($modinfo['or'])) $filters['or'][] = $modinfo['or']; if (isset($modinfo['or'])) {
if (isset($modinfo['and'])) $filters['and'][] = $modinfo['and']; $filters['or'][] = $modinfo['or'];
}
if (isset($modinfo['and'])) {
$filters['and'][] = $modinfo['and'];
}
} }
// build OR filter // build OR filter
if (sizeof($filters['or']) == 1) { if (sizeof($filters['or']) == 1) {
@ -111,15 +117,17 @@ function get_ldap_filter($scope) {
$orFilter = "(|" . implode("", $filters['or']) . ")"; $orFilter = "(|" . implode("", $filters['or']) . ")";
} }
// add built OR filter to AND filters // add built OR filter to AND filters
if ($orFilter != '') $filters['and'][] = $orFilter; if (!empty($orFilter)) {
$filters['and'][] = $orFilter;
}
// add type filter // add type filter
$typeSettings = $_SESSION['config']->get_typeSettings(); $typeSettings = $_SESSION['config']->get_typeSettings();
if (isset($typeSettings['filter_' . $scope]) && ($typeSettings['filter_' . $scope] != '')) { if (isset($typeSettings['filter_' . $typeId]) && ($typeSettings['filter_' . $typeId] != '')) {
if (strpos($typeSettings['filter_' . $scope], '(') === 0) { if (strpos($typeSettings['filter_' . $typeId], '(') === 0) {
$filters['and'][] = $typeSettings['filter_' . $scope]; $filters['and'][] = $typeSettings['filter_' . $typeId];
} }
else { else {
$filters['and'][] = '(' . $typeSettings['filter_' . $scope] . ')'; $filters['and'][] = '(' . $typeSettings['filter_' . $typeId] . ')';
} }
} }
// collapse AND filters // collapse AND filters
@ -140,12 +148,12 @@ function get_ldap_filter($scope) {
* *
* The list is already sorted by the priority given by the nodules. * The list is already sorted by the priority given by the nodules.
* *
* @param string $scope account type (user, group, host) * @param string $typeId account type (user, group, host)
* @param array $selectedModules return only RDN attributes of these modules * @param array $selectedModules return only RDN attributes of these modules
* @return array list of LDAP attributes * @return array list of LDAP attributes
*/ */
function getRDNAttributes($scope, $selectedModules=null) { function getRDNAttributes($typeId, $selectedModules=null) {
$mods = $_SESSION['config']->get_AccountModules($scope); $mods = $_SESSION['config']->get_AccountModules($typeId);
if ($selectedModules != null) { if ($selectedModules != null) {
$mods = $selectedModules; $mods = $selectedModules;
} }
@ -155,7 +163,7 @@ function getRDNAttributes($scope, $selectedModules=null) {
$attrs_high = array(); $attrs_high = array();
for ($i = 0; $i < sizeof($mods); $i++) { for ($i = 0; $i < sizeof($mods); $i++) {
// get list of attributes // get list of attributes
$module = moduleCache::getModule($mods[$i], $scope); $module = moduleCache::getModule($mods[$i], \LAM\TYPES\getScopeFromTypeId($typeId));
$attrs = $module->get_RDNAttributes(); $attrs = $module->get_RDNAttributes();
$keys = array_keys($attrs); $keys = array_keys($attrs);
// sort attributes // sort attributes
@ -595,14 +603,17 @@ function doUploadPostActions($scope, &$data, $ids, $failed, $selectedModules, &$
*/ */
function getRequiredExtensions() { function getRequiredExtensions() {
$extList = array(); $extList = array();
$scopes = $_SESSION['config']->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager();
for ($i = 0; $i < sizeof($scopes); $i++) { $types = $typeManager->getConfiguredTypes();
$mods = $_SESSION['config']->get_AccountModules($scopes[$i]); foreach ($types as $type) {
$mods = $_SESSION['config']->get_AccountModules($type->getId());
for ($m = 0; $m < sizeof($mods); $m++) { for ($m = 0; $m < sizeof($mods); $m++) {
$module = moduleCache::getModule($mods[$m], $scopes[$i]); $module = moduleCache::getModule($mods[$m], $type->getScope());
$ext = $module->getRequiredExtensions(); $ext = $module->getRequiredExtensions();
for ($e = 0; $e < sizeof($ext); $e++) { for ($e = 0; $e < sizeof($ext); $e++) {
if (!in_array($ext[$e], $extList)) $extList[] = $ext[$e]; if (!in_array($ext[$e], $extList)) {
$extList[] = $ext[$e];
}
} }
} }
} }
@ -1727,7 +1738,7 @@ class accountContainer {
$errors = array(); $errors = array();
$ldapUser = $_SESSION['ldap']->decrypt_login(); $ldapUser = $_SESSION['ldap']->decrypt_login();
$ldapUser = $ldapUser[0]; $ldapUser = $ldapUser[0];
$module = array_keys ($this->module); $module = array_keys($this->module);
$attributes = array(); $attributes = array();
// load attributes // load attributes
foreach ($module as $singlemodule) { foreach ($module as $singlemodule) {
@ -1737,7 +1748,7 @@ class accountContainer {
// merge changes // merge changes
$DNs = array_keys($temp); $DNs = array_keys($temp);
if (is_array($temp)) $attributes = array_merge_recursive($temp, $attributes); if (is_array($temp)) $attributes = array_merge_recursive($temp, $attributes);
for ($i=0; $i<count($DNs); $i++) { for ($i = 0; $i < count($DNs); $i++) {
$ops = array_keys($temp[$DNs[$i]]); $ops = array_keys($temp[$DNs[$i]]);
for ($j=0; $j<count($ops); $j++) { for ($j=0; $j<count($ops); $j++) {
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]); $attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);

View File

@ -206,7 +206,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$existingContainer->addElement(new htmlSpacer(null, '10px'), true); $existingContainer->addElement(new htmlSpacer(null, '10px'), true);
} }
$existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['typeId'] . '.png')); $existingContainer->addElement(new htmlImage('../../graphics/' . \LAM\TYPES\getScopeFromTypeId($profileClasses[$i]['typeId']) . '.png'));
$existingContainer->addElement(new htmlSpacer('3px', null)); $existingContainer->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title'])); $existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title']));
$existingContainer->addElement(new htmlSpacer('3px', null)); $existingContainer->addElement(new htmlSpacer('3px', null));