More strict and ui-lib conversion

This commit is contained in:
Jamie Cameron
2014-03-05 16:40:37 -08:00
parent abe19d407a
commit 02de99acbb
6 changed files with 64 additions and 52 deletions

View File

@ -1,52 +1,46 @@
use strict;
use warnings;
our (%text, %in);
do 'webalizer-lib.pl';
# acl_security_form(&options)
# Output HTML for editing security options for the webalizer module
sub acl_security_form
{
print "<tr> <td><b>$text{'acl_view'}</b></td>\n";
printf "<td nowrap><input type=radio name=view value=1 %s> %s\n",
$_[0]->{'view'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=view value=0 %s> %s</td>\n",
$_[0]->{'view'} ? "" : "checked", $text{'no'};
my ($o) = @_;
print "<td><b>$text{'acl_global'}</b></td>\n";
printf "<td nowrap><input type=radio name=global value=1 %s> %s\n",
$_[0]->{'global'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=global value=0 %s> %s</td> </tr>\n",
$_[0]->{'global'} ? "" : "checked", $text{'no'};
print &ui_table_row($text{'acl_view'},
&ui_yesno_radio("view", $o->{'view'}));
print "<tr> <td><b>$text{'acl_add'}</b></td>\n";
printf "<td nowrap><input type=radio name=add value=1 %s> %s\n",
$_[0]->{'add'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=add value=0 %s> %s</td> </tr>\n",
$_[0]->{'add'} ? "" : "checked", $text{'no'};
print &ui_table_row($text{'acl_global'},
&ui_yesno_radio("global", $o->{'global'}));
print "<tr> <td><b>$text{'acl_user'}</b></td>\n";
printf "<td colspan=3><input type=radio name=user_def value=1 %s> %s\n",
$_[0]->{'user'} eq "" ? "checked" : "", $text{'acl_this'};
printf "<input type=radio name=user_def value=2 %s> %s\n",
$_[0]->{'user'} eq "*" ? "checked" : "", $text{'acl_any'};
printf "<input type=radio name=user_def value=0 %s>\n",
$_[0]->{'user'} eq "*" || $_[0]->{'user'} eq "" ? "" : "checked";
printf "<input name=user size=8 value='%s'> %s</td> </tr>\n",
$_[0]->{'user'} eq "*" ? "" : $_[0]->{'user'},
&user_chooser_button("user");
print &ui_table_row($text{'acl_add'},
&ui_yesno_radio("add", $o->{'add'}));
print "<tr> <td><b>$text{'acl_dir'}</b></td>\n";
print "<td colspan=3><input name=dir size=50 value='$_[0]->{'dir'}'></td> </tr>\n";
print &ui_table_row($text{'acl_user'},
&ui_radio("user_def", $o->{'user'} eq "" ? 1 :
$o->{'user'} eq "*" ? 2 : 0,
[ [ 1, $text{'acl_this'} ],
[ 2, $text{'acl_any'} ],
[ 0, &ui_userbox("user", $o->{'user'} eq "*" ? "" :
$o->{'user'}, 20) ] ]));
print &ui_table_row($text{'acl_dir'},
&ui_textbox("dir", $o->{'dir'}, 60), 3);
}
# acl_security_save(&options)
# acl_security_save(&options, &in)
# Parse the form for security options for the shell module
sub acl_security_save
{
$_[0]->{'view'} = $in{'view'};
$_[0]->{'global'} = $in{'global'};
$_[0]->{'add'} = $in{'add'};
$_[0]->{'dir'} = $in{'dir'};
$_[0]->{'user'} = $in{'user_def'} == 2 ? "*" :
$in{'user_def'} == 1 ? "" : $in{'user'};
my ($o, $in) = @_;
$o->{'view'} = $in->{'view'};
$o->{'global'} = $in->{'global'};
$o->{'add'} = $in->{'add'};
$o->{'dir'} = $in->{'dir'};
$o->{'user'} = $in->{'user_def'} == 2 ? "*" :
$in->{'user_def'} == 1 ? "" : $in->{'user'};
}

View File

@ -1,19 +1,22 @@
use strict;
use warnings;
our (%text, %in, $module_config_directory, $cron_cmd, %config);
do 'webalizer-lib.pl';
# backup_config_files()
# Returns files and directories that can be backed up
sub backup_config_files
{
local @rv = ( $config{'webalizer_conf'} );
local $f;
opendir(DIR, $module_config_directory);
while($f = readdir(DIR)) {
my @rv = ( $config{'webalizer_conf'} );
my $fh;
opendir($fh, $module_config_directory);
while(my $f = readdir($fh)) {
if ($f =~ /\.conf$/ || $f =~ /\.log$/) {
push(@rv, "$module_config_directory/$f");
}
}
closedir(DIR);
closedir($fh);
return @rv;
}
@ -44,12 +47,12 @@ sub post_restore
{
# Re-setup all needed cron jobs
&foreign_require("cron", "cron-lib.pl");
local @jobs = &cron::list_cron_jobs();
foreach $log (&get_all_logs()) {
local $lconf = &get_log_config($log->{'file'});
my @jobs = &cron::list_cron_jobs();
foreach my $log (&get_all_logs()) {
my $lconf = &get_log_config($log->{'file'});
if ($lconf->{'sched'}) {
local ($job) = grep { $_->{'command'} eq
"$cron_cmd $log->{'file'}" } @jobs;
my ($job) = grep { $_->{'command'} eq
"$cron_cmd $log->{'file'}" } @jobs;
if (!$job) {
# Need to create!
$job->{'user'} = 'root';

View File

@ -1,4 +1,7 @@
use strict;
use warnings;
our (%text, %access);
do 'webalizer-lib.pl';
sub cgi_args

View File

@ -1,5 +1,8 @@
# install_check.pl
use strict;
use warnings;
our (%config);
do 'webalizer-lib.pl';
# is_installed(mode)
@ -9,7 +12,8 @@ do 'webalizer-lib.pl';
sub is_installed
{
return 0 if (!&has_command($config{'webalizer'}));
local $ver = &get_webalizer_version(\$dummy);
my $dummy;
my $ver = &get_webalizer_version(\$dummy);
return 0 if (!$ver || $ver < 2);
return $_[0] ? 2 : 1;
}

View File

@ -1,13 +1,16 @@
# log_parser.pl
# Functions for parsing this module's logs
use strict;
use warnings;
our (%text);
do 'webalizer-lib.pl';
# parse_webmin_log(user, script, action, type, object, &params)
# Converts logged information from this module into human-readable form
sub parse_webmin_log
{
local ($user, $script, $action, $type, $object, $p) = @_;
my ($user, $script, $action, $type, $object, $p) = @_;
if ($type eq "log") {
return &text("log_${action}_log", "<tt>".&html_escape($object)."</tt>");
}

View File

@ -2,21 +2,26 @@
# webalizer.pl
# Generate a report on schedule
use strict;
use warnings;
our ($no_acl_check, %config);
$no_acl_check++;
require './webalizer-lib.pl';
$lconf = &get_log_config($ARGV[0]);
my $lconf = &get_log_config($ARGV[0]);
$lconf || die "Logfile $ARGV[0] config file does not exist";
open(NULL, ">/dev/null");
my $fh;
open($fh, ">/dev/null");
&clean_language();
$ok = &generate_report($ARGV[0], NULL, 0);
my $ok = &generate_report($ARGV[0], $fh, 0);
&reset_environment();
close(NULL);
close($fh);
if ($ok && $lconf->{'clear'}) {
# Truncate or delete the files for this report
@files = $config{'skip_old'} ? ( $ARGV[0] ) : &all_log_files($ARGV[0]);
foreach $f (@files) {
my @files = $config{'skip_old'} ? ( $ARGV[0] )
: &all_log_files($ARGV[0]);
foreach my $f (@files) {
next if (!-r $f);
if ($f eq $ARGV[0]) {
# Just truncate the main log file