From: eldy <> Date: Sun, 20 Jun 2004 18:45:44 +0000 (+0000) Subject: Some change to add scheduler management for update process X-Git-Tag: AWSTATS_6_2_BETA~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7280df3db68069aa47c6af449c729cbfb11229ba;p=thirdparty%2FAWStats.git Some change to add scheduler management for update process Creating new config files can be done by copying an old one. --- diff --git a/tools/webmin/awstats/awstats-webmin_changelog.txt b/tools/webmin/awstats/awstats-webmin_changelog.txt index 985817d5..0835e64e 100644 --- a/tools/webmin/awstats/awstats-webmin_changelog.txt +++ b/tools/webmin/awstats/awstats-webmin_changelog.txt @@ -2,6 +2,13 @@ AWStats-Webmin module Changelog ------------------------------- $Revision$ - $Author$ - $Date$ +1.400 + +New features/improvements: +- Some change to add scheduler management for update process +- Creating new config files can be done by copying an old one. + + 1.300 Fixes: diff --git a/tools/webmin/awstats/edit_config.cgi b/tools/webmin/awstats/edit_config.cgi index 7e16db5e..ac9bba23 100644 --- a/tools/webmin/awstats/edit_config.cgi +++ b/tools/webmin/awstats/edit_config.cgi @@ -34,31 +34,62 @@ foreach my $key (keys %$lconf) { $lconf->{$key}=~s/[\"\']\s*$//; } +# Put in @conflist, list of all existing config +my @conflist=(); +foreach my $dir (split(/\s+/, $access{'dir'})) { + push(@conflist, map { $_->{'custom'} = 1; $_ } &scan_config_dir($dir)); +} + + print "
\n"; print < -function Submit_onClick() { - if (document.editconfig.LogFormat.value=='') { - alert('$text{save_errLogFormat}'); - document.editconfig.LogFormat.focus(); - return false; - } - if (document.editconfig.LogFile.value.match(/maillogconvert.pl/)!=null && document.editconfig.LogType.value != 'M') { - alert('Your log file is preprocessed by maillogconvert.pl but is not defined as a "Mail" log type.\\nChange LogFile or LogType parameter.'); - document.editconfig.LogType.focus(); - return false; - } - if (document.editconfig.SiteDomain.value=='') { - alert('$text{save_errSiteDomain}'); - document.editconfig.SiteDomain.focus(); - return false; - } - if (document.editconfig.DirData.value=='') { - alert('$text{save_errDirData}'); - document.editconfig.DirData.focus(); - return false; - } +function Submit_onClick() { +EOF +# If create +if ($in{'new'} && scalar @conflist) { +print <\n"; -print "\n"; +print "
\n"; print "
"; if ($in{'new'}) { print &text('edit_headernew'); @@ -98,12 +129,29 @@ print "
\n"; my $filenametosave=""; if ($in{'new'}) { print "\n"; - print "\n"; + print "
$text{'edit_add'} \n"; - my $newfile="/etc/awstats/awstats.newconfig.conf"; print ""; - print "

\n"; + + if (scalar @conflist) { + print "
".$text{'edit_create_by_copy'}; + print "
\n"; + print "\n"; + print "\n"; + print "
$text{'edit_config_to_copy'} \n"; + print ""; + print "
\n"; + } + + print "
".$text{'edit_create_from_scratch'}; + print "
\n"; + print "\n"; } else { print "\n"; } @@ -111,9 +159,9 @@ print "\n"; print "\n"; -print "\n"; -print "\n"; -print "\n"; print "\n"; -print "\n"; print "\n"; @@ -142,6 +190,7 @@ print "\n"; print "\n"; +print "\n"; @@ -531,11 +580,9 @@ if ($advanced) { print "\n"; print "\n"; print "\n"; - print "
MAIN SETUP SECTION (Required to make AWStats work)

LogFile ".&file_chooser_button("LogFile",0,0)." "; +print "
LogFile* ".&file_chooser_button("LogFile",0,0)." "; print &hblink($text{'help_help'}, "help.cgi?param=LogFile")."
LogType "; +print "
LogType* "; print "\n"; print " "; print &hblink($text{'help_help'}, "help.cgi?param=LogType")."
LogFormat "; +print "
LogFormat* "; print &hblink($text{'help_help'}, "help.cgi?param=LogFormat"),"
LogSeparator "; print &hblink($text{'help_help'}, "help.cgi?param=LogSeparator")."
SiteDomain "; +print "
SiteDomain* "; print &hblink($text{'help_help'}, "help.cgi?param=SiteDomain")."
HostAliases "; print &hblink($text{'help_help'}, "help.cgi?param=HostAliases")."
AllowToUpdateStatsFromBrowser
AllowFullYearView "; print &hblink($text{'help_help'}, "help.cgi?param=AllowFullYearView")."
* are required parameters with no default value. They can't be empty. "; print "

OPTIONAL SETUP SECTION (Not required but increase AWStats features)



$text{'index_hideadvanced'}

\n"; -} -else{ - print "
\n"; } +print "\n"; +print "\n"; @b=(); if ($in{'new'}) { @@ -555,6 +602,7 @@ else { print "\n"; +# Back to config list print "
\n"; &footer("", $text{'index_return'}); diff --git a/tools/webmin/awstats/lang/en b/tools/webmin/awstats/lang/en index 124f0e18..c64db3b4 100644 --- a/tools/webmin/awstats/lang/en +++ b/tools/webmin/awstats/lang/en @@ -37,6 +37,9 @@ edit_header=Editor Assistant for config file $1 edit_headernew=Config file Builder Assistant edit_file=File content edit_add=Config file name to create +edit_create_by_copy=Create a new config file by copying an existing one +edit_create_from_scratch=Create a new config file with folowing parameters +edit_config_to_copy=Config file name to copy edit_user=Run AWStats as user edit_ecannot=You are not allowed to edit this config file edit_efilecannot=The config file '$1' is not in an allowed directory diff --git a/tools/webmin/awstats/lang/fr b/tools/webmin/awstats/lang/fr index 1f113d03..2415dcc8 100644 --- a/tools/webmin/awstats/lang/fr +++ b/tools/webmin/awstats/lang/fr @@ -37,6 +37,9 @@ edit_header=Assistant d' edit_headernew=Assistant de création de nouveau fichier de configuration edit_file=Contenu du fichier edit_add=Nom du fichier de config à créer +edit_create_by_copy=Créer une nouvelle configuration par recopie d'une existante +edit_create_from_scratch=Créer une nouvelle configuration avec les paramètres suivants +edit_config_to_copy=Nom de la configuration à recopier edit_user=Lancer AWStats sous l'utilisateur edit_ecannot=Vous n'êtes pas autorisés à éditer ce fichier de configuration edit_efilecannot=Le fichier de configuration '$1' n'est pas dans un répertoire autorisé diff --git a/tools/webmin/awstats/save_config.cgi b/tools/webmin/awstats/save_config.cgi index a8a5af36..8a10c41f 100644 --- a/tools/webmin/awstats/save_config.cgi +++ b/tools/webmin/awstats/save_config.cgi @@ -40,7 +40,7 @@ elsif ($in{'delete'}) { } else { - # Validate and store inputs + # Validate and store inputs. $in{'new'} is new file to create or update. if (!$in{'new'} && !$in{'file'}) { &error($text{'save_efile'}); } my $dir=$in{'file'}; $dir =~ s/[\\\/][^\\\/]+$//; @@ -52,48 +52,62 @@ else { if ($in{'new'} && -r $in{'$file'}) { &error($text{'save_fileexists'}); } if (! -d $dir) { &error($text{'save_dirnotexists'}); } - %conf=(); - foreach my $key (keys %in) { - if ($key eq 'file') { next; } - if ($key eq 'new') { next; } - if ($key eq 'submit') { next; } - if ($key eq 'oldfile') { next; } - $conf{$key} = $in{$key}; - if ($conf{key} ne ' ') { - $conf{$key} =~ s/^\s+//; - $conf{$key} =~ s/\s+$//; - } - } - if ($conf{'LogSeparator'} eq '') { $conf{'LogSeparator'}=' '; } - - # Check data - my $logfile=''; - if ($conf{'LogFile'} !~ /|\s*$/) { # LogFile is not a piped valued - $logfile=$conf{'LogFile'}; - } - else { # LogFile is piped - # It can be - # '/xxx/maillogconvert.pl standard /aaa/mail.log |' - # '/xxx/logresolvermerge.pl *' - - # TODO test something here ? - } - if ($logfile && ! -r $logfile) { &error(&text(save_errLogFile,$logfile)); } - if (! $conf{'SiteDomain'}) { &error(&text(save_errSiteDomain,$conf{'SiteDomain'})); } - if (! -d $conf{'DirData'}) { &error(&text(save_errDirData,$conf{'DirData'})); } + my $modelconf=$config{'alt_conf'}; + + # If create by copy + if ($in{'new'} && $in{'create_mode'} eq 'by_copy') { + $modelconf=$in{'file_to_copy'}; + $in{'new'} =~ s/([^\\\/]+)$//; + my $to=$1; + if (! $modelconf || ! -r $modelconf) { &error('You must choose a config to copy'); } + # Add a new config file + &system_logged("cp '$modelconf' '$dir/$to'"); + } + else { + %conf=(); + foreach my $key (keys %in) { + if ($key eq 'file') { next; } + if ($key eq 'new') { next; } + if ($key eq 'submit') { next; } + if ($key eq 'oldfile') { next; } + $conf{$key} = $in{$key}; + if ($conf{key} ne ' ') { + $conf{$key} =~ s/^\s+//; + $conf{$key} =~ s/\s+$//; + } + } + if ($conf{'LogSeparator'} eq '') { $conf{'LogSeparator'}=' '; } + + # Check data + my $logfile=''; + if ($conf{'LogFile'} !~ /|\s*$/) { # LogFile is not a piped valued + $logfile=$conf{'LogFile'}; + } + else { # LogFile is piped + # It can be + # '/xxx/maillogconvert.pl standard /aaa/mail.log |' + # '/xxx/logresolvermerge.pl *' + + # TODO test something here ? + } + if ($logfile && ! -r $logfile) { &error(&text(save_errLogFile,$logfile)); } + if (! $conf{'SiteDomain'}) { &error(&text(save_errSiteDomain,$conf{'SiteDomain'})); } + if (! -d $conf{'DirData'}) { &error(&text(save_errDirData,$conf{'DirData'})); } + + if ($in{'new'}) { + # Add a new config file + &system_logged("cp '$modelconf' '$in{'new'}'"); + } + + # Update the config file's options + local $cfile = $in{'file'}; + &lock_file($cfile); + &update_config($cfile, \%conf); + &unlock_file($cfile); + } - if ($in{'new'}) { - # Add a new config file to the configuration - &system_logged("cp '$config{'alt_conf'}' '$in{'new'}'"); - } - - # Update the config file's options - local $cfile = $in{'file'}; - &lock_file($cfile); - &update_config($cfile, \%conf); - &unlock_file($cfile); &webmin_log($in{'new'} ? "create" : "modify", "log", $in{'file'}); - } +} &redirect(""); diff --git a/tools/webmin/awstats/schedule_stats.cgi b/tools/webmin/awstats/schedule_stats.cgi index 2136efc0..852d988e 100644 --- a/tools/webmin/awstats/schedule_stats.cgi +++ b/tools/webmin/awstats/schedule_stats.cgi @@ -17,131 +17,71 @@ if ($in{'file'} =~ /^(.*)[\\\/][^\\\/]+$/) { $dir=$1; } print "
\n"; - -print "Feature not yet available\n"; -print "You must manually check if AWStats update process is"; -print " in crontab"; -print " or added into a logrotate preprocessor task
"; +print "AWStats scheduled update processes detected for config file ".$in{'file'}."
\n"; +print "
\n"; print "
\n"; -# Read cron +# Load other modules lib &foreign_require("cron", "cron-lib.pl"); -#@procs = &foreign_call("proc", "list_processes"); -#&foreign_call("proc", "renice_proc", $pid, -10); - -# Read logrotate &foreign_require("logrotate", "logrotate-lib.pl"); -#@procs = &foreign_call("proc", "list_processes"); -#&foreign_call("proc", "renice_proc", $pid, -10); - # For global update +print "Update processes scheduled by a cron task :
"; print "\n"; -print "\n"; - -print ""; +print "\n"; -if ( foreign_installed('cron', 0) || foreign_installed('logrotate', 0) ) { - print "
"; -print "Scheduled AWStats global update process (For all files in /etc/awstats)"; -print "
"; +print "
UserTaskActiveNote on taskAction
\n"; +my $globalupdate=0; +my $confupdate=0; +if ( foreign_installed('cron', 0) ) { # Show cron found - if ( foreign_installed('cron', 0) ) { - $idcron=0; - @jobs = &foreign_call("cron","list_cron_jobs"); - - #TODO detect idcron for /.*/awstats_updateall.pl in @jobs - - print "\n"; + my $regupdateall="awstats_updateall\.pl"; + my $regupdate="awstats\.pl"; + foreach my $j (grep { $_->{'command'} =~ /$regupdate/ || $_->{'command'} =~ /$regupdateall/ } &foreign_call("cron","list_cron_jobs")) { + my $global=0; + if ($j->{'command'} =~ /$regupdateall/) { $globalupdate++; $global=1; } + print ""; + print ""; + print ""; + print ""; + if ($global) { print ""; } + else { print ""; } + print ""; + print ""; } - # Loop on each logrotate found - if ( foreign_installed('logrotate', 0) ) { - print " "; - - print " "; - print " "; - } - print "
By cron "; - if (! $idcron) { - print "Off\n"; - } - else { - print "On\n"; - } - print " "; - if (! $idcron) { - print "Add AWStats global update process in cron\n"; - } else { - print "Edit cron task to update all AWStats config files "; - } - print "
".$j->{'user'}."".$j->{'command'}."".($j->{'active'}?'yes':'no')."Update all config filesUpdate this config file only{'index'}."\">Jump to cron task
By logrotate preprocess File: NA Edit logrotate file
"; - - print "Add a logrotate for this file"; - - print "
"; } else { - print "Nor cron, nor logrotate module are installed. They are required to setup AWStats scheduled tasks"; + print "Webmin cron module is not installed. It is required to setup cron scheduled tasks"; } - -print " \n"; print ""; +print "
\n"; +print "Add an AWStats cron task to update all AWStats config files
"; +print "(You must add the command \"/usr/local/awstats/tools/awstats_updateall.pl now >/dev/null\")
\n"; +print "
\n"; +print "Add an AWStats cron task to update this config files
\n"; +print "(You must add the command \"$config{'awstats'} -update -config=$conf >/dev/null\")
\n"; +print "
\n"; +print "
\n"; print "
\n"; -# For particular config file update +# For logrotate scheduling +print "Update processes scheduled by a logrotate task :
"; print "\n"; -print "\n"; +print ""; +print "\n"; + +if ( foreign_installed('logrotate', 0) ) { -print ""; } - -print "\n"; print "
"; -print "Scheduled AWStats update process for this config file only (".$in{'file'}.")"; -print "
Logrotate fileTaskNote on taskAction
"; -if ( foreign_installed('cron', 0) || foreign_installed('logrotate', 0) ) { - print "\n"; - # Show cron found - if ( foreign_installed('cron', 0) ) { - @jobs = &foreign_call("cron","list_cron_jobs"); - - #TODO detect idcron for /.*/awstats_updateall.pl in @jobs - - print "\n"; - } - # Loop on each logrotate found - if ( foreign_installed('logrotate', 0) ) { - print " "; - print " "; - print " "; - - } - print "
By cron "; - if (! $idcron) { - print "Off\n"; - } - else { - print "On\n"; - } - print " "; - if (! $idcron) { - print "Add AWStats update process in cron for config file\n"; - } else { - print "Edit cron task to update only this AWStats config files "; - } - print "
By logrotate preprocess File: NA Edit logrotate file
"; - - print "Add a logrotate for this file"; - - print "
"; } else { - print "Nor cron, nor logrotate module are installed. They are required to setup AWStats scheduled tasks"; + print "
Webmin logrotate module is not installed. It is required to setup logrotate scheduled tasks
"; - +print "Add a logrotate for this file"; print "
\n";