Merge pull request #16 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2016-12-29 20:13:56 +01:00 committed by GitHub
commit 6b6cd4538f
3 changed files with 55 additions and 33 deletions

View File

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

View File

@ -1,4 +1,9 @@
<?php
namespace LAM\CONFIG;
use \moduleCache;
use \htmlSpacer;
use \htmlTable;
use \htmlButton;
/*
$Id$
@ -94,7 +99,7 @@ if (isset($_POST['saveSettings']) || isset($_POST['editmodules'])
}
}
$allTypes = LAM\TYPES\getTypes();
$allTypes = \LAM\TYPES\getTypes();
echo $_SESSION['header'];
@ -203,13 +208,16 @@ jQuery(document).ready(function() {
// module settings
$types = $conf->get_ActiveTypes();
$typeManager = new \LAM\TYPES\TypeManager($conf);
$types = $typeManager->getConfiguredTypes();
// get list of scopes of modules
$scopes = array();
for ($m = 0; $m < sizeof($types); $m++) {
$mods = $conf->get_AccountModules($types[$m]);
for ($i = 0; $i < sizeof($mods); $i++) $scopes[$mods[$i]][] = $types[$m];
foreach ($types as $type) {
$mods = $conf->get_AccountModules($type->getId());
for ($i = 0; $i < sizeof($mods); $i++) {
$scopes[$mods[$i]][] = $type->getScope();
}
}
// get module options
@ -281,7 +289,8 @@ function checkInput() {
return array();
}
$conf = &$_SESSION['conf_config'];
$types = $conf->get_ActiveTypes();
$typeManager = new \LAM\TYPES\TypeManager($conf);
$types = $typeManager->getConfiguredTypes();
// check module options
// create option array to check and save
@ -289,9 +298,11 @@ function checkInput() {
// get list of scopes of modules
$scopes = array();
for ($m = 0; $m < sizeof($types); $m++) {
$mods = $conf->get_AccountModules($types[$m]);
for ($i = 0; $i < sizeof($mods); $i++) $scopes[$mods[$i]][] = $types[$m];
foreach ($types as $type) {
$mods = $conf->get_AccountModules($type->getId());
for ($i = 0; $i < sizeof($mods); $i++) {
$scopes[$mods[$i]][] = $type->getScope();
}
}
// check options
$errors = checkConfigOptions($scopes, $options);

View File

@ -206,7 +206,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$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 htmlOutputText($profileClasses[$i]['title']));
$existingContainer->addElement(new htmlSpacer('3px', null));