Handle hostnames with upper-case letters
[webmin.git] / squid / save_refresh.cgi
1 #!/usr/local/bin/perl
2 # Save or delete a refresh pattern
3
4 require './squid-lib.pl';
5 $access{'refresh'} || &error($text{'refresh_ecannot'});
6 &ReadParse();
7 &lock_file($config{'squid_conf'});
8 $conf = &get_config();
9 &error_setup($text{'refresh_err'});
10
11 @refresh = &find_config("refresh_pattern", $conf);
12 if (defined($in{'index'})) {
13         $h = $conf->[$in{'index'}];
14         }
15 if ($in{'delete'}) {
16         # delete this restriction
17         splice(@refresh, &indexof($h, @refresh), 1);
18         }
19 else {
20         # update or create
21         $in{'re'} =~ /^\S+$/ || &error($text{'refresh_ere'});
22         $in{'min'} =~ /^\d+$/ || &error($text{'refresh_emin'});
23         $in{'max'} =~ /^\d+$/ || &error($text{'refresh_emax'});
24         $in{'pc'} =~ /^\d+$/ && $in{'pc'} >= 0 && $in{'pc'} <= 100 ||
25                 &error($text{'refresh_epc'});
26         push(@vals, "-i") if ($in{'caseless'});
27         push(@vals, $in{'re'}, $in{'min'}, $in{'pc'}.'%', $in{'max'});
28         push(@vals, split(/\0/, $in{'options'}));
29         $newr = { 'name' => 'refresh_pattern',
30                   'values' => \@vals };
31         $idx = &indexof($h, @refresh);
32         if ($h) { splice(@refresh, &indexof($h, @refresh), 1, $newr); }
33         else { push(@refresh, $newr); }
34         }
35 &save_directive($conf, "refresh_pattern", \@refresh);
36 &flush_file_lines();
37 &unlock_file($config{'squid_conf'});
38 &webmin_log($in{'delete'} ? 'delete' : $h ? 'modify' : 'create',
39             "refresh", $in{'re'});
40 &redirect("list_refresh.cgi");
41