From f267672ae2914393c50678d0768bbf3d27494483 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 2 Jan 2014 16:04:08 -0800 Subject: [PATCH] more strict and ui-lib conversion --- squid/always.cgi | 73 ++++++++++++++++++++++--------------------- squid/always_save.cgi | 18 ++++++----- squid/never.cgi | 73 ++++++++++++++++++++++--------------------- squid/never_save.cgi | 18 ++++++----- 4 files changed, 98 insertions(+), 84 deletions(-) diff --git a/squid/always.cgi b/squid/always.cgi index f2fd3b6d0..3cf55d660 100755 --- a/squid/always.cgi +++ b/squid/always.cgi @@ -2,11 +2,15 @@ # always.cgi # A form for editing or creating http_access directives +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'othercaches'} || &error($text{'eicp_ecannot'}); &ReadParse(); -$conf = &get_config(); +my $conf = &get_config(); +my @always; if (!defined($in{'index'})) { &ui_print_header(undef, $text{'always_create'}, "", undef, 0, 0, 0, &restart_button()); @@ -17,47 +21,46 @@ else { @always = @{$conf->[$in{'index'}]->{'values'}}; } -print "
\n"; +print &ui_form_start("always_save.cgi", "post"); if (@always) { - print "\n"; + print &ui_hidden("index", $in{'index'}); } -print "\n"; -print "\n"; -print "
$text{'always_header'}
\n"; +print &ui_table_start($text{'always_header'}, undef, 2); -print "\n", - $always[0] eq "allow" ? "" : "checked"; +# Allow or deny this ACL? +print &ui_table_row($text{'ahttp_a'}, + &ui_radio("action", $always[0] || "allow", + [ [ "allow", $text{'ahttp_a1'} ], + [ "deny", $text{'ahttp_d'} ] ])); -for($i=1; $i<@always; $i++) { $match{$always[$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<@always; $i++) { + if ($always[$i] =~ /^!(.*)/) { + push(@no, $1); + } + else { + push(@yes, $always[$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", - $always[0] eq "allow" ? "checked" : ""; -printf " $text{'ahttp_d'}
$text{'ahttp_ma'}$text{'ahttp_dma'}

