Handle hostnames with upper-case letters
[webmin.git] / wuftpd / edit_acl.cgi
1 #!/usr/local/bin/perl
2 # edit_acl.cgi
3 # Display access control options
4
5 require './wuftpd-lib.pl';
6 &ui_print_header(undef, $text{'acl_title'}, "", "acl");
7
8 $conf = &get_ftpaccess();
9 @class = &find_value("class", $conf);
10
11 print "<form action=save_acl.cgi>\n";
12 print "<table border width=100%>\n";
13 print "<tr $tb> <td><b>$text{'acl_header'}</b></td> </tr>\n";
14 print "<tr $cb> <td><table width=100%>\n";
15
16 # Display addresses to deny from
17 @deny = ( &find_value("deny", $conf), [ ] );
18 print "<tr> <td valign=top><b>$text{'acl_deny'}</b></td>\n";
19 print "<td colspan=3><table border>\n";
20 print "<tr $tb> <td><b>$text{'acl_daddrs'}</b></td>\n",
21       "<td><b>$text{'acl_dmsg'}</b></td> </tr>\n";
22 $i = 0;
23 foreach $d (@deny) {
24         print "<tr $cb>\n";
25         print "<td><input name=daddrs_$i size=20 value='$d->[0]'></td>\n";
26         print "<td><input name=dmsg_$i size=35 value='$d->[1]'></td>\n";
27         print "</tr>\n";
28         $i++;
29         }
30 print "</table></td> </tr>\n";
31 print "<tr> <td colspan=4><hr></td> </tr>\n";
32
33 # Display concurrent login limits
34 @limit = ( &find_value("limit", $conf), [ ] );
35 print "<tr> <td valign=top><b>$text{'acl_limit'}</b></td>\n";
36 print "<td colspan=3><table border>\n";
37 print "<tr $tb> <td><b>$text{'acl_class'}</b></td>\n",
38       "<td><b>$text{'acl_n'}</b></td>\n",
39       "<td><b>$text{'acl_times'}</b></td>\n",
40       "<td><b>$text{'acl_lmsg'}</b></td> </tr>\n";
41 $i = 0;
42 foreach $l (@limit) {
43         print "<tr $cb>\n";
44         print "<td><select name=lclass_$i>\n";
45         printf "<option value='' %s>&nbsp;\n", $l->[0] ? '' : 'checked';
46         foreach $c (@class) {
47                 printf "<option %s>%s\n",
48                         $l->[0] eq $c->[0] ? 'selected' : '', $c->[0];
49                 }
50         print "</select></td>\n";
51
52         printf "<td><input type=radio name=ln_def_$i value=1 %s> %s\n",
53                 $l->[1] =~ /^\d+$/ ? '' : 'checked', $text{'acl_unlimited'};
54         printf "<input type=radio name=ln_def_$i value=0 %s>\n",
55                 $l->[1] =~ /^\d+$/ ? 'checked' : '';
56         printf "<input name=ln_$i size=8 value='%s'></td>\n",
57                 $l->[1] =~ /^\d+$/ ? $l->[1] : '';
58
59         printf "<td><input type=radio name=ltimes_def_$i value=1 %s> %s\n",
60                 lc($l->[2]) eq 'any' ? 'checked' : '', $text{'acl_any'};
61         printf "<input type=radio name=ltimes_def_$i value=0 %s>\n",
62                 lc($l->[2]) eq 'any' ? '' : 'checked';
63         printf "<input name=ltimes_$i size=10 value='%s'></td>\n",
64                 lc($l->[2]) eq 'any' ? '' : $l->[2];
65
66         print "<td><input name=lmsg_$i size=20 value='$l->[3]'></td>\n";
67         print "</tr>\n";
68         $i++;
69         }
70 print "</table></td> </tr>\n";
71 print "<tr> <td colspan=4><hr></td> </tr>\n";
72
73 # Display file and byte limits
74 @fblimit = sort { $a->{'line'} <=> $b->{'line'} }
75                 ( &find("file-limit", $conf), &find("data-limit", $conf) );
76 push(@fblimit, { });
77 print "<tr> <td valign=top><b>$text{'acl_file'}</b></td>\n";
78 print "<td colspan=3><table border>\n";
79 print "<tr $tb> <td><b>$text{'acl_fblimit'}</b></td>\n",
80       "<td><b>$text{'acl_inout'}</b></td>\n",
81       "<td><b>$text{'acl_raw'}</b></td>\n",
82       "<td><b>$text{'acl_count'}</b></td>\n",
83       "<td><b>$text{'acl_class'}</b></td> </tr>\n";
84 $i = 0;
85 foreach $l (@fblimit) {
86         $f = $l->{'values'};
87         splice(@$f, 0, 0, '0') if ($f->[0] ne 'raw');
88         print "<tr $cb>\n";
89         print "<td><select name=fblimit_$i>\n";
90         printf "<option value='' %s>&nbsp;\n",
91                 $l->{'name'} ? '' : 'selected';
92         printf "<option value=file-limit %s>%s\n",
93                 $l->{'name'} eq 'file-limit' ? 'selected' : '',
94                 $text{'acl_flimit'};
95         printf "<option value=byte-limit %s>%s\n",
96                 $l->{'name'} eq 'byte-limit' ? 'selected' : '',
97                 $text{'acl_blimit'};
98         print "</select></td>\n";
99
100         print "<td><select name=fbinout_$i>\n";
101         printf "<option value=total %s>%s\n",
102                 $f->[1] eq 'total' ? 'selected' : '', $text{'acl_total'};
103         printf "<option value=in %s>%s\n",
104                 $f->[1] eq 'in' ? 'selected' : '', $text{'acl_in'};
105         printf "<option value=out %s>%s\n",
106                 $f->[1] eq 'out' ? 'selected' : '', $text{'acl_out'};
107         print "</select></td>\n";
108
109         printf "<td><input type=radio name=fbraw_$i value=0 %s> %s\n",
110                 $f->[0] eq 'raw' ? '' : 'checked', $text{'yes'};
111         printf "<input type=radio name=fbraw_$i value=1 %s> %s</td>\n",
112                 $f->[0] eq 'raw' ? 'checked' : '', $text{'no'};
113
114         print "<td><input name=fbcount_$i size=10 value='$f->[2]'></td>\n";
115
116         print "<td><select name=fbclass_$i>\n";
117         printf "<option value='' %s> %s\n",
118                 $f->[3] ? '' : 'selected', $text{'acl_all'};
119         foreach $c (@class) {
120                 printf "<option %s>%s\n",
121                         $f->[3] eq $c->[0] ? 'selected' : '', $c->[0];
122                 }
123         print "</select></td>\n";
124         print "</tr>\n";
125         $i++;
126         }
127 print "</table></td> </tr>\n";
128 print "<tr> <td colspan=4><hr></td> </tr>\n";
129
130 # File access controls
131 @noret = ( &find_value("noretrieve", $conf), [ ] );
132 print "<tr> <td valign=top><b>$text{'acl_noret'}</b></td>\n";
133 print "<td colspan=3><table border>\n";
134 print "<tr $tb> <td><b>$text{'acl_nfiles'}</b></td>\n",
135       "<td><b>$text{'acl_nrel'}</b></td>\n",
136       "<td><b>$text{'acl_nclass'}</b></td> </tr>\n";
137 $i = 0;
138 foreach $n (@noret) {
139         local (@f, %c);
140         foreach $nn (@$n) {
141                 if ($nn =~ /^class=(\S+)/) { $c{$1}++; }
142                 elsif ($nn !~ /^(absolute|relative)$/) { push(@f, $nn); }
143                 }
144         print "<tr $cb>\n";
145         printf "<td><input name=nfiles_$i size=30 value='%s'></td>\n",
146                 join(" ", @f);
147         printf "<td><input type=radio name=nrel_$i value=1 %s> %s\n",
148                 $n->[0] eq 'relative' ? 'checked' : '', $text{'yes'};
149         printf "<input type=radio name=nrel_$i value=0 %s> %s</td>\n",
150                 $n->[0] eq 'relative' ? '' : 'checked', $text{'no'};
151         print "<td>\n";
152         foreach $c (@class) {
153                 printf "<input type=checkbox name=nclass_$i value=%s %s> %s\n",
154                         $c->[0], !%c || $c{$c->[0]} ? 'checked' : '', $c->[0];
155                 }
156         print "</tr>\n";
157         $i++;
158         }
159 print "</table></td> </tr>\n";
160
161 @allowret = ( &find_value("allow-retrieve", $conf), [ ] );
162 print "<tr> <td valign=top><b>$text{'acl_allowret'}</b></td>\n";
163 print "<td colspan=3><table border>\n";
164 print "<tr $tb> <td><b>$text{'acl_afiles'}</b></td>\n",
165       "<td><b>$text{'acl_arel'}</b></td>\n",
166       "<td><b>$text{'acl_aclass'}</b></td> </tr>\n";
167 $i = 0;
168 foreach $n (@allowret) {
169         local (@f, %c);
170         foreach $nn (@$n) {
171                 if ($nn =~ /^class=(\S+)/) { $c{$1}++; }
172                 elsif ($nn !~ /^(absolute|relative)$/) { push(@f, $nn); }
173                 }
174         print "<tr $cb>\n";
175         printf "<td><input name=afiles_$i size=30 value='%s'></td>\n",
176                 join(" ", @f);
177         printf "<td><input type=radio name=arel_$i value=1 %s> %s\n",
178                 $n->[0] eq 'relative' ? 'checked' : '', $text{'yes'};
179         printf "<input type=radio name=arel_$i value=0 %s> %s</td>\n",
180                 $n->[0] eq 'relative' ? '' : 'checked', $text{'no'};
181         print "<td>\n";
182         foreach $c (@class) {
183                 printf "<input type=checkbox name=aclass_$i value=%s %s> %s\n",
184                         $c->[0], !%c || $c{$c->[0]} ? 'checked' : '', $c->[0];
185                 }
186         print "</tr>\n";
187         $i++;
188         }
189 print "</table></td> </tr>\n";
190 print "<tr> <td colspan=4><hr></td> </tr>\n";
191
192 # Display time-limit options
193 foreach $l (&find_value("limit-time", $conf)) {
194         if ($l->[0] eq '*') {
195                 $limit{'anonymous'} = $limit{'guest'} = $l->[1];
196                 }
197         else {
198                 $limit{$l->[0]} = $l->[1];
199                 }
200         }
201 print "<tr> <td><b>$text{'acl_alimit'}</b></td>\n";
202 printf "<td><input type=radio name=alimit_def value=1 %s> %s\n",
203         $limit{'anonymous'} ? '' : 'checked', $text{'acl_unlimited'};
204 printf "<input type=radio name=alimit_def value=0 %s>\n",
205         $limit{'anonymous'} ? 'checked' : '';
206 printf "<input name=alimit size=6 value='%s'> %s</td>\n",
207         $limit{'anonymous'}, $text{'acl_mins'};
208 print "<td><b>$text{'acl_glimit'}</b></td>\n";
209 printf "<td><input type=radio name=glimit_def value=1 %s> %s\n",
210         $limit{'guest'} ? '' : 'checked', $text{'acl_unlimited'};
211 printf "<input type=radio name=glimit_def value=0 %s>\n",
212         $limit{'guest'} ? 'checked' : '';
213 printf "<input name=glimit size=6 value='%s'> %s</td> </tr>\n",
214         $limit{'guest'}, $text{'acl_mins'};
215
216 # Other security options
217 $lf = &find_value('loginfails', $conf);
218 print "<tr> <td><b>$text{'acl_fails'}</b></td>\n";
219 printf "<td><input type=radio name=fails_def value=1 %s> %s\n",
220         $lf ? '' : 'checked', $text{'default'};
221 printf "<input type=radio name=fails_def value=0 %s>\n",
222         $lf ? 'checked' : '';
223 print "<input name=fails size=6 value='$lf->[0]'></td>\n";
224
225 $pr = &find_value('private', $conf); 
226 print "<td><b>$text{'acl_private'}</b></td>\n";
227 printf "<td><input type=radio name=private value=yes %s> %s\n",
228         $pr->[0] eq 'yes' ? 'checked' : '', $text{'yes'};
229 printf "<input type=radio name=private value=no %s> %s</td> </tr>\n",
230         $pr->[0] eq 'yes' ? '' : 'checked',  $text{'no'};
231
232 print "</table></td></tr></table>\n";
233 print "<input type=submit value=\"$text{'save'}\"></form>\n";
234
235 &ui_print_footer("", $text{'index_return'});
236