File awstats-update of Package awstats

#!/usr/bin/perl -w
#-Description-------------------------------------------
# Launch update process for all config files found in a particular directory.
# See COPYING.TXT file about AWStats GNU General Public License.
#-------------------------------------------------------
# Based on awstats_updateall.pl from Laurent Destailleur
use strict;

my $DEBUG=0;
my $DIRCONFIG = "/etc/awstats";
my $AWSTATSSCRIPT = "/srv/www/cgi-bin/awstats.pl";

# Scan directory $DIRCONFIG 
opendir(DIR, "$DIRCONFIG") || die "Can't scan directory $DIRCONFIG\n";
my @files = grep { /^awstats\.(.*)conf$/ } sort readdir(DIR);
closedir(DIR);

# Run update process for each config file found
if (@files) {
	foreach (@files) {
		if ($_ =~ /^awstats\.(.*)conf$/) {
			my $domain = $1||"default"; 
			my $AllowToUpdateStatsFromBrowser=0;
			my $DirData="";
			$domain =~ s/\.$//;
			open (FILE,"<$DIRCONFIG/$_") || die "Could not open $_:$!\n";
			while (<FILE>){
				if (/^AllowToUpdateStatsFromBrowser\s*=\s*1/){
					$AllowToUpdateStatsFromBrowser=1;
				}
				if ((/^DirData\s*=\s*\"(.*)\"/) || (/^DirData\s*=\s*(.*)/)){	
					$DirData=$1;
				}
			}
			close(FILE);
			if ($DEBUG){
				print "Update domain                : $domain\n";
				print "AllowToUpdateStatsFromBrowser: $AllowToUpdateStatsFromBrowser\n";
				print "DirData                      : $DirData\n";
				print "Running: $AWSTATSSCRIPT -config=$domain -update 2>&1\n";
			} 
			my $output = `"$AWSTATSSCRIPT" -config=$domain -update 2>&1` if (!$DEBUG);
			if ($AllowToUpdateStatsFromBrowser){
				opendir(DIRDATA, "$DirData") || die "Can not scan $DirData: $!\n";
				my @datafiles = grep { /.*$domain.*/ } sort readdir(DIRDATA);
				closedir(DIRDATA);
				if (@datafiles){
					system("chown wwwrun:www $DirData/*$domain*");
					print "chown wwwrun:www $DirData/*$domain*\n" if ($DEBUG);
				}
			}
		}
	}
} 

0;	# Do not remove this line
openSUSE Build Service is sponsored by