2009-06-30 08:09:20 +00:00
|
|
|
<?php
|
2009-06-30 09:24:29 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/create.php,v 1.32 2005/03/05 06:27:06 wurley Exp $
|
2009-06-30 09:22:30 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
/**
|
2009-06-30 08:05:37 +00:00
|
|
|
* Creates a new object.
|
|
|
|
*
|
|
|
|
* Variables that come in as POST vars:
|
|
|
|
* - new_dn
|
|
|
|
* - attrs (an array of attributes)
|
|
|
|
* - vals (an array of values for the above attrs)
|
|
|
|
* - required_attrs (an array with indices being the attributes,
|
|
|
|
* and the values being their respective values)
|
|
|
|
* - object_classes (rawurlencoded, and serialized array of objectClasses)
|
|
|
|
* - server_id
|
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 realpath( './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:09:20 +00:00
|
|
|
$new_dn = isset( $_POST['new_dn'] ) ? $_POST['new_dn'] : null;
|
2009-06-30 09:22:30 +00:00
|
|
|
$vals = isset( $_POST['vals'] ) ? $_POST['vals'] : array();
|
|
|
|
$attrs = isset( $_POST['attrs'] ) ? $_POST['attrs'] : array();
|
2009-06-30 08:07:14 +00:00
|
|
|
$required_attrs = isset( $_POST['required_attrs'] ) ? $_POST['required_attrs'] : false;
|
2009-06-30 08:05:37 +00:00
|
|
|
$object_classes = unserialize( rawurldecode( $_POST['object_classes'] ) );
|
2009-06-30 09:22:30 +00:00
|
|
|
$redirect = isset( $_POST['redirect'] ) ? $_POST['redirect'] : false;
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
$encoded_dn = rawurlencode( $new_dn );
|
|
|
|
$container = get_container( $new_dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
|
|
|
|
// build the new entry
|
|
|
|
$new_entry = array();
|
2009-06-30 08:09:20 +00:00
|
|
|
if( isset( $required_attrs ) && is_array( $required_attrs ) ) {
|
|
|
|
foreach( $required_attrs as $attr => $val ) {
|
2009-06-30 08:05:37 +00:00
|
|
|
if( $val == '' )
|
2009-06-30 08:09:20 +00:00
|
|
|
pla_error( sprintf( $lang['create_required_attribute'], htmlspecialchars( $attr ) ) );
|
2009-06-30 09:24:29 +00:00
|
|
|
$new_entry[ $attr ][] = $val;
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
if( isset( $attrs ) && is_array( $attrs ) ) {
|
|
|
|
foreach( $attrs as $i => $attr ) {
|
2009-06-30 09:24:29 +00:00
|
|
|
if( is_attr_binary( $ldapserver, $attr ) ) {
|
2009-06-30 09:22:30 +00:00
|
|
|
if( isset( $_FILES['vals']['name'][$i] ) && $_FILES['vals']['name'][$i] != '' ) {
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:07:14 +00:00
|
|
|
// read in the data from the file
|
|
|
|
$file = $_FILES['vals']['tmp_name'][$i];
|
|
|
|
$f = fopen( $file, 'r' );
|
|
|
|
$binary_data = fread( $f, filesize( $file ) );
|
|
|
|
fclose( $f );
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:07:14 +00:00
|
|
|
$val = $binary_data;
|
|
|
|
$new_entry[ $attr ][] = $val;
|
|
|
|
}
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:07:14 +00:00
|
|
|
} else {
|
2009-06-30 09:24:29 +00:00
|
|
|
$val = isset( $vals[$i] ) ? $vals[$i] : '';
|
|
|
|
|
2009-06-30 08:10:17 +00:00
|
|
|
if( '' !== trim($val) )
|
2009-06-30 09:24:29 +00:00
|
|
|
$new_entry[ $attr ][] = $val;
|
2009-06-30 08:07:14 +00:00
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_entry['objectClass'] = $object_classes;
|
|
|
|
if( ! in_array( 'top', $new_entry['objectClass'] ) )
|
|
|
|
$new_entry['objectClass'][] = 'top';
|
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
foreach( $new_entry as $attr => $vals ) {
|
|
|
|
|
|
|
|
// Check to see if this is a unique Attribute
|
2009-06-30 09:24:29 +00:00
|
|
|
if( $badattr = checkUniqueAttr( $ldapserver, $new_dn, $attr, $vals ) ) {
|
|
|
|
$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,$new_dn,$search_href ) );
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
if( ! is_attr_binary( $ldapserver, $attr ) )
|
2009-06-30 08:09:20 +00:00
|
|
|
if( is_array( $vals ) )
|
|
|
|
foreach( $vals as $i => $v )
|
2009-06-30 09:24:29 +00:00
|
|
|
$new_entry[ $attr ][ $i ] = $v;
|
|
|
|
|
|
|
|
else
|
|
|
|
$new_entry[ $attr ] = $vals;
|
2009-06-30 09:22:30 +00:00
|
|
|
}
|
2009-06-30 08:07:14 +00:00
|
|
|
|
|
|
|
//echo "<pre>"; var_dump( $new_dn );print_r( $new_entry ); echo "</pre>";
|
|
|
|
|
2009-06-30 08:09:20 +00:00
|
|
|
// Check the user-defined custom call back first
|
2009-06-30 09:24:29 +00:00
|
|
|
if( true === run_hook ( 'pre_entry_create', array ( 'server_id' => $server_id,'dn' => $new_dn,'attrs' => $new_entry ) ) )
|
|
|
|
$add_result = @ldap_add( $ldapserver->connect(), $new_dn, $new_entry );
|
|
|
|
|
|
|
|
else {
|
|
|
|
pla_error( $lang['create_could_not_add'] );
|
2009-06-30 08:09:20 +00:00
|
|
|
exit;
|
2009-06-30 09:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $add_result ) {
|
|
|
|
run_hook ( 'post_entry_create', array ( 'server_id' => $server_id, 'dn' => $new_dn, 'attrs' => $new_entry ) );
|
|
|
|
|
|
|
|
if( $redirect )
|
|
|
|
$redirect_url = $redirect;
|
|
|
|
|
|
|
|
else
|
|
|
|
$redirect_url = "edit.php?server_id=$server_id&dn=" . rawurlencode( $new_dn );
|
|
|
|
|
|
|
|
if( array_key_exists( 'tree', $_SESSION ) ) {
|
2009-06-30 08:05:37 +00:00
|
|
|
$tree = $_SESSION['tree'];
|
|
|
|
$tree_icons = $_SESSION['tree_icons'];
|
|
|
|
|
|
|
|
if( isset( $tree[$server_id][$container] ) ) {
|
|
|
|
$tree[$server_id][$container][] = $new_dn;
|
2009-06-30 08:07:14 +00:00
|
|
|
sort( $tree[$server_id][$container] );
|
2009-06-30 09:24:29 +00:00
|
|
|
$tree_icons[$server_id][$new_dn] = get_icon( $ldapserver, $new_dn );
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION['tree'] = $tree;
|
|
|
|
$_SESSION['tree_icons'] = $tree_icons;
|
|
|
|
session_write_close();
|
|
|
|
}
|
|
|
|
?>
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:05:37 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
<?php if( isset( $tree[$server_id][$container] ) || $new_dn == $servers[$server_id]['base'] ) { ?>
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
<!-- refresh the tree view (with the new DN renamed)
|
|
|
|
and redirect to the edit_dn page -->
|
|
|
|
<script language="javascript">
|
|
|
|
parent.left_frame.location.reload();
|
|
|
|
location.href='<?php echo $redirect_url; ?>';
|
|
|
|
</script>
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
<?php } ?>
|
|
|
|
|
|
|
|
<meta http-equiv="refresh" content="0; url=<?php echo $redirect_url; ?>" />
|
2009-06-30 08:05:37 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 09:22:30 +00:00
|
|
|
<?php echo $lang['redirecting'] ?> <a href="<?php echo $redirect_url; ?>"><?php echo $lang['here']?></a>.
|
2009-06-30 09:24:29 +00:00
|
|
|
|
2009-06-30 08:05:37 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
2009-06-30 09:24:29 +00:00
|
|
|
<?php } else {
|
|
|
|
pla_error( $lang['create_could_not_add'], ldap_error( $ldapserver->connect() ), ldap_errno( $ldapserver->connect() ) );
|
|
|
|
}
|
2009-06-30 08:05:37 +00:00
|
|
|
?>
|