phpldapadmin/htdocs/update.php

133 lines
4.2 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 09:40:37 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/update.php,v 1.24.2.1 2005/10/09 09:07:21 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
* Updates or deletes a value from a specified attribute for a specified dn.
*
2009-06-30 08:05:37 +00:00
* Variables that come in on the query string:
* - dn (rawurlencoded)
* - server_id
2009-06-30 08:07:14 +00:00
* - update_array (an array in the form expected by PHP's ldap_modify, except for deletions)
2009-06-30 08:05:37 +00:00
* (will never be empty: update_confirm.php ensures that)
2009-06-30 08:07:14 +00:00
*
* Attribute deletions:
2009-06-30 09:29:51 +00:00
* To specify that an attribute is to be deleted (whether multi- or single-valued),
2009-06-30 08:07:14 +00:00
* enter that attribute in the update array like this: attr => ''. For example, to
* delete the 'sn' attribute from an entry, the update array would look like this:
* Array (
* sn => ''
2009-06-30 09:29:51 +00:00
* )
*
* On success, redirect to edit.php. On failure, echo an error.
2009-06-30 08:07:14 +00:00
*
2009-06-30 09:29:51 +00:00
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:29:51 +00:00
require './common.php';
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
if ($ldapserver->isReadOnly())
pla_error($lang['no_updates_in_read_only_mode']);
if (! $ldapserver->haveAuthInfo())
pla_error($lang['not_enough_login_info']);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$dn = $_POST['dn'];
$encoded_dn = rawurlencode($dn);
$update_array = isset($_POST['update_array']) ? $_POST['update_array'] : array();
is_array($update_array) or pla_error($lang['update_array_malformed']);
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$failed_attrs = array();
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
run_hook ('pre_update',array ('server_id' => $ldapserver->server_id,
'dn' => $dn,'update_array' => $update_array));
// check for delete attributes (indicated by the attribute entry appearing like this: attr => ''
foreach ($update_array as $attr => $val)
if (! is_array($val))
if ($val == '')
2009-06-30 08:05:37 +00:00
$update_array[ $attr ] = array();
2009-06-30 08:07:14 +00:00
else
$update_array[ $attr ] = $val;
else
2009-06-30 09:29:51 +00:00
foreach ($val as $i => $v)
2009-06-30 08:07:14 +00:00
$update_array[ $attr ][ $i ] = $v;
2009-06-30 09:29:51 +00:00
// Call the custom callback for each attribute modification
2009-06-30 08:09:20 +00:00
// and verify that it should be modified.
2009-06-30 09:29:51 +00:00
foreach ($update_array as $attr_name => $val) {
2009-06-30 09:22:30 +00:00
// Check to see if this is a unique Attribute
2009-06-30 09:29:51 +00:00
if ($badattr = checkUniqueAttr($ldapserver,$dn,$attr_name,$val)) {
$search_href = sprintf('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',$ldapserver->server_id,$attr_name,$badattr);
pla_error(sprintf($lang['unique_attr_failed'],$attr_name,$badattr,$dn,$search_href));
}
if (true !== run_hook ('pre_attr_modify',array ('server_id' => $ldapserver->server_id,
'dn' => $dn,'attr_name' => $attr_name,'new_value' => $val))) {
unset($update_array[ $attr_name ]);
$failed_attrs[$attr_name] = $val;
2009-06-30 09:22:30 +00:00
}
2009-06-30 09:29:51 +00:00
elseif (is_attr_read_only($ldapserver,$attr))
pla_error(sprintf($lang['attr_is_read_only'],htmlspecialchars($attr_name)));
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 09:40:37 +00:00
$res = $ldapserver->modify($dn,$update_array);
2009-06-30 09:29:51 +00:00
if ($res) {
2009-06-30 08:09:20 +00:00
// Fire the post modification event to the user's custom
// callback function.
2009-06-30 09:29:51 +00:00
foreach ($update_array as $attr_name => $val) {
run_hook ('post_attr_modify',array('server_id' => $ldapserver->server_id,
2009-06-30 09:40:37 +00:00
'dn' => $dn,'attr_name' => $attr_name,'new_value' => $val));
2009-06-30 08:09:20 +00:00
// Was this a user's password modification who is currently
// logged in? If so, they need to logout and log back in
// with the new password.
2009-06-30 09:29:51 +00:00
if (0 === strcasecmp($attr_name,'userPassword') &&
in_array($ldapserver->auth_type,array('cookie','session')) &&
0 === pla_compare_dns(get_logged_in_dn($ldapserver),$dn)) {
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
unset_login_dn($ldapserver);
unset_lastactivity($ldapserver);
include './header.php';
2009-06-30 08:09:20 +00:00
?>
<script language="javascript">
parent.left_frame.location.reload();
</script>
<br />
<center>
2009-06-30 09:22:30 +00:00
<b><?php echo $lang['modification_successful']; ?></b><br />
2009-06-30 08:09:20 +00:00
<br />
2009-06-30 09:22:30 +00:00
<?php echo $lang['change_password_new_login']; ?> &nbsp;
2009-06-30 09:29:51 +00:00
<a href="login_form.php?server_id=<?php echo $ldapserver->server_id; ?>"><?php echo $lang['login_link']; ?></a>
2009-06-30 08:09:20 +00:00
</center>
</body>
</html>
<?php
exit;
}
}
2009-06-30 09:29:51 +00:00
run_hook ('post_update',array ('server_id' => $ldapserver->server_id,'dn' => $dn,'update_array' => $update_array));
$redirect_url = sprintf("edit.php?server_id=%s&dn=%s",$ldapserver->server_id,$encoded_dn);
foreach ($update_array as $attr => $junk)
2009-06-30 08:05:37 +00:00
$redirect_url .= "&modified_attrs[]=$attr";
2009-06-30 09:29:51 +00:00
foreach ($failed_attrs as $attr => $junk)
$redirect_url .= "&failed_attrs[]=$attr";
header("Location: $redirect_url");
} else {
2009-06-30 09:40:37 +00:00
pla_error($lang['could_not_perform_ldap_modify'],
$ldapserver->error(),$ldapserver->errno());
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
?>