phpldapadmin/add_value.php

76 lines
2.3 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/add_value.php,v 1.17 2005/03/12 10:42:27 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
/**
2009-06-30 08:05:37 +00:00
* Adds a value to an attribute for a given dn.
2009-06-30 09:24:29 +00:00
*
2009-06-30 08:05:37 +00:00
* Variables that come in as POST vars:
* - dn (rawurlencoded)
2009-06-30 09:24:29 +00:00
* - attr (rawurlencoded) the attribute to which we are adding a value
2009-06-30 08:05:37 +00:00
* - server_id
* - new_value (form element)
2009-06-30 09:24:29 +00:00
* - binary
*
* On success, redirect to the edit_dn page. On failure, echo an error.
2009-06-30 08:05:37 +00:00
*
2009-06-30 09:24:29 +00:00
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:22:30 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
$server_id = (isset($_POST['server_id']) ? $_POST['server_id'] : '');
$ldapserver = new LDAPServer($server_id);
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:07:14 +00:00
$attr = $_POST['attr'];
$new_value = $_POST['new_value'];
2009-06-30 09:24:29 +00:00
$dn = rawurldecode( $_POST['dn'] );
2009-06-30 08:07:14 +00:00
$is_binary_val = isset( $_POST['binary'] ) ? true : false;
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
$encoded_dn = rawurlencode( $dn );
$encoded_attr = rawurlencode( $attr );
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
if( is_attr_read_only( $ldapserver, $attr ) )
pla_error(sprintf($lang['attr_is_read_only'],htmlspecialchars( $attr )));
2009-06-30 08:07:14 +00:00
2009-06-30 09:24:29 +00:00
// special case for binary attributes:
2009-06-30 08:05:37 +00:00
// we must go read the data from the file.
2009-06-30 09:24:29 +00:00
if( $is_binary_val ) {
2009-06-30 08:07:14 +00:00
$file = $_FILES['new_value']['tmp_name'];
2009-06-30 09:24:29 +00:00
2009-06-30 08:05:37 +00:00
$f = fopen( $file, 'r' );
2009-06-30 08:07:14 +00:00
$binary_value = fread( $f, filesize( $file ) );
2009-06-30 08:05:37 +00:00
fclose( $f );
2009-06-30 09:24:29 +00:00
2009-06-30 08:07:14 +00:00
$new_value = $binary_value;
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:24:29 +00:00
$new_entry = array( $attr => $new_value );
2009-06-30 09:22:30 +00:00
// Check to see if this is a unique Attribute
2009-06-30 09:24:29 +00:00
if( $badattr = checkUniqueAttr( $ldapserver, $dn, $attr, $new_entry ) ) {
$search_href = sprintf('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',$server_id,$attr,$badattr);
pla_error(sprintf( $lang['unique_attr_failed'],$attr,$badattr,$dn,$search_href ) );
2009-06-30 09:22:30 +00:00
}
// Call the custom callback for each attribute modification
// and verify that it should be modified.
2009-06-30 09:24:29 +00:00
if( run_hook ( 'pre_attr_add', array ( 'server_id' => $server_id, 'dn' => $dn, 'attr_name' => $attr,
'new_value' => $new_entry ) ) ) {
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
$add_result = @ldap_mod_add( $ldapserver->connect(), $dn, $new_entry );
2009-06-30 08:05:37 +00:00
if( ! $add_result )
2009-06-30 09:24:29 +00:00
pla_error( $lang['could_not_perform_ldap_mod_add'], ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 08:09:20 +00:00
header( "Location: edit.php?server_id=$server_id&dn=$encoded_dn&modified_attrs[]=$encoded_attr" );
2009-06-30 08:05:37 +00:00
?>