mirror of
https://github.com/LDAPAccountManager/lam.git
synced 2025-10-05 19:42:31 +02:00
#408 updated LDIF
This commit is contained in:
parent
441404676d
commit
335875fca5
1 changed files with 57 additions and 53 deletions
|
@ -26,7 +26,7 @@ use LamTemporaryFilesManager;
|
|||
/*
|
||||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2013 - 2023 Roland Gruber
|
||||
Copyright (C) 2013 - 2025 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
|
||||
|
@ -346,38 +346,64 @@ function readLDAPData(): array {
|
|||
*/
|
||||
function generateActions(): array {
|
||||
$actions = [];
|
||||
foreach ($_SESSION['multiEdit_status']['entries'] as $entry) {
|
||||
$dn = $entry['dn'];
|
||||
foreach ($_SESSION['multiEdit_status']['entries'] as $oldEntry) {
|
||||
$dn = $oldEntry['dn'];
|
||||
$newEntry = $oldEntry;
|
||||
foreach ($_SESSION['multiEdit_operations'] as $op) {
|
||||
$opType = $op[0];
|
||||
$attr = $op[1];
|
||||
$val = replaceWildcards($op[2], $entry);
|
||||
$val = replaceWildcards($op[2], $oldEntry);
|
||||
switch ($opType) {
|
||||
case ADD:
|
||||
if (empty($entry[$attr]) || !in_array_ignore_case($val, $entry[$attr])) {
|
||||
$actions[] = [ADD, $dn, $attr, $val];
|
||||
if (empty($oldEntry[$attr]) || !in_array_ignore_case($val, $oldEntry[$attr])) {
|
||||
$newEntry[$attr][] = $val;
|
||||
}
|
||||
break;
|
||||
case MOD:
|
||||
if (empty($entry[$attr])) {
|
||||
if (empty($oldEntry[$attr]) || !in_array_ignore_case($val, $oldEntry[$attr])) {
|
||||
// attribute not yet exists, add it
|
||||
$actions[] = [ADD, $dn, $attr, $val];
|
||||
}
|
||||
elseif (!empty($entry[$attr]) && !in_array_ignore_case($val, $entry[$attr])) {
|
||||
// attribute exists and value is not included, replace old values
|
||||
$actions[] = [MOD, $dn, $attr, $val];
|
||||
$newEntry[$attr] = [$val];
|
||||
}
|
||||
break;
|
||||
case DEL:
|
||||
if (empty($val) && !empty($entry[$attr])) {
|
||||
$actions[] = [DEL, $dn, $attr, null];
|
||||
if (empty($val) && !empty($oldEntry[$attr])) {
|
||||
unset($newEntry[$attr]);
|
||||
}
|
||||
elseif (!empty($val) && isset($entry[$attr]) && in_array($val, $entry[$attr])) {
|
||||
$actions[] = [DEL, $dn, $attr, $val];
|
||||
elseif (!empty($val) && isset($oldEntry[$attr]) && in_array($val, $oldEntry[$attr])) {
|
||||
$newEntry[$attr] = array_delete([$val], $newEntry[$attr]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($oldEntry['dn']);
|
||||
unset($newEntry['dn']);
|
||||
// cleanup
|
||||
foreach ($newEntry as $name => &$values) {
|
||||
// remove empty values
|
||||
$values = array_values($values);
|
||||
for ($i = 0; $i < count($values); $i++) {
|
||||
if ($values[$i] === '') {
|
||||
unset($values[$i]);
|
||||
}
|
||||
}
|
||||
$values = array_values($values);
|
||||
// remove empty list of values
|
||||
if (count($values) === 0) {
|
||||
unset($newEntry[$name]);
|
||||
}
|
||||
}
|
||||
// find deleted attributes (in $oldEntry but no longer in $newEntry)
|
||||
foreach ($oldEntry as $name => $value) {
|
||||
if (!isset($newEntry[$name])) {
|
||||
$actions[$dn][$name] = [];
|
||||
}
|
||||
}
|
||||
// find changed attributes
|
||||
foreach ($newEntry as $name => $value) {
|
||||
if (!isset($orig[$name]) || !areArrayContentsEqual($value, $orig[$name])) {
|
||||
$actions[$dn][$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
// save actions
|
||||
$_SESSION['multiEdit_status']['actions'] = $actions;
|
||||
|
@ -399,46 +425,24 @@ function dryRun(): array {
|
|||
$ldif = '# LDAP Account Manager' . $pro . ' ' . LAMVersion() . "\n\nversion: 1\n\n";
|
||||
$log = '';
|
||||
// fill LDIF and log file
|
||||
$lastDN = '';
|
||||
foreach ($_SESSION['multiEdit_status']['actions'] as $action) {
|
||||
$opType = $action[0];
|
||||
$dn = $action[1];
|
||||
$attr = $action[2];
|
||||
$val = $action[3];
|
||||
if ($lastDN != $dn) {
|
||||
if ($lastDN != '') {
|
||||
$log .= "\r\n";
|
||||
}
|
||||
$lastDN = $dn;
|
||||
$log .= $dn . "\r\n";
|
||||
}
|
||||
if ($lastDN != '') {
|
||||
$ldif .= "\n";
|
||||
}
|
||||
foreach ($_SESSION['multiEdit_status']['actions'] as $dn => $changes) {
|
||||
$log .= $dn . "\r\n";
|
||||
$ldif .= 'dn: ' . $dn . "\n";
|
||||
$ldif .= 'changetype: modify' . "\n";
|
||||
switch ($opType) {
|
||||
case ADD:
|
||||
$log .= '+' . $attr . '=' . $val . "\r\n";
|
||||
$ldif .= 'add: ' . $attr . "\n";
|
||||
$ldif .= $attr . ': ' . $val . "\n";
|
||||
break;
|
||||
case DEL:
|
||||
$ldif .= 'delete: ' . $attr . "\n";
|
||||
if (empty($val)) {
|
||||
$log .= '-' . $attr . "\r\n";
|
||||
}
|
||||
else {
|
||||
$log .= '-' . $attr . '=' . $val . "\r\n";
|
||||
$ldif .= $attr . ': ' . $val . "\n";
|
||||
}
|
||||
break;
|
||||
case MOD:
|
||||
$log .= '*' . $attr . '=' . $val . "\r\n";
|
||||
$ldif .= 'replace: ' . $attr . "\n";
|
||||
$ldif .= $attr . ': ' . $val . "\n";
|
||||
break;
|
||||
$isFirstChange = true;
|
||||
foreach ($changes as $attr => $values) {
|
||||
$log .= '* ' . $attr . '=' . implode(', ', $values) . "\r\n";
|
||||
if (!$isFirstChange) {
|
||||
$ldif .= "-\n";
|
||||
}
|
||||
$ldif .= 'replace: ' . $attr . "\n";
|
||||
foreach ($values as $value) {
|
||||
$ldif .= $attr . ': ' . $value . "\n";
|
||||
}
|
||||
$isFirstChange = false;
|
||||
}
|
||||
$ldif .= "\n";
|
||||
$log .= "\r\n";
|
||||
}
|
||||
// build meta HTML
|
||||
$container = new htmlTable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue