Ispman.makeawstats
From ISPMan
TODOS:
- sanity checking - does awstats.conf.template exist?
- instead of running awstats like this:
- system("/usr/bin/perl /usr/share/doc/awstats/examples/awstats_buildstaticpages.pl -config=$VHOST.$DOMAIN -output -awstatsprog=/usr/lib/cgi-bin/awstats.pl -staticlinks -language=de -update -dir=$STATSPATH/report");
- replace debian's wrapper.pl with own lines
- add a switch to build previous month's stats
If you want Dynamic pages built nightly with a (user update now) button on http://$vhost.$domain/stats-aw Works on Debian, should be mostly standard, make sure the log and vhost directory setup is the same as your system and that you like the permissions setup. If you don't get pretty colors/icons from awstats fix the /stats-files link below.
- add this to the vhosts template
<IfModule mod_rewrite.c> #If we have mod_rewrite then we can use awstats RewriteEngine On RewriteRule /stats-aw /awstats-cgi-bin/awstats.pl [R] Alias /stats-files /usr/share/awstats ScriptAlias /awstats-cgi-bin /usr/lib/cgi-bin </IfModule>
/etc/cron.d/daily/makeawstats.sh
#!/bin/sh # awstatsreporting.sh # cronjob to update awstats pages for ISPMan virtual hosts # Modified by annonymous Jul 03, 2006 # Author: Wim Kerkhoff <wim@nyetwork.org>, July 28, 2004 # See: http://www.nyetwork.org/wiki/AWStats # loosely based on awstats4vhost by Dave Capella # http://grox.net/software/mine/awstats4vhost/index.php # original copyright notice from install.awstats4vhost follows: # ETCDIR=/etc/awstats CFGHEADLESS=$ETCDIR/awstats.conf.local CGI='/usr/lib/cgi-bin/awstats.pl' DOMAIN_ROOT=/ispman/domains CACHE_ROOT=/ispman/domain/awstats CRONFILE=/etc/cron.hourly/awstats LOGDIR=$DOMAIN_ROOT #LOGRESOLVE=/usr/share/doc/awstats/examples/logresolvemerge.pl LOGRESOLVE=/usr/sbin/logresolve2 if [ "$1" != "" ]; then echo "Running on domain $1 only" DOM_LIST=$1 else DOM_LIST=$(ls $DOMAIN_ROOT/) fi if [ "$UID" != "0" ] ; then echo "must be run by root. I quit." exit 2 fi rm -rf $CRONFILE for domain in $DOM_LIST ; do if [ -d $DOMAIN_ROOT/$domain/vhosts ] ; then for pre in $(ls $DOMAIN_ROOT/$domain/vhosts) ; do VHOST=$pre.$domain echo "$VHOST" LOGFILE="$LOGDIR/$domain/logs/$pre/${VHOST}.access" RAWLOGFILE="$LOGDIR/$domain/logs/$pre/${VHOST}.errors" CFGFILE=$ETCDIR/awstats.$VHOST.conf CACHEDIR="$CACHE_ROOT/$VHOST" if [ -r $LOGFILE ] ; then # make a cache directory. if [ ! -d "$CACHEDIR" ]; then mkdir -p "$CACHEDIR" fi chgrp www-data "$CACHEDIR" chmod -R 775 "$CACHEDIR" # create config file SLASHED=`echo ${VHOST} | sed -e 's/\./\\\./g'` touch $CFGFILE chmod 644 $CFGFILE # generate config contents # append a * to ${LOGFILE} to process all # the rotated logs as well. cat > ${CFGFILE} << EOF LogFormat="1" LogFile="$LOGRESOLVE < ${LOGFILE} |" RawLogFile="$RAWLOGFILE" DirData="${CACHEDIR}" SiteDomain="${VHOST}" HostAliases="${VHOST} ${domain} localhost 127.0.0.1" AllowToUpdateStatsFromBrowser="1" EnableLockForUpdate="1" AllowFullYearView="3" #LoadPlugin="rawlog" EOF # add the rest of the template cat $CFGHEADLESS >> $CFGFILE # update the stats... $CGI -- -config=$VHOST -update >> $CACHEDIR/update.log 2>&1 else rm -rf $CFGFILE $CACHEDIR fi done fi done