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) {
36 xpm_label = new Gtk_HBox(GTK_HBOX(this->get_child()->gtkobj()));
37 xpm_label->remove_c(xpm_label->children()->nth_data(0));
38 xpm_label->remove_c(xpm_label->children()->nth_data(0));
40 else xpm_label = new Gtk_HBox();
41 debug(this->hostname);
42 if (strcasecmp(this->hostname,"localhost") == 0)
43 xpm_icon=new Gtk_Pixmap(*xpm_label, local_server);
44 else xpm_icon=new Gtk_Pixmap(*xpm_label, remote_server);
45 // sprintf(c, "%s:%i", this->hostname, this->port);
47 label = new Gtk_Label(this->hostname);
48 xpm_label->pack_start(*xpm_icon, false, false, 1);
49 xpm_label->pack_start(*label, false, false, 1);
50 if (this->get_child() == NULL) this->add(xpm_label);
56 int Gtk_LdapServer::showDetails() {
57 debug("Gtk_LdapServer::showDetails()\n");
58 if (this->notebook == NULL) this->getOptions();
59 if (this->notebook != NULL) {
60 debug("Have a notebook here");
61 if (par->viewport2->get_child() != NULL) {
62 debug(" and viewport has children");
63 par->viewport2->remove(par->viewport2->get_child());
64 debug(" which have been removed");
66 else debug(" and viewport without children");
67 par->viewport2->add(this->notebook);
68 this->notebook->show();
69 par->viewport2->show();
76 int Gtk_LdapServer::getConfig() {
77 debug("Gtk_LdapServer::getConfig()\n");
78 int error, entriesCount;
79 LDAPMessage *entry, *result_identifier;
83 if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
87 error = ldap_search_s(this->ld, "cn=config", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
88 entriesCount = ldap_count_entries(this->ld, result_identifier);
89 if (entriesCount == 0) {
93 debug("%i entry\n", entriesCount);
94 for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) {
95 for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) {
96 debug("Attrib: %s\n", attribute);
97 if (strcasecmp(attribute, "database") == 0) {
98 debug("have database here\n");
99 this->databases = new G_List<char>;
100 t = ldap_get_values(this->ld, entry, attribute);
101 for (int i=0; i<ldap_count_values(t); i++) {
102 this->databases->append(strdup(t[i]));
105 debug("databases loaded\n");
106 for (int i=0; i<this->databases->length(); i++) {
107 debug("database(%i) %s\n", i, this->databases->nth_data(i));
111 debug("entry done\n");
113 // debug("got %i entries\n", entriesCount);
117 #ifndef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
118 char* Gtk_LdapServer::getOptDescription(int option) {
119 debug("Gtk_LdapServer::getOptDescription(%i) ", option);
122 case LDAP_OPT_API_INFO: c = "API info"; break;
123 case LDAP_OPT_CLIENT_CONTROLS: c = "Client controls"; break;
124 case LDAP_OPT_DEREF: c = "Dereference"; break;
125 case LDAP_OPT_DESC: c = "Description"; break;
126 case LDAP_OPT_DNS: c = "DNS Lookup"; break;
127 case LDAP_OPT_ERROR_NUMBER: c = "Error number"; break;
128 case LDAP_OPT_ERROR_STRING: c = "Error string"; break;
129 case LDAP_OPT_SIZELIMIT: c = "Size limit"; break;
130 case LDAP_OPT_TIMELIMIT: c = "Time limit"; break;
131 case LDAP_OPT_REFERRALS: c = "Referrals"; break;
132 case LDAP_OPT_RESTART: c = "Started"; break;
133 case LDAP_OPT_PROTOCOL_VERSION: c = "Protocol version"; break;
134 case LDAP_OPT_HOST_NAME: c = "Host name"; break;
135 case LDAP_OPT_SERVER_CONTROLS: c = "Server controls"; break;
136 default: c = "No description"; break;
142 int Gtk_LdapServer::getOptType(int option) {
143 debug("Gtk_LdapServer::getOptType(%i) ", option);
145 * 0 = int, 1 = string, 2 = boolean,
146 * 3 = range, 4 = LDAPAPIInfo, 5 = unknown
153 case LDAP_OPT_ERROR_NUMBER:
154 case LDAP_OPT_PROTOCOL_VERSION: type = 0; break;
156 case LDAP_OPT_ERROR_STRING:
157 case LDAP_OPT_HOST_NAME: type = 1; break;
159 case LDAP_OPT_REFERRALS:
161 case LDAP_OPT_RESTART: type = 2; break;
163 case LDAP_OPT_SIZELIMIT:
164 case LDAP_OPT_TIMELIMIT: type = 3; break;
166 case LDAP_OPT_API_INFO: type = 4; break;
168 case LDAP_OPT_SERVER_CONTROLS:
169 case LDAP_OPT_CLIENT_CONTROLS:
170 default: type = 5; break;
175 #endif /* LDAP_GET_OPT */
177 int Gtk_LdapServer::getOptions() {
178 debug("Gtk_LdapServer::getOptions()\n");
179 if (this->notebook != NULL) return 0;
180 #ifdef LDAP_GET_OPT /* a temporary fix for usability with (old) U-MICH api */
182 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");
183 this->notebook = new Gtk_Frame("LDAP Options");
184 this->notebook->add(*label);
186 this->notebook->show();
190 Gtk_HBox *hbox, *mini_hbox;
191 Gtk_VBox *vbox, *mini_vbox;
194 Gtk_RadioButton *radio1, *radio2;
196 Gtk_Adjustment *adjustment;
197 char *description = NULL, *s_value = NULL;
203 LDAP_OPT_CLIENT_CONTROLS,
207 // LDAP_OPT_ERROR_NUMBER,
208 // LDAP_OPT_ERROR_STRING,
210 LDAP_OPT_PROTOCOL_VERSION,
213 LDAP_OPT_SERVER_CONTROLS,
218 /* if (GTK_TREE_ITEM(this->gtkobj())->subtree == NULL) {
222 // debug("getting ldap options");
223 // vbox = new Gtk_VBox();
224 table = new Gtk_Table(10, 1, TRUE);
226 for (int i=0; i<10; i++) {
228 hbox = new Gtk_HBox(TRUE, 2);
229 hbox->set_border_width(2);
230 description = this->getOptDescription(things[i]);
231 label = new Gtk_Label(description);
232 label->set_justify(GTK_JUSTIFY_LEFT);
233 label->set_alignment(0, 0);
234 hbox->pack_start(*label);
236 switch (this->getOptType(things[i])) {
238 ldap_get_option(this->ld, things[i], &i_value);
239 debug("%s value %d\n", description, i_value);
240 sprintf(s_value, "%d", i_value);
241 label = new Gtk_Label(s_value);
242 label->set_justify(GTK_JUSTIFY_LEFT);
243 label->set_alignment(0, 0);
244 hbox->pack_end(*label);
248 ldap_get_option(this->ld, things[i], &s_value);
249 label = new Gtk_Label(s_value);
250 label->set_justify(GTK_JUSTIFY_LEFT);
251 label->set_alignment(0, 0);
252 hbox->pack_end(*label);
256 ldap_get_option(this->ld, things[i], &i_value);
257 radio1 = new Gtk_RadioButton(static_cast<GSList*>(0), "Enabled");
258 radio2 = new Gtk_RadioButton(*radio1, "Disabled");
259 if (i_value == 1) radio1->set_active(true);
260 else radio2->set_active(true);
261 mini_hbox = new Gtk_HBox(FALSE, 2);
262 mini_hbox->set_border_width(2);
263 mini_hbox->pack_start(*radio1);
265 mini_hbox->pack_end(*radio2);
267 hbox->pack_end(*mini_hbox);
271 ldap_get_option(this->ld, things[i], &i_value);
272 adjustment = new Gtk_Adjustment(i_value, 1.0, 20.0, 1.0, 1.0, 0.0);
273 scale = new Gtk_HScale(*adjustment);
274 scale->set_update_policy(GTK_UPDATE_CONTINUOUS);
275 scale->set_value_pos(GTK_POS_TOP);
276 scale->set_digits(0);
277 scale->set_draw_value(true);
278 hbox->pack_end(*scale);
282 #ifdef LDAP_API_INFO_VERSION
283 api.ldapai_info_version = LDAP_API_INFO_VERSION;
285 api.ldapai_info_version = 1;
287 if (ldap_get_option(this->ld, things[i], &api) != LDAP_SUCCESS) {
288 perror(this->getOptDescription(things[i]));
291 s_value = api.ldapai_vendor_name;
292 label = new Gtk_Label(s_value);
293 label->set_justify(GTK_JUSTIFY_LEFT);
294 label->set_alignment(0, 0);
295 hbox->pack_end(*label);
299 label = new Gtk_Label("Not implemented (yet)");
300 label->set_justify(GTK_JUSTIFY_LEFT);
301 label->set_alignment(0, 0);
302 hbox->pack_end(*label);
306 // hbox->pack_end(*label);
308 table->attach_defaults(*hbox, 0, 1, i, i+1);
311 table->set_border_width(2);
312 this->notebook = new Gtk_Frame("LDAP Options");
313 this->notebook->add(*table);
316 #endif /* LDAP_GET_OPT */
319 Gtk_Tree* Gtk_LdapServer::getSubtree() {
320 debug("Gtk_LdapServer::getSubtree()\n");
321 Gtk_LdapTree *tree, *subtree;
322 Gtk_LdapTreeItem *treeitem;
325 debug("this->hostname=%s\n", this->hostname);
326 debug("this->port=%i", this->port);
331 int len = this->databases->length();
332 debug("this->databases->length()=%i\n", len);
334 tree = new Gtk_LdapTree();
335 for (int i=0; i<len; i++) {
336 tok = strdup(this->databases->nth_data(i));
337 tok = strtok(tok, ":");
338 // c = strtok(NULL, " ");
339 c = strtok(NULL, "\0");
340 debug("database %i %s\n", i, c);
341 treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld);
342 subtree = treeitem->getSubtree(this->ld, 1);
343 debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
344 tree->append(*treeitem);
345 treeitem->set_subtree(*subtree);
349 // this->set_subtree(*tree);
350 debug("getSubtree() done\n");
354 void Gtk_LdapServer::show_impl() {
355 debug("%s showed\n", this->hostname);
356 BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
357 if (!sig->show) return;
359 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
360 // sig->show(GTK_WIDGET(gtkobj()));
363 void Gtk_LdapServer::select_impl() {
364 debug("%s selected\n", this->hostname);
365 // Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
366 // if (!sig->select) return;
368 // sig->select(GTK_ITEM(gtkobj()));
369 Gtk_TreeItem::select_impl();
372 void Gtk_LdapServer::collapse_impl() {
373 debug("%s collapsed\n", this->hostname);
374 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
375 // if (!sig->collapse) return;
376 // sig->collapse(GTK_TREE_ITEM(gtkobj()));
377 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
378 Gtk_TreeItem::collapse_impl();
381 void Gtk_LdapServer::expand_impl() {
382 debug("%s expanded\n", this->hostname);
383 Gtk_TreeItem::expand_impl();
384 // BaseClassType *sig=static_cast<BaseClassType *>(get_parent_class());
387 // sig->expand(gtkobj());
388 // Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
389 // if (!sig->expand) return;
390 // sig->expand(GTK_TREE_ITEM(gtkobj()));
392 // t = new Gtk_Tree(GTK_TREE(GTK_TREE_ITEM(this->gtkobj())->subtree));
393 // bool vis = t->visible();
394 // if (vis == false) {
395 // gtk_widget_show(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
396 // cout << this->dn << " expanded" << endl;
399 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
400 // cout << this->dn << " collapsed" << endl;