phpldapadmin/tree.php

311 lines
10 KiB
PHP
Raw Permalink Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tree.php,v 1.84 2005/03/25 13:04:34 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
* This script displays the LDAP tree for all the servers that you have
2009-06-30 09:24:29 +00:00
* in config.php.
*
* We read the session variable 'tree' to know which dns are expanded or collapsed.
* No query string parameters are expected, however, you can use a '#' offset to
* scroll to a given dn. The syntax is tree.php#<server_id>_<rawurlencoded dn>, so
* if I wanted to scroll to dc=example,dc=com for server 3, the URL would be:
*
2009-06-30 08:05:37 +00:00
* tree.php#3_dc%3Dexample%2Cdc%3Dcom
2009-06-30 09:24:29 +00:00
*
* @package phpLDAPadmin
* @author The phpLDAPadmin development team
*/
/**
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
global $servers;
2009-06-30 08:05:37 +00:00
// no expire header stuff
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
2009-06-30 09:22:30 +00:00
// This allows us to display large sub-trees without running out of time.
@set_time_limit( 0 );
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
// do we not have a tree and tree icons yet? Build a new ones.
initialize_session_tree();
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
// get the tree and tree icons.
2009-06-30 08:05:37 +00:00
$tree = $_SESSION['tree'];
$tree_icons = $_SESSION['tree_icons'];
2009-06-30 09:24:29 +00:00
// Test to see if any have timedout.
// Initialize array of recently timed out servers
$recently_timed_out_servers = array();
// Set a default META REFRESH value in sec. before determining it
$meta_refresh_variable = ( session_cache_expire()-1 )*60;
foreach( $servers as $server_id => $server_tree ) {
// $ldapserver wont be set, so we'll create it.
$ldapserver = new LDAPServer($server_id,true);
# Test to see if we should log out the user due to the timeout.
if ( $ldapserver->haveAuthInfo() ) {
// If time out value has been reached:
// - log out user
// - put $server_id in array of recently timed out servers
if ( session_timed_out( $ldapserver ) )
array_push($recently_timed_out_servers, $server_id);
}
// Now recalc the new meta refresh.
if ( $ldapserver->haveAuthInfo() && isset($servers[ $server_id ][ 'session_timeout' ])) {
// if the timeout value is less than the previous $meta_refresh_variable value
// set $meta_refresh_variable to $servers[ $server_id ][ 'session_timeout' ]
if ( ($servers[ $server_id ][ 'session_timeout' ]*60) < $meta_refresh_variable )
$meta_refresh_variable = $servers[ $server_id ][ 'session_timeout' ]*60;
}
}
2009-06-30 09:22:30 +00:00
// Close the session for faster page loading (we're done with session data anyway).
2009-06-30 09:24:29 +00:00
// Unfortunately, now that we dont show a plus '+' for leafs in a tree, we need to keep
// the session open, so that if we create an entry, it'll cause the refresh of the tree view.
// Hope this doesnt affect performance...?
// pla_session_close();
2009-06-30 09:22:30 +00:00
include './header.php';
?>
2009-06-30 08:05:37 +00:00
<body>
2009-06-30 09:22:30 +00:00
<?php
2009-06-30 08:07:14 +00:00
$bug_href = get_href( 'add_bug' );
$feature_href = get_href( 'add_rfe' );
2009-06-30 09:22:30 +00:00
$donate_href = get_href( 'donate' );
$help_href = get_href( 'help' );
2009-06-30 08:05:37 +00:00
?>
2009-06-30 08:07:14 +00:00
<h3 class="subtitle" style="margin:0px">phpLDAPadmin - <?php echo pla_version(); ?></h3>
2009-06-30 09:22:30 +00:00
<!-- Links at the top of the tree viewer -->
2009-06-30 09:24:29 +00:00
<table class="edit_dn_menu" width=100%>
2009-06-30 08:05:37 +00:00
<tr>
2009-06-30 09:24:29 +00:00
<td><img src="images/home.png" alt="<?php echo $lang['home']; ?>" /></td>
<td width=50%><nobr><a href="welcome.php" target="right_frame"><?php echo $lang['home']; ?></a></nobr></td>
<td><img src="images/trash.png" alt="<?php echo $lang['purge_cache']; ?>" /></td>
<td width=50%><nobr><a href="purge_cache.php" target="right_frame" title="<?php echo $lang['purge_cache_tooltip']; ?>"><?php echo $lang['purge_cache']; ?></a></nobr></td>
</tr>
<tr>
<?php if ( ! hide_configuration_management() ) { ?>
2009-06-30 09:22:30 +00:00
<td><img src="images/light.png" alt="<?php echo $lang['light']; ?>" /></td>
2009-06-30 09:24:29 +00:00
<td width=50%><nobr><a href="<?php echo $feature_href; ?>" target="new"><?php echo $lang['request_new_feature']; ?></a></nobr></td>
2009-06-30 09:22:30 +00:00
<td><img src="images/bug.png" alt="<?php echo $lang['bug']; ?>" /></td>
2009-06-30 09:24:29 +00:00
<td width=50%><nobr><a href="<?php echo $bug_href; ?>" target="new"><?php echo $lang['report_bug']; ?></a></nobr></td>
2009-06-30 09:22:30 +00:00
</tr>
2009-06-30 09:24:29 +00:00
<tr>
2009-06-30 09:22:30 +00:00
<td><img src="images/smile.png" alt="<?php echo $lang['donate']; ?>" /></td>
2009-06-30 09:24:29 +00:00
<td width=50%><nobr><a href="<?php echo $donate_href; ?>" target="right_frame"><?php echo $lang['donate']; ?></a></nobr></td>
<?php } ?>
2009-06-30 09:22:30 +00:00
<td><img src="images/help.png" alt="<?php echo $lang['help']; ?>" /></td>
<td><nobr><a href="help.php" target="right_frame"><?php echo $lang['help']; ?></a></nobr></td>
2009-06-30 08:05:37 +00:00
</tr>
</table>
2009-06-30 08:07:14 +00:00
2009-06-30 08:05:37 +00:00
<table class="tree" cellspacing="0">
2009-06-30 09:24:29 +00:00
<?php
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
// We want the std tree function as a fallback
require_once( 'tree_functions.php' );
// For each of the configured servers
2009-06-30 09:24:29 +00:00
foreach( $servers as $server_id => $server_tree ) {
// $ldapserver wont be set, so we'll create it.
$ldapserver = new LDAPServer($server_id);
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
if ( $ldapserver->isVisible() )
2009-06-30 09:22:30 +00:00
{
$filename = get_custom_file( $server_id, 'tree_functions.php' );
require_once( $filename );
call_custom_function( $server_id, 'draw_server_tree' );
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:24:29 +00:00
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:24:29 +00:00
// Case where user not logged into any server
if ( $meta_refresh_variable == 0 )
$meta_refresh_variable = ( session_cache_expire()-1 )*60;
2009-06-30 08:05:37 +00:00
?>
2009-06-30 09:24:29 +00:00
<META HTTP-EQUIV="REFRESH" CONTENT="<?php echo $meta_refresh_variable?>">
2009-06-30 08:05:37 +00:00
</table>
2009-06-30 09:24:29 +00:00
<?php
// echo "<pre>"; print_r( $tree );
2009-06-30 08:07:14 +00:00
?>
2009-06-30 08:05:37 +00:00
</body>
</html>
2009-06-30 09:22:30 +00:00
<?php
2009-06-30 08:05:37 +00:00
exit;
/**
* Recursively descend on the given dn and draw the tree in html
2009-06-30 09:24:29 +00:00
*
* @param dn $dn Current dn.
* @param object $LDAPServer LDAPServer object
* @param int $level Level to start drawing (defaults to 0)
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:24:29 +00:00
function draw_tree_html( $dn, $ldapserver, $level = 0 )
2009-06-30 08:05:37 +00:00
{
2009-06-30 09:22:30 +00:00
global $servers, $tree, $tree_icons, $lang, $search_result_size_limit;
2009-06-30 08:05:37 +00:00
$encoded_dn = rawurlencode( $dn );
2009-06-30 09:24:29 +00:00
$expand_href = sprintf("expand.php?server_id=%s&amp;dn=%s",$ldapserver->server_id,$encoded_dn);
$collapse_href = sprintf("collapse.php?server_id=%s&amp;dn=%s",$ldapserver->server_id,$encoded_dn);
$edit_href = sprintf("edit.php?server_id=%s&amp;dn=%s",$ldapserver->server_id,$encoded_dn);
2009-06-30 08:05:37 +00:00
// should never happen, but just in case
2009-06-30 09:24:29 +00:00
if( ! isset( $tree_icons[ $ldapserver->server_id ][ $dn ] ) )
$tree_icons[ $ldapserver->server_id ][ $dn ] = get_icon( $ldapserver, $dn );
$img_src = 'images/' . $tree_icons[ $ldapserver->server_id ][ $dn ];
2009-06-30 08:05:37 +00:00
2009-06-30 08:10:17 +00:00
$rdn = get_rdn( $dn );
2009-06-30 08:05:37 +00:00
echo '<tr>';
for( $i=0; $i<=$level; $i++ ) {
2009-06-30 08:07:14 +00:00
echo '<td class="spacer"></td>' . "\n";
2009-06-30 08:05:37 +00:00
}
2009-06-30 08:09:20 +00:00
// Shall we draw the "mass-delete" checkbox?
2009-06-30 09:24:29 +00:00
if( $ldapserver->isMassDeleteEnabled() ) {
printf('<td><input type="checkbox" name="mass_delete[%s]" /></td>',htmlspecialchars($dn));
2009-06-30 08:09:20 +00:00
}
2009-06-30 08:07:14 +00:00
// is this node expanded? (deciding whether to draw "+" or "-")
2009-06-30 09:24:29 +00:00
if( isset( $tree[$ldapserver->server_id][$dn] ) ) { ?>
<?php $child_count = number_format( count( $tree[$ldapserver->server_id][$dn] ) );
if ((! $child_count) && (! $ldapserver->isShowCreateEnabled())) { ?>
<td class="expander">
<nobr>
<img src="images/minus.png" alt="-" />
</nobr>
</td>
<?php } else { ?>
2009-06-30 08:05:37 +00:00
<td class="expander">
<nobr>
2009-06-30 09:22:30 +00:00
<a href="<?php echo $collapse_href; ?>"><img src="images/minus.png" alt="-" /></a>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
2009-06-30 09:24:29 +00:00
<?php }
} else {
$limit = isset( $search_result_size_limit ) ? $search_result_size_limit : 50;
if( $ldapserver->isLowBandwidth() ) {
$child_count = null;
} else {
$child_count = count( get_container_contents( $ldapserver, $dn, $limit+1,
'(objectClass=*)', get_tree_deref_setting() ) );
if( $child_count > $limit )
$child_count = $limit . '+';
}
if (($child_count === 0) && (! $ldapserver->isShowCreateEnabled())) {
// Since we know the tree is empty, we'll create a $tree object anyway, just incase we
// create something later (otherwise it doesnt cause the tree to get refreshed).
$_SESSION['tree'][$ldapserver->server_id][$dn] = array();
$_SESSION['tree_icons'][$ldapserver->server_id][$dn] = get_icon( $ldapserver, $dn ); ?>
<td class="expander">
<nobr>
<img src="images/minus.png" alt="-" />
</nobr>
</td>
<?php } else { ?>
2009-06-30 08:05:37 +00:00
<td class="expander">
<nobr>
2009-06-30 09:22:30 +00:00
<a href="<?php echo $expand_href; ?>"><img src="images/plus.png" alt="+" /></a>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
2009-06-30 09:24:29 +00:00
<?php }
} ?>
2009-06-30 08:05:37 +00:00
<td class="icon">
<a href="<?php echo $edit_href; ?>"
target="right_frame"
2009-06-30 09:24:29 +00:00
name="<?php echo $ldapserver->server_id; ?>_<?php echo $encoded_dn; ?>"><img src="<?php echo $img_src; ?>" alt="img" /></a>
2009-06-30 08:05:37 +00:00
</td>
2009-06-30 08:07:14 +00:00
<td class="rdn" colspan="<?php echo (97-$level); ?>">
2009-06-30 08:05:37 +00:00
<nobr>
<a href="<?php echo $edit_href; ?>"
2009-06-30 09:24:29 +00:00
target="right_frame"><?php echo ( draw_formatted_dn( $ldapserver, $dn ) ); /*pretty_print_dn( $rdn ) );*/ ?></a>
2009-06-30 09:22:30 +00:00
<?php if( $child_count ) { ?>
<span class="count">(<?php echo $child_count; ?>)</span>
<?php } ?>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
</tr>
2009-06-30 09:24:29 +00:00
<?php
if( isset( $tree[$ldapserver->server_id][$dn] ) && is_array( $tree[$ldapserver->server_id][$dn] ) ) {
// Draw the "create new" link at the top of the tree list if there are more than 10
// entries in the listing for this node.
if(( count( $tree[$ldapserver->server_id][$dn] ) > 10 ) && ( $ldapserver->isShowCreateEnabled() ))
draw_create_link( $ldapserver->server_id, $rdn, $level, $encoded_dn );
foreach( $tree[$ldapserver->server_id][$dn] as $dn )
draw_tree_html( $dn, $ldapserver, $level+1 );
// Always draw the "create new" link at the bottom of the listing
if( $ldapserver->isShowCreateEnabled() )
draw_create_link( $ldapserver->server_id, $rdn, $level, $encoded_dn );
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
/**
* Print the HTML to show the "create new entry here".
*
* @param int $server_id
* @param dn $rdn
* @param int $level
* @param dn $encoded_dn
*/
2009-06-30 09:22:30 +00:00
function draw_create_link( $server_id, $rdn, $level, $encoded_dn )
{
2009-06-30 09:24:29 +00:00
global $lang;
// print the "Create New object" link.
$create_href = sprintf("create_form.php?server_id=%s&amp;container=%s",$server_id,$encoded_dn);
$create_html = '<tr>';
for( $i=0; $i<=$level; $i++ ) {
$create_html .= '<td class="spacer"></td>';
}
$create_html .= '<td class="spacer"></td>';
$create_html .= '<td class="icon"><a href="' . $create_href .
'" target="right_frame"><img src="images/star.png" alt="' . $lang['new'] . '" /></a></td>';
$create_html .= '<td class="create" colspan="' . (97-$level) . '"><a href="' . $create_href .
'" target="right_frame" title="' . $lang['create_new_entry_in'] . ' ' . $rdn.'">' .
$lang['create_new'] . '</a></td>';
$create_html .= '</tr>';
echo $create_html;
2009-06-30 08:05:37 +00:00
}
?>