3 # Save cache and request options
5 require './squid-lib.pl';
6 $access{'copts'} || &error($text{'ec_ecannot'});
8 &lock_file($config{'squid_conf'});
10 $whatfailed = $text{'scache_ftsco'};
12 if ($in{'cache_dir_def'}) {
13 &save_directive($conf, "cache_dir", [ ]);
16 for($i=0; defined($dir = $in{"cache_dir_$i"}); $i++) {
17 if ($squid_version >= 2.4) {
18 $lv1 = $in{"cache_lv1_$i"}; $lv2 = $in{"cache_lv2_$i"};
19 $size = $in{"cache_size_$i"};
20 $type = $in{"cache_type_$i"};
21 $opts = $in{"cache_opts_$i"};
22 next if (!$dir && !$lv1 && !$lv2 && !$size);
23 if ($type ne "coss") {
24 &check_error(\&check_dir, $dir);
26 &check_error(\&check_dirsize, $size);
27 &check_error(\&check_dircount, $lv1);
28 &check_error(\&check_dircount, $lv2);
29 push(@chd, { 'name' => 'cache_dir',
30 'values' => [ $type, $dir, $size,
31 $lv1, $lv2, $opts ] });
33 elsif ($squid_version >= 2.3) {
34 $lv1 = $in{"cache_lv1_$i"}; $lv2 = $in{"cache_lv2_$i"};
35 $size = $in{"cache_size_$i"};
36 $type = $in{"cache_type_$i"};
37 next if (!$dir && !$lv1 && !$lv2 && !$size);
38 &check_error(\&check_dir, $dir);
39 &check_error(\&check_dirsize, $size);
40 &check_error(\&check_dircount, $lv1);
41 &check_error(\&check_dircount, $lv2);
42 push(@chd, { 'name' => 'cache_dir',
43 'values' => [ $type, $dir, $size,
46 elsif ($squid_version >= 2) {
47 $lv1 = $in{"cache_lv1_$i"}; $lv2 = $in{"cache_lv2_$i"};
48 $size = $in{"cache_size_$i"};
49 next if (!$dir && !$lv1 && !$lv2 && !$size);
50 &check_error(\&check_dir, $dir);
51 &check_error(\&check_dirsize, $size);
52 &check_error(\&check_dircount, $lv1);
53 &check_error(\&check_dircount, $lv2);
54 push(@chd, { 'name' => 'cache_dir',
55 'values' => [ $dir, $size, $lv1, $lv2 ] });
59 &check_error(\&check_dir, $dir);
60 push(@chd, { 'name' => 'cache_dir',
61 'values' => [ $dir ] });
65 &error($text{'scache_emsg0'});
67 &save_directive($conf, "cache_dir", \@chd);
69 if ($squid_version < 2) {
70 &save_opt("swap_level1_dirs", \&check_dircount, $conf);
71 &save_opt("swap_level2_dirs", \&check_dircount, $conf);
72 &save_opt("store_avg_object_size", \&check_objsize, $conf);
75 &save_opt_bytes("store_avg_object_size", $conf);
77 &save_opt("store_objects_per_bucket", \&check_bucket, $conf);
78 if ($squid_version < 2) {
79 &save_list("cache_stoplist", undef, $conf);
80 &save_list("cache_stoplist_pattern", undef, $conf);
82 @noch = split(/\0/, $in{'no_cache'});
83 $nochname = $squid_version >= 2.6 ? 'cache' : 'no_cache';
85 $nc[0] = { 'name' => $nochname,
86 'values' => [ "deny", @noch ] };
88 &save_directive($conf, $nochname, \@nc, "acl");
89 &save_opt_time("reference_age", $conf);
90 if ($squid_version < 2) {
91 &save_opt("request_size", \&check_size, $conf);
92 &save_opt("negative_ttl", \&check_ttl, $conf);
93 &save_opt("positive_dns_ttl", \&check_dns_ttl, $conf);
94 &save_opt("negative_dns_ttl", \&check_dns_ttl, $conf);
97 if ($squid_version >= 2.3) {
98 &save_opt_bytes("request_body_max_size", $conf);
99 &save_opt_bytes("request_header_max_size", $conf);
100 if ($squid_version < 2.5) {
101 &save_opt_bytes("reply_body_max_size", $conf);
104 &save_opt_bytes("read_ahead_gap", $conf);
108 &save_opt_bytes("request_size", $conf);
110 &save_opt_time("negative_ttl", $conf);
111 &save_opt_time("positive_dns_ttl", $conf);
112 &save_opt_time("negative_dns_ttl", $conf);
114 if ($squid_version >= 2.5) {
115 # Parse list of max reply body sizes
116 for($i=0; defined($s = $in{"reply_body_max_size_$i"}); $i++) {
118 &error(&text('scache_emaxrs', $i+1)) if ($s !~ /^\d+$/);
119 local @a = split(/\s+/, $in{"reply_body_max_acls_$i"});
120 push(@rbms, { 'name' => 'reply_body_max_size',
121 'values' => [ $s, @a ] });
123 &save_directive($conf, "reply_body_max_size", \@rbms);
125 if ($squid_version < 2) {
126 &save_opt("connect_timeout", \&check_timeout, $conf);
127 &save_opt("read_timeout", \&check_timeout, $conf);
128 &save_opt("client_lifetime", \&check_lifetime, $conf);
129 &save_opt("shutdown_lifetime", \&check_lifetime, $conf);
132 &save_opt_time("connect_timeout", $conf);
133 &save_opt_time("read_timeout", $conf);
134 &save_opt_time("siteselect_timeout", $conf);
135 &save_opt_time("request_timeout", $conf);
136 &save_opt_time("client_lifetime", $conf);
137 &save_opt_time("shutdown_lifetime", $conf);
138 &save_choice("half_closed_clients", "on", $conf);
139 &save_opt_time("pconn_timeout", $conf);
141 if ($squid_version < 2) {
142 if (!$in{'wais_relay_def'}) {
143 &check_error(\&check_host, $in{'wais_relay1'});
144 &check_error(\&check_port, $in{'wais_relay2'});
145 $wr[0] = { 'name' => 'wais_relay',
146 'values' => [ $in{'wais_relay1'}, $in{'wais_relay2'} ] };
148 &save_directive($conf, "wais_relay", \@wr);
151 &save_opt("wais_relay_host", \&check_host, $conf);
152 &save_opt("wais_relay_port", \&check_port, $conf);
156 &unlock_file($config{'squid_conf'});
157 &webmin_log("cache", undef, undef, \%in);
162 return (-d $_[0]) ? undef : &text('scache_emsg1',$_[0]);
167 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg2',$_[0]);
172 return $_[0] =~ /^\d+$/ ? undef
173 : &text('scache_emsg3',$_[0]);
178 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg4',$_[0]);
183 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg5',$_[0]);
188 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg6',$_[0]);
193 return $_[0] !~ /^\d+$/ ? &text('scache_emsg7',$_[0]) :
194 $_[0] < 1 ? $text{'scache_emsg8'} :
195 $_[0] > 256 ? $text{'scache_emsg9'} : undef;
201 return $_[0] =~ /^\d+/ ? undef : &text('scache_emsg10',$_[0]);
206 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg11',$_[0]);
211 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg12',$_[0]);
216 return &to_ipaddress($_[0]) || &to_ip6address($_[0]) ? undef
217 : &text('scache_emsg13',$_[0]);
222 return $_[0] =~ /^\d+$/ ? undef : &text('scache_emsg14',$_[0]);