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
use \LAM\TYPES\TypeManager;
use function LAM\TYPES\getScopeFromTypeId;
use LAM\TYPES\ConfiguredType;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
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
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
if (sizeof($needAutoGID) > 0) {
$errorsTemp = array();
$gids = $this->getNextGIDs(sizeof($needAutoGID), $errorsTemp);
$gids = $this->getNextGIDs(sizeof($needAutoGID), $errorsTemp, $type);
if (is_array($gids)) {
for ($i = 0; $i < sizeof($needAutoGID); $i++) {
$partialAccounts[$i]['gidNumber'] = $gids[$i];
@ -716,7 +716,7 @@ class posixGroup extends baseModule implements passwordService {
if ($this->manageCnAndDescription($modules) && ($this->attributes['cn'][0] == '')) {
return false;
}
if ($this->attributes['gidNumber'][0] == '') {
if ((!isset($this->attributes['gidNumber'][0])) || $this->attributes['gidNumber'][0] === '') {
return false;
}
return true;
@ -795,7 +795,7 @@ class posixGroup extends baseModule implements passwordService {
if ($this->attributes['gidNumber'][0]=='') {
// No id-number given, find free GID
if (!isset($this->orig['gidNumber'][0])) {
$newGID = $this->getNextGIDs(1, $errors);
$newGID = $this->getNextGIDs(1, $errors, $this->getAccountContainer()->get_type());
if (is_array($newGID)) {
$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
}
else {
$gids = $this->getGIDs();
$gids = $this->getGIDs($this->getAccountContainer()->get_type());
// Check manual ID
if ($this->getAccountContainer()->isNewAccount || !isset($this->orig['gidNumber'][0]) || ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) {
// check range
@ -1063,9 +1063,10 @@ class posixGroup extends baseModule implements passwordService {
*
* @param integer $count Number of needed free GIDs.
* @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.
*/
function getNextGIDs($count, &$errors) {
function getNextGIDs($count, &$errors, $type) {
// check if UIDs should be taken from Samba pool entry
if (isset($this->moduleSettings['posixGroup_gidGenerator']) && ($this->moduleSettings['posixGroup_gidGenerator'][0] == 'sambaPool')) {
return $this->getNextSambaPoolGIDs($count, $errors);
@ -1085,7 +1086,7 @@ class posixGroup extends baseModule implements passwordService {
$ret = array();
$minID = intval($this->moduleSettings['posixGroup_minGID'][0]);
$maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]);
$gidList = $this->getGIDs();
$gidList = $this->getGIDs($type);
$gids = array();
foreach ($gidList as $gid) {
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.
*
* @param ConfiguredType $type account type
* @return array list of GID numbers
*/
private function getGIDs() {
private function getGIDs($type) {
if ($this->cachedGIDList != null) {
return $this->cachedGIDList;
}
$this->cachedGIDList = array();
$attrs = array('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] != '')) {
$suffix = $this->moduleSettings['posixGroup_gidCheckSuffix'][0];
}

View File

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

View File

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

View File

@ -11,7 +11,7 @@ use \htmlHiddenInput;
$Id$
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
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-disposition: attachment; filename=lam.ldif');
$accounts = unserialize(lamDecrypt($_SESSION['mass_accounts']));
for ($i = 0; $i < sizeof($accounts); $i++) {
echo "DN: " . $accounts[$i]['dn'] . "\n";
unset($accounts[$i]['dn']);
$keys = array_keys($accounts[$i]);
foreach ($accounts as $account) {
echo "DN: " . $account['dn'] . "\n";
unset($account['dn']);
$keys = array_keys($account);
for ($k = 0; $k < sizeof($keys); $k++) {
if (strpos($keys[$k], 'INFO.') === 0) {
continue;
}
if (is_array($accounts[$i][$keys[$k]])) {
for ($x = 0; $x < sizeof($accounts[$i][$keys[$k]]); $x++) {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]][$x] . "\n";
if (is_array($account[$keys[$k]])) {
for ($x = 0; $x < sizeof($account[$keys[$k]]); $x++) {
echo $keys[$k] . ": " . $account[$keys[$k]][$x] . "\n";
}
}
else {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]] . "\n";
echo $keys[$k] . ": " . $account[$keys[$k]] . "\n";
}
}
echo "\n";