Handle hostnames with upper-case letters
[webmin.git] / ldap-client / popup_browser.cgi
1 #!/usr/local/bin/perl
2 # Show the LDAP tree in a popup browser window, for selecting something
3
4 $trust_unknown_referers = 1;
5 require './ldap-client-lib.pl';
6 &popup_header($text{'browser_title'});
7 &ReadParse();
8
9 # Connect to LDAP server, or die trying
10 $ldap = &ldap_connect(1);
11 if (!ref($ldap)) {
12         print &text('browser_econn', $ldap),"<p>\n";
13         &popup_footer();
14         exit;
15         }
16
17 # Work out the base (current navigation level)
18 if ($in{'parent'}) {
19         $base = $in{'parent'};
20         }
21 elsif (!$in{'base'}) {
22         $conf = &get_config();
23         $base = &find_value("base", $conf);
24         }
25 else {
26         $base = $in{'base'};
27         }
28
29 # Javascript to update original field
30 print "<script>\n";
31 print "function ldap_select(f)\n";
32 print "{\n";
33 print "top.opener.ifield.value = f;\n";
34 print "top.close();\n";
35 print "window.close();\n";
36 print "return false;\n";
37 print "}\n";
38 print "</script>\n";
39
40 # Find the actual base object
41 $rv2 = $ldap->search(base => $base,
42                      filter => '(objectClass=*)',
43                      score => 'base');
44 if (!$rv2->code) {
45         ($bo) = $rv2->all_entries;
46         ($top) = grep { $_ eq "top" } $bo->get_value("objectClass");
47         }
48
49 # Show current base (with option to change), and parent button
50 print &ui_form_start("popup_browser.cgi"),"\n";
51 print &ui_hidden("node", $in{'node'}),"\n";
52 print "<b>$text{'browser_base'}</b>\n";
53 print &ui_textbox("base", $base, 40)," ",&ui_submit($text{'browser_ok'}),"\n";
54 $parent = $base;
55 $parent =~ s/^[^,]+,\s*//;
56
57 # Show the OK button only if the object type is appropriatye
58 if ($in{'node'} == 0 && $top ||
59     $in{'node'} == 1 && !$top ||
60     $in{'node'} == 2) {
61         print "<input type=button onClick='return ldap_select(\"".
62               &quote_escape($base, '"'),"\")' ",
63               "value='$text{'browser_sel'}'>\n";
64         }
65 print &ui_form_end();
66
67 # Find sub-objects
68 $rv = $ldap->search(base => $base,
69                     filter => '(objectClass=*)',
70                     scope => 'one');
71 if ($rv->code) {
72         # Search failed
73         print &text('browser_esearch', $rv->error),"<p>\n";
74         &popup_footer();
75         exit;
76         }
77
78 print "<table width=100%>\n";
79 if ($parent =~ /\S/) {
80         print "<tr> <td><i><a href='popup_browser.cgi?node=".
81               &urlize($in{'node'})."&base=",
82               &urlize($parent),"'><img src=images/up.gif border=0> ",
83               &html_escape($parent),"</a></td> </tr>\n";
84         }
85 if ($rv->all_entries) {
86         # If this object has sub-objects, show them
87         foreach $dn (sort { lc($a->dn()) cmp lc($b->dn()) } $rv->all_entries) {
88                 print "<tr> <td><a href='popup_browser.cgi?node=".
89                       &urlize($in{'node'}),"&",
90                       "base=".&urlize($dn->dn()).
91                       "'><img src=images/open.gif border=0>",
92                       " ",&html_escape($dn->dn()),"</a></td> </tr>\n";
93                 }
94         }
95 else {
96         # Show attributes
97         foreach $a (sort { lc($a) cmp lc($b) } $bo->attributes()) {
98                 @v = $bo->get_value($a);
99                 print "<tr> <td>$a</td> <td>:</td> <td>",
100                       join(" , ", @v),"</td> </tr>\n";
101                 }
102         }
103 print "</table>\n";
104
105 &popup_footer();