]> git.sur5r.net Git - openldap/blob - contrib/gtk-tool/ldap_manager.cc
Update contrib with latest from -devel, including php3-tool and gtk-tool.
[openldap] / contrib / gtk-tool / ldap_manager.cc
1 #include "ldap_entry.h"
2
3 class ldap_manager {
4         ldap_entry *entries;
5         int result_identifier;
6         char *search_filter, *base_dn;
7         char *ldap_action, *host;
8         int link_identifier;
9         int entriesCount;
10
11         int connect(char *host) {
12                 this->link_identifier = ldap_connect(host);
13                 if (this->link_identifier) return 1;
14                 return 0;
15         }
16
17         void disconnect() {
18         //      ldap_close($this->link_identifier);
19         }
20
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);
25                         return 1;
26                 }
27                 return 0;
28         }
29         
30         int getEntries() {
31                 int i=0;
32                 entry = new ldap_entry(this->link_identifier);
33                 entry->r_e_i = ldap_first_entry(this->link_identifier, this->result_identifier);
34                 while(entry->r_e_i) {
35                         entry->dn = ldap_get_dn(this->link_identifier, entry->r_e_i);
36                         entry->getAttributes();
37                         this->entries[i] = $entry;
38                         i++;
39                         r = entry->r_e_i;
40                         entry = new ldap_entry(this->link_identifier);
41                         entry->r_e_i = ldap_next_entry(this->link_identifier, r);
42                 }
43 //              ldap_free_result(this->result_identifier);
44         }
45
46         void displayEntries() {
47                 printf(this->formatHTMLEntries());
48         }
49
50         void loadAttributeNames() {
51                 global $attribute_names;
52                 fp = fopen("at.conf2", "r");
53                 int i = 0;
54                 while (!feof(fp)) {
55                         string = "";
56                         foo = "";
57                         string = fgets(fp, 80);
58                         foo = strtok(string, " ");
59                         attribute_names[i][0] = foo;
60                         foo = strtok("\n");
61                         attribute_names[i][1] = foo;
62                         i++;
63                 }
64                 return $attribute_names;
65         }
66         char* formatHTMLBaseDN(char *dn) {
67                 global $FILE, $host;
68                 char *string = "";
69                 attribs = ldap_explode_dn(dn, 0);
70                 names = ldap_explode_dn(dn, 1);
71                 for (int i=0; i<attribs["count"]; i++) {
72                         s = attribs[i];
73                         for (j=i+1; j<attribs["count"]; j++) {
74                                 s = sprintf(",", attribs[j]);
75                         }
76                         if ((s[0] == "c") && (s[1] == "n")) {
77                                 string = sprintf("<a href=".$FILE."?ldap_action=read&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
78                         }
79                         else {
80                                 $string .= "<a href=".$FILE."?ldap_action=list&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
81                         }
82                 }
83                 return $string;
84         }
85
86         cfunction formatHTMLEntries() {
87                 $string = "";
88                 $string .= '<table width="100%" border=1 cellpadding=0 cellspacing=0>';
89                 $string .= "\n";
90                 for ($i=0; $i<count($this->entries); $i++) {
91                         $e = $this->entries[$i];
92                         $string .= $e->formatHTMLAttributes();
93                 }       
94                 $string .= "</table>\n";
95                 return $string;
96         }
97
98         cfunction calculateTime($string, $s_t, $e_t) {
99                 $tok1 = strtok($s_t, " ");
100                 $msecs1 = $tok1;
101                 $tok1 = strtok(" ");
102                 $secs1 = $tok1;
103          
104                 $tok2 = strtok($e_t, " ");
105                 $msecs2 = $tok2;
106                 $tok2 = strtok(" ");
107                 $secs2 = $tok2;
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";
112                 return (float) $t_t;
113         }
114         
115         cfunction stripString($string, $tokens) {
116                 $s = $string;
117                 for ($i=0; $i<count($tokens); $i++) {
118                         $result = "";
119                         $tok = strtok($s, $tokens[$i]);
120                         while($tok) {
121                                 $result .= $tok;
122                         //      echo "result = ".$result."\n";
123                                 $tok = strtok($tokens[$i]);
124                         }
125                         $s = $result;
126                 //      echo "s = ".$s."\n";
127                 }
128         //      echo "result = ".$result."\n";
129                 return $result;
130         }
131 }
132 ?>