(file) Return to awstats_updateall.pl CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / tools

  1 rizwank 1.1 #!/usr/bin/perl
  2             #------------------------------------------------------------------------------
  3             # Launch update process for all config files found in a particular directory.
  4             # See COPYING.TXT file about AWStats GNU General Public License.
  5             #------------------------------------------------------------------------------
  6             # $Revision: 1.10 $ - $Author: eldy $ - $Date: 2004/06/07 12:27:26 $
  7             
  8             
  9             #------------------------------------------------------------------------------
 10             # Defines
 11             #------------------------------------------------------------------------------
 12             my $REVISION='$Revision: 1.10 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;
 13             my $VERSION="1.0 (build $REVISION)";
 14             
 15             # Default value of DIRCONFIG
 16             my $DIRCONFIG = "/etc/awstats";
 17             
 18             my $Debug=0;
 19             
 20             my $Awstats='awstats.pl';
 21             
 22 rizwank 1.1 my $AwstatsDir='';
 23             my $AwstatsProg='';
 24             
 25             
 26             
 27             #------------------------------------------------------------------------------
 28             # Functions
 29             #------------------------------------------------------------------------------
 30             
 31             #------------------------------------------------------------------------------
 32             # Function:		Write error message and exit
 33             # Parameters:	$message
 34             # Input:		None
 35             # Output:		None
 36             # Return:		None
 37             #------------------------------------------------------------------------------
 38             sub error {
 39             	print "Error: $_[0].\n";
 40                 exit 1;
 41             }
 42             
 43 rizwank 1.1 
 44             #------------------------------------------------------------------------------
 45             # Function:     Write debug message and exit
 46             # Parameters:   $string $level
 47             # Input:        %HTMLOutput  $Debug=required level  $DEBUGFORCED=required level forced
 48             # Output:		None
 49             # Return:		None
 50             #------------------------------------------------------------------------------
 51             sub debug {
 52             	my $level = $_[1] || 1;
 53             	if ($Debug >= $level) {
 54             		my $debugstring = $_[0];
 55             		if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /&nbsp&nbsp /; $debugstring .= "<br>"; }
 56             		print localtime(time)." - DEBUG $level - $debugstring\n";
 57             	}
 58             }
 59             
 60             
 61             #------------------------------------------------------------------------------
 62             # MAIN
 63             #------------------------------------------------------------------------------
 64 rizwank 1.1 
 65             # Change default value if options are used
 66             my $helpfound=0;my $nowfound=0;
 67             my %confexcluded=();
 68             for (0..@ARGV-1) {
 69             	if ($ARGV[$_] =~ /^-*h/i)     		  	 { $helpfound=1; last; }
 70             	if ($ARGV[$_] =~ /^-*awstatsprog=(.*)/i) { $Awstats="$1"; next; }
 71             	if ($ARGV[$_] =~ /^-*configdir=(.*)/i)   { $DIRCONFIG="$1"; next; }
 72             	if ($ARGV[$_] =~ /^-*excludeconf=(.*)/i) { $confexcluded{"$1"}=1; next; }
 73             	if ($ARGV[$_] =~ /^-*debug=(\d+)/i)  	 { $Debug=$1; next; }
 74             	if ($ARGV[$_] =~ /^now/i)     		  	 { $nowfound=1; next; }
 75             }
 76             
 77             # Show usage help
 78             my $DIR; my $PROG; my $Extension;
 79             ($DIR=$0) =~ s/([^\/\\]*)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
 80             if (!$nowfound || $helpfound || ! @ARGV) {
 81             	print "----- $PROG $VERSION (c) Laurent Destailleur -----\n";
 82             	print "awstats_updateall launches update process for all AWStats config files (except\n";
 83             	print "awstats.model.conf) found in a particular directory, so you can easily setup a\n";
 84             	print "cron/scheduler job. The scanned directory is by default $DIRCONFIG.\n";
 85 rizwank 1.1 	print "\n";
 86             	print "Usage:  $PROG.$Extension now [options]\n";
 87             	print "\n";
 88             	print "Where options are:\n";
 89             	print "  -awstatsprog=pathtoawstatspl\n";
 90             	print "  -configdir=directorytoscan\n";
 91             	print "  -excludeconf=conftoexclude (Note: awstats.model.conf is always excluded)\n";
 92             	print "\n";
 93             	exit 0;
 94             }
 95             
 96             debug("Scan directory $DIRCONFIG");
 97             
 98             # Scan directory $DIRCONFIG 
 99             opendir(DIR, $DIRCONFIG) || error("Can't scan directory $DIRCONFIG");
100             my @filesindir = grep { /^awstats\.(.*)conf$/ } sort readdir(DIR);
101             closedir(DIR);
102             
103             debug("List of files found :".join(",",@filesindir));
104             
105             # Build file list
106 rizwank 1.1 my @files=();
107             foreach my $file (@filesindir) {
108                 if ($confexcluded{$file}) { next; }         # Should be useless
109                 if ($file =~ /^awstats\.(.*)conf$/) {
110                     my $conf=$1; $conf =~ s/\.$//;
111             		if ($conf eq 'model') { next; }
112                     if ($confexcluded{$conf}) { next; }
113                 }
114                 push @files, $file;
115             }
116             
117             debug("List of files qualified :".join(",",@files));
118             
119             # Run update process for each config file found
120             if (@files) {
121             	# Check if AWSTATS prog is found
122             	my $AwstatsFound=0;
123             	if (-s "$Awstats") { $AwstatsFound=1; }
124             	elsif (-s "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl") {
125             		$Awstats="/usr/local/awstats/wwwroot/cgi-bin/awstats.pl";
126             		$AwstatsFound=1;
127 rizwank 1.1 	}
128             	if (! $AwstatsFound) {
129             		error("Can't find AWStats program ('$Awstats').\nUse -awstatsprog option to solve this");
130             		exit 1;
131             	}
132             	# Define AwstatsDir and AwstatsProg
133             	($AwstatsDir=$Awstats) =~ s/([^\/\\]+)$//; $AwstatsProg=$1;
134             	$AwstatsDir||='.'; $AwstatsDir =~ s/([^\/\\])[\\\/]+$/$1/;
135             	debug("AwstatsDir=$AwstatsDir");
136             	debug("AwstatsProg=$AwstatsProg");
137             
138             	foreach (@files) {
139             		if ($_ =~ /^awstats\.(.*)conf$/) {
140             			my $domain = $1||"default"; $domain =~ s/\.$//;
141             			# Define command line
142             			my $command="\"$AwstatsDir/$AwstatsProg\" -update -config=$domain";
143             			$command.=" -configdir=\"$DIRCONFIG\"";
144             			# Run command line
145             			print "Running '$command' to update config $domain\n";
146             			my $output = `$command 2>&1`;
147             			print "$output\n";
148 rizwank 1.1 		}
149             	}
150             } else {
151             	print "No AWStats config file found in $DIRCONFIG\n";	
152             }
153             
154             0;	# Do not remove this line

Rizwan Kassim
Powered by
ViewCVS 0.9.2