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");
141 debug("databases loaded\n");
143 for (int i=0;i<g_list_length(this->databases);i++) {
144 t = g_list_nth(this->databases, i);
145 debug("database(%i) %s\n", i, (char*) t->data);
149 debug("entry done\n");
154 #ifndef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
155 char* Gtk_LdapServer::getOptDescription(int option) {
156 debug("Gtk_LdapServer::getOptDescription(%i) ", option);
159 case LDAP_OPT_API_INFO: c = "API info"; break;
160 case LDAP_OPT_CLIENT_CONTROLS: c = "Client controls"; break;
161 case LDAP_OPT_DEREF: c = "Dereference"; break;
162 case LDAP_OPT_DESC: c = "Description"; break;
163 case LDAP_OPT_DNS: c = "DNS Lookup"; break;
164 case LDAP_OPT_ERROR_NUMBER: c = "Error number"; break;
165 case LDAP_OPT_ERROR_STRING: c = "Error string"; break;
166 case LDAP_OPT_SIZELIMIT: c = "Size limit"; break;
167 case LDAP_OPT_TIMELIMIT: c = "Time limit"; break;
168 case LDAP_OPT_REFERRALS: c = "Referrals"; break;
169 case LDAP_OPT_RESTART: c = "Started"; break;
170 case LDAP_OPT_PROTOCOL_VERSION: c = "Protocol version"; break;
171 case LDAP_OPT_HOST_NAME: c = "Host name"; break;
172 case LDAP_OPT_SERVER_CONTROLS: c = "Server controls"; break;
173 default: c = "No description"; break;
179 int Gtk_LdapServer::getOptType(int option) {
180 debug("Gtk_LdapServer::getOptType(%i) ", option);
182 * 0 = int, 1 = string, 2 = boolean,
183 * 3 = range, 4 = LDAPAPIInfo, 5 = unknown
190 case LDAP_OPT_ERROR_NUMBER:
191 case LDAP_OPT_PROTOCOL_VERSION: type = 0; break;
193 case LDAP_OPT_ERROR_STRING:
194 case LDAP_OPT_HOST_NAME: type = 1; break;
196 case LDAP_OPT_REFERRALS:
198 case LDAP_OPT_RESTART: type = 2; break;
200 case LDAP_OPT_SIZELIMIT:
201 case LDAP_OPT_TIMELIMIT: type = 3; break;
203 case LDAP_OPT_API_INFO: type = 4; break;
205 case LDAP_OPT_SERVER_CONTROLS:
206 case LDAP_OPT_CLIENT_CONTROLS:
207 default: type = 5; break;
212 #endif /* LDAP_GET_OPT */
214 int Gtk_LdapServer::getOptions() {
215 debug("Gtk_LdapServer::getOptions()\n");
216 if (this->notebook != NULL) return 0;
217 #ifdef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
219 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");
220 this->notebook = new Gtk_Frame("LDAP Options");
221 this->notebook->add(*label);
223 //this->notebook->show();
224 this->notebook->show_all();
228 Gtk_HBox *hbox, *mini_hbox;
229 Gtk_VBox *vbox, *mini_vbox;
232 Gtk_RadioButton *radio1, *radio2;
234 Gtk_Adjustment *adjustment;
235 char *description = NULL, *s_value = NULL;
241 LDAP_OPT_CLIENT_CONTROLS,
245 // LDAP_OPT_ERROR_NUMBER,
246 // LDAP_OPT_ERROR_STRING,
248 LDAP_OPT_PROTOCOL_VERSION,
251 LDAP_OPT_SERVER_CONTROLS,
256 /* if (GTK_TREE_ITEM(this->gtkobj())->subtree == NULL) {
260 // vbox = new Gtk_VBox();
261 table = new Gtk_Table(10, 1, TRUE);
263 for (int i=0; i<10; i++) {
266 hbox = new Gtk_HBox(TRUE, 2);
267 hbox->set_border_width(2);
268 description = this->getOptDescription(things[i]);
269 label = new Gtk_Label(description);
270 label->set_justify(GTK_JUSTIFY_LEFT);
271 label->set_alignment(0, 0);
272 hbox->pack_start(*label);
274 switch (this->getOptType(things[i])) {
276 ldap_get_option(this->ld, things[i], &i_value);
277 debug("%s value %d\n", description, i_value);
278 sprintf(s_value, "%d", i_value);
279 label = new Gtk_Label(s_value);
280 label->set_justify(GTK_JUSTIFY_LEFT);
281 label->set_alignment(0, 0);
282 hbox->pack_end(*label);
286 ldap_get_option(this->ld, things[i], &s_value);
287 label = new Gtk_Label(s_value);
288 label->set_justify(GTK_JUSTIFY_LEFT);
289 label->set_alignment(0, 0);
290 hbox->pack_end(*label);
294 ldap_get_option(this->ld, things[i], &i_value);
295 radio1 = new Gtk_RadioButton("Enabled");
296 radio2 = new Gtk_RadioButton("Disabled");
297 radio2->set_group(radio1->group());
298 if (i_value == 1) radio1->set_active(true);
299 else radio2->set_active(true);
300 mini_hbox = new Gtk_HBox(FALSE, 2);
301 mini_hbox->set_border_width(2);
302 mini_hbox->pack_start(*radio1);
304 mini_hbox->pack_end(*radio2);
306 hbox->pack_end(*mini_hbox);
310 ldap_get_option(this->ld, things[i], &i_value);
311 debug("i_value: %s\n", i_value);
312 adjustment = new Gtk_Adjustment(i_value, 0.0, 20.0, 1.0, 1.0, 0.0);
313 scale = new Gtk_HScale(*adjustment);
314 scale->set_update_policy(GTK_UPDATE_CONTINUOUS);
315 scale->set_value_pos(GTK_POS_TOP);
316 scale->set_digits(0);
317 scale->set_draw_value(true);
318 hbox->pack_end(*scale);
322 #ifdef LDAP_API_INFO_VERSION
323 api.ldapai_info_version = LDAP_API_INFO_VERSION;
325 api.ldapai_info_version = 1;
327 if (ldap_get_option(this->ld, things[i], &api) != LDAP_SUCCESS) {
328 perror(this->getOptDescription(things[i]));
331 s_value = api.ldapai_vendor_name;
332 label = new Gtk_Label(s_value);
333 label->set_justify(GTK_JUSTIFY_LEFT);
334 label->set_alignment(0, 0);
335 hbox->pack_end(*label);
339 label = new Gtk_Label("Not implemented (yet)");
340 label->set_justify(GTK_JUSTIFY_LEFT);
341 label->set_alignment(0, 0);
342 hbox->pack_end(*label);
346 // hbox->pack_end(*label);
348 table->attach(*hbox, 0, 1, i, i+1);
351 table->set_border_width(2);
352 this->notebook = new Gtk_Frame("LDAP Options");
353 this->notebook->add(*table);
355 this->notebook->show_all();
357 #endif /* LDAP_GET_OPT */
360 Gtk_Tree* Gtk_LdapServer::getSubtree() {
361 debug("Gtk_LdapServer::getSubtree()\n");
362 Gtk_LdapTree *tree, *subtree;
363 Gtk_LdapTreeItem *treeitem;
366 debug("this->hostname=%s\n", this->hostname);
367 debug("this->port=%i", this->port);
372 int len = g_list_length(this->databases);
373 debug("this->databases->length()=%i\n", len);
375 tree = new Gtk_LdapTree();
376 for (int i=0; i<len; i++) {
377 GList *t = g_list_nth(this->databases, i);
378 tok = strdup((char*)t->data);
379 tok = strtok(tok, ":");
380 // c = strtok(NULL, " ");
381 c = strtok(NULL, "\0");
382 debug("database %i %s\n", i, c);
383 treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld);
384 subtree = treeitem->getSubtree(this->ld, 1);
385 debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
386 tree->append(*treeitem);
387 if (subtree != NULL) treeitem->set_subtree(*subtree);
391 // this->set_subtree(*tree);
392 debug("getSubtree() done\n");
396 void Gtk_LdapServer::show_impl() {
397 debug("%s showed\n", this->hostname);
398 BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
399 if (!sig->show) return;
401 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
402 // sig->show(GTK_WIDGET(gtkobj()));
405 void Gtk_LdapServer::select_impl() {
406 debug("%s selected\n", this->hostname);
407 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
408 // if (!sig->select) return;
410 // sig->select(GTK_ITEM(gtkobj()));
411 Gtk_TreeItem::select_impl();
414 void Gtk_LdapServer::collapse_impl() {
415 debug("%s collapsed\n", this->hostname);
416 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
417 // if (!sig->collapse) return;
418 // sig->collapse(GTK_TREE_ITEM(gtkobj()));
419 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
420 Gtk_TreeItem::collapse_impl();
423 void Gtk_LdapServer::expand_impl() {
424 debug("%s expanded\n", this->hostname);
425 Gtk_TreeItem::expand_impl();
426 // BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
429 // sig->expand(gtkobj());
430 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
431 // if (!sig->expand) return;
432 // sig->expand(GTK_TREE_ITEM(gtkobj()));
434 // t = new Gtk_Tree(GTK_TREE(GTK_TREE_ITEM(this->gtkobj())->subtree));
435 // bool vis = t->visible();
436 // if (vis == false) {
437 // gtk_widget_show(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
438 // cout << this->dn << " expanded" << endl;
441 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
442 // cout << this->dn << " collapsed" << endl;