Handle hostnames with upper-case letters
[webmin.git] / module_chooser.cgi
1 #!/usr/local/bin/perl
2 # This CGI generates the HTML for choosing a module or list of modules
3
4 BEGIN { push(@INC, ".."); };
5 use WebminCore;
6
7 $trust_unknown_referers = 1;
8 &init_config();
9 &ReadParse(undef, undef, 2);
10 %access = &get_module_acl();
11
12 if ($in{'multi'}) {
13         # selecting multiple modules
14         if ($in{'frame'} == 0) {
15                 # base frame
16                 &PrintHeader();
17                 print "<script>\n";
18                 @ul = split(/\s+/, $in{'module'});
19                 $len = @ul;
20                 print "sel = new Array($len);\n";
21                 print "selr = new Array($len);\n";
22                 for($i=0; $i<$len; $i++) {
23                         %minfo = &get_module_info($ul[$i]);
24                         if (%minfo) {
25                                 print "sel[$i] = \"$ul[$i]\";\n";
26                                 print "selr[$i] = \"$minfo{'desc'}\";\n";
27                                 }
28                         }
29                 print "</script>\n";
30                 print "<title>$text{'modules_title1'}</title>\n";
31                 print "<frameset cols='50%,50%'>\n";
32                 print "<frame src=\"/module_chooser.cgi?frame=1&multi=1\">\n";
33                 print "<frameset rows='*,50' frameborder=no>\n";
34                 print " <frame src=\"/module_chooser.cgi?frame=2&multi=1\">\n";
35                 print " <frame src=\"/module_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
36                 print "</frameset>\n";
37                 print "</frameset>\n";
38                 }
39         elsif ($in{'frame'} == 1) {
40                 # list of all modules to choose from
41                 &popup_header();
42                 print "<script>\n";
43                 print "function addmodule(u, r)\n";
44                 print "{\n";
45                 print "top.sel[top.sel.length] = u\n";
46                 print "top.selr[top.selr.length] = r\n";
47                 print "top.frames[1].location = top.frames[1].location\n";
48                 print "return false;\n";
49                 print "}\n";
50                 print "</script>\n";
51                 print "<font size=+1>$text{'modules_all'}</font>\n";
52                 print "<table width=100%>\n";
53                 foreach $m (&get_all_module_infos()) {
54                         if ($in{'module'} eq $m->{'dir'}) { print "<tr $cb>\n"; }
55                         else { print "<tr>\n"; }
56                         print "<td width=20%><a href=\"\" onClick='return addmodule(\"$m->{'dir'}\", \"$m->{'desc'}\")'>$m->{'dir'}</a></td>\n";
57                         print "<td>$m->{'desc'}</td> </tr>\n";
58                         }
59                 print "</table>\n";
60                 &popup_footer();
61                 }
62         elsif ($in{'frame'} == 2) {
63                 # show chosen modules
64                 &popup_header();
65                 print "<font size=+1>$text{'modules_sel'}</font>\n";
66                 print <<'EOF';
67 <table width=100%>
68 <script>
69 function sub(j)
70 {
71 sel2 = new Array(); selr2 = new Array();
72 for(k=0,l=0; k<top.sel.length; k++) {
73         if (k != j) {
74                 sel2[l] = top.sel[k];
75                 selr2[l] = top.selr[k];
76                 l++;
77                 }
78         }
79 top.sel = sel2; top.selr = selr2;
80 top.frames[1].location = top.frames[1].location;
81 return false;
82 }
83 for(i=0; i<top.sel.length; i++) {
84         document.write("<tr>\n");
85         document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
86         document.write("<td>"+top.selr[i]+"</td>\n");
87         }
88 </script>
89 </table>
90 EOF
91                 &popup_footer();
92                 }
93         elsif ($in{'frame'} == 3) {
94                 # output OK and Cancel buttons
95                 &popup_header();
96                 print "<script>\n";
97                 print "function qjoin(l)\n";
98                 print "{\n";
99                 print "rv = \"\";\n";
100                 print "for(i=0; i<l.length; i++) {\n";
101                 print "    if (rv != '') rv += ' ';\n";
102                 print "    if (l[i].indexOf(' ') < 0) rv += l[i];\n";
103                 print "    else rv += '\"'+l[i]+'\"'\n";
104                 print "    }\n";
105                 print "return rv;\n";
106                 print "}\n";
107                 print "</script>\n";
108                 print "<form>\n";
109                 print "<input type=button value=\"$text{'modules_ok'}\" ",
110                       "onClick='top.opener.ifield.value = qjoin(top.sel); ",
111                       "top.close()'>\n";
112                 print "<input type=button value=\"$text{'modules_cancel'}\" ",
113                       "onClick='top.close()'>\n";
114                 print "&nbsp;&nbsp;<input type=button value=\"$text{'modules_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
115                 print "</form>\n";
116                 &popup_footer();
117                 }
118         }
119 else {
120         # selecting just one module .. display a list of all modules to
121         # choose from
122         &popup_header($text{'modules_title2'});
123         print "<script>\n";
124         print "function select(f)\n";
125         print "{\n";
126         print "top.opener.ifield.value = f;\n";
127         print "top.close();\n";
128         print "return false;\n";
129         print "}\n";
130         print "</script>\n";
131         print "<table width=100%>\n";
132         foreach $m (&get_all_module_infos()) {
133                 if ($in{'user'} eq $m->{'dir'}) { print "<tr $cb>\n"; }
134                 else { print "<tr>\n"; }
135                 print "<td width=20%><a href=\"\" onClick='return select(\"$m->{'dir'}\")'>$m->{'dir'}</a></td>\n";
136                 print "<td>$m->{'dir'}</td> </tr>\n";
137                 }
138         print "</table>\n";
139         &popup_footer();
140         }
141
142