phpldapadmin/add_value.php

60 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2009-06-30 08:12:47 +00:00
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/add_value.php,v 1.10 2004/03/19 20:13:08 i18phpldapadmin Exp $
2009-06-30 08:05:37 +00:00
/*
* add_value.php
* Adds a value to an attribute for a given dn.
* Variables that come in as POST vars:
* - dn (rawurlencoded)
* - attr (rawurlencoded) the attribute to which we are adding a value
* - server_id
* - new_value (form element)
2009-06-30 08:07:14 +00:00
* - binary
2009-06-30 08:05:37 +00:00
*
* On success, redirect to the edit_dn page.
* On failure, echo an error.
*/
2009-06-30 08:07:14 +00:00
require 'common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 08:07:14 +00:00
$dn = rawurldecode( $_POST['dn'] );
2009-06-30 08:05:37 +00:00
$encoded_dn = rawurlencode( $dn );
2009-06-30 08:07:14 +00:00
$attr = $_POST['attr'];
2009-06-30 08:05:37 +00:00
$encoded_attr = rawurlencode( $attr );
$server_id = $_POST['server_id'];
2009-06-30 08:07:14 +00:00
$new_value = $_POST['new_value'];
$is_binary_val = isset( $_POST['binary'] ) ? true : false;
2009-06-30 08:05:37 +00:00
2009-06-30 08:07:14 +00:00
if( is_server_read_only( $server_id ) )
pla_error( $lang['no_updates_in_read_only_mode'] );
2009-06-30 08:12:47 +00:00
if( is_attr_read_only( $attr ) )
pla_error( "The attribute '" . htmlspecialchars( $attr ) . "' is flagged as read only in the phpLDAPadmin configuration." );
2009-06-30 08:05:37 +00:00
2009-06-30 08:07:14 +00:00
check_server_id( $server_id ) or pla_error( $lang['bad_server_id'] );
have_auth_info( $server_id ) or pla_error( $lang['not_enough_login_info'] );
2009-06-30 08:05:37 +00:00
2009-06-30 08:07:14 +00:00
$ds = pla_ldap_connect( $server_id ) or pla_error( $lang['could_not_connect'] );
// 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 08:07:14 +00:00
if( $is_binary_val )
2009-06-30 08:05:37 +00:00
{
2009-06-30 08:07:14 +00:00
$file = $_FILES['new_value']['tmp_name'];
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 08:07:14 +00:00
$new_value = $binary_value;
2009-06-30 08:05:37 +00:00
}
2009-06-30 08:12:47 +00:00
$new_entry = array( $attr => $new_value );
2009-06-30 08:05:37 +00:00
$add_result = @ldap_mod_add( $ds, $dn, $new_entry );
if( ! $add_result )
2009-06-30 08:07:14 +00:00
pla_error( $lang['could_not_perform_ldap_mod_add'], ldap_error( $ds ), ldap_errno( $ds ) );
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
?>