refactoring

This commit is contained in:
Roland Gruber 2018-01-07 17:19:28 +01:00
parent 5f714c4ab5
commit 7db09169be
4 changed files with 34 additions and 32 deletions

View File

@ -1,12 +1,12 @@
<?php <?php
use \LAM\TYPES\TypeManager; use \LAM\TYPES\TypeManager;
use function LAM\TYPES\getScopeFromTypeId; use function LAM\TYPES\getScopeFromTypeId;
use LAM\TYPES\ConfiguredType;
/* /*
$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
2007 - 2017 Roland Gruber 2007 - 2018 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
@ -140,7 +140,7 @@ class posixGroup extends baseModule implements passwordService {
// fill in autoGIDs // fill in autoGIDs
if (sizeof($needAutoGID) > 0) { if (sizeof($needAutoGID) > 0) {
$errorsTemp = array(); $errorsTemp = array();
$gids = $this->getNextGIDs(sizeof($needAutoGID), $errorsTemp); $gids = $this->getNextGIDs(sizeof($needAutoGID), $errorsTemp, $type);
if (is_array($gids)) { if (is_array($gids)) {
for ($i = 0; $i < sizeof($needAutoGID); $i++) { for ($i = 0; $i < sizeof($needAutoGID); $i++) {
$partialAccounts[$i]['gidNumber'] = $gids[$i]; $partialAccounts[$i]['gidNumber'] = $gids[$i];
@ -716,7 +716,7 @@ class posixGroup extends baseModule implements passwordService {
if ($this->manageCnAndDescription($modules) && ($this->attributes['cn'][0] == '')) { if ($this->manageCnAndDescription($modules) && ($this->attributes['cn'][0] == '')) {
return false; return false;
} }
if ($this->attributes['gidNumber'][0] == '') { if ((!isset($this->attributes['gidNumber'][0])) || $this->attributes['gidNumber'][0] === '') {
return false; return false;
} }
return true; return true;
@ -795,7 +795,7 @@ class posixGroup extends baseModule implements passwordService {
if ($this->attributes['gidNumber'][0]=='') { if ($this->attributes['gidNumber'][0]=='') {
// No id-number given, find free GID // No id-number given, find free GID
if (!isset($this->orig['gidNumber'][0])) { if (!isset($this->orig['gidNumber'][0])) {
$newGID = $this->getNextGIDs(1, $errors); $newGID = $this->getNextGIDs(1, $errors, $this->getAccountContainer()->get_type());
if (is_array($newGID)) { if (is_array($newGID)) {
$this->attributes['gidNumber'][0] = $newGID[0]; $this->attributes['gidNumber'][0] = $newGID[0];
} }
@ -807,7 +807,7 @@ class posixGroup extends baseModule implements passwordService {
// old account -> return id-number which has been used // old account -> return id-number which has been used
} }
else { else {
$gids = $this->getGIDs(); $gids = $this->getGIDs($this->getAccountContainer()->get_type());
// Check manual ID // Check manual ID
if ($this->getAccountContainer()->isNewAccount || !isset($this->orig['gidNumber'][0]) || ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) { if ($this->getAccountContainer()->isNewAccount || !isset($this->orig['gidNumber'][0]) || ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) {
// check range // check range
@ -1063,9 +1063,10 @@ class posixGroup extends baseModule implements passwordService {
* *
* @param integer $count Number of needed free GIDs. * @param integer $count Number of needed free GIDs.
* @param array $errors list of error messages where errors can be added * @param array $errors list of error messages where errors can be added
* @param ConfiguredType $type account type
* @return mixed Null if no GIDs are free else an array of free GIDs. * @return mixed Null if no GIDs are free else an array of free GIDs.
*/ */
function getNextGIDs($count, &$errors) { function getNextGIDs($count, &$errors, $type) {
// check if UIDs should be taken from Samba pool entry // check if UIDs should be taken from Samba pool entry
if (isset($this->moduleSettings['posixGroup_gidGenerator']) && ($this->moduleSettings['posixGroup_gidGenerator'][0] == 'sambaPool')) { if (isset($this->moduleSettings['posixGroup_gidGenerator']) && ($this->moduleSettings['posixGroup_gidGenerator'][0] == 'sambaPool')) {
return $this->getNextSambaPoolGIDs($count, $errors); return $this->getNextSambaPoolGIDs($count, $errors);
@ -1085,7 +1086,7 @@ class posixGroup extends baseModule implements passwordService {
$ret = array(); $ret = array();
$minID = intval($this->moduleSettings['posixGroup_minGID'][0]); $minID = intval($this->moduleSettings['posixGroup_minGID'][0]);
$maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]); $maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]);
$gidList = $this->getGIDs(); $gidList = $this->getGIDs($type);
$gids = array(); $gids = array();
foreach ($gidList as $gid) { foreach ($gidList as $gid) {
if (($gid <= $maxID) && ($gid >= $minID)) $gids[] = $gid; // ignore GIDs > maxID and GIDs < minID if (($gid <= $maxID) && ($gid >= $minID)) $gids[] = $gid; // ignore GIDs > maxID and GIDs < minID
@ -1225,16 +1226,17 @@ class posixGroup extends baseModule implements passwordService {
/** /**
* Returns a list of existing GID numbers. * Returns a list of existing GID numbers.
* *
* @param ConfiguredType $type account type
* @return array list of GID numbers * @return array list of GID numbers
*/ */
private function getGIDs() { private function getGIDs($type) {
if ($this->cachedGIDList != null) { if ($this->cachedGIDList != null) {
return $this->cachedGIDList; return $this->cachedGIDList;
} }
$this->cachedGIDList = array(); $this->cachedGIDList = array();
$attrs = array('gidNumber'); $attrs = array('gidNumber');
$filter = '(&(objectClass=posixGroup)(gidNumber=*))'; $filter = '(&(objectClass=posixGroup)(gidNumber=*))';
$suffix = $this->getAccountContainer()->get_type()->getSuffix(); $suffix = $type->getSuffix();
if (isset($this->moduleSettings['posixGroup_gidCheckSuffix'][0]) && ($this->moduleSettings['posixGroup_gidCheckSuffix'][0] != '')) { if (isset($this->moduleSettings['posixGroup_gidCheckSuffix'][0]) && ($this->moduleSettings['posixGroup_gidCheckSuffix'][0] != '')) {
$suffix = $this->moduleSettings['posixGroup_gidCheckSuffix'][0]; $suffix = $this->moduleSettings['posixGroup_gidCheckSuffix'][0];
} }

View File

@ -87,10 +87,10 @@ if ($result) {
} }
// get additional information if monitoring is enabled // get additional information if monitoring is enabled
$monitorResult = searchLDAP('cn=monitor', 'objectClass=*', array('*', '+')); $monitorResults = searchLDAP('cn=monitor', 'objectClass=*', array('*', '+'));
$monitorEntries = array(); $monitorEntries = array();
for ($i = 0; $i < sizeof($monitorResult); $i++) { foreach ($monitorResults as $monitorResult) {
$monitorEntries[$monitorResult[$i]['dn']] = array_change_key_case($monitorResult[$i], CASE_LOWER); $monitorEntries[$monitorResult['dn']] = array_change_key_case($monitorResult, CASE_LOWER);
} }
$monitorEntries = array_change_key_case($monitorEntries, CASE_LOWER); $monitorEntries = array_change_key_case($monitorEntries, CASE_LOWER);

View File

@ -52,9 +52,9 @@ include '../lib/adminHeader.inc';
$availableTools = getTools(); $availableTools = getTools();
// sort tools // sort tools
$toSort = array(); $toSort = array();
for ($i = 0; $i < sizeof($availableTools); $i++) { foreach ($availableTools as $availableTool) {
$myTool = new $availableTools[$i](); $myTool = new $availableTool();
$toSort[$availableTools[$i]] = $myTool->getPosition(); $toSort[$availableTool] = $myTool->getPosition();
} }
asort($toSort); asort($toSort);
$tools = array(); $tools = array();
@ -69,27 +69,27 @@ $container = new htmlResponsiveRow();
$container->add(new htmlTitle(_('Tools')), 12); $container->add(new htmlTitle(_('Tools')), 12);
$toolSettings = $_SESSION['config']->getToolSettings(); $toolSettings = $_SESSION['config']->getToolSettings();
for ($i = 0; $i < sizeof($tools); $i++) { foreach ($tools as $tool) {
// check access level // check access level
if ($tools[$i]->getRequiresWriteAccess() && !checkIfWriteAccessIsAllowed()) { if ($tool->getRequiresWriteAccess() && !checkIfWriteAccessIsAllowed()) {
continue; continue;
} }
if ($tools[$i]->getRequiresPasswordChangeRights() && !checkIfPasswordChangeIsAllowed()) { if ($tool->getRequiresPasswordChangeRights() && !checkIfPasswordChangeIsAllowed()) {
continue; continue;
} }
// check visibility // check visibility
if (!$tools[$i]->isVisible()) { if (!$tool->isVisible()) {
continue; continue;
} }
// check if hidden by config // check if hidden by config
$className = get_class($tools[$i]); $className = get_class($tool);
$toolName = substr($className, strrpos($className, '\\') + 1); $toolName = substr($className, strrpos($className, '\\') + 1);
if (isset($toolSettings['tool_hide_' . $toolName]) && ($toolSettings['tool_hide_' . $toolName] == 'true')) { if (isset($toolSettings['tool_hide_' . $toolName]) && ($toolSettings['tool_hide_' . $toolName] == 'true')) {
continue; continue;
} }
// add tool // add tool
$container->add(new htmlLink($tools[$i]->getName(), $tools[$i]->getLink(), '../graphics/' . $tools[$i]->getImageLink()), 12, 4); $container->add(new htmlLink($tool->getName(), $tool->getLink(), '../graphics/' . $tool->getImageLink()), 12, 4);
$container->add(new htmlOutputText($tools[$i]->getDescription()), 12, 8); $container->add(new htmlOutputText($tool->getDescription()), 12, 8);
$container->addVerticalSpacer('2rem'); $container->addVerticalSpacer('2rem');
} }

View File

@ -11,7 +11,7 @@ use \htmlHiddenInput;
$Id$ $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) 2004 - 2017 Roland Gruber Copyright (C) 2004 - 2018 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
@ -75,21 +75,21 @@ if (isset($_GET['showldif'])) {
header('Content-Type: text/plain'); header('Content-Type: text/plain');
header('Content-disposition: attachment; filename=lam.ldif'); header('Content-disposition: attachment; filename=lam.ldif');
$accounts = unserialize(lamDecrypt($_SESSION['mass_accounts'])); $accounts = unserialize(lamDecrypt($_SESSION['mass_accounts']));
for ($i = 0; $i < sizeof($accounts); $i++) { foreach ($accounts as $account) {
echo "DN: " . $accounts[$i]['dn'] . "\n"; echo "DN: " . $account['dn'] . "\n";
unset($accounts[$i]['dn']); unset($account['dn']);
$keys = array_keys($accounts[$i]); $keys = array_keys($account);
for ($k = 0; $k < sizeof($keys); $k++) { for ($k = 0; $k < sizeof($keys); $k++) {
if (strpos($keys[$k], 'INFO.') === 0) { if (strpos($keys[$k], 'INFO.') === 0) {
continue; continue;
} }
if (is_array($accounts[$i][$keys[$k]])) { if (is_array($account[$keys[$k]])) {
for ($x = 0; $x < sizeof($accounts[$i][$keys[$k]]); $x++) { for ($x = 0; $x < sizeof($account[$keys[$k]]); $x++) {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]][$x] . "\n"; echo $keys[$k] . ": " . $account[$keys[$k]][$x] . "\n";
} }
} }
else { else {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]] . "\n"; echo $keys[$k] . ": " . $account[$keys[$k]] . "\n";
} }
} }
echo "\n"; echo "\n";