More strict compliance and ui-lib conversion

This commit is contained in:
Jamie Cameron
2014-01-02 23:27:03 -08:00
parent 89e0984a8e
commit d8e8170a3c
4 changed files with 91 additions and 93 deletions

View File

@@ -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.

View File

@@ -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 "<form action=save_logs.cgi>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'elogs_lalo'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\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 "<tr>\n";
print &opt_input($text{'elogs_alf'}, "cache_access_log", $conf, $text{'default'}, 50);
print "</tr>\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'} ] ])."<br>\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 "<tr> <td valign=top><b>$text{'elogs_logformat'}</b></td>\n";
print "<td colspan=3>$ltable</td> </tr>\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,
[ [ "", "&lt;".$text{'default'}."&gt;" ],
map { [ $_->{'values'}->[0] ] } @logformat ]),
map { [ $_->{'values'}->[0] ] } @logformat ],
1, 0, 1),
&ui_textbox("aacls_$i", join(" ", @aacls), 20)
]);
$i++;
}
$atable .= &ui_columns_end();
print "<tr> <td valign=top><b>$text{'elogs_access'}</b></td>\n";
print "<td colspan=3>$atable</td> </tr>\n";
print "<tr> <td colspan=4><hr></td> </tr>\n";
print "</table><table width=100%>\n";
print &ui_table_row($text{'elogs_access'}, $atable, 3);
}
print "<tr>\n";
print &opt_input($text{'elogs_dlf'}, "cache_log", $conf, $text{'default'}, 50);
print "</tr>\n";
print "<tr>\n";
$cslv = &find_config("cache_store_log", $conf);
$cslm = $cslv->{'value'} eq 'none' ? 2 : $cslv->{'value'} ? 0 : 1;
print "<td valign=top><b>$text{'elogs_slf'}</b></td>\n";
print "<td nowrap colspan=3>\n";
printf "<input type=radio name=cache_store_log_def value=1 %s> %s\n",
$cslm == 1 ? "checked" : "", $text{'default'};
printf "<input type=radio name=cache_store_log_def value=2 %s> %s\n",
$cslm == 2 ? "checked" : "", $text{'elogs_none'};
printf "<input type=radio name=cache_store_log_def value=0 %s>\n",
$cslm == 0 ? "checked" : "";
printf "<input name=cache_store_log size=50 value=\"%s\"></td>\n",
$cslm == 0 ? $cslv->{'value'} : "";
print "</tr>\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 "<tr>\n";
print &opt_input($text{'elogs_cmf'}, "cache_swap_log", $conf, $text{'default'}, 50);
print "</tr>\n";
print &opt_input($text{'elogs_cmf'}, "cache_swap_log", $conf,
$text{'default'}, 50);
print "<tr>\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 "</tr>\n";
print "<tr>\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 "</tr>\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 "<tr><td valign=top><b>$text{'elogs_prilfa'}</b></td> <td colspan=3>\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 "<input type=checkbox name=ident_lookup_access ".
"value=$aclv %s>$aclv\n",
$ila{$aclv} ? "checked" : "";
push(@cbs, &ui_checkbox("ident_lookup_access", $aclv,
$aclv, $ila{$aclv}));
}
print "</td> </tr>\n";
print &ui_table_row($text{'elogs_prilfa'},
join("\n", @cbs), 3);
}
else { print "<input type=hidden name=complex_ident value=1>\n"; }
print "<tr>\n";
@@ -133,28 +123,24 @@ if ($squid_version >= 2.2) {
$conf, $text{'default'}, 6);
}
else {
print "<tr>\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 "</tr>\n";
print "<tr>\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 "</tr>\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 "<tr>\n";
print &opt_input($text{'elogs_mht'}, "mime_table",
$conf, $text{'default'}, 20);
print "</tr>\n";
}
print "</table></td></tr></table>\n";
print "<input type=submit value=$text{'buttsave'}></form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'buttsave'} ] ]);
&ui_print_footer("", $text{'elogs_return'});

View File

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

View File

@@ -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) = @_;