/** * Create an instance of the tree - this is used when we call this class directly * Tree::getInstance($index) * * @return object Tree */ public static function getInstance($server_id) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $tree = get_cached_item($server_id, 'tree'); if (!$tree) { $server = $_SESSION[APPCONFIG]->getServer($server_id); if (!$server) { return null; } $treeclass = $_SESSION[APPCONFIG]->getValue('appearance', 'tree'); $tree = new $treeclass($server_id); # If we are not logged in, just return the empty tree. if (is_null($server->getLogin(null))) { return $tree; } foreach ($server->getBaseDN(null) as $base) { if ($base) { $tree->addEntry($base); if ($server->getValue('appearance', 'open_tree')) { $baseEntry = $tree->getEntry($base); $baseEntry->open(); } } } set_cached_item($server_id, 'tree', 'null', $tree); } return $tree; }
/** * Rename objects */ public function rename($dn, $new_rdn, $container, $deleteoldrdn, $method = null) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $result = false; if (run_hook('pre_entry_rename', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'rdn' => $new_rdn, 'container' => $container))) { $result = @ldap_rename($this->connect($method), $dn, $new_rdn, $container, $deleteoldrdn); if ($result) { # Update the tree $tree = get_cached_item($this->index, 'tree'); $newdn = sprintf('%s,%s', $new_rdn, $container); $tree->renameEntry($dn, $newdn); set_cached_item($this->index, 'tree', 'null', $tree); run_hook('post_entry_rename', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'rdn' => $new_rdn, 'container' => $container)); } } return $result; }
/** * Gets a list of child entries for an entry. Given a DN, this function fetches the list of DNs of * child entries one level beneath the parent. For example, for the following tree: * * <code> * dc=example,dc=com * ou=People * cn=Dave * cn=Fred * cn=Joe * ou=More People * cn=Mark * cn=Bob * </code> * * Calling <code>getContainerContents("ou=people,dc=example,dc=com")</code> * would return the following list: * * <code> * cn=Dave * cn=Fred * cn=Joe * ou=More People * </code> * * @param string $dn The DN of the entry whose children to return. * @param int $size_limit (optional) The maximum number of entries to return. * If unspecified, no limit is applied to the number of entries in the returned. * @param string $filter (optional) An LDAP filter to apply when fetching children, example: "(objectClass=inetOrgPerson)" * @return array An array of DN strings listing the immediate children of the specified entry. */ function getContainerContents($dn, $size_limit = 0, $filter = '(objectClass=*)', $deref = LDAP_DEREF_ALWAYS) { $tree = get_cached_item($this->server_id, 'tree'); if (isset($tree['browser'][$dn]['children']) && $filter == '(objectClass=*)') { if (!isset($tree['browser'][$dn]['size_limited']) || !$tree['browser'][$dn]['size_limited']) { return $tree['browser'][$dn]['children']; } } $return = array(); $search = $this->search(null, dn_escape($dn), $filter, array('dn'), 'one', true, $deref, $size_limit > 0 ? $size_limit + 1 : $size_limit); if (!$search) { $tree['browser'][$dn]['children'] = array(); } else { foreach ($search as $searchdn => $entry) { $child_dn = dn_unescape($entry['dn']); $tree['browser'][$child_dn]['icon'] = get_icon($this, $child_dn); $return[] = $child_dn; } usort($return, 'pla_compare_dns'); $tree['browser'][$dn]['children'] = $return; if ($size_limit > 0 && count($tree['browser'][$dn]['children']) > $size_limit) { $tree['browser'][$dn]['size_limited'] = true; } else { if (isset($tree['browser'][$dn]['size_limited'])) { unset($tree['browser'][$dn]['size_limited']); } } } set_cached_item($this->server_id, 'tree', 'null', $tree); if (DEBUG_ENABLED) { debug_log('%s::getContainerContents(): Entered with (%s,%s,%s,%s), Returning (%s)', 17, get_class($this), $dn, $size_limit, $filter, $deref, $return); } return $tree['browser'][$dn]['children']; }
/** * Returns an array of Syntax objects that this LDAP server uses mapped to * their descriptions. The key of each entry is the OID of the Syntax. */ public function SchemaSyntaxes($method = null, $dn = '') { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); } # Set default return $return = null; if ($return = get_cached_item($this->index, 'schema', 'syntaxes')) { if (DEBUG_ENABLED) { debug_log('Returning CACHED [%s] (%s).', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'syntaxes'); } return $return; } $raw = $this->getRawSchema($method, 'ldapSyntaxes', $dn); if ($raw) { # build the array of attributes $return = array(); foreach ($raw as $line) { if (is_null($line) || !strlen($line)) { continue; } $syntax = new Syntax($line); $key = strtolower(trim($syntax->getOID())); if (!$key) { continue; } $return[$key] = $syntax; } ksort($return); # cache the schema to prevent multiple schema fetches from LDAP server set_cached_item($this->index, 'schema', 'syntaxes', $return); } if (DEBUG_ENABLED) { debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); } return $return; }
* Note: this script is equal and opposite to collapse.php * @package phpLDAPadmin * @see collapse.php */ /** */ require './common.php'; no_expire_header(); if (!$ldapserver->haveAuthInfo()) { pla_error(_('Not enough information to login to server. Please check your configuration.')); } # This allows us to display large sub-trees without running out of time. @set_time_limit(0); $dn = $_GET['dn']; # We dont need this result, as we'll use the SESSION value when we call tree.php $ldapserver->getContainerContents($dn, 0, '(objectClass=*)', $config->GetValue('deref', 'tree')); $tree = get_cached_item($ldapserver->server_id, 'tree'); $tree['browser'][$dn]['open'] = true; set_cached_item($ldapserver->server_id, 'tree', 'null', $tree); /* This is for Opera. By putting "random junk" in the query string, it thinks that it does not have a cached version of the page, and will thus fetch the page rather than display the cached version */ $time = gettimeofday(); $random_junk = md5(strtotime('now') . $time['usec']); /* If cookies were disabled, build the url parameter for the session id. It will be append to the url to be redirect */ $id_session_param = ''; if (SID != '') { $id_session_param = sprintf('&%s=%s', session_name(), session_id()); } header(sprintf('Location:tree.php?foo=%s#%s_%s%s', $random_junk, $ldapserver->server_id, rawurlencode($dn), $id_session_param));
function Templates($server_id) { if (DEBUG_ENABLED) { debug_log('%s::__construct(): Entered with ()', 5, get_class($this)); } if ($this->_template = get_cached_item($server_id, 'template', 'all')) { if (DEBUG_ENABLED) { debug_log('%s::init(): Using CACHED [%s]', 5, get_class($this), 'templates'); } } else { $dir = opendir(TMPLDIR); $this->template_num = 0; while (($file = readdir($dir)) !== false) { if (!preg_match('/.xml$/', $file)) { continue; } $objXML = new xml2array(); $xmldata = $objXML->parse(TMPLDIR . $file); $template_name = preg_replace('/.xml$/', '', $file); $this->storeTemplate($template_name, $xmldata); } masort($this->_template, 'title'); set_cached_item($server_id, 'template', 'all', $this->_template); } }
} $treesave = false; if ($request['dn']) { $dnentry = $tree->getEntry($request['dn']); if (!$dnentry) { $tree->addEntry($request['dn']); $dnentry = $tree->getEntry($request['dn']); $treesave = true; } switch ($request['action']) { case 0: $dnentry->close(); break; case 2: default: if ($dnentry->isSizeLimited()) { $tree->readChildren($request['dn'], true); $treesave = true; } $dnentry->open(); } } if ($treesave) { set_cached_item($app['server']->getIndex(), 'tree', 'null', $tree); } if ($request['dn']) { echo $tree->draw_children($dnentry, $request['code']); } else { $tree->draw($request['noheader']); } die;
function __construct($server_id) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $this->server_id = $server_id; $server = $_SESSION[APPCONFIG]->getServer($this->server_id); $custom_prefix = $server->getValue('custom', 'pages_prefix'); $class = $this->getClassVars(); $changed = false; # Try to get the templates from our CACHE. if ($this->templates = get_cached_item($server_id, $class['item'])) { if (DEBUG_ENABLED) { debug_log('Using CACHED templates', 4, 0, __FILE__, __LINE__, __METHOD__); } # See if the template_time has expired to see if we should reload the templates. foreach ($this->templates as $index => $template) { # If the file no longer exists, we'll delete the template. if (!file_exists($template->getFileName())) { unset($this->templates[$index]); $changed = true; system_message(array('title' => _('Template XML file removed.'), 'body' => sprintf('%s %s (%s)', _('Template XML file has removed'), $template->getName(false), $template->getType()), 'type' => 'info', 'special' => true)); continue; } if ($template->getReadTime() < time() - $class['cachetime'] && filectime($template->getFileName()) > $template->getReadTime()) { system_message(array('title' => _('Template XML file changed.'), 'body' => sprintf('%s %s (%s)', _('Template XML file has changed and been reread'), $template->getName(false), $template->getType()), 'type' => 'info', 'special' => true)); $changed = true; eval(sprintf('$this->templates[$index] = new %s($this->server_id,$template->getName(false),$template->getFileName(),$template->getType(),$index);', $class['name'])); } } if (DEBUG_ENABLED) { debug_log('Templates refreshed', 4, 0, __FILE__, __LINE__, __METHOD__); } # See if there are any new template files $index = max(array_keys($this->templates)) + 1; foreach ($class['types'] as $type) { $dir = $class['dir'] . $type; $dh = opendir($dir); if (!$type) { $type = 'template'; } while ($file = readdir($dh)) { # Ignore any files that are not XML files. if (!preg_match('/.xml$/', $file)) { continue; } # Ignore any files that are not the predefined custom files. if ($_SESSION[APPCONFIG]->getValue('appearance', 'custom_templates_only') && !preg_match("/^{$custom_prefix}/", $file)) { continue; } $filename = sprintf('%s/%s', $dir, $file); if (!in_array($filename, $this->getTemplateFiles())) { $templatename = preg_replace('/.xml$/', '', $file); eval(sprintf('$this->templates[$index] = new %s($this->server_id,$templatename,$filename,$type,$index);', $class['name'])); $index++; $changed = true; system_message(array('title' => _('New Template XML found.'), 'body' => sprintf('%s %s (%s)', _('A new template XML file has been loaded'), $file, $type), 'type' => 'info', 'special' => true)); } } } } else { if (DEBUG_ENABLED) { debug_log('Parsing templates', 4, 0, __FILE__, __LINE__, __METHOD__); } # Need to reset this, as get_cached_item() returns null if nothing cached. $this->templates = array(); $changed = true; $counter = 0; foreach ($class['types'] as $type) { $dir = $class['dir'] . $type; $dh = opendir($class['dir'] . $type); if (!$type) { $type = 'template'; } while ($file = readdir($dh)) { # Ignore any files that are not XML files. if (!preg_match('/.xml$/', $file)) { continue; } # Ignore any files that are not the predefined custom files. if ($_SESSION[APPCONFIG]->getValue('appearance', 'custom_templates_only') && !preg_match("/^{$custom_prefix}/", $file)) { continue; } $filename = sprintf('%s/%s', $dir, $file); # Store the template $templatename = preg_replace('/.xml$/', '', $file); eval(sprintf('$this->templates[$counter] = new %s($this->server_id,$templatename,$filename,$type,$counter);', $class['name'])); $counter++; } } } if (DEBUG_ENABLED) { debug_log('Templates loaded', 4, 0, __FILE__, __LINE__, __METHOD__); } if ($changed) { masort($this->templates, 'title'); set_cached_item($server_id, $class['item'], 'null', $this->templates); } }