Handle hostnames with upper-case letters
[webmin.git] / squid / icp_access_save.cgi
1 #!/usr/local/bin/perl
2 # icp_access_save.cgi
3 # Save or delete a proxy restriction
4
5 require './squid-lib.pl';
6 $access{'actrl'} || &error($text{'eacl_ecannot'});
7 &ReadParse();
8 &lock_file($config{'squid_conf'});
9 $conf = &get_config();
10 $whatfailed = $text{'saicp_ftsir'};
11
12 @icps = &find_config("icp_access", $conf);
13 if (defined($in{'index'})) {
14         $icp = $conf->[$in{'index'}];
15         }
16 if ($in{'delete'}) {
17         # delete this restriction
18         splice(@icps, &indexof($icp, @icps), 1);
19         }
20 else {
21         # update or create
22         @vals = ( $in{'action'} );
23         foreach $y (split(/\0/, $in{'yes'})) {
24                 push(@vals, $y);
25                 $used{$y}++;
26                 }
27         foreach $n (split(/\0/, $in{'no'})) {
28                 push(@vals, "!$n");
29                 $used{$n}++;
30                 }
31         $newicp = { 'name' => 'icp_access', 'values' => \@vals };
32         if ($icp) { splice(@icps, &indexof($icp, @icps), 1, $newicp); }
33         else { push(@icps, $newicp); }
34         }
35
36 # Find the last referenced ACL
37 @acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf);
38 $lastacl = @acls ? $acls[$#acls] : undef;
39
40 &save_directive($conf, "icp_access", \@icps, $lastacl);
41 &flush_file_lines();
42 &unlock_file($config{'squid_conf'});
43 &webmin_log($in{'delete'} ? 'delete' : $icp ? 'modify' : 'create', "icp");
44 &redirect("edit_acl.cgi?mode=icp");
45