Handle hostnames with upper-case letters
[webmin.git] / squid / edit_cache.cgi
1 #!/usr/local/bin/perl
2 # edit_cache.cgi
3 # A form for editing cache options
4
5 require './squid-lib.pl';
6 $access{'copts'} || &error($text{'ec_ecannot'});
7 &ui_print_header(undef, $text{'ec_header'}, "", "edit_cache", 0, 0, 0, &restart_button());
8 $conf = &get_config();
9
10 print "<form action=save_cache.cgi>\n";
11 print "<table border width=100%>\n";
12 print "<tr $tb> <td><b>$text{'ec_cro'}</b></td> </tr>\n";
13 print "<tr $cb> <td><table width=100%>\n";
14
15 print "<tr>\n";
16 @dirs = &find_config("cache_dir", $conf);
17 print "<td valign=top><b>$text{'ec_cdirs'}</b></td> <td colspan=3>\n";
18 printf "<input type=radio name=cache_dir_def value=1 %s> $text{'ec_default'} ($config{'cache_dir'})\n",
19         @dirs ? "" : "checked";
20 printf "<input type=radio name=cache_dir_def value=0 %s> $text{'ec_listed'}<br>\n",
21         @dirs ? "checked" : "";
22 print "<table border>\n";
23 if ($squid_version >= 2) {
24         print "<tr $tb> <td><b>$text{'ec_directory'}</b></td>\n";
25         if ($squid_version >= 2.3) {
26                 print "<td><b>$text{'ec_type'}</b></td>\n";
27                 }
28         print "<td><b>$text{'ec_size'}</b></td>\n";
29         print "<td><b>$text{'ec_1dirs'}</b></td>\n";
30         print "<td><b>$text{'ec_2dirs'}</b></td>\n";
31         if ($squid_version >= 2.4) {
32                 print "<td><b>$text{'ec_opts'}</b></td>\n";
33                 }
34         print "</tr>\n";
35         }
36 for($i=0; $i<=@dirs; $i++) {
37         @dv = $i<@dirs ? @{$dirs[$i]->{'values'}} : ();
38         print "<tr $cb>\n";
39         if ($squid_version >= 2.4) {
40                 print "<td><input name=cache_dir_$i size=30 ",
41                       "value=\"$dv[1]\"></td>\n";
42                 print "<td><select name=cache_type_$i>\n";
43                 printf "<option value=ufs %s>$text{'ec_u'}\n",
44                         $dv[0] eq 'ufs' ? 'selected' : '';
45                 printf "<option value=diskd %s>$text{'ec_diskd'}\n",
46                         $dv[0] eq 'diskd' ? 'selected' : '';
47                 printf "<option value=aufs %s>$text{'ec_ua'}\n",
48                         $dv[0] eq 'aufs' ? 'selected' : '';
49                 printf "<option value=coss %s>$text{'ec_coss'}\n",
50                         $dv[0] eq 'coss' ? 'selected' : '';
51                 print "</select></td>\n";
52                 print "<td><input name=cache_size_$i size=8 ",
53                       "value=\"$dv[2]\"></td>\n";
54                 print "<td><input name=cache_lv1_$i size=8 ",
55                       "value=\"$dv[3]\"></td>\n";
56                 print "<td><input name=cache_lv2_$i size=8 ",
57                       "value=\"$dv[4]\"></td>\n";
58                 print "<td><input name=cache_opts_$i size=10 ",
59                       "value=\"",join(" ",@dv[5..$#dv]),"\"></td>\n";
60                 }
61         elsif ($squid_version >= 2.3) {
62                 print "<td><input name=cache_dir_$i size=30 ",
63                       "value=\"$dv[1]\"></td>\n";
64                 print "<td><select name=cache_type_$i>\n";
65                 printf "<option value=ufs %s>$text{'ec_u'}\n",
66                         $dv[0] eq 'ufs' ? 'selected' : '';
67                 printf "<option value=asyncufs %s>$text{'ec_ua'}\n",
68                         $dv[0] eq 'asyncufs' ? 'selected' : '';
69                 print "</select></td>\n";
70                 print "<td><input name=cache_size_$i size=8 ",
71                       "value=\"$dv[2]\"></td>\n";
72                 print "<td><input name=cache_lv1_$i size=8 ",
73                       "value=\"$dv[3]\"></td>\n";
74                 print "<td><input name=cache_lv2_$i size=8 ",
75                       "value=\"$dv[4]\"></td>\n";
76                 }
77         elsif ($squid_version >= 2) {
78                 print "<td><input name=cache_dir_$i size=30 ",
79                       "value=\"$dv[0]\"></td>\n";
80                 print "<td><input name=cache_size_$i size=8 ",
81                       "value=\"$dv[1]\"></td>\n";
82                 print "<td><input name=cache_lv1_$i size=8 ",
83                       "value=\"$dv[2]\"></td>\n";
84                 print "<td><input name=cache_lv2_$i size=8 ",
85                       "value=\"$dv[3]\"></td>\n";
86                 }
87         else {
88                 print "<td><input name=cache_dir_$i size=30 ",
89                       "value=\"$dv[0]\"></td>\n";
90                 }
91         print "</tr>\n";
92         }
93 print "</table></td> </tr>\n";
94 print "<tr> <td colspan=4><hr></td> </tr>\n";
95
96 if ($squid_version < 2) {
97         print "<tr>\n";
98         print &opt_input($text{'ec_1dirs1'}, "swap_level1_dirs", $conf,
99                          $text{'ec_default'}, 6);
100         print &opt_input($text{'ec_2dirs2'}, "swap_level2_dirs", $conf,
101                          $text{'ec_default'}, 6);
102         print "</tr>\n";
103         }
104
105 print "<tr>\n";
106 if ($squid_version < 2) {
107         print &opt_input($text{'ec_aos'}, "store_avg_object_size", $conf,
108                          $text{'ec_default'}, 6, $text{'ec_kb'});
109         }
110 else {
111         print &opt_bytes_input($text{'ec_aos'}, "store_avg_object_size",
112                                $conf, $text{'ec_default'}, 6);
113         }
114 print &opt_input($text{'ec_opb'}, "store_objects_per_bucket", $conf,
115                  $text{'ec_default'}, 6);
116 print "</tr>\n";
117
118 if ($squid_version < 2) {
119         print "<tr>\n";
120         print &list_input($text{'ec_ncuc'}, "cache_stoplist",
121                           $conf, 1, $text{'ec_default'});
122         print "</tr>\n";
123
124         print "<tr>\n";
125         print &list_input($text{'ec_ncum'}, "cache_stoplist_pattern",
126                           $conf, 1, $text{'ec_default'});
127         print "</tr>\n";
128         }
129
130 # ACLs not to cache
131 print "<tr> <td valign=top><b>$text{'ec_ncua'}</b></td> <td>\n";
132 print "<table>\n";
133 @acls = grep { !$acldone{$_->{'values'}->[0]}++ } &find_config("acl", $conf);
134 unshift(@acls, { 'values' => [ 'all' ] }) if ($squid_version >= 3);
135 if ($squid_version >= 2.6) {
136         # 2.6+ plus uses "cache deny"
137         @v = &find_config("cache", $conf);
138         }
139 else {
140         # Older versions use cache
141         @v = &find_config("no_cache", $conf);
142         }
143 foreach $v (@v) {
144         foreach $ncv (@{$v->{'values'}}) {
145                 $noca{$ncv}++;
146                 }
147         }
148 $i = 0;
149 foreach $acl (@acls) {
150         print "<tr>\n" if ($i%3 == 0);
151         $aclv = $acl->{'values'}->[0];
152         printf "<td nowrap><input type=checkbox name=no_cache value=$aclv %s>$aclv</td>\n",
153                 $noca{$aclv} ? "checked" : "";
154         print "</tr>\n" if ($i++%3 == 2);
155         }
156 print "</table></td>\n";
157
158 print &opt_time_input($text{'ec_mct'}, "reference_age", $conf,
159                       $text{'default'}, 6);
160 print "</tr>\n";
161
162 print "<tr>\n";
163 if ($squid_version >= 2) {
164         if ($squid_version >= 2.3) {
165                 print &opt_bytes_input($text{'ec_mrbs'},
166                         "request_body_max_size", $conf, $text{'default'}, 6);
167                 print &opt_bytes_input($text{'ec_mrhs'},
168                         "request_header_max_size", $conf, $text{'default'}, 6);
169                 print "</tr>\n";
170
171                 print "<tr>\n";
172                 if ($squid_version < 2.5) {
173                         print &opt_bytes_input($text{'ec_mrbs1'},
174                            "reply_body_max_size", $conf, $text{'default'}, 6);
175                         }
176                 else {
177                         print &opt_bytes_input($text{'ec_gap'},
178                            "read_ahead_gap", $conf, $text{'default'}, 6);
179                         }
180                 }
181         else {
182                 print &opt_bytes_input($text{'ec_mrs'}, "request_size",
183                                        $conf, $text{'default'}, 6);
184                 }
185         print &opt_time_input($text{'ec_frct'},
186                               "negative_ttl", $conf, $text{'default'}, 4);
187         }
188 else {
189         print &opt_input($text{'ec_mrs'}, "request_size", $conf,
190                          $text{'default'}, 8, $text{'ec_kb'});
191         print &opt_input($text{'ec_frct'}, "negative_ttl", $conf,
192                          $text{'default'}, 4, $text{'ec_mins'});
193         }
194 print "</tr>\n";
195
196 if ($squid_version >= 2.5) {
197         # Max reply size can be limited by ACL
198         print "<tr>\n";
199         print "<td valign=top><b>$text{'ec_maxreplies'}</b></td>\n";
200         print "<td colspan=3><table border>\n";
201         print "<tr $tb> <td><b>$text{'ec_maxrn'}</b></td> ",
202               "<td><b>$text{'ec_maxracls'}</b></td> </tr>\n";
203         @maxrs = &find_config("reply_body_max_size", $conf);
204         $i = 0;
205         foreach $m (@maxrs, { }) {
206                 local ($s, @a) = @{$m->{'values'}};
207                 print "<tr $cb>\n";
208                 printf "<td><input name=reply_body_max_size_%d size=8 value='%s'></td>\n",
209                         $i, $s;
210                 printf "<td><input name=reply_body_max_acls_%d size=50 value='%s'></td>\n",
211                         $i, join(" ", @a);
212                 print "</tr>\n";
213                 $i++;
214                 }
215         print "</table></tr>\n";
216         }
217
218 print "<tr>\n";
219 if ($squid_version < 2) {
220         print &opt_input($text{'ec_dlct'}, "positive_dns_ttl", $conf,
221                          $text{'default'}, 4, $text{'ec_mins'});
222         print &opt_input($text{'ec_fdct'}, "negative_dns_ttl", $conf,
223                          $text{'default'}, 4, $text{'ec_mins'});
224         }
225 else {
226         print &opt_time_input($text{'ec_dlct'}, "positive_dns_ttl",
227                               $conf, $text{'default'}, 4);
228         print &opt_time_input($text{'ec_fdct'}, "negative_dns_ttl",
229                               $conf, $text{'default'}, 4);
230         }
231 print "</tr>\n";
232
233 if ($squid_version < 2) {
234         print "<tr>\n";
235         print &opt_input($text{'ec_ct'}, "connect_timeout", $conf,
236                          $text{'default'}, 4, $text{'ec_secs'});
237         print &opt_input($text{'ec_rt'}, "read_timeout", $conf,
238                          $text{'default'}, 4, $text{'ec_secs'});
239         print "</tr>\n";
240
241         print "<tr>\n";
242         print &opt_input($text{'ec_mcct'}, "client_lifetime", $conf,
243                          $text{'default'}, 4, $text{'ec_mins'});
244         print &opt_input($text{'ec_mst'}, "shutdown_lifetime", $conf,
245                          $text{'default'}, 4, $text{'ec_mins'});
246         print "</tr>\n";
247         }
248 else {
249         print "<tr>\n";
250         print &opt_time_input($text{'ec_ct'}, "connect_timeout", $conf,
251                               $text{'default'}, 4);
252         print &opt_time_input($text{'ec_rt'}, "read_timeout", $conf,
253                               $text{'default'}, 4);
254         print "<tr>\n";
255
256         print "</tr>\n";
257         print &opt_time_input($text{'ec_sst'}, "siteselect_timeout",
258                               $conf, $text{'default'}, 4);
259         print &opt_time_input($text{'ec_crt'}, "request_timeout",
260                               $conf, $text{'default'}, 4);
261         print "</tr>\n";
262
263         print "<tr>\n";
264         print &opt_time_input($text{'ec_mcct'}, "client_lifetime",
265                               $conf, $text{'default'}, 4);
266         print &opt_time_input($text{'ec_mst'}, "shutdown_lifetime",
267                               $conf, $text{'default'}, 4);
268         print "</tr>\n";
269
270         print "<tr>\n";
271         print &choice_input($text{'ec_hcc'}, "half_closed_clients",
272                             $conf, "on", $text{'on'},"on", $text{'off'},"off");
273         print &opt_time_input($text{'ec_pt'}, "pconn_timeout",
274                               $conf, $text{'default'}, 4);
275         print "</tr>\n";
276         }
277
278 if ($squid_version < 2) {
279         print "<tr> <td><b>$text{'ec_wr'}</b></td> <td colspan=3>\n";
280         $v = &find_config("wais_relay", $conf);
281         printf "<input type=radio name=wais_relay_def value=1 %s> $text{'none'}\n",
282                 $v ? "" : "checked";
283         printf "<input type=radio name=wais_relay_def value=0 %s> $text{'ec_host'}\n",
284                 $v ? "checked" : "";
285         @wrv = $v ? @{$v->{'values'}} : ();
286         print "<input size=20 name=wais_relay1 value=\"$wrv[0]\">&nbsp;$text{'ec_port'}\n";
287         print "<input size=6 name=wais_relay2 value=\"$wrv[1]\"></td>\n";
288         print "</tr>\n";
289         }
290 else {
291         print "<tr>\n";
292         print &opt_input($text{'ec_wrh'}, "wais_relay_host",
293                          $conf, $text{'none'}, 20);
294         print &opt_input($text{'ec_wrp'}, "wais_relay_port",
295                          $conf, $text{'default'}, 6);
296         print "</tr>\n";
297         }
298
299 print "</table></td></tr></table>\n";
300 print "<input type=submit value=$text{'buttsave'}></form>\n";
301
302 &ui_print_footer("", $text{'ec_return'});
303