2009-06-30 09:22:30 +00:00
|
|
|
<?php
|
2009-06-30 10:46:00 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/update_confirm.php,v 1.49 2007/12/15 07:50:30 wurley Exp $
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
/**
|
2009-06-30 10:26:08 +00:00
|
|
|
* Takes the results of clicking "Save" in template_engine.php and determines which
|
2009-06-30 09:22:30 +00:00
|
|
|
* attributes need to be updated (ie, which ones actually changed). Then,
|
|
|
|
* we present a confirmation table to the user outlining the changes they
|
2009-06-30 09:29:51 +00:00
|
|
|
* are about to make. That form submits directly to update.php, which
|
2009-06-30 09:22:30 +00:00
|
|
|
* makes the change.
|
|
|
|
*
|
2009-06-30 09:29:51 +00:00
|
|
|
* @package phpLDAPadmin
|
|
|
|
*/
|
|
|
|
/**
|
2009-06-30 09:22:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
require './common.php';
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
if ($ldapserver->isReadOnly())
|
|
|
|
pla_error(_('You cannot perform updates while server is in read-only mode'));
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/***************/
|
|
|
|
/* get entry */
|
|
|
|
/***************/
|
|
|
|
|
|
|
|
$entry['dn']['string'] = get_request('dn');
|
|
|
|
$entry['dn']['encode'] = rawurlencode($entry['dn']['string']);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $entry['dn']['string'] || ! $ldapserver->dnExists($entry['dn']['string']))
|
|
|
|
pla_error(sprintf(_('The entry (%s) does not exist.'),htmlspecialchars($entry['dn']['string'])),null,-1,true);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$tree = get_cached_item($ldapserver->server_id,'tree');
|
|
|
|
$entry['ldap'] = null;
|
|
|
|
if ($tree) {
|
|
|
|
$entry['ldap'] = $tree->getEntry($entry['dn']['string']);
|
2009-06-30 10:26:08 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $entry['ldap'])
|
|
|
|
$tree->addEntry($entry['dn']['string']);
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$entry['ldap'] = $tree->getEntry($entry['dn']['string']);
|
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $entry['ldap'] || $entry['ldap']->isReadOnly())
|
|
|
|
pla_error(sprintf(_('The entry (%s) is in readonly mode.'),htmlspecialchars($entry['dn']['string'])),null,-1,true);
|
2009-06-30 09:40:37 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/***************/
|
|
|
|
/* old values */
|
|
|
|
/***************/
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$entry['values']['old'] = array();
|
|
|
|
foreach ($entry['ldap']->getAttributes() as $old_attr) {
|
|
|
|
$name = $old_attr->getName();
|
|
|
|
$entry['values']['old'][$name] = array();
|
2009-06-30 09:40:37 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
foreach ($old_attr->getValues() as $old_val) {
|
|
|
|
if (strlen($old_val) > 0)
|
|
|
|
$entry['values']['old'][$name][] = $old_val;
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/***************/
|
|
|
|
/* new values */
|
|
|
|
/***************/
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
eval('$reader = new '.$_SESSION['plaConfig']->GetValue('appearance','entry_reader').'($ldapserver);');
|
|
|
|
$entry['ldap']->accept($reader);
|
|
|
|
|
|
|
|
$entry['values']['new'] = array();
|
|
|
|
foreach ($entry['ldap']->getAttributes() as $new_attr) {
|
|
|
|
if ($new_attr->hasBeenModified()) {
|
|
|
|
$name = $new_attr->getName();
|
|
|
|
|
|
|
|
if (!isset($entry['values']['old'][$name]))
|
|
|
|
$entry['values']['old'][$name] = array();
|
|
|
|
|
|
|
|
$entry['values']['new'][$name] = array();
|
|
|
|
|
|
|
|
foreach ($new_attr->getValues() as $i => $new_val) {
|
|
|
|
if ($new_attr instanceof BinaryAttribute) {
|
|
|
|
$n = $new_attr->getFileName($i);
|
|
|
|
$p = $new_attr->getFilePath($i);
|
|
|
|
$new_val = md5("$n|$p");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($new_val) > 0)
|
|
|
|
$entry['values']['new'][$name][] = $new_val;
|
2009-06-30 10:26:08 +00:00
|
|
|
}
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
2009-06-30 10:40:33 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/************************/
|
|
|
|
/* objectClass deletion */
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
$oc_to_delete = array();
|
|
|
|
$attr_to_delete = array();
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
// if objectClass attribute is modified
|
|
|
|
if (isset($entry['values']['new']['objectClass'])) {
|
|
|
|
if (!isset($entry['values']['old']['objectClass'])) {
|
|
|
|
pla_error(_('An entry should have one structural objectClass.'));
|
|
|
|
}
|
|
|
|
// deleted objectClasses
|
|
|
|
foreach ($entry['values']['old']['objectClass'] as $oldOC) {
|
|
|
|
if (!in_array($oldOC, $entry['values']['new']['objectClass'])) {
|
|
|
|
$oc_to_delete[] = $oldOC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// search the attributes used by each deleted objecClass
|
|
|
|
// we must maybe delete these attributes
|
|
|
|
foreach ($oc_to_delete as $oc) {
|
|
|
|
$soc = $ldapserver->getSchemaObjectClass($oc);
|
|
|
|
if ($soc) {
|
|
|
|
$ocs = $ldapserver->SchemaObjectClasses();
|
|
|
|
$ma = $soc->getMustAttrs($ocs);
|
|
|
|
foreach ($ma as $a) {
|
|
|
|
if (!isset($attr_to_delete[$a->getName()])) {
|
|
|
|
$attr_to_delete[$a->getName()] = $a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ma = $soc->getMayAttrs($ocs);
|
|
|
|
foreach ($ma as $a) {
|
|
|
|
if (!isset($attr_to_delete[$a->getName()])) {
|
|
|
|
$attr_to_delete[$a->getName()] = $a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if an attribute is still used by an objectClass we don't delete,
|
|
|
|
// we don't delete this attribute
|
|
|
|
foreach ($attr_to_delete as $name => $ad) {
|
|
|
|
$found = false;
|
|
|
|
$at = $ldapserver->getSchemaAttribute($name);
|
|
|
|
foreach ($at->getUsedInObjectClasses() as $oc) {
|
|
|
|
if (in_array($oc, $entry['values']['new']['objectClass'])) {
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
foreach ($at->getRequiredByObjectClasses() as $oc) {
|
|
|
|
if (in_array($oc, $entry['values']['new']['objectClass'])) {
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($found) {
|
|
|
|
unset($attr_to_delete[$name]);
|
|
|
|
} else {
|
|
|
|
if (isset($entry['values']['old'][$name]) && (count($entry['values']['old'][$name]) > 0)) {
|
|
|
|
$found = true;
|
|
|
|
} else {
|
|
|
|
foreach ($entry['values']['new'] as $attr_name => $attr_values) {
|
|
|
|
if ($name == $attr_name) {
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
unset($attr_to_delete[$name]);
|
|
|
|
} else {
|
|
|
|
$entry['values']['new'][$name] = array();
|
|
|
|
$attr_to_delete[$name] = $name;
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 10:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/****************/
|
|
|
|
/* update array */
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
eval('$writer = new '.$_SESSION['plaConfig']->GetValue('appearance','entry_writer').'($ldapserver);');
|
|
|
|
$writer->draw('Title',$entry['ldap']);
|
|
|
|
$writer->draw('Subtitle',$entry['ldap']);
|
|
|
|
|
|
|
|
echo "\n\n";
|
2009-06-30 10:26:08 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
run_hook('pre_update_array_processing',
|
|
|
|
array('server_id'=>$ldapserver->server_id,'dn'=>$entry['dn']['string'],'old_values'=>$entry['values']['old'],'new_values'=>$entry['values']['new']));
|
2009-06-30 10:26:08 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
/***************/
|
|
|
|
/* confirm */
|
|
|
|
/***************/
|
|
|
|
|
|
|
|
if (count($entry['values']['new']) > 0) {
|
2009-06-30 10:26:08 +00:00
|
|
|
echo '<br />';
|
|
|
|
echo '<center>';
|
|
|
|
echo _('Do you want to make these changes?');
|
|
|
|
echo '<br /><br />';
|
|
|
|
|
|
|
|
# <!-- Commit button and acompanying form -->
|
|
|
|
echo "\n\n";
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '<form action="cmd.php" method="post">';
|
|
|
|
echo '<input type="hidden" name="cmd" value="update" />';
|
2009-06-30 10:26:08 +00:00
|
|
|
echo "\n";
|
|
|
|
echo '<table class="confirm">';
|
|
|
|
echo "\n";
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
printf('<tr class="heading"><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
|
2009-06-30 10:26:08 +00:00
|
|
|
_('Attribute'),_('Old Value'),_('New Value'),_('Skip'));
|
|
|
|
|
|
|
|
echo "\n\n";
|
|
|
|
$counter = 0;
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$friendly_attrs = $_SESSION['plaConfig']->friendly_attrs;
|
|
|
|
foreach ($entry['values']['new'] as $attr => $new_val) {
|
2009-06-30 09:29:51 +00:00
|
|
|
$counter++;
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
printf('<tr class="%s">',$counter%2 ? 'even' : 'odd');
|
2009-06-30 10:46:00 +00:00
|
|
|
echo '<td><b>';
|
|
|
|
$attr_display = isset($friendly_attrs[strtolower($attr)]) ? $friendly_attrs[strtolower($attr)] : $attr;
|
|
|
|
if (strcmp($attr,$attr_display) && $_SESSION['plaConfig']->isCommandAvailable('schema')) {
|
|
|
|
printf('<acronym title="Alias for %s">%s</acronym>',$attr,htmlspecialchars($attr_display));
|
|
|
|
} else {
|
|
|
|
echo htmlspecialchars($attr_display);
|
|
|
|
}
|
|
|
|
echo '</b></td>';
|
2009-06-30 10:41:18 +00:00
|
|
|
echo '<td><span style="white-space: nowrap;">';
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
if (strcasecmp($attr,'userPassword') == 0) {
|
2009-06-30 10:46:00 +00:00
|
|
|
foreach ($entry['values']['old'][$attr] as $key => $value) {
|
|
|
|
if (obfuscate_password_display(get_enc_type($entry['values']['old'][$attr][$key])))
|
|
|
|
echo preg_replace('/./','*',$entry['values']['old'][$attr][$key]).'<br />';
|
2009-06-30 10:26:08 +00:00
|
|
|
else
|
2009-06-30 10:46:00 +00:00
|
|
|
echo nl2br(htmlspecialchars($entry['values']['old'][$attr][$key])).'<br />';
|
2009-06-30 10:26:08 +00:00
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
} elseif (is_array($entry['values']['old'][$attr]))
|
|
|
|
foreach ($entry['values']['old'][$attr] as $v)
|
2009-06-30 10:40:03 +00:00
|
|
|
echo nl2br(htmlspecialchars($v)).'<br />';
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
else
|
2009-06-30 10:46:00 +00:00
|
|
|
echo nl2br(htmlspecialchars($entry['values']['old'][$attr])).'<br />';
|
2009-06-30 10:26:08 +00:00
|
|
|
|
2009-06-30 10:41:18 +00:00
|
|
|
echo '</span></td>';
|
|
|
|
echo '<td><span style="white-space: nowrap;">';
|
2009-06-30 10:26:08 +00:00
|
|
|
|
|
|
|
# Is this a multi-valued attribute?
|
|
|
|
if (is_array($new_val)) {
|
|
|
|
if (strcasecmp($attr,'userPassword') == 0) {
|
2009-06-30 10:46:00 +00:00
|
|
|
foreach ($entry['values']['new'][$attr] as $key => $value) {
|
2009-06-30 10:26:08 +00:00
|
|
|
if (isset($new_val[$key])) {
|
|
|
|
if (obfuscate_password_display(get_enc_type($new_val[$key])))
|
|
|
|
echo preg_replace('/./','*',$new_val[$key]).'<br />';
|
|
|
|
else
|
2009-06-30 10:40:03 +00:00
|
|
|
echo htmlspecialchars($new_val[$key]).'<br />';
|
2009-06-30 10:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
} else {
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
foreach ($new_val as $i => $v) {
|
2009-06-30 10:40:03 +00:00
|
|
|
echo nl2br(htmlspecialchars($v)).'<br />';
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
if (! $new_val) {
|
2009-06-30 10:26:08 +00:00
|
|
|
printf('<span style="color: red">%s</span>',_('[attribute deleted]'));
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
} elseif ($new_val == '')
|
2009-06-30 10:26:08 +00:00
|
|
|
printf('<span style="color: red">%s</span>',_('[attribute deleted]'));
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:41:18 +00:00
|
|
|
echo '</span></td>';
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$input_disabled = '';
|
|
|
|
if (in_array($attr, $attr_to_delete)) $input_disabled = 'disabled="disabled"';
|
|
|
|
$input_onclick = '';
|
|
|
|
if ($attr == 'objectClass' && (count($attr_to_delete) > 0)) {
|
|
|
|
$input_onclick = 'onclick="if (this.checked) {';
|
|
|
|
foreach ($attr_to_delete as $ad_name) {
|
|
|
|
$input_onclick .= "document.forms[0].elements['skip_array[$ad_name]'].disabled = false;";
|
|
|
|
$input_onclick .= "document.forms[0].elements['skip_array[$ad_name]'].checked = true;";
|
|
|
|
}
|
|
|
|
$input_onclick .= '} else {';
|
|
|
|
foreach ($attr_to_delete as $ad_name) {
|
|
|
|
$input_onclick .= "document.forms[0].elements['skip_array[$ad_name]'].checked = false;";
|
|
|
|
$input_onclick .= "document.forms[0].elements['skip_array[$ad_name]'].disabled = true;";
|
|
|
|
}
|
|
|
|
$input_onclick .= '}"';
|
|
|
|
}
|
|
|
|
printf('<td><input name="skip_array[%s]" type="checkbox" %s %s/></td>',htmlspecialchars($attr),$input_disabled,$input_onclick);
|
2009-06-30 10:26:08 +00:00
|
|
|
echo '</tr>'."\n\n";
|
|
|
|
}
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
echo '</table><table class="form">';
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td>';
|
|
|
|
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
|
2009-06-30 10:46:00 +00:00
|
|
|
printf('<input type="hidden" name="dn" value="%s" />',$entry['dn']['string']);
|
|
|
|
|
|
|
|
foreach ($entry['values']['new'] as $attr => $val) {
|
|
|
|
if (count($val) > 0) {
|
|
|
|
if (is_array($val)) {
|
|
|
|
foreach($val as $i => $v)
|
|
|
|
printf('<input type="hidden" name="update_array[%s][%s]" value="%s" />',
|
|
|
|
htmlspecialchars($attr),$i,htmlspecialchars($v));
|
|
|
|
} else {
|
|
|
|
printf('<input type="hidden" name="update_array[%s]" value="%s" />',
|
|
|
|
htmlspecialchars($attr),htmlspecialchars($val));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf('<input type="hidden" name="update_array[%s]" value="" />',
|
|
|
|
htmlspecialchars($attr));
|
|
|
|
}
|
2009-06-30 10:26:08 +00:00
|
|
|
}
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
printf('<input type="submit" value="%s" class="happy" />',_('Commit'));
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td>';
|
|
|
|
printf('<input type="submit" name="cancel" value="%s" class="scary" />',_('Cancel'));
|
|
|
|
echo '</td>';
|
|
|
|
echo '</tr>';
|
|
|
|
echo '</table>';
|
|
|
|
echo '</form>';
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
if (count($attr_to_delete) > 0) {
|
|
|
|
echo '<table class="form"><tr><td><br/>';
|
|
|
|
echo _('The deletion of objectClass(es)');
|
|
|
|
echo _(':');
|
|
|
|
echo ' <b>';
|
|
|
|
echo implode('</b>, <b>', $oc_to_delete);
|
|
|
|
echo '</b><br/>';
|
|
|
|
echo _('will delete the attribute(s)');
|
|
|
|
echo _(':');
|
|
|
|
echo ' <b>';
|
|
|
|
$i = 0;
|
|
|
|
foreach ($attr_to_delete as $attr) {
|
|
|
|
if ($i++ != 0) echo '</b>, <b>';
|
|
|
|
$attr_display = isset($friendly_attrs[strtolower($attr)]) ? $friendly_attrs[strtolower($attr)] : $attr;
|
|
|
|
if (strcmp($attr,$attr_display) && $_SESSION['plaConfig']->isCommandAvailable('schema')) {
|
|
|
|
printf('<acronym title="Alias for %s">%s</acronym>',$attr,htmlspecialchars($attr_display));
|
|
|
|
} else {
|
|
|
|
echo htmlspecialchars($attr_display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</b></td></tr></table>';
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
echo '</center>';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
echo '<center>';
|
|
|
|
echo _('You made no changes');
|
2009-06-30 10:46:00 +00:00
|
|
|
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',
|
|
|
|
$ldapserver->server_id,$entry['dn']['encode']);
|
|
|
|
|
|
|
|
printf(' <a href="%s">%s</a>.',htmlspecialchars($href),_('Go back'));
|
2009-06-30 10:26:08 +00:00
|
|
|
echo '</center>';
|
|
|
|
}
|
|
|
|
?>
|