diff --git a/squid/http_access.cgi b/squid/http_access.cgi index a5d0271e9..fabfa2548 100755 --- a/squid/http_access.cgi +++ b/squid/http_access.cgi @@ -2,11 +2,15 @@ # http_access.cgi # A form for editing or creating a proxy access restriction +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'actrl'} || &error($text{'eacl_ecannot'}); &ReadParse(); -$conf = &get_config(); +my $conf = &get_config(); +my @http; if (!defined($in{'index'})) { &ui_print_header(undef, $text{'ahttp_header'}, "", undef, 0, 0, 0, &restart_button()); @@ -17,49 +21,45 @@ else { @http = @{$conf->[$in{'index'}]->{'values'}}; } -print "
\n"; +print &ui_form_start("http_access_save.cgi", "post"); if (@http) { - print "\n"; + print &ui_hidden("index", $in{'index'}); } -print "\n"; -print "\n"; -print "
$text{'ahttp_pr'}
\n"; +print &ui_table_start($text{'ahttp_pr'}, undef, 2); -print "\n", - $http[0] eq "allow" ? "" : "checked"; +# Allow or deny ACLs +print &ui_table_row($text{'ahttp_a'}, + &ui_radio("action", $http[0] || "allow", + [ [ "allow", $text{'ahttp_a1'} ], + [ "deny", $text{'ahttp_d'} ] ])); -for($i=1; $i<@http; $i++) { $match{$http[$i]}++; } -@acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf); +# Get list of ACLs being matched, and all ACLs +my (@yes, @no); +for(my $i=1; $i<@http; $i++) { + if ($http[$i] =~ /^!(.*)/) { + push(@no, $1); + } + else { + push(@yes, $http[$i]); + } + } +my %done; +my @acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf); unshift(@acls, { 'values' => [ 'all' ] }) if ($squid_version >= 3); -$r = @acls; $r = 10 if ($r > 10); +my $r = @acls; +$r = 10 if ($r > 10); -print "\n"; -print "\n"; +print &ui_table_row($text{'ahttp_ma'}, + &ui_select("yes", \@yes, [ map { $_->{'values'}->[0] } @acls ], + $r, 1, 1)); -print "\n"; -print "\n"; +print &ui_table_row($text{'ahttp_dma'}, + &ui_select("no", \@no, [ map { $_->{'values'}->[0] } @acls ], + $r, 1, 1)); -print "
$text{'ahttp_a'} \n"; -printf " $text{'ahttp_a1'}\n", - $http[0] eq "allow" ? "checked" : ""; -printf " $text{'ahttp_d'}
$text{'ahttp_ma'}$text{'ahttp_dma'}
\n"; -print "\n"; -if (@http) { - print "\n"; - } -print "
\n"; +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'buttsave'} ], + @http ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]); &ui_print_footer("edit_acl.cgi?mode=http", $text{'ahttp_return'}, "", $text{'index_return'}); diff --git a/squid/http_access_save.cgi b/squid/http_access_save.cgi index 0e8c00010..a58502dec 100755 --- a/squid/http_access_save.cgi +++ b/squid/http_access_save.cgi @@ -2,14 +2,18 @@ # http_access_save.cgi # Save or delete a proxy restriction +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'actrl'} || &error($text{'eacl_ecannot'}); &ReadParse(); &lock_file($config{'squid_conf'}); -$conf = &get_config(); -$whatfailed = $text{'sahttp_ftspr'}; +my $conf = &get_config(); +&error_setup($text{'sahttp_ftspr'}); -@https = &find_config("http_access", $conf); +my @https = &find_config("http_access", $conf); +my ($http, %used); if (defined($in{'index'})) { $http = $conf->[$in{'index'}]; } @@ -19,23 +23,23 @@ if ($in{'delete'}) { } else { # update or create - @vals = ( $in{'action'} ); - foreach $y (split(/\0/, $in{'yes'})) { + my @vals = ( $in{'action'} ); + foreach my $y (split(/\0/, $in{'yes'})) { push(@vals, $y); $used{$y}++; } - foreach $n (split(/\0/, $in{'no'})) { + foreach my $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); $used{$n}++; } - $newhttp = { 'name' => 'http_access', 'values' => \@vals }; + my $newhttp = { 'name' => 'http_access', 'values' => \@vals }; if ($http) { splice(@https, &indexof($http, @https), 1, $newhttp); } else { push(@https, $newhttp); } } # Find the last referenced ACL -@acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf); -$lastacl = @acls ? $acls[$#acls] : undef; +my @acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf); +my $lastacl = @acls ? $acls[$#acls] : undef; &save_directive($conf, "http_access", \@https, $lastacl); &flush_file_lines();