/** * Bind with searchDN and searchPW and search for the user's DN. * Use search_base and search_filter defined in config file. * Return the found DN. */ function search_userdn($rcmail) { $ldapConfig = array('binddn' => $rcmail->config->get('password_ldap_searchDN'), 'bindpw' => $rcmail->config->get('password_ldap_searchPW'), 'basedn' => $rcmail->config->get('password_ldap_basedn'), 'host' => $rcmail->config->get('password_ldap_host'), 'port' => $rcmail->config->get('password_ldap_port'), 'starttls' => $rcmail->config->get('password_ldap_starttls'), 'version' => $rcmail->config->get('password_ldap_version')); $ldap = Net_LDAP2::connect($ldapConfig); if (PEAR::isError($ldap)) { return ''; } $base = $rcmail->config->get('password_ldap_search_base'); $filter = substitute_vars($rcmail->config->get('password_ldap_search_filter')); $options = array('scope' => 'sub', 'attributes' => array()); $result = $ldap->search($base, $filter, $options); $ldap->done(); if (PEAR::isError($result) || $result->count() != 1) { return ''; } return $result->current()->dn(); }
/** * Applies the bound variables to the selected template * @param array $bind_array (optional) * @param array $select (optional) */ public function apply(array $bind_array = array(), array $select = array()) { $working_template = $this->getTemplate($select); //now get every descendent and process with bound values $xpath = new DOMXpath($this->_template_data); $n_query = "./descendant-or-self::text()"; $nodes = $xpath->query($n_query, $working_template); if ($nodes->length > 0) { for ($i = 0, $len = $nodes->length; $i < $len; $i++) { $node = $nodes->item($i); $text = $node->wholeText; $text_len = strlen($text); $text = substitute_vars($text, $bind_array); $node->replaceData(0, $text_len, $text); } } }