2 include 'include/ldap_entry.inc';
5 var $result_identifier, $search_filter, $base_dn;
6 var $ldap_action, $host;
10 function connect($host) {
11 $this->link_identifier = ldap_connect($host);
12 if ($this->link_identifier) return 1;
16 function disconnect() {
17 ldap_close($this->link_identifier);
20 function ldapTakeAction($a = "search") {
21 $func_ptr = "ldap_".$a;
22 if ($this->result_identifier = $func_ptr($this->link_identifier, $this->base_dn, $this->search_filter)) {
23 $this->entriesCount = ldap_count_entries($this->link_identifier, $this->result_identifier);
29 cfunction getEntries() {
31 $entry = new ldap_entry($this->link_identifier);
32 $entry->r_e_i = ldap_first_entry($this->link_identifier, $this->result_identifier);
33 while($entry->r_e_i) {
34 $entry->dn = ldap_get_dn($this->link_identifier, $entry->r_e_i);
35 $entry->getAttributes();
36 $this->entries[$i] = $entry;
39 $entry = new ldap_entry($this->link_identifier);
40 $entry->r_e_i = ldap_next_entry($this->link_identifier, $r);
42 // ldap_free_result($this->result_identifier);
45 cfunction displayEntries() {
46 echo $this->formatHTMLEntries();
49 cfunction formatHTMLBaseDN($dn) {
52 $attribs = ldap_explode_dn($dn, 0);
53 $names = ldap_explode_dn($dn, 1);
54 for ($i=0; $i<$attribs["count"]; $i++) {
56 for ($j=$i+1; $j<$attribs["count"]; $j++) {
57 $s .= ",".$attribs[$j];
59 if (($s[0] == "c") && ($s[1] == "n")) {
60 $string .= "<a href=".$FILE."?ldap_action=read&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
63 $string .= "<a href=".$FILE."?ldap_action=list&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
69 cfunction formatHTMLEntries() {
71 $string .= '<table width="100%" border=1 cellpadding=0 cellspacing=0>';
73 for ($i=0; $i<count($this->entries); $i++) {
74 $e = $this->entries[$i];
75 $string .= $e->formatHTMLAttributes();
77 $string .= "</table>\n";
81 cfunction calculateTime($string, $s_t, $e_t) {
82 $tok1 = strtok($s_t, " ");
87 $tok2 = strtok($e_t, " ");
91 $t_t = (float) ($secs2 + $msecs2) - (float) ($secs1 + $msecs1);
92 echo "execution time for <b>".$string."</b> : <b>".$t_t."</b> seconds<br>\n";
93 // echo "start: ".$secs1."<br>\n";
94 // echo "end: ".$secs2."<br>\n";
98 cfunction stripString($string, $tokens) {
100 for ($i=0; $i<count($tokens); $i++) {
102 $tok = strtok($s, $tokens[$i]);
105 // echo "result = ".$result."\n";
106 $tok = strtok($tokens[$i]);
109 // echo "s = ".$s."\n";
111 // echo "result = ".$result."\n";