getServer(); echo ''; if (! $onlytree) $this->draw_server_name(); $this->javascript = ''; $javascript_id = 0; /* 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)? */ if ($server->isLoggedIn(null)) { if (! $onlytree) { $this->draw_menu(); if ($server->getAuthType() != 'config') $this->draw_logged_in_user(); else printf('',$this->getDepth()+3); if ($server->isReadOnly()) printf('',$this->getDepth()+3-1,_('read only')); else printf('',$this->getDepth()+3); printf(''; echo '
 
(%s)
 
 
', $_SESSION[APPCONFIG]->getValue('appearance','tree_width') ? sprintf('width: %spx; ',$_SESSION[APPCONFIG]->getValue('appearance','tree_width')) : '', $_SESSION[APPCONFIG]->getValue('appearance','tree_height') ? sprintf('height: %spx; ',$_SESSION[APPCONFIG]->getValue('appearance','tree_height')) : '', $server->getIndex()); } echo ''; if (! count($this->getBaseEntries())) { # We didnt get any baseDN entries in our tree? printf('', $this->getDepth()+3-2, ('Could not determine the root of your LDAP tree.'), ('It appears that the LDAP server has been configured to not reveal its root.'), ('Please specify it in config.php')); echo '
%s
%s
%s
'; if (! $onlytree) echo '
'; return; } /** * Check if the LDAP server is not yet initialized * (ie, the base DN configured in config.php does not exist) */ foreach ($this->getBaseEntries() as $base) { if (! $base->isInLDAP()) { $js_drawn = false; $javascript_id++; $rdn = explode('=',get_rdn($base->getDN())); printf('%s', IMGDIR,$this->getDepth()+3-3,pretty_print_dn($base->getDN())); $this->javascript .= sprintf('
',$server->getIndex(),$javascript_id); $this->javascript .= '
'; $this->javascript .= ''; $this->javascript .= sprintf('',$server->getIndex()); $this->javascript .= sprintf('',htmlspecialchars($server->getContainer($base->getDN()))); $this->javascript .= sprintf('',get_rdn($base->getDN())); $this->javascript .= sprintf('',$rdn[0]); $this->javascript .= sprintf('',$rdn[0],$rdn[1]); $this->javascript .= ''; $this->javascript .= ''; $this->javascript .= '
'; $this->javascript .= sprintf('
'); if (preg_match('/,/',$base->getDN())) printf('%s', $this->getDepth()+3-3,('This base cannot be created with PLA.')); else printf('%s %s', $this->getDepth()+3-3,('This base entry does not exist.'),$server->getIndex(),$javascript_id,('Create it?')); } else { $this->draw_item($base->getDN(),-1); } } echo ''; if (! $onlytree) echo ''; # We are not logged in, draw a login... link. } else { switch ($server->getAuthType()) { case 'cookie': case 'http': case 'session': $this->draw_login_link(); break; case 'config': case 'proxy': case 'sasl': break; default: die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$server->getAuthType())); } } # Tree Footer. echo ''; echo "\n\n"; if (! $js_drawn) { $this->draw_javascript(); $js_drawn = true; } } /** * Draw the server name */ protected function draw_server_name() { return; if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); echo ''; printf('%s',IMGDIR,_('Server')); printf('',$this->getDepth()+3-1); printf('%s',$server->getName()); if (! is_null($server->inactivityTime())) { $m = sprintf(('Inactivity will log you off at %s'), strftime('%H:%M',$server->inactivityTime())); printf(' %s',IMGDIR,$m,'Timeout'); } echo ''; } /** * Draw the tree menu options */ protected function draw_menu() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $links = ''; if (is_array($_SESSION[APPCONFIG]->getValue('menu','session'))) foreach ($_SESSION[APPCONFIG]->getValue('menu','session') as $link => $title) { if ($this->get_menu_item($link)) $links .= sprintf('%s',$this->get_menu_item($link)); } # Finally add our logout link. $links .= sprintf('%s',$this->get_logout_menu_item()); # Draw the quick-links below the server name: if ($links) { printf('',$this->getDepth()+3-1); printf('%s
',$links); echo ''; } } /** * Get the HTML for each tree menu option */ protected function get_menu_item($item) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); $menu = array(); switch($item) { case 'schema': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) return ''; $menu['cmd'] = 'schema'; $menu['ajax'] = ('Loading Schema'); $menu['div'] = 'BODY'; $menu['title'] = ('View schema for'); $menu['img'] = 'schema-big.png'; $menu['name'] = ('schema'); break; case 'search': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','query_engine')) return ''; $menu['cmd'] = 'query_engine'; $menu['ajax'] = _('Loading Search'); $menu['div'] = 'BODY'; $menu['title'] = _('Search'); $menu['img'] = 'search-big.png'; $menu['name'] = _('search'); break; case 'refresh': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','refresh')) return ''; $menu['cmd'] = 'refresh'; $menu['href'] = '&noheader=1&purge=1'; $menu['ajax'] = _('Refreshing Tree'); $menu['div'] = sprintf('SID_%s_nodes',$server->getIndex()); $menu['title'] = _('Refresh'); $menu['img'] = 'refresh-big.png'; $menu['name'] = _('refresh'); break; case 'server_info': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','server_info')) return ''; $menu['cmd'] = 'server_info'; $menu['ajax'] = ('Loading Info'); $menu['div'] = 'BODY'; $menu['title'] = ('Info'); $menu['img'] = 'info-big.png'; $menu['name'] = ('info'); break; case 'monitor': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','monitor')) return ''; $attrs = $server->getRootDSE(); if (! $attrs || ! isset($attrs['monitorcontext'])) return ''; $menu['cmd'] = 'monitor'; $menu['ajax'] = ('Loading Monitor Info'); $menu['div'] = 'BODY'; $menu['title'] = ('Monitor'); $menu['img'] = 'monitorserver-big.png'; $menu['name'] = ('monitor'); break; case 'import': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','import_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','import') || $server->isReadOnly()) return ''; $menu['cmd'] = 'import_form'; $menu['ajax'] = _('Loading Import'); $menu['div'] = 'BODY'; $menu['title'] = _('Import'); $menu['img'] = 'import-big.png'; $menu['name'] = _('import'); break; case 'export': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) return ''; $menu['cmd'] = 'export_form'; $menu['ajax'] = _('Loading Export'); $menu['div'] = 'BODY'; $menu['title'] = _('Export'); $menu['img'] = 'export-big.png'; $menu['name'] = _('export'); break; default: return false; } $href_parms = htmlspecialchars(sprintf('cmd=%s&server_id=%s%s',$menu['cmd'],$server->getIndex(),isset($menu['href']) ? $menu['href'] : '')); if (isAjaxEnabled()) return sprintf('%s
%s
', $href_parms,$menu['div'],$href_parms,$menu['ajax'],$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']); else return sprintf('%s
%s
', $href_parms,$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']); } protected function get_logout_menu_item() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); $href = sprintf('cmd.php?cmd=logout&server_id=%s',$server->getIndex()); if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','logout') || in_array($server->getAuthType(),array('config','http','proxy'))) return ''; else return sprintf('%s
%s
', htmlspecialchars($href),('Logout of this server'),IMGDIR,'logout-big.png',('logout'),('logout')); } /** * Draw the Logged in User */ protected function draw_logged_in_user() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); $logged_in_dn = $server->getLogin(null); echo ''; echo ''; printf('%s: ',$this->getDepth()+3-1,('Logged in as')); if ($server->getContainerTop($logged_in_dn) == $logged_in_dn) { $logged_in_branch = ''; $logged_in_dn_array = array(); } else { $logged_in_branch = preg_replace('/,'.$server->getContainerTop($logged_in_dn).'$/','',$logged_in_dn); $logged_in_dn_array = pla_explode_dn($logged_in_branch); } $bases = $server->getContainerTop($logged_in_dn); if (is_array($bases) && count($bases)) array_push($logged_in_dn_array,$bases); $rdn = $logged_in_dn; # Some sanity checking here, in case our DN doesnt look like a DN if (! is_array($logged_in_dn_array)) $logged_in_dn_array = array($logged_in_dn); if (trim($logged_in_dn)) { if ($server->dnExists($logged_in_dn)) foreach ($logged_in_dn_array as $rdn_piece) { $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($rdn)); printf('%s',htmlspecialchars($href),pretty_print_dn($rdn_piece)); if ($rdn_piece != end($logged_in_dn_array)) echo ','; $rdn = substr($rdn,(1 + strpos($rdn,','))); } else echo $logged_in_dn; } else { echo 'Anonymous'; } echo ''; echo ''; } /** * Recursively descend on the given dn and draw the tree in html * * @param dn $dn Current dn. * @param int $level Level to start drawing (start to -1) */ protected function draw_item($item,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); # Get entry to display as node $entry = $this->getEntry($item); # If the entry doesnt exist, we'll add it. if (! $entry) { $this->addEntry($item); $entry = $this->getEntry($item); } # If the entry doesnt exist in the server, then return here with an empty string. if (! $entry) return; # Get our children. $child_count = $this->readChildrenNumber($item); $rdn = get_rdn($item); $dnENCODE = rawurlencode($item); $href['expand'] = htmlspecialchars(sprintf('cmd.php?cmd=expand&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE)); $href['collapse'] = htmlspecialchars(sprintf('cmd.php?cmd=collapse&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE)); $href['edit'] = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),$dnENCODE)); echo ''; printf('',$level+2); # Is this node expanded? (deciding whether to draw "+" or "-") if ($entry->isOpened()) if (! $child_count && ! $this->getServer()->isShowCreateEnabled()) printf('-',IMGDIR); else printf('-',$href['collapse'],IMGDIR); else if (($child_count !== false) && (! $child_count) && (! $this->getServer()->isShowCreateEnabled())) printf('-',IMGDIR); else printf('+',$href['expand'],IMGDIR); printf('img', $href['edit'],$server->getIndex(),preg_replace('/=/','_',base64_encode($item)),IMGDIR,$entry->getIcon()); printf('',$this->getDepth()+3-$level); printf('%s',$href['edit'],$this->get_formatted_dn($entry,$level)); if ($child_count) printf(' (%s)',$child_count); echo ''; if ($entry->isOpened()) { /* 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 (!$server->isReadOnly() && (count($entry->getChildren()) > 10) && $this->getServer()->isShowCreateEnabled()) { $this->draw_create_link($rdn,$level,$dnENCODE); } foreach ($entry->getChildren() as $dnChildEntry) $this->draw_item($dnChildEntry,$level+1); # Always draw the "create new" link at the bottom of the listing if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled()) { $this->draw_create_link($rdn,$level,$dnENCODE); } } if (DEBUG_ENABLED) debug_log('Leaving (%s,%s)',33,0,__FILE__,__LINE__,__METHOD__,$item,$level); } protected function get_formatted_dn($entry,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); if ($level < 0) return pretty_print_dn($entry->getDN()); else return draw_formatted_dn($this->getServer(),$entry); } /** * Print the HTML to show the "create new entry here". * * @param dn $rdn * @param int $level * @param dn $encoded_dn */ protected function draw_create_link($rdn,$level,$encoded_dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); # print the "Create New object" link. $href = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$encoded_dn)); echo ''; printf('',$level+3); printf('%s',$href,IMGDIR,_('new')); printf('%s', $this->getDepth()+3-$level,$href,_('Create a new entry in'),$rdn,_('Create new entry here')); echo ''; } /** * Draw login link */ protected function draw_login_link() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); $href_parm = htmlspecialchars(sprintf('cmd=%s&server_id=%s',get_custom_file($server->getIndex(),'login_form',''),$server->getIndex())); echo ''; if (isAjaxEnabled()) { printf('%s', $href_parm,$href_parm,('Loading Login'),('Login to'),$server->getName(),IMGDIR,'login.png',('login')); printf('%s', $this->getDepth()+3-2,$href_parm,$href_parm,('Loading Login'),('Login to'),$server->getName(),('login')); } else { printf('%s',$href_parm,IMGDIR,'login.png',_('login')); printf('%s...',$this->getDepth()+3-2,$href_parm,_('Login')); } echo ''; printf(' ',$this->getDepth()+3); printf(' ',$this->getDepth()+3); } /** * If there is javascript, draw it */ protected function draw_javascript() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); if ($this->javascript) { echo "\n"; echo $this->javascript; echo "\n"; $this->javascript = ''; } } /** * Work out how deep the "opened" tree is. */ public function getDepth() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $server = $this->getServer(); # If we are not logged in if (! $server->isLoggedIn(null)) return 0; static $depths = array(); if (! isset($depths[$server->getIndex()])) { $max = 0; # BaseDN are open, so we start at 1. foreach ($this->entries as $dn) { $basedepth = count(pla_explode_dn($server->getContainerPath($dn->getDN(),'/'))); $depth = 0; $depth = count(pla_explode_dn($dn->getDN()))+1-$basedepth; if ($depth > $max) $max = $depth; } $depths[$server->getIndex()] = $max; } return $depths[$server->getIndex()]; } } ?>