diff --git a/squid/calamaris.cgi b/squid/calamaris.cgi index e4736a25e..53ebdff16 100755 --- a/squid/calamaris.cgi +++ b/squid/calamaris.cgi @@ -2,6 +2,9 @@ # calamaris.cgi # Run calamaris on the squid logfile(s) +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config, %gconfig, $module_name); require './squid-lib.pl'; $access{'calamaris'} || &error($text{'calamaris_ecannot'}); &ui_print_header(undef, $text{'calamaris_title'}, ""); @@ -15,10 +18,12 @@ if (!&has_command($config{'calamaris'})) { } # Work out Calamaris version and args -if (`$config{'calamaris'} -V 2>&1` =~ /(revision:|Calamaris)\s+(\d\S+)/i) { +my $ver; +if (&backquote_command("$config{'calamaris'} -V 2>&1") =~ + /(revision:|Calamaris)\s+(\d\S+)/i) { $ver = $2; } -$args = $config{'cal_all'} ? " -a" : ""; +my $args = $config{'cal_all'} ? " -a" : ""; if ($ver >= 2.5) { if ($config{'cal_fmt'} eq 'w') { $args .= " -F html"; @@ -33,10 +38,12 @@ else { $args .= " $config{'cal_extra'}"; # are there any logfiles to analyse? -$ld = $config{'log_dir'}; -opendir(DIR, $ld); -while($f = readdir(DIR)) { - local @st = stat("$ld/$f"); +my $ld = $config{'log_dir'}; +my $fh; +my @files; +opendir($fh, $ld); +while(my $f = readdir($fh)) { + my @st = stat("$ld/$f"); if ($f =~ /^access.log.*gz$/) { push(@files, [ "gunzip -c $ld/$f |", $st[9] ]); } @@ -47,7 +54,7 @@ while($f = readdir(DIR)) { push(@files, [ "$ld/$f", $st[9] ]); } } -closedir(DIR); +closedir($fh); if (!@files) { print &text('calamaris_elogs', "$ld", "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; @@ -56,62 +63,69 @@ if (!@files) { } # run calamaris, parsing newest files and records first -$temp = &transname(); -open(CAL, "| $config{'calamaris'} $args >$temp 2>/dev/null"); +my $temp = &transname(); +my $fh2; +open($fh2, "| $config{'calamaris'} $args >$temp 2>/dev/null"); if ($config{'cal_max'}) { # read only the last N lines print &text('calamaris_last', $config{'cal_max'}),"
\n";
@files = sort { $b->[1] <=> $a->[1] } @files;
- $lnum = 0;
- foreach $f (@files) {
- $left = $config{'cal_max'} - $lnum;
+ my $lnum = 0;
+ foreach my $f (@files) {
+ my $left = $config{'cal_max'} - $lnum;
last if ($left <= 0);
+ my $fh3;
if ($f->[0] =~ /\|$/) {
- open(LOG, "$f->[0] tail -$left |");
+ open($fh3, "$f->[0] tail -$left |");
}
else {
- open(LOG, "tail -$left $f->[0] |");
+ open($fh3, "tail -$left $f->[0] |");
}
- while( $text{'clear_stop'} ", &text('icache_itscwtc',$cmd), "";
- while(
";
}
else {
- while(
\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,35 +52,36 @@ if ($pid && kill(0, $pid)) {
}
# Initialize the cache
-($user, $group) = &get_squid_user($conf);
+my ($user, $group) = &get_squid_user($conf);
if ($user) {
- foreach $c (split(/\s+/, $in{'caches'})) {
- mkdir($c, 0755);
+ foreach my $c (split(/\s+/, $in{'caches'})) {
+ &make_dir($c, 0755);
}
}
&chown_files($user, $group, $conf);
-$cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z";
+my $cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z";
print "
\n";
print "\n";
&additional_log('exec', undef, $cmd);
-open(INIT, "$cmd 2>&1 |");
-while(\n";
# Try to re-start squid (if it was running before)
if ($stopped) {
- $temp = &transname();
+ my $temp = &transname();
&system_logged("$config{'squid_path'} -sY -f $config{'squid_conf'} >$temp 2>&1 /dev/null 2>&1");
print "$text{'clear_failrestart'}
\n";
- print "$errs
\n";
+ print "".&html_escape($errs)."
\n";
}
}
diff --git a/squid/purge.cgi b/squid/purge.cgi
index a674f529b..63fde33a9 100755
--- a/squid/purge.cgi
+++ b/squid/purge.cgi
@@ -1,6 +1,9 @@
#!/usr/local/bin/perl
# Call squidclient to remove just one URL
+use strict;
+use warnings;
+our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
&error_setup($text{'purge_err'});
$access{'rebuild'} || &error($text{'clear_ecannot'});
@@ -10,10 +13,11 @@ $in{'url'} || &error($text{'purge_eurl'});
&ui_print_header(undef, $text{'purge_title'}, "");
# Get the port number
-$conf = &get_config();
+my $conf = &get_config();
+my $port;
if ($squid_version >= 2.3) {
- @ports = &find_config("http_port", $conf);
- foreach $p (@ports) {
+ my @ports = &find_config("http_port", $conf);
+ foreach my $p (@ports) {
if ($p->{'values'}->[0] =~ /(\d+)$/) {
$port = $1;
last;
@@ -27,9 +31,9 @@ else {
# Run it
print &text('purge_doing', "$in{'url'}"),"\n";
-$cmd = "$config{'squidclient'} -p $port -m PURGE ".quotemeta($in{'url'});
-$out = &backquote_logged("$cmd 2>&1");
-print "$out
\n";
+my $cmd = "$config{'squidclient'} -p $port -m PURGE ".quotemeta($in{'url'});
+my $out = &backquote_logged("$cmd 2>&1");
+print "".&html_escape($out)."
\n";
if ($?) {
print $text{'purge_failed'},"
\n";
}
diff --git a/squid/save_auth.cgi b/squid/save_auth.cgi
deleted file mode 100755
index 82d8b41b5..000000000
--- a/squid/save_auth.cgi
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/local/bin/perl
-# save_auth.cgi
-# Save authentication options
-
-require './squid-lib.pl';
-$access{'proxyauth'} || &error($text{'eauth_ecannot'});
-&ReadParse();
-&lock_file($config{'squid_conf'});
-$conf = &get_config();
-$whatfailed = $text{'sauth_ftsao'};
-
-if ($in{'authfile_def'}) {
- &save_directive($conf, "proxy_auth", [ ]);
- }
-else {
- $in{'authfile'} =~ /^\// || &error($text{'sauth_iomuf'});
- if (!-r $in{'authfile'}) {
- &open_tempfile(AUTH, ">$in{'authfile'}");
- &close_tempfile(AUTH);
- ($user, $group) = &get_squid_user($conf);
- if ($user) {
- @uinfo = getpwnam($user);
- @ginfo = getgrnam($group);
- chown($uinfo[2], $ginfo[2], $in{'authfile'});
- chmod(0644, $in{'authfile'});
- }
- }
- push(@vals, $in{'authfile'});
- if (!$in{'authdom_def'}) {
- $in{'authdom'}=~/^\S+$/ || &error($text{'sauth_iomd'});
- push(@vals, $in{'authdom'});
- }
- &save_directive($conf, "proxy_auth",
- [ { 'name' => 'proxy_auth',
- 'values' => \@vals } ]);
- }
-&flush_file_lines();
-
-# check if the proxy_auth directive is supported
-$out = `$config{'squid_path'} -f $config{'squid_conf'} -k check 2>&1`;
-if ($out =~ /proxy_auth/) {
- # it isn't .. roll back
- &save_directive($conf, "proxy_auth", [ ]);
- &flush_file_lines();
- &error($text{'sauth_msg1'});
- }
-&unlock_file($config{'squid_conf'});
-&redirect("");
-