From a7f0eeb09bf116e53f0d1db1caf2dd408bce9169 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 8 Jan 2014 15:37:10 -0800 Subject: [PATCH] strict and ui-lib conversion --- squid/clear.cgi | 49 +++++++++++++++++++++-------------------- squid/edit_cachemgr.cgi | 21 ++++++++++-------- squid/save_cachemgr.cgi | 11 ++++++--- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/squid/clear.cgi b/squid/clear.cgi index 1bc1dc585..f35b3ec5a 100755 --- a/squid/clear.cgi +++ b/squid/clear.cgi @@ -2,20 +2,24 @@ # clear.cgi # Delete the cache, chown the directory to the correct user and re-run squid -z +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'rebuild'} || &error($text{'clear_ecannot'}); &ReadParse(); $config{'cache_dir'} =~ /^\/\S+/ || &error("Cache directory not set"); -$conf = &get_config(); +my $conf = &get_config(); if (!$in{'confirm'}) { # Ask the user if he is sure &ui_print_header(undef, $text{'clear_header'}, ""); - print $text{'clear_msgclear'},"
\n"; - print $text{'clear_msgclear2'},"

\n"; - print "

\n"; - print "
\n"; + + print &ui_confirmation_form( + "clear.cgi", + $text{'clear_msgclear'}."
".$text{'clear_msgclear2'}, + [], + [ [ undef, $text{'clear_buttclear'} ] ]); if (&has_command($config{'squidclient'})) { # Show form to clear just one URL @@ -23,7 +27,7 @@ if (!$in{'confirm'}) { print &ui_form_start("purge.cgi"); print "$text{'clear_url'}\n"; print &ui_textbox("url", undef, 50),"\n"; - print &ui_submit($text{'clear_ok'}),"\n"; + print &ui_submit($text{'clear_ok'}),"
\n"; print &ui_form_end(); } @@ -34,19 +38,13 @@ if (!$in{'confirm'}) { &ui_print_unbuffered_header(undef, $text{'clear_header'}, ""); # Stop squid (if running) -if ($pidstruct = &find_config("pid_filename", $conf)) { - $pidfile = $pidstruct->{'values'}->[0]; - } -else { $pidfile = $config{'pid_file'}; } -if (open(PID, $pidfile)) { - =~ /(\d+)/; $pid = $1; - close(PID); - } +my $pid = &is_squid_running(); +my $stopped = 0; if ($pid && kill(0, $pid)) { print "$text{'clear_stop'}
\n"; &system_logged("$config{'squid_path'} -f $config{'squid_conf'} ". "-k shutdown >/dev/null 2>&1"); - for($i=0; $i<40; $i++) { + for(my $i=0; $i<40; $i++) { if (!kill(0, $pid)) { last; } sleep(1); } @@ -55,7 +53,8 @@ if ($pid && kill(0, $pid)) { } # Get list of cache dirs -if (@cachestruct = &find_config("cache_dir", $conf)) { +my @caches; +if (my @cachestruct = &find_config("cache_dir", $conf)) { if ($squid_version >= 2.3) { @caches = map { $_->{'values'}->[1] } @cachestruct; } @@ -63,14 +62,16 @@ if (@cachestruct = &find_config("cache_dir", $conf)) { @caches = map { $_->{'values'}->[0] } @cachestruct; } } -else { @caches = ( $config{'cache_dir'} ); } +else { + @caches = ( $config{'cache_dir'} ); + } # Delete old cache files and re-create with same permissions! print "$text{'clear_del'}
\n"; -foreach $c (@caches) { - @st = stat($c); +foreach my $c (@caches) { + my @st = stat($c); if (@st) { - &system_logged("rm -rf $c/* >/dev/null 2>&1"); + &system_logged("rm -rf ".quotemeta($c)."/* >/dev/null 2>&1"); #mkdir($c, 0755); # only remove contents #chown($st[4], $st[5], $c); #chmod($st[2], $c); @@ -78,7 +79,7 @@ foreach $c (@caches) { } print "$text{'clear_done'}

\n"; -$cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z"; +my $cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z"; print &text('clear_init',$cmd)."
\n"; print "

\n";
 &additional_log('exec', undef, $cmd);
@@ -92,10 +93,10 @@ print "$text{'clear_done'}

\n"; # Try to re-start squid if ($stopped) { - $temp = &transname(); + my $temp = &transname(); &system_logged("$config{'squid_path'} -sY -f $config{'squid_conf'} >$temp 2>&1 /dev/null 2>&1"); diff --git a/squid/edit_cachemgr.cgi b/squid/edit_cachemgr.cgi index 25c67ef83..13f904b27 100755 --- a/squid/edit_cachemgr.cgi +++ b/squid/edit_cachemgr.cgi @@ -1,14 +1,17 @@ #!/usr/local/bin/perl # Show a list of per-function cache manager passwords +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'cachemgr'} || &error($text{'cachemgr_ecannot'}); &ui_print_header(undef, $text{'cachemgr_title'}, "", "edit_cachemgr", 0, 0, 0, &restart_button()); # Find password directives -$conf = &get_config(); -@cachemgr = &find_config("cachemgr_passwd", $conf); +my $conf = &get_config(); +my @cachemgr = &find_config("cachemgr_passwd", $conf); # Show them in a table print &ui_form_start("save_cachemgr.cgi", "post"); @@ -16,17 +19,17 @@ print &ui_radio("cachemgr_def", @cachemgr ? 0 : 1, [ [ 1, $text{'cachemgr_def1'} ], [ 0, $text{'cachemgr_def0'} ] ]),"
\n"; print &ui_columns_start([ $text{'cachemgr_pass'}, $text{'cachemsg_actions'} ], 100, 0); -$i = 0; -foreach $c (@cachemgr, { 'values' => [ 'none' ] }) { - @grid = ( ); - ($p, @acts) = @{$c->{'values'}}; - %acts = map { $_, 1 } @acts; +my $i = 0; +foreach my $c (@cachemgr, { 'values' => [ 'none' ] }) { + my @grid = ( ); + my ($p, @acts) = @{$c->{'values'}}; + my %acts = map { $_, 1 } @acts; foreach my $a (&list_cachemgr_actions()) { push(@grid, &ui_checkbox("action_$i", $a, $a, $acts{$a})); delete($acts{$a}); } - @others = grep { $_ ne 'all' } keys %acts; - $pmode = $p eq "none" ? "none" : $p eq "disable" ? "disable" : undef; + my @others = grep { $_ ne 'all' } keys %acts; + my $pmode = $p eq "none" ? "none" : $p eq "disable" ? "disable" : undef; print &ui_columns_row([ &ui_radio("pass_def_$i", $pmode, [ [ "none", $text{'cachemgr_none'}."
" ], diff --git a/squid/save_cachemgr.cgi b/squid/save_cachemgr.cgi index 124e7b415..492b5ed24 100755 --- a/squid/save_cachemgr.cgi +++ b/squid/save_cachemgr.cgi @@ -1,6 +1,9 @@ #!/usr/local/bin/perl # Save the list of per-function cache manager passwords +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; &error_setup($text{'cachemgr_err'}); $access{'cachemgr'} || &error($text{'cachemgr_ecannot'}); @@ -8,7 +11,7 @@ $access{'cachemgr'} || &error($text{'cachemgr_ecannot'}); # Validate and store inputs &lock_file($config{'squid_conf'}); -$conf = &get_config(); +my $conf = &get_config(); if ($in{'cachemgr_def'}) { # Clear them all @@ -16,8 +19,10 @@ if ($in{'cachemgr_def'}) { } else { # Build up list and save - for($i=0; defined($pmode = $in{"pass_def_$i"}); $i++) { - $pass = $pmode || $in{"pass_$i"}; + my @rv; + for(my $i=0; defined(my $pmode = $in{"pass_def_$i"}); $i++) { + my $pass = $pmode || $in{"pass_$i"}; + my @actions; if ($in{"all_$i"}) { @actions = ( "all" ); }