\n"; -print "\n"; -if (@always) { print "\n"; } -print "
\n"; +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'buttsave'} ], + @always ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]); -&ui_print_footer("edit_acl.cgi", $text{'ahttp_return'}); +&ui_print_footer("edit_icp.cgi", $text{'ahttp_return'}); diff --git a/squid/always_save.cgi b/squid/always_save.cgi index 2ec1a2822..4e201bf22 100755 --- a/squid/always_save.cgi +++ b/squid/always_save.cgi @@ -2,13 +2,17 @@ # always_save.cgi # Save or delete an always_direct directive +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'othercaches'} || &error($text{'eicp_ecannot'}); &ReadParse(); &lock_file($config{'squid_conf'}); -$conf = &get_config(); +my $conf = &get_config(); -@always = &find_config("always_direct", $conf); +my @always = &find_config("always_direct", $conf); +my $always; if (defined($in{'index'})) { $always = $conf->[$in{'index'}]; } @@ -18,10 +22,10 @@ if ($in{'delete'}) { } else { # update or create - @vals = ( $in{'action'} ); - foreach $y (split(/\0/, $in{'yes'})) { push(@vals, $y); } - foreach $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); } - $newalways = { 'name' => 'always_direct', 'values' => \@vals }; + my @vals = ( $in{'action'} ); + foreach my $y (split(/\0/, $in{'yes'})) { push(@vals, $y); } + foreach my $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); } + my $newalways = { 'name' => 'always_direct', 'values' => \@vals }; if ($always) { splice(@always, &indexof($always, @always), 1, $newalways); } else { push(@always, $newalways); } @@ -29,6 +33,6 @@ else { &save_directive($conf, "always_direct", \@always); &flush_file_lines(); &unlock_file($config{'squid_conf'}); -&webmin_log($in{'delete'} ? 'delete' : $always ? 'modify' : 'create', "always"); +&webmin_log($in{'delete'} ? 'delete' : $always ? 'modify' : 'create', 'always'); &redirect("edit_icp.cgi"); diff --git a/squid/never.cgi b/squid/never.cgi index 0f7ed1d88..224b62b4f 100755 --- a/squid/never.cgi +++ b/squid/never.cgi @@ -2,11 +2,15 @@ # never.cgi # A form for editing or creating http_access directives +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'othercaches'} || &error($text{'eicp_ecannot'}); &ReadParse(); -$conf = &get_config(); +my $conf = &get_config(); +my @never; if (!defined($in{'index'})) { &ui_print_header(undef, $text{'never_create'}, "", undef, 0, 0, 0, &restart_button()); @@ -17,47 +21,46 @@ else { @never = @{$conf->[$in{'index'}]->{'values'}}; } -print "
\n"; +print &ui_form_start("never_save.cgi", "post"); if (@never) { - print "\n"; + print &ui_hidden("index", $in{'index'}); } -print "\n"; -print "\n"; -print "
$text{'never_header'}
\n"; +print &ui_table_start($text{'never_header'}, undef, 2); -print "\n", - $never[0] eq "allow" ? "" : "checked"; +# Allow or deny this ACL? +print &ui_table_row($text{'ahttp_a'}, + &ui_radio("action", $never[0] || "allow", + [ [ "allow", $text{'ahttp_a1'} ], + [ "deny", $text{'ahttp_d'} ] ])); -for($i=1; $i<@never; $i++) { $match{$never[$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<@never; $i++) { + if ($never[$i] =~ /^!(.*)/) { + push(@no, $1); + } + else { + push(@yes, $never[$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", - $never[0] eq "allow" ? "checked" : ""; -printf " $text{'ahttp_d'}
$text{'ahttp_ma'}$text{'ahttp_dma'}

\n"; -print "\n"; -if (@never) { print "\n"; } -print "
\n"; +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'buttsave'} ], + @never ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]); -&ui_print_footer("edit_acl.cgi", $text{'ahttp_return'}); +&ui_print_footer("edit_icp.cgi", $text{'ahttp_return'}); diff --git a/squid/never_save.cgi b/squid/never_save.cgi index 76b22b508..77b06402b 100755 --- a/squid/never_save.cgi +++ b/squid/never_save.cgi @@ -2,13 +2,17 @@ # never_save.cgi # Save or delete an never_direct directive +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'othercaches'} || &error($text{'eicp_ecannot'}); &ReadParse(); &lock_file($config{'squid_conf'}); -$conf = &get_config(); +my $conf = &get_config(); -@never = &find_config("never_direct", $conf); +my @never = &find_config("never_direct", $conf); +my $never; if (defined($in{'index'})) { $never = $conf->[$in{'index'}]; } @@ -18,10 +22,10 @@ if ($in{'delete'}) { } else { # update or create - @vals = ( $in{'action'} ); - foreach $y (split(/\0/, $in{'yes'})) { push(@vals, $y); } - foreach $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); } - $newnever = { 'name' => 'never_direct', 'values' => \@vals }; + my @vals = ( $in{'action'} ); + foreach my $y (split(/\0/, $in{'yes'})) { push(@vals, $y); } + foreach my $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); } + my $newnever = { 'name' => 'never_direct', 'values' => \@vals }; if ($never) { splice(@never, &indexof($never, @never), 1, $newnever); } else { push(@never, $newnever); } @@ -29,6 +33,6 @@ else { &save_directive($conf, "never_direct", \@never); &flush_file_lines(); &unlock_file($config{'squid_conf'}); -&webmin_log($in{'delete'} ? 'delete' : $never ? 'modify' : 'create', "never"); +&webmin_log($in{'delete'} ? 'delete' : $never ? 'modify' : 'create', 'never'); &redirect("edit_icp.cgi");