replace existing accounts during upload

This commit is contained in:
Roland Gruber 2018-08-06 20:41:07 +02:00
parent c2cae621e7
commit 96b29d8919
5 changed files with 54 additions and 2 deletions

View File

@ -1,5 +1,6 @@
September 2018 6.5 September 2018 6.5
- Password change possible via LDAP EXOP operation (set LDAP_EXOP as password hash) - Password change possible via LDAP EXOP operation (set LDAP_EXOP as password hash)
- Upload: allow to overwrite existing accounts
- Kolab updates - Kolab updates
- LAM Pro: - LAM Pro:
-> Auto deletion of entries with dynamic directory services support (requires PHP 7.2). -> Auto deletion of entries with dynamic directory services support (requires PHP 7.2).

View File

@ -231,6 +231,8 @@ $helpArray = array (
// profile editor, file upload // profile editor, file upload
"301" => array ("Headline" => _("RDN identifier"), "301" => array ("Headline" => _("RDN identifier"),
"Text" => _("This is the identifier for the relative DN value. It must be one of the given allowed LDAP attributes (e.g. user accounts usually use \"uid\" while groups use \"cn\").")), "Text" => _("This is the identifier for the relative DN value. It must be one of the given allowed LDAP attributes (e.g. user accounts usually use \"uid\" while groups use \"cn\").")),
"302" => array ("Headline" => _("Overwrite"),
"Text" => _("Set to true to overwrite an existing LDAP entry.")),
"360" => array ("Headline" => _("Profile name"), "360" => array ("Headline" => _("Profile name"),
"Text" => _("Name under which the profile will be saved. If a profile with the same name exists, it will be overwritten.")), "Text" => _("Name under which the profile will be saved. If a profile with the same name exists, it will be overwritten.")),
"361" => array ("Headline" => _("DN suffix"), "361" => array ("Headline" => _("DN suffix"),

View File

@ -6,7 +6,7 @@ use accountContainer;
$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) 2016 - 2017 Roland Gruber Copyright (C) 2016 - 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
@ -142,6 +142,12 @@ class Uploader {
} }
} }
if ($preActionOk) { if ($preActionOk) {
$errors = $this->deleteOldEntryIfNeeded($dn, $this->accounts[$position]);
if (!empty($errors)) {
$_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $errors);
$_SESSION['mass_failed'][] = $position;
return;
}
// add LDAP entry // add LDAP entry
$success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs); $success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs);
if (!$success) { if (!$success) {
@ -156,6 +162,23 @@ class Uploader {
} }
} }
/**
* Deletes an existing entry if overwrite option is used.
*
* @param string $dn DN
* @param array $attributes attribute list
* @return array list of error messages
*/
private function deleteOldEntryIfNeeded($dn, $attributes) {
if (isset($attributes['INFO.overwrite']) && ($attributes['INFO.overwrite'] === 'true')) {
$attrs = ldapGetDN($dn, array('dn'));
if ($attrs !== null) {
return deleteDN($dn, true);
}
}
return array();
}
/** /**
* Starts the file upload. * Starts the file upload.
* *

View File

@ -202,8 +202,8 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
if ($accounts !== false) { if ($accounts !== false) {
$rdnList = getRDNAttributes($type->getId(), $selectedModules); $rdnList = getRDNAttributes($type->getId(), $selectedModules);
$suffix = $type->getSuffix(); $suffix = $type->getSuffix();
// set DN
foreach ($accounts as $i => $account) { foreach ($accounts as $i => $account) {
// set DN
// check against list of possible RDN attributes // check against list of possible RDN attributes
if (!in_array($data[$i][$ids['dn_rdn']], $rdnList) || !isset($account[$data[$i][$ids['dn_rdn']]])) { if (!in_array($data[$i][$ids['dn_rdn']], $rdnList) || !isset($account[$data[$i][$ids['dn_rdn']]])) {
$errors[] = array(_('Account %s:') . ' dn_rdn ' . $account[$data[$i][$ids['dn_rdn']]], _("Invalid RDN attribute!"), array($i)); $errors[] = array(_('Account %s:') . ' dn_rdn ' . $account[$data[$i][$ids['dn_rdn']]], _("Invalid RDN attribute!"), array($i));
@ -214,6 +214,10 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
else $account_dn = $account_dn . $data[$i][$ids['dn_suffix']]; else $account_dn = $account_dn . $data[$i][$ids['dn_suffix']];
$accounts[$i]['dn'] = $account_dn; $accounts[$i]['dn'] = $account_dn;
} }
// set overwrite
if (isset($ids['overwrite']) && ($data[$i][$ids['overwrite']] === 'true')) {
$accounts[$i]['INFO.overwrite'] = 'true';
}
} }
// print errors if DN could not be built // print errors if DN could not be built
if (sizeof($errors) > 0) { if (sizeof($errors) > 0) {

View File

@ -324,6 +324,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$row->add($dnTitle, 12); $row->add($dnTitle, 12);
$titles = array(_('Name'), _("Identifier"), _("Example value"), _("Default value"), _("Possible values")); $titles = array(_('Name'), _("Identifier"), _("Example value"), _("Default value"), _("Possible values"));
$data = array(); $data = array();
// DN suffix
$dnSuffixRowCells = array(); $dnSuffixRowCells = array();
$nameGroup = new htmlGroup(); $nameGroup = new htmlGroup();
$help = new htmlHelpLink('361'); $help = new htmlHelpLink('361');
@ -340,6 +341,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$dnSuffixRowCells[] = new htmlOutputText($type->getSuffix()); $dnSuffixRowCells[] = new htmlOutputText($type->getSuffix());
$dnSuffixRowCells[] = new htmlOutputText(''); $dnSuffixRowCells[] = new htmlOutputText('');
$data[] = $dnSuffixRowCells; $data[] = $dnSuffixRowCells;
// RDN
$dnRDNRowCells = array(); $dnRDNRowCells = array();
$rdnText = new htmlOutputText(_("RDN identifier")); $rdnText = new htmlOutputText(_("RDN identifier"));
$rdnText->setMarkAsRequired(true); $rdnText->setMarkAsRequired(true);
@ -360,6 +362,24 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$dnRDNRowCells[] = new htmlOutputText(implode(", ", $rdnAttributes)); $dnRDNRowCells[] = new htmlOutputText(implode(", ", $rdnAttributes));
$dnRDNRowCells[] = new htmlHelpLink('301'); $dnRDNRowCells[] = new htmlHelpLink('301');
$data[] = $dnRDNRowCells; $data[] = $dnRDNRowCells;
// replace existing
$replaceRowCells = array();
$nameGroup = new htmlGroup();
$help = new htmlHelpLink('302');
$help->setCSSClasses(array('hide-on-mobile'));
$nameGroup->addElement($help);
$nameGroup->addElement(new htmlSpacer('0.25rem', '16px'));
$nameGroup->addElement(new htmlOutputText(_("Overwrite")));
$help = new htmlHelpLink('302');
$help->setCSSClasses(array('hide-on-tablet'));
$nameGroup->addElement($help);
$replaceRowCells[] = $nameGroup;
$replaceRowCells[] = new htmlOutputText('overwrite');
$replaceRowCells[] = new htmlOutputText('false');
$replaceRowCells[] = new htmlOutputText('false');
$replaceRowCells[] = new htmlOutputText('true, false');
$data[] = $replaceRowCells;
$table = new htmlResponsiveTable($titles, $data); $table = new htmlResponsiveTable($titles, $data);
$table->setCSSClasses(array('alternating-color')); $table->setCSSClasses(array('alternating-color'));
$row->add($table, 12); $row->add($table, 12);
@ -434,6 +454,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
// DN attributes // DN attributes
$sampleCSV_head[] = "\"dn_suffix\""; $sampleCSV_head[] = "\"dn_suffix\"";
$sampleCSV_head[] = "\"dn_rdn\""; $sampleCSV_head[] = "\"dn_rdn\"";
$sampleCSV_head[] = "\"overwrite\"";
// module attributes // module attributes
foreach ($modules as $moduleName) { foreach ($modules as $moduleName) {
if (sizeof($columns[$moduleName]) < 1) { if (sizeof($columns[$moduleName]) < 1) {
@ -447,6 +468,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
// DN attributes // DN attributes
$sampleCSV_row[] = "\"" . $type->getSuffix() . "\""; $sampleCSV_row[] = "\"" . $type->getSuffix() . "\"";
$sampleCSV_row[] = "\"" . $RDNs[0] . "\""; $sampleCSV_row[] = "\"" . $RDNs[0] . "\"";
$sampleCSV_row[] = "\"false\"";
// module attributes // module attributes
foreach ($modules as $moduleName) { foreach ($modules as $moduleName) {
if (sizeof($columns[$moduleName]) < 1) { if (sizeof($columns[$moduleName]) < 1) {