Handle hostnames with upper-case letters
[webmin.git] / ldap-client / browser.cgi
1 #!/usr/local/bin/perl
2 # Show the LDAP server's data tree
3
4 require './ldap-client-lib.pl';
5 &ui_print_header(undef, $text{'browser_title'}, "", "browser");
6 &ReadParse();
7
8 # Connect to LDAP server, or die trying
9 $ldap = &ldap_connect(1);
10 if (!ref($ldap)) {
11         print &text('browser_econn', $ldap),"<p>\n";
12         &ui_print_footer("", $text{'index_return'});
13         exit;
14         }
15
16 # Work out the base (current navigation level)
17 if ($in{'goparent'}) {
18         $base = $in{'parent'};
19         }
20 elsif (!$in{'base'}) {
21         $conf = &get_config();
22         $base = &find_value("base", $conf);
23         }
24 else {
25         $base = $in{'base'};
26         }
27
28 # Show current base (with option to change), and parent button
29 print &ui_form_start("browser.cgi"),"\n";
30 print "<b>$text{'browser_base'}</b>\n";
31 print &ui_textbox("base", $base, 60)," ",&ui_submit($text{'browser_ok'}),"\n";
32 $parent = $base;
33 $parent =~ s/^[^,]+,\s*//;
34 if ($parent =~ /\S/) {
35         print &ui_hidden("parent", $parent),"\n";
36         print "&nbsp;&nbsp;\n";
37         print &ui_submit($text{'browser_parent'}, "goparent"),"\n";
38         }
39 print &ui_form_end();
40
41 # Show list of objects under the base, and its attributes
42 $rv = $ldap->search(base => $base,
43                     filter => '(objectClass=*)',
44                     scope => 'one');
45 if ($rv->code) {
46         # Search failed
47         print &text('browser_esearch', $rv->error),"<p>\n";
48         }
49 else {
50         print "<table width=100%><tr>\n";
51         print "<td width=50%><b>$text{'browser_subs'}</b></td>\n";
52         print "<td width=50%><b>$text{'browser_attrs'}</b></td>\n";
53         print "</tr> <tr><td width=50% valign=top>\n";
54
55         # Show sub-objects
56         foreach $dn (sort { lc($a->dn()) cmp lc($b->dn()) } $rv->all_entries) {
57                 print "<a href='browser.cgi?base=".&urlize($dn->dn())."'>".
58                       &html_escape($dn->dn())."</a><br>\n";
59                 }
60         if (!$rv->all_entries) {
61                 print "<i>$text{'browser_none'}</i><br>\n";
62                 }
63         
64         print "</td><td width=50% valign=top>\n";
65         print "<table>\n";
66
67         # Show attributes
68         $rv2 = $ldap->search(base => $base,
69                              filter => '(objectClass=*)',
70                              score => 'base');
71         ($bo) = $rv2->all_entries;
72         foreach $a (sort { lc($a) cmp lc($b) } $bo->attributes()) {
73                 @v = $bo->get_value($a);
74                 print "<tr> <td>$a</td> <td>:</td> <td>",
75                       join(" , ", @v),"</td> </tr>\n";
76                 }
77         if (!$bo->attributes()) {
78                 print "<tr> <td><i>$text{'browser_none'}</i></td> </tr>\n";
79                 }
80         print "</table>\n";
81
82         print "</td></tr></table>\n";
83         }
84
85 $ldap->disconnect();
86 &ui_print_footer("", $text{'index_return'});
87