1 #include "ldap_entry.h"
6 char *search_filter, *base_dn;
7 char *ldap_action, *host;
11 int connect(char *host) {
12 this->link_identifier = ldap_connect(host);
13 if (this->link_identifier) return 1;
18 // ldap_close($this->link_identifier);
21 int ldapTakeAction(char *a) {
22 char *func_ptr = "ldap_".$a;
23 if (this->result_identifier = func_ptr(this->link_identifier, this->base_dn, this->search_filter)) {
24 this->entriesCount = ldap_count_entries(this->link_identifier, this->result_identifier);
32 entry = new ldap_entry(this->link_identifier);
33 entry->r_e_i = ldap_first_entry(this->link_identifier, this->result_identifier);
35 entry->dn = ldap_get_dn(this->link_identifier, entry->r_e_i);
36 entry->getAttributes();
37 this->entries[i] = $entry;
40 entry = new ldap_entry(this->link_identifier);
41 entry->r_e_i = ldap_next_entry(this->link_identifier, r);
43 // ldap_free_result(this->result_identifier);
46 void displayEntries() {
47 printf(this->formatHTMLEntries());
50 void loadAttributeNames() {
51 global $attribute_names;
52 fp = fopen("at.conf2", "r");
57 string = fgets(fp, 80);
58 foo = strtok(string, " ");
59 attribute_names[i][0] = foo;
61 attribute_names[i][1] = foo;
64 return $attribute_names;
66 char* formatHTMLBaseDN(char *dn) {
69 attribs = ldap_explode_dn(dn, 0);
70 names = ldap_explode_dn(dn, 1);
71 for (int i=0; i<attribs["count"]; i++) {
73 for (j=i+1; j<attribs["count"]; j++) {
74 s = sprintf(",", attribs[j]);
76 if ((s[0] == "c") && (s[1] == "n")) {
77 string = sprintf("<a href=".$FILE."?ldap_action=read&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
80 $string .= "<a href=".$FILE."?ldap_action=list&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
86 cfunction formatHTMLEntries() {
88 $string .= '<table width="100%" border=1 cellpadding=0 cellspacing=0>';
90 for ($i=0; $i<count($this->entries); $i++) {
91 $e = $this->entries[$i];
92 $string .= $e->formatHTMLAttributes();
94 $string .= "</table>\n";
98 cfunction calculateTime($string, $s_t, $e_t) {
99 $tok1 = strtok($s_t, " ");
104 $tok2 = strtok($e_t, " ");
108 $t_t = (float) ($secs2 + $msecs2) - (float) ($secs1 + $msecs1);
109 echo "execution time for <b>".$string."</b> : <b>".$t_t."</b> seconds<br>\n";
110 // echo "start: ".$secs1."<br>\n";
111 // echo "end: ".$secs2."<br>\n";
115 cfunction stripString($string, $tokens) {
117 for ($i=0; $i<count($tokens); $i++) {
119 $tok = strtok($s, $tokens[$i]);
122 // echo "result = ".$result."\n";
123 $tok = strtok($tokens[$i]);
126 // echo "s = ".$s."\n";
128 // echo "result = ".$result."\n";