strict and ui-lib conversion

This commit is contained in:
Jamie Cameron
2014-01-08 15:37:10 -08:00
parent 868a1974fc
commit a7f0eeb09b
3 changed files with 45 additions and 36 deletions

View File

@@ -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'},"<br>\n";
print $text{'clear_msgclear2'},"<p>\n";
print "<form action=clear.cgi>\n";
print "<center><input type=submit name=confirm ",
"value=\"$text{'clear_buttclear'}\"></center></form>\n";
print &ui_confirmation_form(
"clear.cgi",
$text{'clear_msgclear'}."<br>".$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 "<b>$text{'clear_url'}</b>\n";
print &ui_textbox("url", undef, 50),"\n";
print &ui_submit($text{'clear_ok'}),"\n";
print &ui_submit($text{'clear_ok'}),"<br>\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)) {
<PID> =~ /(\d+)/; $pid = $1;
close(PID);
}
my $pid = &is_squid_running();
my $stopped = 0;
if ($pid && kill(0, $pid)) {
print "$text{'clear_stop'}<br>\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'}<br>\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'}<p>\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)."<br>\n";
print "<pre>\n";
&additional_log('exec', undef, $cmd);
@@ -92,10 +93,10 @@ print "$text{'clear_done'}<p>\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 &");
sleep(3);
$errs = `cat $temp`;
my $errs = &read_file_contents($temp);
unlink($temp);
if ($errs) {
&system_logged("$config{'squid_path'} -k shutdown -f $config{'squid_conf'} >/dev/null 2>&1");

View File

@@ -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'} ] ]),"<br>\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'}."<br>" ],

View File

@@ -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" );
}