Handle hostnames with upper-case letters
[webmin.git] / usermin / edit_configs.cgi.bak
1 #!/usr/local/bin/perl
2 # edit_configs.cgi
3 # Display all usermin modules and the config for one
4
5 require './usermin-lib.pl';
6 &ReadParse();
7 &header($text{'configs_title2'}, "");
8 &get_usermin_miniserv_config(\%miniserv);
9
10 if (-r "$miniserv{'root'}/$in{'mod'}/config.info") {
11         # Display config form for the module
12         %minfo = &get_usermin_module_info($in{'mod'});
13         print "<hr>\n";
14         print "<form action=\"save_configs.cgi\">\n";
15         print "<input type=hidden name=mod value=\"$in{'mod'}\">\n";
16         print "<table border>\n";
17         print "<tr $tb> <td><b>",&text('config_header', $minfo{'desc'}),
18               "</b></td> </tr>\n";
19         print "<tr $cb> <td><table width=100%>\n";
20         &read_file("$config{'usermin_dir'}/$in{'mod'}/config", \%config);
21
22         # Use config.info to create config inputs
23         &read_file("$miniserv{'root'}/$in{'mod'}/config.info",
24                    \%info, \@info_order);
25         %einfo = %info;
26         foreach $o (@lang_order_list) {
27                 &read_file("$miniserv{'root'}/$in{'mod'}/config.info.$o",
28                            \%info, \@info_order);
29                 }
30         @info_order = &unique(@info_order);
31
32         foreach $c (@info_order) {
33                 @p = split(/,/, $info{$c});
34                 @ep = split(/,/, $einfo{$c});
35                 if (scalar(@ep) > scalar(@p)) {
36                         push(@p, @ep[scalar(@p) .. @ep-1]);
37                         }
38                 if ($p[1] == 11) {
39                         print "<tr><td colspan=3 $tb>\n" ;
40                         print "\t<b>" . $p[0] . "</b>\n</td></tr>\n" ;
41                         next;
42                         }
43                 print "<tr> <td valign=top><b>$p[0]</b></td>\n";
44                 print "<td nowrap>\n";
45                 $qw = $config{$c} =~ /'/ ? '"' : "'";
46                 if ($p[1] == 0) {
47                         $size = $p[2] ? "size=$p[2]" : "size=40";
48                         $max = $p[3] ? "maxlength=$p[3]" : "";
49                         print "<input name=\"$c\" $size $max value=$qw$config{$c}$qw>\n";
50                         }
51                 elsif ($p[1] == 1) {
52                         for($i=2; $i<@p; $i++) {
53                                 $p[$i] =~ /^(\S*)\-(.*)$/;
54                                 printf "<input type=radio name=\"$c\" value='$1' %s>\n",
55                                         $config{$c} eq $1 ? "checked" : "";
56                                 print "$2 &nbsp;&nbsp;\n";
57                                 }
58                         }
59                 elsif ($p[1] == 2) {
60                         local %sel;
61                         map { $sel{$_}++ } split(/,/, $config{$c});
62                         print "<select name=\"$c\" size=4 multiple>\n";
63                         for($i=2; $i<@p; $i++) {
64                                 $p[$i] =~ /^(\S+)\-(.*)$/;
65                                 printf "<option value=\"$1\" %s>$2\n",
66                                         $sel{$1} ? "selected" : "";
67                                 }
68                         print "</select>\n";
69                         }
70                 elsif ($p[1] == 3) {
71                         $none = $p[2] ? $p[2] : $text{'config_none'};
72                         printf "<input type=radio name=\"%s_none\" value=1 %s> $none\n",
73                                 $c, $config{$c} eq "" ? "checked" : "";
74                         print "&nbsp;&nbsp;\n";
75                         printf "<input type=radio name=\"%s_none\" value=0 %s>\n",
76                                 $c, $config{$c} eq "" ? "" : "checked";
77                         print "<input name=\"$c\" size=20 value=$qw$config{$c}$qw>\n";
78                         }
79                 elsif ($p[1] == 4) {
80                         print "<select name=\"$c\">\n";
81                         for($i=2; $i<@p; $i++) {
82                                 $p[$i] =~ /^(\S+)\-(.*)$/;
83                                 printf "<option value=\"$1\" %s>$2\n",
84                                         $config{$c} eq $1 ? "selected" : "";
85                                 }
86                         print "</select>\n";
87                         }
88                 elsif ($p[1] == 5) {
89                         if ($p[2]) {
90                                 printf
91                                    "<input type=radio name=${c}_def value=1 %s>$p[2]\n",
92                                    $config{$c} eq "" ? "checked" : "";
93                                 printf "<input type=radio name=${c}_def value=0 %s>\n",
94                                    $config{$c} eq "" ? "" : "checked";
95                                 }
96                         print &unix_user_input($c, $config{$c});
97                         }
98                 elsif ($p[1] == 6) {
99                         if ($p[2]) {
100                                 printf
101                                    "<input type=radio name=${c}_def value=1 %s>$p[2]\n",
102                                    $config{$c} eq "" ? "checked" : "";
103                                 printf "<input type=radio name=${c}_def value=0 %s>\n",
104                                    $config{$c} eq "" ? "" : "checked";
105                                 }
106                         print &unix_group_input($c, $config{$c});
107                         }
108                 elsif ($p[1] == 7) {
109                         print "<input name=\"$c\" size=40 value=$qw$config{$c}$qw> ",
110                               &file_chooser_button($c, 1);
111                         }
112                 elsif ($p[1] == 8) {
113                         print "<input name=\"$c\" size=40 value=$qw$config{$c}$qw> ",
114                               &file_chooser_button($c, 0);
115                         }
116                 elsif ($p[1] == 9) {
117                         local $cols = $p[2] ? $p[2] : 40;
118                         local $rows = $p[3] ? $p[3] : 5;
119                         local $sp = $p[4] ? eval "\"$p[4]\"" : " ";
120                         print "<textarea name=\"$c\" rows=$rows cols=$cols>",
121                                 join("\n", split(/$sp/, $config{$c})),
122                                 "</textarea>\n";
123                         }
124                 elsif ($p[1] == 10) {
125                         local $fv = $config{$c};
126                         for($i=2; $i<@p; $i++) {
127                                 $p[$i] =~ /^(\S*)\-(.*)$/;
128                                 printf "<input type=radio name=\"$c\" value=\"$1\" %s>\n",
129                                         $config{$c} eq $1 ? "checked" : "";
130                                 print "$2 &nbsp;&nbsp;\n";
131                                 $fv = undef if ($config{$c} eq $1);
132                                 }
133                         printf "<input type=radio name=\"$c\" value=free %s>\n",
134                                 $fv ? "checked" : "";
135                         print "<input name=\"${c}_free\" value='$fv'>\n";
136                         }
137                 print "</td> </tr>\n";
138                 }
139         print "</table></td></tr></table>\n";
140         print "<input type=submit value=\"$text{'save'}\"></form>\n";
141         }
142
143 if (-r "$miniserv{'root'}/$in{'mod'}/uconfig.info") {
144         # Display default user config form for the module
145         %minfo = &get_usermin_module_info($in{'mod'});
146         print "<hr>\n";
147         print "<form action=\"save_uconfigs.cgi\">\n";
148         print "<input type=hidden name=mod value=\"$in{'mod'}\">\n";
149         print "<table border>\n";
150         print "<tr $tb> <td><b>",&text('configs_uheader', $minfo{'desc'}),
151               "</b></td> </tr>\n";
152         print "<tr $cb> <td><table width=100%>\n";
153         &read_file("$miniserv{'root'}/$in{'mod'}/defaultuconfig", \%uconfig);
154         &read_file("$config{'usermin_dir'}/$in{'mod'}/uconfig", \%uconfig);
155
156         # Use config.info to create config inputs
157         &read_file("$miniserv{'root'}/$in{'mod'}/uconfig.info",
158                    \%uinfo, \@uinfo_order);
159         %einfo = %uinfo;
160         &read_file("$miniserv{'root'}/$in{'mod'}/uconfig.info.$current_lang",
161                    \%uinfo, \@uinfo_order);
162         @uinfo_order = &unique(@uinfo_order);
163
164         foreach $c (@uinfo_order) {
165                 @p = split(/,/, $uinfo{$c});
166                 @ep = split(/,/, $einfo{$c});
167                 if (scalar(@ep) > scalar(@p)) {
168                         push(@p, @ep[scalar(@p) .. @ep-1]);
169                         }
170                 if ($p[1] == 11) {
171                         print "<tr><td colspan=3 $tb>\n" ;
172                         print "\t<b>" . $p[0] . "</b>\n</td></tr>\n" ;
173                         next;
174                         }
175                 print "<tr> <td valign=top><b>$p[0]</b></td>\n";
176                 print "<td nowrap>\n";
177                 $qw = $uconfig{$c} =~ /'/ ? '"' : "'";
178                 if ($p[1] == 0) {
179                         $size = $p[2] ? "size=$p[2]" : "size=40";
180                         $max = $p[3] ? "maxlength=$p[3]" : "";
181                         print "<input name=\"$c\" $size $max value=$qw$uconfig{$c}$qw>\n";
182                         }
183                 elsif ($p[1] == 1) {
184                         for($i=2; $i<@p; $i++) {
185                                 $p[$i] =~ /^(\S*)\-(.*)$/;
186                                 printf "<input type=radio name=\"$c\" value='$1' %s>\n",
187                                         $uconfig{$c} eq $1 ? "checked" : "";
188                                 print "$2 &nbsp;&nbsp;\n";
189                                 }
190                         }
191                 elsif ($p[1] == 2) {
192                         local %sel;
193                         map { $sel{$_}++ } split(/,/, $uconfig{$c});
194                         print "<select name=\"$c\" size=4 multiple>\n";
195                         for($i=2; $i<@p; $i++) {
196                                 $p[$i] =~ /^(\S+)\-(.*)$/;
197                                 printf "<option value=\"$1\" %s>$2\n",
198                                         $sel{$1} ? "selected" : "";
199                                 }
200                         print "</select>\n";
201                         }
202                 elsif ($p[1] == 3) {
203                         $none = $p[2] ? $p[2] : $text{'config_none'};
204                         printf "<input type=radio name=\"%s_none\" value=1 %s> $none\n",
205                                 $c, $uconfig{$c} eq "" ? "checked" : "";
206                         print "&nbsp;&nbsp;\n";
207                         printf "<input type=radio name=\"%s_none\" value=0 %s>\n",
208                                 $c, $uconfig{$c} eq "" ? "" : "checked";
209                         print "<input name=\"$c\" size=20 value=$qw$uconfig{$c}$qw>\n";
210                         }
211                 elsif ($p[1] == 4) {
212                         print "<select name=\"$c\">\n";
213                         for($i=2; $i<@p; $i++) {
214                                 $p[$i] =~ /^(\S+)\-(.*)$/;
215                                 printf "<option value=\"$1\" %s>$2\n",
216                                         $uconfig{$c} eq $1 ? "selected" : "";
217                                 }
218                         print "</select>\n";
219                         }
220                 elsif ($p[1] == 5) {
221                         if ($p[2]) {
222                                 printf
223                                    "<input type=radio name=${c}_def value=1 %s>$p[2]\n",
224                                    $uconfig{$c} eq "" ? "checked" : "";
225                                 printf "<input type=radio name=${c}_def value=0 %s>\n",
226                                    $uconfig{$c} eq "" ? "" : "checked";
227                                 }
228                         print &unix_user_input($c, $uconfig{$c});
229                         }
230                 elsif ($p[1] == 6) {
231                         if ($p[2]) {
232                                 printf
233                                    "<input type=radio name=${c}_def value=1 %s>$p[2]\n",
234                                    $uconfig{$c} eq "" ? "checked" : "";
235                                 printf "<input type=radio name=${c}_def value=0 %s>\n",
236                                    $uconfig{$c} eq "" ? "" : "checked";
237                                 }
238                         print &unix_group_input($c, $uconfig{$c});
239                         }
240                 elsif ($p[1] == 7) {
241                         print "<input name=\"$c\" size=40 value=$qw$uconfig{$c}$qw> ",
242                               &file_chooser_button($c, 1);
243                         }
244                 elsif ($p[1] == 8) {
245                         print "<input name=\"$c\" size=40 value=$qw$uconfig{$c}$qw> ",
246                               &file_chooser_button($c, 0);
247                         }
248                 elsif ($p[1] == 9) {
249                         local $cols = $p[2] ? $p[2] : 40;
250                         local $rows = $p[3] ? $p[3] : 5;
251                         print "<textarea name=\"$c\" rows=$rows cols=$cols>",
252                                 join("\n", split(/\s+/, $uconfig{$c})),
253                                 "</textarea>\n";
254                         }
255                 elsif ($p[1] == 10) {
256                         local $fv = $uconfig{$c};
257                         for($i=2; $i<@p; $i++) {
258                                 $p[$i] =~ /^(\S*)\-(.*)$/;
259                                 printf "<input type=radio name=\"$c\" value=$1 %s>\n",
260                                         $uconfig{$c} eq $1 ? "checked" : "";
261                                 print "$2 &nbsp;&nbsp;\n";
262                                 $fv = undef if ($uconfig{$c} eq $1);
263                                 }
264                         printf "<input type=radio name=\"$c\" value=free %s>\n",
265                                 $fv ? "checked" : "";
266                         print "<input name=\"${c}_free\" value='$fv'>\n";
267                         }
268                 print "</td> </tr>\n";
269                 }
270         print "</table></td></tr></table>\n";
271         print "<input type=submit value=\"$text{'save'}\"></form>\n";
272         }
273
274 print "<hr>\n";
275 &footer("list_configs.cgi", $text{'configs_return'});
276