]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Allow to exclude several conf files
authoreldy <>
Thu, 25 May 2006 00:22:01 +0000 (00:22 +0000)
committereldy <>
Thu, 25 May 2006 00:22:01 +0000 (00:22 +0000)
tools/awstats_updateall.pl

index a1e63c2c1fad5ace81286b499b75b588122e9e42..49ac841e9bd2ed3e00eaed572f73403ba32ce391 100644 (file)
-#!/usr/bin/perl
-#------------------------------------------------------------------------------
-# Launch update process for all config files found in a particular directory.
-# See COPYING.TXT file about AWStats GNU General Public License.
-#------------------------------------------------------------------------------
-# $Revision$ - $Author$ - $Date$
-
-
-#------------------------------------------------------------------------------
-# Defines
-#------------------------------------------------------------------------------
-my $REVISION='$Revision$'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;
-my $VERSION="1.0 (build $REVISION)";
-
-# Default value of DIRCONFIG
-my $DIRCONFIG = "/etc/awstats";
-
-my $Debug=0;
-
-my $Awstats='awstats.pl';
-
-my $AwstatsDir='';
-my $AwstatsProg='';
-
-
-
-#------------------------------------------------------------------------------
-# Functions
-#------------------------------------------------------------------------------
-
-#------------------------------------------------------------------------------
-# Function:            Write error message and exit
-# Parameters:  $message
-# Input:               None
-# Output:              None
-# Return:              None
-#------------------------------------------------------------------------------
-sub error {
-       print "Error: $_[0].\n";
-    exit 1;
-}
-
-
-#------------------------------------------------------------------------------
-# Function:     Write debug message and exit
-# Parameters:   $string $level
-# Input:        %HTMLOutput  $Debug=required level  $DEBUGFORCED=required level forced
-# Output:              None
-# Return:              None
-#------------------------------------------------------------------------------
-sub debug {
-       my $level = $_[1] || 1;
-       if ($Debug >= $level) {
-               my $debugstring = $_[0];
-               if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br />"; }
-               print localtime(time)." - DEBUG $level - $debugstring\n";
-       }
-}
-
-
-#------------------------------------------------------------------------------
-# MAIN
-#------------------------------------------------------------------------------
-
-# Change default value if options are used
-my $helpfound=0;my $nowfound=0;
-my %confexcluded=();
-for (0..@ARGV-1) {
-       if ($ARGV[$_] =~ /^-*h/i)                        { $helpfound=1; last; }
-       if ($ARGV[$_] =~ /^-*awstatsprog=(.*)/i) { $Awstats="$1"; next; }
-       if ($ARGV[$_] =~ /^-*configdir=(.*)/i)   { $DIRCONFIG="$1"; next; }
-       if ($ARGV[$_] =~ /^-*excludeconf=(.*)/i) { $confexcluded{"$1"}=1; next; }
-       if ($ARGV[$_] =~ /^-*debug=(\d+)/i)      { $Debug=$1; next; }
-       if ($ARGV[$_] =~ /^now/i)                        { $nowfound=1; next; }
-}
-
-# Show usage help
-my $DIR; my $PROG; my $Extension;
-($DIR=$0) =~ s/([^\/\\]*)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
-if (!$nowfound || $helpfound || ! @ARGV) {
-       print "----- $PROG $VERSION (c) Laurent Destailleur -----\n";
-       print "awstats_updateall launches update process for all AWStats config files (except\n";
-       print "awstats.model.conf) found in a particular directory, so you can easily setup a\n";
-       print "cron/scheduler job. The scanned directory is by default $DIRCONFIG.\n";
-       print "\n";
-       print "Usage:  $PROG.$Extension now [options]\n";
-       print "\n";
-       print "Where options are:\n";
-       print "  -awstatsprog=pathtoawstatspl\n";
-       print "  -configdir=directorytoscan\n";
-       print "  -excludeconf=conftoexclude (Note: awstats.model.conf is always excluded)\n";
-       print "\n";
-       exit 0;
-}
-
-debug("Scan directory $DIRCONFIG");
-
-# Scan directory $DIRCONFIG 
-opendir(DIR, $DIRCONFIG) || error("Can't scan directory $DIRCONFIG");
-my @filesindir = grep { /^awstats\.(.*)conf$/ } sort readdir(DIR);
-closedir(DIR);
-
-debug("List of files found :".join(",",@filesindir));
-
-# Build file list
-my @files=();
-foreach my $file (@filesindir) {
-    if ($confexcluded{$file}) { next; }         # Should be useless
-    if ($file =~ /^awstats\.(.*)conf$/) {
-        my $conf=$1; $conf =~ s/\.$//;
-               if ($conf eq 'model') { next; }
-        if ($confexcluded{$conf}) { next; }
-    }
-    push @files, $file;
-}
-
-debug("List of files qualified :".join(",",@files));
-
-# Run update process for each config file found
-if (@files) {
-       # Check if AWSTATS prog is found
-       my $AwstatsFound=0;
-       if (-s "$Awstats") { $AwstatsFound=1; }
-       elsif (-s "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl") {
-               $Awstats="/usr/local/awstats/wwwroot/cgi-bin/awstats.pl";
-               $AwstatsFound=1;
-       }
-       if (! $AwstatsFound) {
-               error("Can't find AWStats program ('$Awstats').\nUse -awstatsprog option to solve this");
-               exit 1;
-       }
-       # Define AwstatsDir and AwstatsProg
-       ($AwstatsDir=$Awstats) =~ s/([^\/\\]+)$//; $AwstatsProg=$1;
-       $AwstatsDir||='.'; $AwstatsDir =~ s/([^\/\\])[\\\/]+$/$1/;
-       debug("AwstatsDir=$AwstatsDir");
-       debug("AwstatsProg=$AwstatsProg");
-
-       foreach (@files) {
-               if ($_ =~ /^awstats\.(.*)conf$/) {
-                       my $domain = $1||"default"; $domain =~ s/\.$//;
-                       # Define command line
-                       my $command="\"$AwstatsDir/$AwstatsProg\" -update -config=$domain";
-                       $command.=" -configdir=\"$DIRCONFIG\"";
-                       # Run command line
-                       print "Running '$command' to update config $domain\n";
-                       my $output = `$command 2>&1`;
-                       print "$output\n";
-               }
-       }
-} else {
-       print "No AWStats config file found in $DIRCONFIG\n";   
-}
-
-0;     # Do not remove this line
+#!/usr/bin/perl\r
+#------------------------------------------------------------------------------\r
+# Launch update process for all config files found in a particular directory.\r
+# See COPYING.TXT file about AWStats GNU General Public License.\r
+#------------------------------------------------------------------------------\r
+# $Revision$ - $Author$ - $Date$\r
+\r
+\r
+#------------------------------------------------------------------------------\r
+# Defines\r
+#------------------------------------------------------------------------------\r
+my $REVISION='$Revision$'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;\r
+my $VERSION="1.0 (build $REVISION)";\r
+\r
+# Default value of DIRCONFIG\r
+my $DIRCONFIG = "/etc/awstats";\r
+\r
+my $Debug=0;\r
+\r
+my $Awstats='awstats.pl';\r
+\r
+my $AwstatsDir='';\r
+my $AwstatsProg='';\r
+\r
+\r
+\r
+#------------------------------------------------------------------------------\r
+# Functions\r
+#------------------------------------------------------------------------------\r
+\r
+#------------------------------------------------------------------------------\r
+# Function:            Write error message and exit\r
+# Parameters:  $message\r
+# Input:               None\r
+# Output:              None\r
+# Return:              None\r
+#------------------------------------------------------------------------------\r
+sub error {\r
+       print "Error: $_[0].\n";\r
+    exit 1;\r
+}\r
+\r
+\r
+#------------------------------------------------------------------------------\r
+# Function:     Write debug message and exit\r
+# Parameters:   $string $level\r
+# Input:        %HTMLOutput  $Debug=required level  $DEBUGFORCED=required level forced\r
+# Output:              None\r
+# Return:              None\r
+#------------------------------------------------------------------------------\r
+sub debug {\r
+       my $level = $_[1] || 1;\r
+       if ($Debug >= $level) {\r
+               my $debugstring = $_[0];\r
+               if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br />"; }\r
+               print localtime(time)." - DEBUG $level - $debugstring\n";\r
+       }\r
+}\r
+\r
+\r
+#------------------------------------------------------------------------------\r
+# MAIN\r
+#------------------------------------------------------------------------------\r
+\r
+# Change default value if options are used\r
+my $helpfound=0;my $nowfound=0;\r
+my %confexcluded=();\r
+for (0..@ARGV-1) {\r
+       if ($ARGV[$_] =~ /^-*h/i)                        { $helpfound=1; last; }\r
+       if ($ARGV[$_] =~ /^-*awstatsprog=(.*)/i) { $Awstats="$1"; next; }\r
+       if ($ARGV[$_] =~ /^-*configdir=(.*)/i)   { $DIRCONFIG="$1"; next; }\r
+       if ($ARGV[$_] =~ /^-*excludeconf=(.*)/i) {\r
+                       #try to get the different files to exclude\r
+                       @conftoexclude = split(/,/, $1);\r
+                       foreach (@conftoexclude) {\r
+                               $confexcluded{"$_"}=1;\r
+                       }\r
+                       next; \r
+       }\r
+       if ($ARGV[$_] =~ /^-*debug=(\d+)/i)      { $Debug=$1; next; }\r
+       if ($ARGV[$_] =~ /^now/i)                        { $nowfound=1; next; }\r
+}\r
+\r
+# Show usage help\r
+my $DIR; my $PROG; my $Extension;\r
+($DIR=$0) =~ s/([^\/\\]*)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;\r
+if (!$nowfound || $helpfound || ! @ARGV) {\r
+       print "----- $PROG $VERSION (c) Laurent Destailleur -----\n";\r
+       print "awstats_updateall launches update process for all AWStats config files (except\n";\r
+       print "awstats.model.conf) found in a particular directory, so you can easily setup a\n";\r
+       print "cron/scheduler job. The scanned directory is by default $DIRCONFIG.\n";\r
+       print "\n";\r
+       print "Usage:  $PROG.$Extension now [options]\n";\r
+       print "\n";\r
+       print "Where options are:\n";\r
+       print "  -awstatsprog=pathtoawstatspl\n";\r
+       print "  -configdir=directorytoscan\n";\r
+       print "  -excludeconf=conftoexclude[,conftoexclude2,...] (Note: awstats.model.conf is always excluded)\n";\r
+       print "\n";\r
+       exit 0;\r
+}\r
+\r
+debug("Scan directory $DIRCONFIG");\r
+\r
+# Scan directory $DIRCONFIG \r
+opendir(DIR, $DIRCONFIG) || error("Can't scan directory $DIRCONFIG");\r
+my @filesindir = grep { /^awstats\.(.*)conf$/ } sort readdir(DIR);\r
+closedir(DIR);\r
+\r
+debug("List of files found :".join(",",@filesindir));\r
+\r
+# Build file list\r
+my @files=();\r
+foreach my $file (@filesindir) {\r
+    if ($confexcluded{$file}) { next; }         # Should be useless\r
+    if ($file =~ /^awstats\.(.*)conf$/) {\r
+        my $conf=$1; $conf =~ s/\.$//;\r
+               if ($conf eq 'model') { next; }\r
+        if ($confexcluded{$conf}) { next; }\r
+    }\r
+    push @files, $file;\r
+}\r
+\r
+debug("List of files qualified :".join(",",@files));\r
+\r
+# Run update process for each config file found\r
+if (@files) {\r
+       # Check if AWSTATS prog is found\r
+       my $AwstatsFound=0;\r
+       if (-s "$Awstats") { $AwstatsFound=1; }\r
+       elsif (-s "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl") {\r
+               $Awstats="/usr/local/awstats/wwwroot/cgi-bin/awstats.pl";\r
+               $AwstatsFound=1;\r
+       }\r
+       if (! $AwstatsFound) {\r
+               error("Can't find AWStats program ('$Awstats').\nUse -awstatsprog option to solve this");\r
+               exit 1;\r
+       }\r
+       # Define AwstatsDir and AwstatsProg\r
+       ($AwstatsDir=$Awstats) =~ s/([^\/\\]+)$//; $AwstatsProg=$1;\r
+       $AwstatsDir||='.'; $AwstatsDir =~ s/([^\/\\])[\\\/]+$/$1/;\r
+       debug("AwstatsDir=$AwstatsDir");\r
+       debug("AwstatsProg=$AwstatsProg");\r
+\r
+       foreach (@files) {\r
+               if ($_ =~ /^awstats\.(.*)conf$/) {\r
+                       my $domain = $1||"default"; $domain =~ s/\.$//;\r
+                       # Define command line\r
+                       my $command="\"$AwstatsDir/$AwstatsProg\" -update -config=$domain";\r
+                       $command.=" -configdir=\"$DIRCONFIG\"";\r
+                       # Run command line\r
+                       print "Running '$command' to update config $domain\n";\r
+                       my $output = `$command 2>&1`;\r
+                       print "$output\n";\r
+               }\r
+       }\r
+} else {\r
+       print "No AWStats config file found in $DIRCONFIG\n";   \r
+}\r
+\r
+0;     # Do not remove this line\r
+\r