phpldapadmin/tree_functions.php

295 lines
13 KiB
PHP
Raw Permalink Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tree_functions.php,v 1.11 2005/03/16 21:26:20 wurley Exp $
/**
* @package phpLDAPadmin
* @author The phpLDAPadmin development team
*/
2009-06-30 09:22:30 +00:00
/**
* This function displays the LDAP tree for all the servers that you have
* 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
2009-06-30 09:24:29 +00:00
* dc=example,dc=com for server 3, the URL would be:
2009-06-30 09:22:30 +00:00
* tree.php#3_dc%3Dexample%2Cdc%3Dcom
2009-06-30 09:24:29 +00:00
* @todo Test Mass delete works as expected.
2009-06-30 09:22:30 +00:00
*/
2009-06-30 09:24:29 +00:00
function draw_server_tree() {
2009-06-30 09:22:30 +00:00
global $lang;
global $tree;
global $tree_icons;
2009-06-30 09:24:29 +00:00
global $ldapserver;
global $servers;
global $recently_timed_out_servers;
$server_id = $ldapserver->server_id;
2009-06-30 09:22:30 +00:00
// Does this server want mass deletion availble?
2009-06-30 09:24:29 +00:00
if( $ldapserver->isMassDeleteEnabled() ) {
echo "<form name=\"mass_delete\" action=\"mass_delete.php\" method=\"post\" target=\"right_frame\">\n";
2009-06-30 09:22:30 +00:00
echo "<input type=\"hidden\" name=\"server_id\" value=\"$server_id\" />\n";
}
echo '<tr class="server">';
echo '<td class="icon"><img src="images/server.png" alt="' . $lang['server'] . '" /></td>';
echo '<td colspan="99"><a name="' . $server_id . '"></a>';
2009-06-30 09:24:29 +00:00
echo '<nobr>' . htmlspecialchars( $ldapserver->name ) . ' ';
if ($ldapserver->haveAuthInfo() && isset($servers[$server_id]['session_timeout']))
echo '<acronym title="'.sprintf($lang['timeout_at'],strftime('%H:%M',time()+($servers[$server_id]['session_timeout']*60))).'"><img widht=14 height=14 src="images/timeout.png" alt="timeout"><acronym>';
echo '</nobr></td></tr>';
2009-06-30 09:22:30 +00:00
// do we have what it takes to authenticate here, or do we need to
// present the user with a login link (for 'cookie' and 'session' auth_types)?
2009-06-30 09:24:29 +00:00
if( $ldapserver->haveAuthInfo() ) {
if( $ldapserver->connect(false) ) {
$schema_href = sprintf('schema.php?server_id=%s" target="right_frame',$server_id);
$search_href = sprintf('search.php?server_id=%s" target="right_frame',$server_id);
$refresh_href = sprintf('refresh.php?server_id=%s',$server_id);
2009-06-30 09:22:30 +00:00
$logout_href = get_custom_file( $server_id, 'logout.php') . '?server_id=' . $server_id;
2009-06-30 09:24:29 +00:00
$info_href = sprintf('server_info.php?server_id=%s',$server_id);
$import_href = sprintf('ldif_import_form.php?server_id=%s',$server_id);
$export_href = sprintf('export_form.php?server_id=%s',$server_id);
// Draw the quick-links below the server name:
2009-06-30 09:22:30 +00:00
// ( schema | search | refresh | create )
echo '<tr><td colspan="100" class="links">';
echo '<nobr>';
echo '( ';
2009-06-30 09:24:29 +00:00
echo '<a title="' . $lang['view_schema_for'] . ' ' . $ldapserver->name . '"'.
2009-06-30 09:22:30 +00:00
' href="' . $schema_href . '">' . $lang['schema'] . '</a> | ';
2009-06-30 09:24:29 +00:00
echo '<a title="' . $lang['search'] . ' ' . $ldapserver->name . '"' .
2009-06-30 09:22:30 +00:00
' href="' . $search_href . '">' . $lang['search'] . '</a> | ';
2009-06-30 09:24:29 +00:00
echo '<a title="' . $lang['refresh_expanded_containers'] . ' ' . $ldapserver->name . '"'.
2009-06-30 09:22:30 +00:00
' href="' . $refresh_href . '">' . $lang['refresh'] . '</a> | ';
2009-06-30 09:24:29 +00:00
// if ($ldapserver->isShowCreateEnabled())
// echo '<a title="' . $lang['create_new_entry_on'] . ' ' . $ldapserver->name . '"'.
// ' href="' . sprintf('create_form.php?server_id=%s',$server_id) . '" target="right_frame">' . $lang['create'] . '</a> | ';
2009-06-30 09:22:30 +00:00
echo '<a title="' . $lang['view_server_info'] . '" target="right_frame" '.
'href="' . $info_href . '">' . $lang['info'] . '</a> | ';
echo '<a title="' . $lang['import_from_ldif'] . '" target="right_frame" ' .
'href="' . $import_href .'">' . $lang['import'] . '</a> | ';
2009-06-30 09:24:29 +00:00
echo '<a href="' . $export_href . '" target="right_frame">' . $lang['export_lcase'] . '</a>';
if( $ldapserver->auth_type != 'config' )
echo ' | <a title="' . $lang['logout_of_this_server'] . '" href="' . $logout_href .
2009-06-30 09:22:30 +00:00
'" target="right_frame">' . $lang['logout'] . '</a>';
2009-06-30 09:24:29 +00:00
2009-06-30 09:22:30 +00:00
echo ' )</nobr></td></tr>';
2009-06-30 09:24:29 +00:00
if( $ldapserver->auth_type != 'config' ) {
$logged_in_dn = get_logged_in_dn( $ldapserver );
2009-06-30 09:22:30 +00:00
echo "<tr><td class=\"links\" colspan=\"100\"><nobr>" . $lang['logged_in_as'];
2009-06-30 09:24:29 +00:00
2009-06-30 09:22:30 +00:00
if( strcasecmp( "anonymous", $logged_in_dn ) )
2009-06-30 09:24:29 +00:00
echo "<a class=\"logged_in_dn\" href=\"edit.php?server_id=$server_id&amp;dn=" .
rawurlencode(get_logged_in_dn($ldapserver)) . "\" target=\"right_frame\">" .
2009-06-30 09:22:30 +00:00
pretty_print_dn( $logged_in_dn ) . "</a>";
2009-06-30 09:24:29 +00:00
2009-06-30 09:22:30 +00:00
else
echo "Anonymous";
echo "</nobr></td></tr>";
}
2009-06-30 09:24:29 +00:00
if( $ldapserver->isReadOnly() )
2009-06-30 09:22:30 +00:00
echo "<tr><td class=\"links\" colspan=\"100\"><nobr>" .
"(" . $lang['read_only'] . ")</nobr></td></tr>";
2009-06-30 09:24:29 +00:00
$javascript_forms = '';
$javascript_id = 0;
foreach ($ldapserver->getBaseDN() as $base_dn) {
// Did we get a base_dn for this server somehow?
if( $base_dn ) {
echo "\n\n<!-- base DN row -->\n<tr>\n";
// is the root of the tree expanded already?
if( isset( $tree[$server_id][$base_dn] ) ) {
$expand_href = sprintf('collapse.php?server_id=%s&amp;dn=%s',
$server_id,rawurlencode( $base_dn ));
$expand_img = "images/minus.png";
$expand_alt = "-";
$child_count = number_format( count( $tree[$server_id][$base_dn] ) );
} else {
// Check if the LDAP server is not yet initialized
// (ie, the base DN configured in config.php does not exist)
if( ! dn_exists( $ldapserver, $base_dn ) ) {
$javascript_id++;
?>
2009-06-30 09:22:30 +00:00
<tr>
<td class="spacer"></td>
<td><img src="images/unknown.png" /></td>
<td colspan="98"><?php echo pretty_print_dn( $base_dn ); ?></td>
</tr>
2009-06-30 09:24:29 +00:00
<?php // Move this form and add it to the end of the html - otherwise the javascript
// doesnt work when isMassDeleteEnabled returning true.
$javascript_forms .= sprintf('<form name="create_base_form_%s" method="post" action="creation_template.php" target="right_frame">',$javascript_id);
$javascript_forms .= sprintf('<input type="hidden" name="template" value="custom" />');
$javascript_forms .= sprintf('<input type="hidden" name="server_id" value="%s" />',$server_id);
$javascript_forms .= sprintf('<input type="hidden" name="container" value="" />');
$javascript_forms .= sprintf('<input type="hidden" name="rdn" value="%s" />',htmlspecialchars($base_dn));
$javascript_forms .= sprintf('</form>'); ?>
2009-06-30 09:22:30 +00:00
<tr>
<td class="spacer"></td>
<td colspan="98">
<small><?php echo $lang['base_entry_does_not_exist']; ?>
2009-06-30 09:24:29 +00:00
<a href="javascript:document.create_base_form_<?php echo $javascript_id ?>.submit()"><?php echo $lang['create_it']; ?></a></small>
2009-06-30 09:22:30 +00:00
</td>
</tr>
2009-06-30 09:24:29 +00:00
<?php
2009-06-30 09:22:30 +00:00
2009-06-30 09:24:29 +00:00
continue;
} else {
$expand_href = sprintf('expand.php?server_id=%s&amp;dn=%s',
$server_id,rawurlencode( $base_dn ));
$expand_img = "images/plus.png";
$expand_alt = "+";
$limit = isset( $search_result_size_limit ) ? $search_result_size_limit : 50;
2009-06-30 09:22:30 +00:00
2009-06-30 09:24:29 +00:00
if( $ldapserver->isLowBandwidth() ) {
$child_count = null;
2009-06-30 09:22:30 +00:00
2009-06-30 09:24:29 +00:00
} else {
$child_count = count( get_container_contents(
$ldapserver, $base_dn, $limit+1,
'(objectClass=*)', get_tree_deref_setting() ) );
if( $child_count > $limit )
$child_count = $limit . '+';
}
}
}
$create_href = sprintf('create_form.php?server_id=%s&amp;container=%s',$server_id,
rawurlencode( $base_dn ));
$edit_href = sprintf("edit.php?server_id=%s&amp;dn=%s",$server_id,rawurlencode( $base_dn ));
$icon = isset( $tree_icons[ $server_id ][ $base_dn ] )
? $tree_icons[ $server_id ][ $base_dn ]
: get_icon( $ldapserver, $base_dn );
// Shall we draw the "mass-delete" checkbox?
if( $ldapserver->isMassDeleteEnabled() ) {
echo "<td><input type=\"checkbox\" name=\"mass_delete[" . htmlspecialchars($base_dn) . "]\" /></td>\n";
}
echo "<td class=\"expander\">";
echo "<a href=\"$expand_href\"><img src=\"$expand_img\" alt=\"$expand_alt\" /></a></td>";
echo "<td class=\"icon\"><a href=\"$edit_href\" target=\"right_frame\">";
echo "<img src=\"images/$icon\" alt=\"img\" /></a></td>\n";
echo "<td class=\"rdn\" colspan=\"98\"><nobr><a href=\"$edit_href\" ";
echo " target=\"right_frame\">" . pretty_print_dn( $base_dn ) . '</a>';
if( $child_count )
echo " <span class=\"count\">($child_count)</span>";
echo "</nobr></td>\n";
echo "</tr>\n<!-- end of base DN row -->";
if( $ldapserver->isShowCreateEnabled() && isset( $tree[ $server_id ][ $base_dn ])
&& count( $tree[ $server_id ][ $base_dn ] ) > 10 )
draw_create_link( $ldapserver->server_id, $base_dn, -1, urlencode( $base_dn ));
} else { // end if( $base_dn )
// @todo: Test these conditions.
if( "" === $base_dn || null === $base_dn ) {
// The server refuses to give out the base dn
echo "<tr><td class=\"spacer\"></td><td colspan=\"98\"><small><nobr>";
echo $lang['could_not_determine_root'];
echo '<br />';
echo $lang['ldap_refuses_to_give_root'];
echo '<br />';
echo $lang['please_specify_in_config'];
echo "</small></nobr></td></tr>";
// Proceed to the next server. We cannot draw anything else for this server.
continue;
} else {
// For some unknown reason, we couldn't determine the base dn
echo "<tr><td class=\"spacer\"></td><td colspan=\"99\"><small><nobr>";
echo $lang['could_not_determine_root'];
echo '<br />';
echo $lang['please_specify_in_config'];
echo "</small></nobr></td></tr>";
// Proceed to the next server. We cannot draw anything else for this server.
continue;
}
2009-06-30 09:22:30 +00:00
}
2009-06-30 09:24:29 +00:00
flush();
// Is the root of the tree expanded already?
if( isset( $tree[$server_id][$base_dn] ) && is_array( $tree[$server_id][$base_dn] ) ) {
foreach( $tree[ $server_id ][ $base_dn ] as $child_dn )
draw_tree_html( $child_dn, $ldapserver, 0 );
if( ! $ldapserver->isReadOnly() ) {
echo '<tr><td class="spacer"></td>';
if( $ldapserver->isShowCreateEnabled() ) {
echo '<td class="icon"><a href="' . $create_href .
'" target="right_frame"><img src="images/star.png" alt="' .
$lang['new'] . '" /></a></td>';
echo '<td class="create" colspan="100"><a href="' . $create_href
. '" target="right_frame" title="' . $lang['create_new_entry_in']
. ' ' . $base_dn.'">' . $lang['create_new'] . '</a></td></tr>';
}
2009-06-30 09:22:30 +00:00
}
}
}
2009-06-30 09:24:29 +00:00
} else { // end if( $ldapserver->connect(false) )
2009-06-30 09:22:30 +00:00
// could not connect to LDAP server
echo "<tr>\n";
echo "<td class=\"spacer\"></td>\n";
echo "<td><img src=\"images/warning_small.png\" alt=\"" . $lang['warning'] . "\" /></td>\n";
echo "<td colspan=\"99\"><small><span style=\"color:red\">" . $lang['could_not_connect'] . "</span></small></td>\n";
echo "</tr>\n";
2009-06-30 09:24:29 +00:00
if( $ldapserver->auth_type != 'config' ) {
2009-06-30 09:22:30 +00:00
$logout_href = get_custom_file( $server_id, 'logout.php') . '?server_id=' . $server_id;
echo "<tr>\n";
echo "<td class=\"spacer\"></td>\n";
echo "<td class=\"spacer\"></td>\n";
echo "<td colspan=\"99\"><small>";
echo "<a target=\"right_frame\" href=\"$logout_href\">" . $lang['logout'] . "</a></small></td>\n";
echo "</tr>\n";
}
// Proceed to the next server in the list. We cannot do anything mroe here.
return;
}
2009-06-30 09:24:29 +00:00
} else { // end if $ldapserver->haveAuthInfo()
2009-06-30 09:22:30 +00:00
// We don't have enough information to login to this server
// Draw the "login..." link
$login_href = get_custom_file( $server_id, 'login_form.php' ) . "?server_id=$server_id";
echo '<tr class="login">';
echo '<td class="spacer"></td>';
echo '<td><a href="' . $login_href . '" target="right_frame">';
echo '<img src="images/uid.png" align="top" alt="' . $lang['login'] . '" /></a></td>';
echo '<td colspan="99"><a href="' . $login_href . '" target="right_frame">' . $lang['login_link'] . '</a>';
echo '</td></tr>';
2009-06-30 09:24:29 +00:00
// If the server recently timed out display the message
if ( in_array($server_id,$recently_timed_out_servers) )
echo '<tr><td class="spacer"></td><td colspan="100" class="links">' . $lang['session_timed_out_tree'] . '</td></tr>';
2009-06-30 09:22:30 +00:00
}
2009-06-30 09:24:29 +00:00
if( $ldapserver->isMassDeleteEnabled() ) {
2009-06-30 09:22:30 +00:00
echo "<tr><td colspan=\"99\"><input type=\"submit\" value=\"Delete Checked Entries\" \></td></tr>\n";
echo "<!-- The end of the mass deletion form -->\n";
echo "</form>\n";
}
2009-06-30 09:24:29 +00:00
if (isset($javascript_forms) && $javascript_forms) {
echo "<!-- Forms for javascript submit to call to create base_dns -->\n";
echo $javascript_forms;
echo "<!-- The end of the forms for javascript submit to call to create base_dns -->\n";
}
2009-06-30 09:22:30 +00:00
}
?>