diff --git a/squid/CHANGELOG b/squid/CHANGELOG index a0f27e0ea..7242d533e 100644 --- a/squid/CHANGELOG +++ b/squid/CHANGELOG @@ -32,3 +32,6 @@ Comments at the end of lines are now preserved when Webmin changes directives in Fixed the Calamaris page for newer versions. ---- Changes since 1.510 ---- Improved support for COSS format (single file) Squid caches. +---- Changes since 1.660 ---- +Updated all pages to use the Webmin UI library for a more consistent look. +Made all code Perl strict and warnings compliant. diff --git a/squid/edit_logs.cgi b/squid/edit_logs.cgi index 32b395a7e..915d82f14 100755 --- a/squid/edit_logs.cgi +++ b/squid/edit_logs.cgi @@ -2,33 +2,33 @@ # edit_logs.cgi # A form for editing logging options +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'logging'} || &error($text{'elogs_ecannot'}); &ui_print_header(undef, $text{'elogs_header'}, "", "edit_logs", 0, 0, 0, &restart_button()); -$conf = &get_config(); +my $conf = &get_config(); -print "
\n"; -print "\n"; -print "\n"; -print "
$text{'elogs_lalo'}
\n"; +print &ui_form_start("save_logs.cgi", "post"); +print &ui_table_start($text{'elogs_lalo'}, "width=100%", 4); if ($squid_version < 2.6) { # Just a single logging directive - print "\n"; - print &opt_input($text{'elogs_alf'}, "cache_access_log", $conf, $text{'default'}, 50); - print "\n"; + print &opt_input($text{'elogs_alf'}, "cache_access_log", $conf, + $text{'default'}, 50); } else { # Supports definition of log formats and files - @logformat = &find_config("logformat", $conf); - $ltable = &ui_radio("logformat_def", @logformat ? 0 : 1, + my @logformat = &find_config("logformat", $conf); + my $ltable = &ui_radio("logformat_def", @logformat ? 0 : 1, [ [ 1, $text{'elogs_logformat1'} ], [ 0, $text{'elogs_logformat0'} ] ])."
\n"; $ltable .= &ui_columns_start([ $text{'elogs_fname'}, - $text{'elogs_ffmt'} ]); - $i = 0; - foreach $f (@logformat, { }) { - ($fname, @ffmt) = @{$f->{'values'}}; + $text{'elogs_ffmt'} ]); + my $i = 0; + foreach my $f (@logformat, { 'values' => [] }) { + my ($fname, @ffmt) = @{$f->{'values'}}; $ltable .= &ui_columns_row([ &ui_textbox("fname_$i", $fname, 20), &ui_textbox("ffmt_$i", join(" ", @ffmt), 60) @@ -36,17 +36,16 @@ else { $i++; } $ltable .= &ui_columns_end(); - print "\n"; - print "\n"; + print &ui_table_row($text{'elogs_logformat'}, $ltable, 3); # Show log files - @access = &find_config("access_log", $conf); - $atable = &ui_columns_start([ $text{'elogs_afile'}, - $text{'elogs_afmt'}, - $text{'elogs_aacls'} ]); + my @access = &find_config("access_log", $conf); + my $atable = &ui_columns_start([ $text{'elogs_afile'}, + $text{'elogs_afmt'}, + $text{'elogs_aacls'} ]); $i = 0; - foreach $a (@access, { }) { - ($afile, $afmt, @aacls) = @{$a->{'values'}}; + foreach my $a (@access, { 'values' => [] }) { + my ($afile, $afmt, @aacls) = @{$a->{'values'}}; $atable .= &ui_columns_row([ &ui_radio("afile_def_$i", !$afile ? 1 : $afile eq "none" ? 2 : 0, @@ -58,74 +57,65 @@ else { 30)) ] ]), &ui_select("afmt_$i", $afmt, [ [ "", "<".$text{'default'}.">" ], - map { [ $_->{'values'}->[0] ] } @logformat ]), + map { [ $_->{'values'}->[0] ] } @logformat ], + 1, 0, 1), &ui_textbox("aacls_$i", join(" ", @aacls), 20) ]); $i++; } $atable .= &ui_columns_end(); - print "\n"; - print "\n"; - - print "\n"; - print "
$text{'elogs_logformat'}$ltable
$text{'elogs_access'}$atable

