Creating new config files can be done by copying an old one.
-------------------------------
$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:
$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 "<hr>\n";
print <<EOF;
<SCRIPT LANGUAGE="JavaScript">\r
-function Submit_onClick() {\r
- if (document.editconfig.LogFormat.value=='') {\r
- alert('$text{save_errLogFormat}');\r
- document.editconfig.LogFormat.focus();\r
- return false;\r
- }
- if (document.editconfig.LogFile.value.match(/maillogconvert.pl/)!=null && document.editconfig.LogType.value != 'M') {\r
- alert('Your log file is preprocessed by maillogconvert.pl but is not defined as a "Mail" log type.\\nChange LogFile or LogType parameter.');\r
- document.editconfig.LogType.focus();\r
- return false;\r
- }\r
- if (document.editconfig.SiteDomain.value=='') {\r
- alert('$text{save_errSiteDomain}');\r
- document.editconfig.SiteDomain.focus();\r
- return false;\r
- }\r
- if (document.editconfig.DirData.value=='') {\r
- alert('$text{save_errDirData}');\r
- document.editconfig.DirData.focus();\r
- return false;\r
- }\r
+function Submit_onClick() {
+EOF
+# If create
+if ($in{'new'} && scalar @conflist) {\r
+print <<EOF;
+ if (document.editconfig.create_mode[0].checked) {
+ if (document.editconfig.file_to_copy.value=='') {
+ alert('You must choose a config to copy for creating a new one by copy');\r
+ document.editconfig.file_to_copy.focus();\r
+ return false;\r
+ }\r
+ } else {
+EOF
+}
+# End If create
+print <<EOF;
+ if (document.editconfig.LogFormat.value=='') {\r
+ alert('$text{save_errLogFormat}');\r
+ document.editconfig.LogFormat.focus();\r
+ return false;\r
+ }
+ if (document.editconfig.LogFile.value.match(/maillogconvert.pl/)!=null && document.editconfig.LogType.value != 'M') {\r
+ alert('Your log file is preprocessed by maillogconvert.pl but is not defined as a "Mail" log type.\\nChange LogFile or LogType parameter.');\r
+ document.editconfig.LogType.focus();\r
+ return false;\r
+ }\r
+ if (document.editconfig.SiteDomain.value=='') {\r
+ alert('$text{save_errSiteDomain}');\r
+ document.editconfig.SiteDomain.focus();\r
+ return false;\r
+ }\r
+ if (document.editconfig.DirData.value=='') {\r
+ alert('$text{save_errDirData}');\r
+ document.editconfig.DirData.focus();\r
+ return false;\r
+ }
+EOF\r
+# If create
+if ($in{'new'} && scalar @conflist) {\r
+print <<EOF;
+ }
+EOF
+}
+# End If create
+print <<EOF;
return true;
}
print "<form name='editconfig' action='save_config.cgi'>\n";
-print "<table border width=100%>\n";
+print "<table border width=\"100%\">\n";
print "<tr $tb> <td><b>";
if ($in{'new'}) {
print &text('edit_headernew');
my $filenametosave="";
if ($in{'new'}) {
print "<tr> <td><b>$text{'edit_add'}</b></td> <td>\n";
-
my $newfile="/etc/awstats/awstats.newconfig.conf";
print "<input type=text name=new size=50 value='$newfile'>";
-
print "</td> <td> </td> </tr>\n";
- print "<tr> <td colspan=3><hr></td> </tr>\n";
+ print "</table></td></tr></table>\n";
+
+ if (scalar @conflist) {
+ print "<br><input name=\"create_mode\" type=\"radio\" value=\"by_copy\"> ".$text{'edit_create_by_copy'};
+ print "<table border width=\"100%\"><tr $cb><td>\n";
+ print "<table width=\"100%\">\n";
+ print "<tr> <td><b>$text{'edit_config_to_copy'}</b></td> <td>\n";
+ print "<select name=\"file_to_copy\"><option value='' selected> </option>\n";
+ foreach my $file (@conflist) {
+ next if (!&can_edit_config($file));
+ print "<option value=\"$file\">$file</option>\n";
+ }
+ print "</select>";
+ print "</td> <td> </td> </tr>\n";
+ print "</table></td></tr></table>\n";
+ }
+
+ print "<br><input name=\"create_mode\" type=\"radio\" value=\"from_scratch\" checked=true> ".$text{'edit_create_from_scratch'};
+ print "<table border width=\"100%\"><tr $cb><td>\n";
+ print "<table width=\"100%\">\n";
} else {
print "<input type=hidden name=file value='$in{'file'}'>\n";
}
print "<tr> <td colspan=3>MAIN SETUP SECTION (Required to make AWStats work)<br><hr></td> </tr>\n";
-print "<tr> <td><b>LogFile</b></td> <td> <input type=text name=LogFile size=50 value='$lconf->{'LogFile'}'> ".&file_chooser_button("LogFile",0,0)." </td> <td> ";
+print "<tr> <td><b>LogFile*</b></td> <td> <input type=text name=LogFile size=50 value='$lconf->{'LogFile'}'> ".&file_chooser_button("LogFile",0,0)." </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=LogFile")." </td> </tr>\n";
-print "<tr> <td><b>LogType</b></td> <td> ";
+print "<tr> <td><b>LogType*</b></td> <td> ";
print "<select name=LogType>";
print "<option value='W'".($lconf->{'LogType'} eq 'W'?" selected":"").">W (Web server log file)</option>\n";
print "<option value='S'".($lconf->{'LogType'} eq 'S'?" selected":"").">S (Streaming server log file)</option>\n";
print "</select>\n";
print "</td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=LogType")." </td> </tr>\n";
-print "<tr> <td><b>LogFormat</b></td> <td> <input name=LogFormat type=text size=40 value='$lconf->{'LogFormat'}'> </td> <td> ";
+print "<tr> <td><b>LogFormat*</b></td> <td> <input name=LogFormat type=text size=40 value='$lconf->{'LogFormat'}'> </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=LogFormat")," </td> </tr>\n";
print "<tr> <td><b>LogSeparator</b></td> <td> <input size=10 name=LogSeparator type=text value='$lconf->{'LogSeparator'}'> </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=LogSeparator")." </td> </tr>\n";
-print "<tr> <td><b>SiteDomain</b></td> <td> <input name=SiteDomain type=text value='$lconf->{'SiteDomain'}'> </td> <td> ";
+print "<tr> <td><b>SiteDomain*</b></td> <td> <input name=SiteDomain type=text value='$lconf->{'SiteDomain'}'> </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=SiteDomain")." </td> </tr>\n";
print "<tr> <td><b>HostAliases</b></td> <td> <input size=50 name=HostAliases type=text value='$lconf->{'HostAliases'}'> </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=HostAliases")." </td> </tr>\n";
print &hblink($text{'help_help'}, "help.cgi?param=AllowToUpdateStatsFromBrowser")." </td> </tr>\n";
print "<tr> <td><b>AllowFullYearView</b></td> <td> <input size=10 name=AllowFullYearView type=text value='$lconf->{'AllowFullYearView'}'> </td> <td> ";
print &hblink($text{'help_help'}, "help.cgi?param=AllowFullYearView")." </td> </tr>\n";
+print "<tr> <td colspan=2><b>*</b> are required parameters with no default value. They can't be empty.</td> <td> ";
print "<tr> <td colspan=3><br>OPTIONAL SETUP SECTION (Not required but increase AWStats features)<br><hr></td> </tr>\n";
print "<tr> <td colspan=3><br><hr></td> </tr>\n";
print "<tr> <td colspan=3 align=center><a href='edit_config.cgi?".($in{'new'}?"new=1&":"")."file=$in{'file'}'>$text{'index_hideadvanced'}</a></td></tr>\n";
print "<tr> <td colspan=3><hr></td> </tr>\n";
- print "</table>\n";
-}
-else{
- print "</table>\n";
}
+print "</table>\n";
+print "</td></tr></table>\n";
@b=();
if ($in{'new'}) {
print "</form>\n";
+# Back to config list
print "<hr>\n";
&footer("", $text{'index_return'});
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
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é
}
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/[\\\/][^\\\/]+$//;
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("");
print "<hr>\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<br>";
+print "AWStats scheduled update processes detected for config file <b>".$in{'file'}."</b><br>\n";
+print "<br>\n";
print "<br>\n";
-# Read cron
+# Load other modules lib
&foreign_require("cron", "cron-lib.pl");\r
-#@procs = &foreign_call("proc", "list_processes");\r
-#&foreign_call("proc", "renice_proc", $pid, -10);
-
-# Read logrotate
&foreign_require("logrotate", "logrotate-lib.pl");\r
-#@procs = &foreign_call("proc", "list_processes");\r
-#&foreign_call("proc", "renice_proc", $pid, -10);
-
# For global update
+print "Update processes scheduled by a <b>cron</b> task :<br>";
print "<table border width=100%>\n";
-print "<tr $tb> <td align=left><b>";
-print "Scheduled AWStats global update process (For all files in /etc/awstats)";
-print "</b></td> </tr>\n";
-
-print "<tr> <td> ";
+print "<tr $tb><td align=left>User</td>";
+print "<td>Task</td><td align=center>Active</td><td>Note on task</td><td>Action</td></tr>\n";
-if ( foreign_installed('cron', 0) || foreign_installed('logrotate', 0) ) {
- print "<table border=0 width=100%>\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 "<tr> <td> <b>By cron</b></td> <td> ";
- if (! $idcron) {
- print "Off\n";
- }
- else {
- print "On\n";
- }
- print " </td> <td> ";
- if (! $idcron) {
- print "<a href=\"/cron/edit_cron.cgi?new=1\">Add AWStats global update process in cron</a>\n";
- } else {
- print "<a href=\"/cron/edit_cron.cgi?idx=$idcron\">Edit cron task to update all AWStats config files</a> ";
- }
- print "</td> </tr>\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 "<tr>";
+ print "<td><b>".$j->{'user'}."</b></td>";
+ print "<td>".$j->{'command'}."</td>";
+ print "<td align=center>".($j->{'active'}?'yes':'no')."</td>";
+ if ($global) { print "<td>Update all config files</td>"; }
+ else { print "<td>Update this config file only</td>"; }
+ print "<td><a href=\"/cron/edit_cron.cgi?idx=".$j->{'index'}."\">Jump to cron task</a></td>";
+ print "</tr>";
}
- # Loop on each logrotate found
- if ( foreign_installed('logrotate', 0) ) {
- print "<tr> <td> <b>By logrotate preprocess</b></td> ";
-
- print " <td> File: NA </td> ";
- print " <td> Edit logrotate file<br>";
-
- print "Add a logrotate for this file";
-
- print "</td></tr>";
- }
- print "</table>";
}
else {
- print "Nor cron, nor logrotate module are installed. They are required to setup AWStats scheduled tasks";
+ print "<tr><td colspan=4>Webmin cron module is not installed. It is required to setup cron scheduled tasks</td></tr>";
}
-
-print "</td> </tr>\n";
print "</table>";
+print "<br>\n";
+print "<a href=\"/cron/edit_cron.cgi?new=1\">Add an AWStats cron task to update all AWStats config files</a><br>";
+print "(You must add the command \"/usr/local/awstats/tools/awstats_updateall.pl now >/dev/null\")<br>\n";
+print "<br>\n";
+print "<a href=\"/cron/edit_cron.cgi?new=1\">Add an AWStats cron task to update this config files</a><br>\n";
+print "(You must add the command \"$config{'awstats'} -update -config=$conf >/dev/null\")<br>\n";
+print "<br>\n";
+print "<br>\n";
print "<br>\n";
-# For particular config file update
+# For logrotate scheduling
+print "Update processes scheduled by a <b>logrotate</b> task :<br>";
print "<table border width=100%>\n";
-print "<tr $tb> <td align=left><b>";
-print "Scheduled AWStats update process for this config file only (".$in{'file'}.")";
-print "</b></td> </tr>\n";
+print "<tr $tb><td>Logrotate file</td>";
+print "<td>Task</td><td>Note on task</td><td>Action</td></tr>\n";
+
+if ( foreign_installed('logrotate', 0) ) {
-print "<tr> <td> ";
-if ( foreign_installed('cron', 0) || foreign_installed('logrotate', 0) ) {
- print "<table border=0 width=100%>\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 "<tr> <td> <b>By cron</b></td> <td> ";
- if (! $idcron) {
- print "Off\n";
- }
- else {
- print "On\n";
- }
- print " </td> <td> ";
- if (! $idcron) {
- print "<a href=\"/cron/edit_cron.cgi?new=1\">Add AWStats update process in cron for config file</a>\n";
- } else {
- print "<a href=\"/cron/edit_cron.cgi?idx=$idcron\">Edit cron task to update only this AWStats config files</a> ";
- }
- print "</td> </tr>\n";
- }
- # Loop on each logrotate found
- if ( foreign_installed('logrotate', 0) ) {
- print "<tr> <td> <b>By logrotate preprocess</b></td> ";
- print " <td> File: NA </td> ";
- print " <td> Edit logrotate file<br>";
-
- print "Add a logrotate for this file";
-
- print "</td></tr>";
-
- }
- print "</table>";
}
else {
- print "Nor cron, nor logrotate module are installed. They are required to setup AWStats scheduled tasks";
+ print "<tr><td colspan=4>Webmin logrotate module is not installed. It is required to setup logrotate scheduled tasks</td></tr>";
}
-
-print "</td> </tr>\n";
print "</table>";
-
+print "Add a logrotate for this file";
print "<br>\n";