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->getchild() != NULL) {
36 xpm_label = new Gtk_HBox(GTK_HBOX(this->getchild()->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->getchild() == NULL) this->add(xpm_label);
56 int Gtk_LdapServer::showDetails() {
57 debug("Gtk_LdapServer::showDetails()\n");
58 if (this->notebook != NULL) {
59 // debug("Have notebook here");
60 if (par->viewport->getchild() != NULL) {
61 // debug(" and viewport has children");
62 par->viewport->remove_c(par->viewport->getchild()->gtkobj());
63 // debug(" which have been removed");
65 // else debug(" and viewport without children");
66 par->viewport->add(this->notebook);
67 this->notebook->show();
68 par->viewport->show();
71 if (this->getOptions() != 0) return 1;
77 int Gtk_LdapServer::getConfig() {
78 debug("Gtk_LdapServer::getConfig()\n");
79 int error, entriesCount;
80 LDAPMessage *entry, *result_identifier;
84 if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
88 error = ldap_search_s(this->ld, "cn=config", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
89 entriesCount = ldap_count_entries(this->ld, result_identifier);
90 if (entriesCount == 0) {
94 debug("%i entry\n", entriesCount);
95 for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) {
96 for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) {
97 debug("Attrib: %s\n", attribute);
98 if (strcasecmp(attribute, "database") == 0) {
99 debug("have database here\n");
100 this->databases = new G_List<char>;
101 t = ldap_get_values(this->ld, entry, attribute);
102 for (int i=0; i<ldap_count_values(t); i++) {
103 this->databases->append(strdup(t[i]));
106 debug("databases loaded\n");
107 for (int i=0; i<this->databases->length(); i++) {
108 debug("database(%i) %s\n", i, this->databases->nth_data(i));
112 debug("entry done\n");
114 // debug("got %i entries\n", entriesCount);
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;
176 int Gtk_LdapServer::getOptions() {
177 debug("Gtk_LdapServer::getOptions()\n");
178 if (this->notebook != NULL) return 0;
180 Gtk_HBox *hbox, *mini_hbox;
181 Gtk_VBox *vbox, *mini_vbox;
184 Gtk_RadioButton *radio1, *radio2;
186 Gtk_Adjustment *adjustment;
187 char *description = NULL, *s_value = NULL;
193 LDAP_OPT_CLIENT_CONTROLS,
197 // LDAP_OPT_ERROR_NUMBER,
198 // LDAP_OPT_ERROR_STRING,
200 LDAP_OPT_PROTOCOL_VERSION,
203 LDAP_OPT_SERVER_CONTROLS,
208 /* if (GTK_TREE_ITEM(this->gtkobj())->subtree == NULL) {
212 // debug("getting ldap options");
213 // vbox = new Gtk_VBox();
214 table = new Gtk_Table(10, 1, TRUE);
216 for (int i=0; i<10; i++) {
218 hbox = new Gtk_HBox(TRUE, 2);
219 hbox->border_width(2);
220 description = this->getOptDescription(things[i]);
221 label = new Gtk_Label(description);
222 label->set_justify(GTK_JUSTIFY_LEFT);
223 label->set_alignment(0, 0);
224 hbox->pack_start(*label);
226 switch (this->getOptType(things[i])) {
228 ldap_get_option(this->ld, things[i], &i_value);
229 debug("%s value %d\n", description, i_value);
230 sprintf(s_value, "%d", i_value);
231 label = new Gtk_Label(s_value);
232 label->set_justify(GTK_JUSTIFY_LEFT);
233 label->set_alignment(0, 0);
234 hbox->pack_end(*label);
238 ldap_get_option(this->ld, things[i], &s_value);
239 label = new Gtk_Label(s_value);
240 label->set_justify(GTK_JUSTIFY_LEFT);
241 label->set_alignment(0, 0);
242 hbox->pack_end(*label);
246 ldap_get_option(this->ld, things[i], &i_value);
247 radio1 = new Gtk_RadioButton(static_cast<GSList*>(0), "Enabled");
248 radio2 = new Gtk_RadioButton(*radio1, "Disabled");
249 if (i_value == 1) radio1->set_state(true);
250 else radio2->set_state(true);
251 mini_hbox = new Gtk_HBox(FALSE, 2);
252 mini_hbox->border_width(2);
253 mini_hbox->pack_start(*radio1);
255 mini_hbox->pack_end(*radio2);
257 hbox->pack_end(*mini_hbox);
261 ldap_get_option(this->ld, things[i], &i_value);
262 adjustment = new Gtk_Adjustment(i_value, 1.0, 20.0, 1.0, 1.0, 0.0);
263 scale = new Gtk_HScale(*adjustment);
264 scale->set_update_policy(GTK_UPDATE_CONTINUOUS);
265 scale->set_value_pos(GTK_POS_TOP);
266 scale->set_digits(0);
267 scale->set_draw_value(true);
268 hbox->pack_end(*scale);
272 #ifdef LDAP_API_INFO_VERSION
273 api.ldapai_info_version = LDAP_API_INFO_VERSION;
275 api.ldapai_info_version = 1;
277 if (ldap_get_option(this->ld, things[i], &api) != LDAP_SUCCESS) {
278 perror(this->getOptDescription(things[i]));
281 s_value = api.ldapai_vendor_name;
282 label = new Gtk_Label(s_value);
283 label->set_justify(GTK_JUSTIFY_LEFT);
284 label->set_alignment(0, 0);
285 hbox->pack_end(*label);
289 label = new Gtk_Label("Not implemented (yet)");
290 label->set_justify(GTK_JUSTIFY_LEFT);
291 label->set_alignment(0, 0);
292 hbox->pack_end(*label);
296 // hbox->pack_end(*label);
298 table->attach_defaults(*hbox, 0, 1, i, i+1);
301 table->border_width(2);
302 this->notebook = new Gtk_Frame("LDAP Options");
303 this->notebook->add(*table);
308 Gtk_Tree* Gtk_LdapServer::getSubtree() {
309 debug("Gtk_LdapServer::getSubtree()\n");
310 Gtk_LdapTree *tree, *subtree;
311 Gtk_LdapTreeItem *treeitem;
314 debug("this->hostname=%s\n", this->hostname);
315 debug("this->port=%i", this->port);
320 int len = this->databases->length();
321 debug("this->databases->length()=%i\n", len);
323 tree = new Gtk_LdapTree();
324 for (int i=0; i<len; i++) {
325 tok = strdup(this->databases->nth_data(i));
326 tok = strtok(tok, ":");
327 // c = strtok(NULL, " ");
328 c = strtok(NULL, "\0");
329 debug("database %i %s\n", i, c);
330 treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld);
331 subtree = treeitem->getSubtree(this->ld, 1);
332 debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
333 tree->append(*treeitem);
334 treeitem->set_subtree(*subtree);
338 // this->set_subtree(*tree);
339 debug("getTree() done\n");
343 void Gtk_LdapServer::show_impl() {
344 debug("%s showed\n", this->hostname);
345 Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
346 sig->show(GTK_WIDGET(gtkobj()));
349 void Gtk_LdapServer::select_impl() {
350 debug("%s selected\n", this->hostname);
351 Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
352 if (!sig->select) return;
354 sig->select(GTK_ITEM(gtkobj()));
357 void Gtk_LdapServer::collapse_impl() {
358 debug("%s collapsed\n", this->hostname);
359 Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
360 if (!sig->collapse) return;
361 sig->collapse(GTK_TREE_ITEM(gtkobj()));
362 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
365 void Gtk_LdapServer::expand_impl() {
366 debug("%s expanded\n", this->hostname);
367 Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
368 if (!sig->expand) return;
369 sig->expand(GTK_TREE_ITEM(gtkobj()));
371 // t = new Gtk_Tree(GTK_TREE(GTK_TREE_ITEM(this->gtkobj())->subtree));
372 // bool vis = t->visible();
373 // if (vis == false) {
374 // gtk_widget_show(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
375 // cout << this->dn << " expanded" << endl;
378 // gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
379 // cout << this->dn << " collapsed" << endl;