\n"; + print &ui_table_row($text{'elogs_access'}, $atable, 3); } -print "\n"; print &opt_input($text{'elogs_dlf'}, "cache_log", $conf, $text{'default'}, 50); -print "\n"; -print "\n"; -$cslv = &find_config("cache_store_log", $conf); -$cslm = $cslv->{'value'} eq 'none' ? 2 : $cslv->{'value'} ? 0 : 1; -print "\n"; -print "\n", - $cslm == 0 ? $cslv->{'value'} : ""; -print "\n"; +my $cslv = &find_config("cache_store_log", $conf); +my $cslm = $cslv->{'value'} eq 'none' ? 2 : $cslv->{'value'} ? 0 : 1; +print &ui_table_row($text{'elogs_slf'}, + &ui_radio("cache_store_log_def", $cslm, + [ [ 1, $text{'default'} ], + [ 2, $text{'elogs_none'} ], + [ 0, &ui_textbox("cache_store_log", + $cslm == 0 ? $cslv->{'value'} : "", 50) ] ])); -print "\n"; -print &opt_input($text{'elogs_cmf'}, "cache_swap_log", $conf, $text{'default'}, 50); -print "\n"; +print &opt_input($text{'elogs_cmf'}, "cache_swap_log", $conf, + $text{'default'}, 50); -print "\n"; print &choice_input($text{'elogs_uhlf'}, "emulate_httpd_log", $conf, "off", $text{'yes'}, "on", $text{'no'}, "off"); print &choice_input($text{'elogs_lmh'}, "log_mime_hdrs", $conf, "off", $text{'yes'}, "on", $text{'no'}, "off"); -print "\n"; -print "\n"; -print &opt_input($text{'elogs_ualf'}, "useragent_log", $conf, $text{'none'}, 20); -print &opt_input($text{'elogs_pf'}, "pid_filename", $conf, $text{'default'}, 20); -print "\n"; +print &opt_input($text{'elogs_ualf'}, "useragent_log", $conf, + $text{'none'}, 20); +print &opt_input($text{'elogs_pf'}, "pid_filename", $conf, + $text{'default'}, 20); if ($squid_version >= 2.2) { - @ident = &find_config("ident_lookup_access", $conf); - foreach $i (@ident) { - local @v = @{$i->{'values'}}; - if ($v[0] eq "allow") { map { $ila{$_}++ } @v[1..$#v]; } - elsif ($v[0] eq "deny" && $v[1] ne "all") { $bad_ident++; } + my @ident = &find_config("ident_lookup_access", $conf); + my (%ila, $bad_ident); + foreach my $i (@ident) { + my @v = @{$i->{'values'}}; + if ($v[0] eq "allow") { + %ila = map { $_, 1 } @v[1..$#v]; + } + elsif ($v[0] eq "deny" && $v[1] ne "all") { + $bad_ident++; + } } if (!$bad_ident) { - print "\n"; + print &ui_table_row($text{'elogs_prilfa'}, + join("\n", @cbs), 3); } else { print "\n"; } print "\n"; @@ -133,28 +123,24 @@ if ($squid_version >= 2.2) { $conf, $text{'default'}, 6); } else { - print "\n"; print &choice_input($text{'elogs_dril'}, "ident_lookup", $conf, "off", $text{'yes'}, "on", $text{'no'}, "off"); } print &choice_input($text{'elogs_lfh'}, "log_fqdn", $conf, "off", $text{'yes'}, "on", $text{'no'}, "off"); -print "\n"; -print "\n"; -print &opt_input($text{'elogs_ln'}, "client_netmask", $conf, $text{'default'}, 15); -print &opt_input($text{'elogs_do'}, "debug_options", $conf, $text{'default'}, 15); -print "\n"; +print &opt_input($text{'elogs_ln'}, "client_netmask", $conf, + $text{'default'}, 15); +print &opt_input($text{'elogs_do'}, "debug_options", $conf, + $text{'default'}, 15); if ($squid_version >= 2) { - print "\n"; print &opt_input($text{'elogs_mht'}, "mime_table", $conf, $text{'default'}, 20); - print "\n"; } -print "
$text{'elogs_slf'}\n"; -printf " %s\n", - $cslm == 1 ? "checked" : "", $text{'default'}; -printf " %s\n", - $cslm == 2 ? "checked" : "", $text{'elogs_none'}; -printf "\n", - $cslm == 0 ? "checked" : ""; -printf "
$text{'elogs_prilfa'} \n"; - @acls = &find_config("acl", $conf); + my @acls = &find_config("acl", $conf); unshift(@acls, { 'values' => [ 'all' ] }) if ($squid_version >= 3); - foreach $acl (@acls) { - $aclv = $acl->{'values'}->[0]; + my (%doneacl, @cbs); + foreach my $acl (@acls) { + my $aclv = $acl->{'values'}->[0]; next if ($doneacl{$aclv}++); - printf "$aclv\n", - $ila{$aclv} ? "checked" : ""; + push(@cbs, &ui_checkbox("ident_lookup_access", $aclv, + $aclv, $ila{$aclv})); } - print "
\n"; -print "
\n"; +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'buttsave'} ] ]); &ui_print_footer("", $text{'elogs_return'}); diff --git a/squid/save_logs.cgi b/squid/save_logs.cgi index 530e15104..ce2f31393 100755 --- a/squid/save_logs.cgi +++ b/squid/save_logs.cgi @@ -2,12 +2,15 @@ # save_logs.cgi # Save logging options +use strict; +use warnings; +our (%text, %in, %access, $squid_version, %config); require './squid-lib.pl'; $access{'logging'} || &error($text{'elogs_ecannot'}); &ReadParse(); &lock_file($config{'squid_conf'}); -$conf = &get_config(); -$whatfailed = $text{'slogs_ftslo'}; +my $conf = &get_config(); +&error_setup($text{'slogs_ftslo'}); if ($squid_version < 2.6) { # Just a single logging directive @@ -15,8 +18,9 @@ if ($squid_version < 2.6) { } else { # Supports definition of log formats and files - for($i=0; defined($fname = $in{"fname_$i"}); $i++) { - $ffmt = $in{"ffmt_$i"}; + my @logformat; + for(my $i=0; defined(my $fname = $in{"fname_$i"}); $i++) { + my $ffmt = $in{"ffmt_$i"}; next if (!$fname); $fname =~ /^\S+$/ || &error(&text('slogs_efname', $i+1)); $ffmt =~ /\S/ || &error(&text('slogs_effmt', $i+1)); @@ -26,13 +30,14 @@ else { &save_directive($conf, "logformat", \@logformat); # Save log files - for($i=0; defined($afile = $in{"afile_$i"}); $i++) { - $adef = $in{"afile_def_$i"}; + my @access; + for(my $i=0; defined(my $afile = $in{"afile_$i"}); $i++) { + my $adef = $in{"afile_def_$i"}; next if ($adef == 1); $adef == 2 || $afile =~ /^\/\S+$/ || &error(&text('slogs_eafile', $i+1)); - $afmt = $in{"afmt_$i"}; - $aacls = $in{"aacls_$i"}; + my $afmt = $in{"afmt_$i"}; + my $aacls = $in{"aacls_$i"}; push(@access, { 'name' => 'access_log', 'values' => [ $adef == 2 ? "none" : $afile, @@ -59,7 +64,7 @@ else { &save_opt("pid_filename", \&check_pid_file, $conf); if ($squid_version >= 2.2) { if (!$in{'complex_ident'}) { - local @ila = split(/\0/, $in{'ident_lookup_access'}); + my @ila = split(/\0/, $in{'ident_lookup_access'}); &save_directive($conf, "ident_lookup_access", !@ila ? [ ] : [ { 'name' => 'ident_lookup_access', 'values' => [ 'allow', @ila ] } ]); @@ -83,26 +88,30 @@ if ($squid_version >= 2) { sub check_pid_file { -return $_[0] eq 'none' ? undef : &check_file($_[0]); +my ($file) = @_; +return $file eq 'none' ? undef : &check_file($file); } sub check_file { -$_[0] =~ /^\// || return &text('slogs_emsg1',$_[0]); -$_[0] =~ /^(\S*\/)([^\/\s]+)$/ || return &text('slogs_emsg2',$_[0]); -(-d $1) || return &text('slogs_emsg3',$1); +my ($file) = @_; +$file =~ /^\// || return &text('slogs_emsg1', $file); +$file =~ /^(\S*\/)([^\/\s]+)$/ || return &text('slogs_emsg2', $file); +(-d $1) || return &text('slogs_emsg3', $1); return undef; } sub check_netmask { -&check_ipaddress($_[0]) || return &text('slogs_emsg4',$_[0]); +my ($value) = @_; +&check_ipaddress($value) || return &text('slogs_emsg4', $value); return undef; } sub check_debug { -$_[0] =~ /\S+/ || return &text('slogs_emsg5',$_[0]); +my ($value) = @_; +$value =~ /\S+/ || return &text('slogs_emsg5', $value); return undef; } diff --git a/squid/squid-lib.pl b/squid/squid-lib.pl index aa158f254..e942b66ef 100755 --- a/squid/squid-lib.pl +++ b/squid/squid-lib.pl @@ -195,10 +195,10 @@ my $v = &find_config($name, $conf); return &ui_table_row($label, &ui_radio($name."_def", $v ? 0 : 1, [ [ 1, $def ], - [ 0, &time_field($name, $size, $v ? @{$v->{'values'}} : ( )) ] ])); + [ 0, &time_fields($name, $size, $v ? @{$v->{'values'}} : ( )) ] ])); } -# time_field(name, size, time, units) +# time_fields(name, size, time, units) sub time_fields { my ($name, $size, $time, $units) = @_;