1 #include "Gtk_LdapServer.h"
2 #include <gtk--/base.h>
4 Gtk_LdapServer::Gtk_LdapServer() : Gtk_TreeItem() {
11 Gtk_LdapServer::Gtk_LdapServer(My_Window *w, char *h, int p) : Gtk_TreeItem() {
16 this->notebook = NULL;
17 debug("%s %i\n", this->hostname, this->port);
22 Gtk_LdapServer::Gtk_LdapServer(GtkTreeItem *t) : Gtk_TreeItem(t) {
25 Gtk_LdapServer::~Gtk_LdapServer() {
30 void Gtk_LdapServer::setType(int t) {
31 debug("Gtk_LdapServer::setType(%i)\n", t);
35 if (this->get_child() != NULL) this->remove();
36 xpm_label = new Gtk_HBox();
37 debug(this->hostname);
38 if (strcasecmp(this->hostname,"localhost") == 0)
39 xpm_icon=new Gtk_Pixmap(local_server);
40 else xpm_icon=new Gtk_Pixmap(remote_server);
41 // sprintf(c, "%s:%i", this->hostname, this->port);
43 label = new Gtk_Label(this->hostname);
44 xpm_label->pack_start(*xpm_icon, false, false, 1);
45 xpm_label->pack_start(*label, false, false, 1);
46 if (this->get_child() == NULL) this->add(*xpm_label);
50 int Gtk_LdapServer::showDetails() {
51 debug("Gtk_LdapServer::showDetails()\n");
52 if (this->notebook == NULL) this->getOptions();
53 if (this->notebook != NULL) {
54 debug("Have a notebook here");
55 if (par->viewport2->get_child() != NULL) {
56 debug(" and viewport has children");
57 par->viewport2->remove();
58 debug(" which have been removed\n");
60 else debug(" and viewport without children\n");
61 par->viewport2->add(*this->notebook);
68 int Gtk_LdapServer::getMonitor() {
69 debug("Gtk_LdapServer::getMonitor()\n");
70 int error, entriesCount;
71 LDAPMessage *entry, *result_identifier;
75 if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
79 error = ldap_search_s(this->ld, "cn=monitor", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
80 entriesCount = ldap_count_entries(this->ld, result_identifier);
81 if (entriesCount == 0) {
85 debug("%i tree(s)\n", entriesCount);
86 for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) {
87 for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) {
88 debug("Attrib: %s\n", attribute);
89 if (strcasecmp(attribute, "database") == 0) {
90 debug("have database here\n");
91 this->databases = NULL;
92 t = ldap_get_values(this->ld, entry, attribute);
93 for (int i=0; i<ldap_count_values(t); i++) {
94 this->databases = g_list_append(this->databases, strdup(t[i]));
97 debug("databases loaded\n");
99 for (int i=0;i>g_list_length(this->databases);i++) {
100 t = g_list_nth(this->databases, i);
101 debug("database(%i) %s\n", i, (char*) t->data);
105 debug("entry done\n");
110 int Gtk_LdapServer::getConfig() {
111 debug("Gtk_LdapServer::getConfig()\n");
112 int error, entriesCount;
113 LDAPMessage *entry, *result_identifier;
115 char *attribute, **t;
117 if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
118 perror("connection");
121 error = ldap_search_s(this->ld, "cn=config", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
122 entriesCount = ldap_count_entries(this->ld, result_identifier);
123 if (entriesCount == 0) {
127 // debug("%i tree(s)\n", entriesCount);
128 for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) {
129 for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) {
130 debug("Attrib: %s\n", attribute);
131 if (strcasecmp(attribute, "database") == 0) {
132 debug("have database here\n");
133 this->databases = NULL;
134 t = ldap_get_values(this->ld, entry, attribute);
135 for (int i=0; i<ldap_count_values(t); i++) {
136 this->databases = g_list_append(this->databases, strdup(t[i]));
138 this->databases = g_list_append(this->databases, "ldbm : cn=config");
139 this->databases = g_list_append(this->databases, "ldbm : cn=monitor");
140 this->databases = g_list_append(this->databases, "ldbm : cn=schema");
142 debug("databases loaded\n");
144 for (int i=0;i<g_list_length(this->databases);i++) {
145 t = g_list_nth(this->databases, i);
146 debug("database(%i) %s\n", i, (char*) t->data);
150 debug("entry done\n");
155 #ifndef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
156 char* Gtk_LdapServer::getOptDescription(int option) {
157 debug("Gtk_LdapServer::getOptDescription(%i) ", option);
160 case LDAP_OPT_API_INFO: c = "API info"; break;
161 case LDAP_OPT_CLIENT_CONTROLS: c = "Client controls"; break;
162 case LDAP_OPT_DEREF: c = "Dereference"; break;
163 case LDAP_OPT_DESC: c = "Description"; break;
164 case LDAP_OPT_DNS: c = "DNS Lookup"; break;
165 case LDAP_OPT_ERROR_NUMBER: c = "Error number"; break;
166 case LDAP_OPT_ERROR_STRING: c = "Error string"; break;
167 case LDAP_OPT_SIZELIMIT: c = "Size limit"; break;
168 case LDAP_OPT_TIMELIMIT: c = "Time limit"; break;
169 case LDAP_OPT_REFERRALS: c = "Referrals"; break;
170 case LDAP_OPT_RESTART: c = "Started"; break;
171 case LDAP_OPT_PROTOCOL_VERSION: c = "Protocol version"; break;
172 case LDAP_OPT_HOST_NAME: c = "Host name"; break;
173 case LDAP_OPT_SERVER_CONTROLS: c = "Server controls"; break;
174 default: c = "No description"; break;
180 int Gtk_LdapServer::getOptType(int option) {
181 debug("Gtk_LdapServer::getOptType(%i) ", option);
183 * 0 = int, 1 = string, 2 = boolean,
184 * 3 = range, 4 = LDAPAPIInfo, 5 = unknown
191 case LDAP_OPT_ERROR_NUMBER:
192 case LDAP_OPT_PROTOCOL_VERSION: type = 0; break;
194 case LDAP_OPT_ERROR_STRING:
195 case LDAP_OPT_HOST_NAME: type = 1; break;
197 case LDAP_OPT_REFERRALS:
199 case LDAP_OPT_RESTART: type = 2; break;
201 case LDAP_OPT_SIZELIMIT:
202 case LDAP_OPT_TIMELIMIT: type = 3; break;
204 case LDAP_OPT_API_INFO: type = 4; break;
206 case LDAP_OPT_SERVER_CONTROLS:
207 case LDAP_OPT_CLIENT_CONTROLS:
208 default: type = 5; break;
213 #endif /* LDAP_GET_OPT */
215 int Gtk_LdapServer::getOptions() {
216 debug("Gtk_LdapServer::getOptions()\n");
217 if (this->notebook != NULL) return 0;
218 #ifdef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
220 label = new Gtk_Label("This tool has been compiled with (old) U-MICH API (no LDAP_GET_OPT)\nCompile with the latest -devel (from OpenLDAP cvs tree)\nto get some nice options here");
221 this->notebook = new Gtk_Frame("LDAP Options");
222 this->notebook->add(*label);
224 //this->notebook->show();
225 this->notebook->show_all();
229 Gtk_HBox *hbox, *mini_hbox;
230 Gtk_VBox *vbox, *mini_vbox;
233 Gtk_RadioButton *radio1, *radio2;
235 Gtk_Adjustment *adjustment;
236 char *description = NULL, *s_value = NULL;
242 LDAP_OPT_CLIENT_CONTROLS,
246 // LDAP_OPT_ERROR_NUMBER,
247 // LDAP_OPT_ERROR_STRING,
249 LDAP_OPT_PROTOCOL_VERSION,
252 LDAP_OPT_SERVER_CONTROLS,
257 /* if (GTK_TREE_ITEM(this->gtkobj())->subtree == NULL) {
261 // vbox = new Gtk_VBox();
262 table = new Gtk_Table(10, 1, TRUE);
264 for (int i=0; i<10; i++) {
267 hbox = new Gtk_HBox(TRUE, 2);
268 hbox->set_border_width(2);
269 description = this->getOptDescription(things[i]);
270 label = new Gtk_Label(description);
271 label->set_justify(GTK_JUSTIFY_LEFT);
272 label->set_alignment(0, 0);
273 hbox->pack_start(*label);
275 switch (this->getOptType(things[i])) {
277 ldap_get_option(this->ld, things[i], &i_value);
278 debug("%s value %d\n", description, i_value);
279 sprintf(s_value, "%d", i_value);
280 label = new Gtk_Label(s_value);
281 label->set_justify(GTK_JUSTIFY_LEFT);
282 label->set_alignment(0, 0);
283 hbox->pack_end(*label);
287 ldap_get_option(this->ld, things[i], &s_value);
288 label = new Gtk_Label(s_value);
289 label->set_justify(GTK_JUSTIFY_LEFT);
290 label->set_alignment(0, 0);
291 hbox->pack_end(*label);
295 ldap_get_option(this->ld, things[i], &i_value);
296 radio1 = new Gtk_RadioButton("Enabled");
297 radio2 = new Gtk_RadioButton("Disabled");
298 radio2->set_group(radio1->group());
299 if (i_value == 1) radio1->set_active(true);
300 else radio2->set_active(true);
301 mini_hbox = new Gtk_HBox(FALSE, 2);
302 mini_hbox->set_border_width(2);
303 mini_hbox->pack_start(*radio1);
305 mini_hbox->pack_end(*radio2);
307 hbox->pack_end(*mini_hbox);
311 ldap_get_option(this->ld, things[i], &i_value);
312 debug("i_value: %s\n", i_value);
313 adjustment = new Gtk_Adjustment(i_value, 0.0, 20.0, 1.0, 1.0, 0.0);
314 scale = new Gtk_HScale(*adjustment);
315 scale->set_update_policy(GTK_UPDATE_CONTINUOUS);
316 scale->set_value_pos(GTK_POS_TOP);
317 scale->set_digits(0);
318 scale->set_draw_value(true);
319 hbox->pack_end(*scale);
323 #ifdef LDAP_API_INFO_VERSION
324 api.ldapai_info_version = LDAP_API_INFO_VERSION;
326 api.ldapai_info_version = 1;
328 if (ldap_get_option(this->ld, things[i], &api) != LDAP_SUCCESS) {
329 perror(this->getOptDescription(things[i]));
332 s_value = api.ldapai_vendor_name;
333 label = new Gtk_Label(s_value);
334 label->set_justify(GTK_JUSTIFY_LEFT);
335 label->set_alignment(0, 0);
336 hbox->pack_end(*label);
340 label = new Gtk_Label("Not implemented (yet)");
341 label->set_justify(GTK_JUSTIFY_LEFT);
342 label->set_alignment(0, 0);
343 hbox->pack_end(*label);
347 // hbox->pack_end(*label);
349 table->attach(*hbox, 0, 1, i, i+1);
352 table->set_border_width(2);
353 this->notebook = new Gtk_Frame("LDAP Options");
354 this->notebook->add(*table);
356 this->notebook->show_all();
358 #endif /* LDAP_GET_OPT */
361 Gtk_Tree* Gtk_LdapServer::getSubtree() {
362 debug("Gtk_LdapServer::getSubtree()\n");
363 Gtk_LdapTree *tree, *subtree;
364 Gtk_LdapTreeItem *treeitem;
367 debug("this->hostname=%s\n", this->hostname);
368 debug("this->port=%i", this->port);
373 int len = g_list_length(this->databases);
374 debug("this->databases->length()=%i\n", len);
376 tree = new Gtk_LdapTree();
377 for (int i=0; i<len; i++) {
378 GList *t = g_list_nth(this->databases, i);
379 tok = strdup((char*)t->data);
380 tok = strtok(tok, ":");
381 // c = strtok(NULL, " ");
382 c = strtok(NULL, "\0");
383 debug("database %i %s\n", i, c);
384 treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld);
385 subtree = treeitem->getSubtree(this->ld, 1);
386 debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
387 tree->append(*treeitem);
388 if (subtree != NULL) treeitem->set_subtree(*subtree);
390 // treeitem->setDnd();
393 // this->set_subtree(*tree);
394 debug("getSubtree() done\n");
398 void Gtk_LdapServer::show_impl() {
399 debug("%s showed\n", this->hostname);
400 BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
401 if (!sig->show) return;
403 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
404 // sig->show(GTK_WIDGET(gtkobj()));
407 void Gtk_LdapServer::select_impl() {
408 debug("%s selected\n", this->hostname);
409 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
410 // if (!sig->select) return;
412 // sig->select(GTK_ITEM(gtkobj()));
413 Gtk_TreeItem::select_impl();
416 void Gtk_LdapServer::collapse_impl() {
417 debug("%s collapsed\n", this->hostname);
418 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
419 // if (!sig->collapse) return;
420 // sig->collapse(GTK_TREE_ITEM(gtkobj()));
421 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
422 Gtk_TreeItem::collapse_impl();
425 void Gtk_LdapServer::expand_impl() {
426 debug("%s expanded\n", this->hostname);
427 Gtk_TreeItem::expand_impl();
428 // BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
431 // sig->expand(gtkobj());
432 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
433 // if (!sig->expand) return;
434 // sig->expand(GTK_TREE_ITEM(gtkobj()));
436 // t = new Gtk_Tree(GTK_TREE(GTK_TREE_ITEM(this->gtkobj())->subtree));
437 // bool vis = t->visible();
438 // if (vis == false) {
439 // gtk_widget_show(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
440 // cout << this->dn << " expanded" << endl;
443 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
444 // cout << this->dn << " collapsed" << endl;