initial commit of a *whole bunch* of old Egressive shell scripts, used to make many people redundant.

This commit is contained in:
Dave Lane 2016-03-16 13:43:31 +13:00
commit 43e0f5b59e
329 changed files with 31937 additions and 0 deletions

View file

@ -0,0 +1 @@
For awstats.pl - normally in /var/www/cgi-bin on Mandrake installs - to work with this configuration, you have to ensure that the Perl code defines a "PossibleConfDir" in line 1075 (of the 6.1 version anyway) of "/etc/egscripts/egstats/awstatsconf"...

21
egstats/README.egstats Normal file
View file

@ -0,0 +1,21 @@
Copyright 2005, Egressive Limited, www.egressive.com
This set of scripts is indended to accomplish the following:
For each of a number of configured "domains" on this or another
server, this script will
a. mirror (rsync) a designated HTTP common access_logs to a local access_log.
b. if it does not already exist, create the appropriate AWStats
configuration file, including global and Egressive-specific
configuration defaults as required.
c. if it has not be performed already, initialise the
statistics database
d. update the statistics database
e. produce a series of HTML pages based on the statistics
f. copy the relevant icon and graphics files into a suitable
subdirectory so that they're available for the HTML pages to include
g. put those HTML pages into a web-viewable directory appropriate to
the month within the domain's directory
h. create a sensible "index.html" page so that a browser clicking on
that month directory sees the summary page for that month and can
access the other, more specific pages linked in that summary.

84
egstats/awstats-lastmonth.sh Executable file
View file

@ -0,0 +1,84 @@
#!/bin/bash
#
# create static XHTML pages for statistics for a given awstats config
#
AWSDIR="/usr/local/awstats/"
AWSTOOL="$AWSDIR/tools"
AWSROOT="$AWSDIR/wwwroot"
CONFDIR="/etc/awstats"
CMD="$AWSTOOL/awstats_buildstaticpages.pl"
ARGS="-update -staticlinksext=html"
MODE="help"
CONFIG=""
RESULTDIR=""
LOG="/var/log/awstats-static.log"
NICE="19"
#
# work out dates
MM=`date -d "last month" +%m`
MONTH=`date -d "last month" +%B`
YEAR=`date -d "last month" +%Y`
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONFIG=$1
;;
--results|-r)
shift
RESULTS=$1
;;
--help|?|-h)
shift
MODE="help"
;;
esac
shift
done
#
# check for mode
if test -z $CONFIG -o -z $RESULTS ; then
MODE="help"
else
MODE="run"
fi
if test $MODE == "run" ; then
echo "using config in $CONFDIR/awstats.$CONFIG.conf, putting results into $RESULTS"
if test -d $RESULTS ; then
HTMLFILE="$RESULTS/index.html"
fi
YEARDIR=$RESULTS/$YEAR
if test ! -d $YEARDIR ; then
echo "creating new year directory: $RESULTS/$YEAR"
mkdir $YEARDIR
fi
MONTHDIR=$RESULTS/$YEAR/$MM
if test ! -d $MONTHDIR ; then
echo "creating new month directory: $MONTHDIR"
mkdir $MONTHDIR
fi
if test -d $MONTHDIR ; then
# run the awstats command to build the files for that month
echo "running test on month $MM, year $YEAR"
nice -n $NICE $CMD $ARGS -config=$CONFIG -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null
# link the basic xml file to an index.html...
mv $MONTHDIR/awstats.$CONFIG.xml $MONTHDIR/index.html
else
echo "Couldn't find $DIR! Exiting"
exit 1
fi
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config -r results_path | -h}"
echo "-r or --results - the absolute path to the directory"
echo " to populate with the year/month/ XHTML results files"
echo "-c or --config - the AWSTATS configuration name, probably"
echo " in /etc/awstats - the name is awstats.[name].conf"
echo "-h or --help - this help message"
fi
exit 0

147
egstats/awstats-static.sh Executable file
View file

@ -0,0 +1,147 @@
#!/bin/bash
#
# create static XHTML pages for statistics for a given awstats config
#
YEARS="2003 2004 2005"
MS="1 2 3 4 5 6 7 8 9 10 11 12"
MONTH[1]=January
MONTH[2]=February
MONTH[3]=March
MONTH[4]=April
MONTH[5]=May
MONTH[6]=June
MONTH[7]=July
MONTH[8]=August
MONTH[9]=September
MONTH[10]=October
MONTH[11]=November
MONTH[12]=December
AWSDIR="/usr/local/awstats/"
AWSTOOL="$AWSDIR/tools"
AWSROOT="$AWSDIR/wwwroot"
CONFDIR="/etc/awstats"
CMD="$AWSTOOL/awstats_buildstaticpages.pl"
ARGS="-update -staticlinksext=html"
MODE="help"
CONFIG=""
RESULTS=""
LOG="/var/log/awstats-static.log"
NICE="19"
#
# functions to put content into an index.html file...
starthtml() {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 STRICT//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> " > $HTMLFILE
echo "<html>" >> $HTMLFILE
echo " <head>" >> $HTMLFILE
SITETITLE="Site statistics for $CONFIG"
echo " <title>$SITETITLE</title>" >> $HTMLFILE
echo " </head>" >> $HTMLFILE
echo " <body>" >> $HTMLFILE
echo " <h1>$SITETITLE</h1>" >> $HTMLFILE
echo " <p>Index of statistics by year and month</p>" >> $HTMLFILE
echo " <ul style=\"\">" >> $HTMLFILE
}
startyear() {
echo " <li style=\"\">Statistics for $YEAR:" >> $HTMLFILE
echo " <ul>" >> $HTMLFILE
}
addmonth() {
MONTHNAME=${MONTH[$M]}
echo "MONTHNAME = $MONTHNAME"
echo " <li style=\"\"><a href=\"$YEAR/$MM/index.html\">$MONTHNAME</a></li>" >> $HTMLFILE
}
endyear() {
echo " </ul>" >> $HTMLFILE
echo " </li>" >> $HTMLFILE
}
endhtml() {
echo " </ul>" >> $HTMLFILE
echo " </body>" >> $HTMLFILE
echo "</html>" >> $HTMLFILE
}
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONFIG=$1
;;
--results|-r)
shift
RESULTS=$1
;;
--help|?|-h)
shift
MODE="help"
;;
esac
shift
done
#
# check for mode
if test -z $CONFIG -o -z $RESULTS ; then
MODE="help"
else
MODE="run"
fi
if test $MODE == "run" ; then
echo "using config in $CONFDIR/awstats.$CONFIG.conf, putting results into $RESULTS"
if test -d $RESULTS ; then
HTMLFILE="$RESULTS/index.html"
starthtml
fi
for YEAR in $YEARS
do
startyear
YEARDIR=$RESULTS/$YEAR
if test ! -d $YEARDIR ; then
echo "creating new year directory: $RESULTS/$YEAR"
mkdir $YEARDIR
fi
for M in $MS
do
MM=$(echo $M|sed -e 's/^.$/0&/')
MONTHDIR=$RESULTS/$YEAR/$MM
if test ! -d $MONTHDIR ; then
echo "creating new month directory: $MONTHDIR"
mkdir $MONTHDIR
fi
addmonth
if test -d $DIR ; then
# run the awstats command to build the files for that month
nice -n $NICE $CMD $ARGS -config=$CONFIG -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null
# link the basic xml file to an index.html...
mv $MONTHDIR/awstats.$CONFIG.xml $MONTHDIR/index.html
echo "running test on month $MM, year $YEAR"
else
echo "Couldn't find $DIR! Exiting"
exit 1
fi
done
endyear
done
endhtml
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config -r results_path | -h}"
echo "-r or --results - the absolute path to the directory"
echo " to populate with the year/month/ XHTML results files"
echo "-c or --config - the AWSTATS configuration name, probably"
echo " in /etc/awstats - the name is awstats.[name].conf"
echo "-h or --help - this help message"
fi
exit 0

View file

@ -0,0 +1,160 @@
#
# normal app defaults
DNSLookup=2
DirData="/var/lib/awstats"
DirCgi="/awstats"
AllowToUpdateStatsFromBrowser=0
AllowFullYearView=2
EnableLockForUpdate=0
DNSStaticCacheFile="dnscache.txt"
DNSLastUpdateCacheFile="dnscachelastupdate.txt"
SkipDNSLookupFor=""
AllowAccessFromWebToAuthenticatedUsersOnly=0
AllowAccessFromWebToFollowingAuthenticatedUsers=""
AllowAccessFromWebToFollowingIPAddresses=""
CreateDirDataIfNotExists=0
BuildHistoryFormat=text
SaveDatabaseFilesWithPermissionsForEveryone=0
PurgeLogFile=0
ArchiveLogRecords=0
KeepBackupOfHistoricFiles=0
DefaultFile="index.html"
LogType=W
LogFormat=1
LogSeparator=" "
SkipUserAgents=""
SkipFiles=""
OnlyHosts=""
OnlyUserAgents=""
OnlyFiles=""
ValidHTTPCodes="200 304"
ValidSMTPCodes="1 250"
AuthenticatedUsersNotCaseSensitive=0
URLNotCaseSensitive=0
URLWithAnchor=0
URLQuerySeparators="?;"
URLWithQuery=0
URLWithQueryWithOnlyFollowingParameters=""
URLWithQueryWithoutFollowingParameters=""
URLReferrerWithQuery=0
WarningMessages=1
ErrorMessages=""
DebugMessages=0
NbOfLinesForCorruptedLog=50
WrapperScript=""
DecodeUA=0
MiscTrackerUrl="/js/awstats_misc_tracker.js"
LevelForBrowsersDetection=2 # 0 disables Browsers detection.
# 2 reduces AWStats speed by 2%
LevelForOSDetection=2 # 0 disables OS detection.
# 2 reduces AWStats speed by 3%
LevelForRefererAnalyze=2 # 0 disables Origin detection.
# 2 reduces AWStats speed by 14%
LevelForRobotsDetection=2 # 0 disables Robots detection.
# 2 reduces AWStats speed by 2.5%
LevelForSearchEnginesDetection=2 # 0 disables Search engines detection.
# 2 reduces AWStats speed by 9%
LevelForKeywordsDetection=2 # 0 disables Keyphrases/Keywords detection.
# 2 reduces AWStats speed by 1%
LevelForFileTypesDetection=2 # 0 disables File types detection.
# 2 reduces AWStats speed by 1%
LevelForWormsDetection=0 # 0 disables Worms detection.
# 2 reduces AWStats speed by 15%
UseFramesWhenCGI=1
Expires=0
MaxRowsInHTMLOutput=1000
Lang="auto"
DirLang="./lang"
ShowMenu=1
ShowSummary=UVPHB
ShowMonthStats=UVPHB
ShowDaysOfMonthStats=VPHB
ShowDaysOfWeekStats=PHB
ShowHoursStats=PHB
ShowDomainsStats=PHB
ShowHostsStats=PHBL
ShowAuthenticatedUsers=0
ShowRobotsStats=HBL
ShowWormsStats=0
ShowEMailSenders=0
ShowEMailReceivers=0
ShowSessionsStats=1
ShowPagesStats=PBEX
ShowFileTypesStats=HB
ShowFileSizesStats=0
ShowOSStats=1
ShowBrowsersStats=1
ShowScreenSizeStats=0
ShowOriginStats=PH
ShowKeyphrasesStats=1
ShowKeywordsStats=1
ShowHTTPErrorsStats=1
ShowSMTPErrorsStats=0
ShowClusterStats=0
AddDataArrayMonthStats=1
AddDataArrayShowDaysOfMonthStats=1
AddDataArrayShowDaysOfWeekStats=1
AddDataArrayShowHoursStats=1
IncludeInternalLinksInOriginSection=0
MaxNbOfDomain = 10
MinHitDomain = 1
MaxNbOfHostsShown = 10
MinHitHost = 1
MaxNbOfLoginShown = 10
MinHitLogin = 1
MaxNbOfRobotShown = 10
MinHitRobot = 1
MaxNbOfPageShown = 10
MinHitFile = 1
MaxNbOfOsShown = 10
MinHitOs = 1
MaxNbOfBrowsersShown = 10
MinHitBrowser = 1
MaxNbOfScreenSizesShown = 5
MinHitScreenSize = 1
MaxNbOfWindowSizesShown = 5
MinHitWindowSize = 1
MaxNbOfRefererShown = 10
MinHitRefer = 1
MaxNbOfKeyphrasesShown = 10
MinHitKeyphrase = 1
MaxNbOfKeywordsShown = 10
MinHitKeyword = 1
MaxNbOfEMailsShown = 20
MinHitEMail = 1
FirstDayOfWeek=1
ShowFlagLinks=""
ShowLinksOnUrl=1
UseHTTPSLinkForUrl=""
MaxLengthOfShownURL=64
HTMLHeadSection=""
HTMLEndSection=""
#Logo="awstats_logo6.png"
#LogoLink="http://awstats.sourceforge.net"
Logo="egressiveHostingLogo.png"
LogoLink="http://egressive.com"
BarWidth = 260
BarHeight = 90
StyleSheet=""
color_Background="FFFFFF" # Background color for main page (Default = "FFFFFF")
color_TableBGTitle="CCCCDD" # Background color for table title (Default = "CCCCDD")
color_TableTitle="000000" # Table title font color (Default = "000000")
color_TableBG="CCCCDD" # Background color for table (Default = "CCCCDD")
color_TableRowTitle="FFFFFF" # Table row title font color (Default = "FFFFFF")
color_TableBGRowTitle="ECECEC" # Background color for row title (Default = "ECECEC")
color_TableBorder="ECECEC" # Table border color (Default = "ECECEC")
color_text="000000" # Color of text (Default = "000000")
color_textpercent="606060" # Color of text for percent values (Default = "606060")
color_titletext="000000" # Color of text title within colored Title Rows (Default = "000000")
color_weekend="EAEAEA" # Color for week-end days (Default = "EAEAEA")
color_link="0011BB" # Color of HTML links (Default = "0011BB")
color_hover="605040" # Color of HTML on-mouseover links (Default = "605040")
color_u="FFAA66" # Background color for number of unique visitors (Default = "FFAA66")
color_v="F4F090" # Background color for number of visites (Default = "F4F090")
color_p="4477DD" # Background color for number of pages (Default = "4477DD")
color_h="66DDEE" # Background color for number of hits (Default = "66DDEE")
color_k="2EA495" # Background color for number of bytes (Default = "2EA495")
color_s="8888DD" # Background color for number of search (Default = "8888DD")
color_e="CEC2E8" # Background color for number of entry pages (Default = "CEC2E8")
color_x="C1B2E2" # Background color for number of exit pages (Default = "C1B2E2")
ExtraTrackedRowsLimit=500

View file

@ -0,0 +1,7 @@
#
# local defaults
#SkipHosts="REGEX[^192\.168\.] REGEX[^10\.128\.] REGEX[^*\.kc$] 203.97.50.115 203.97.51.110"
BuildReportFormat=xhtml
NotPageList="css js class gif jpg jpeg png bmp ico swf"
DetailedReportsOnNewWindows=0
ShowMiscStats=anjdfrqwp

37
egstats/conf/cypress.conf Normal file
View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>cypress.co.nz</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.cypress.co.nz</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/cypress/logs</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/cypress</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/cypress</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>davelane.name</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.davelane.name</alias>
<alias>www.davelane.org</alias>
<alias>davelane.org</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/dlane/logs/davelane.org</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/davelane</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/davelane</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>egressive.com</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.egressive.com</alias>
<alias>www.egressive.co.nz</alias>
<alias>egressive.co.nz</alias>
<alias>www.egressive.org</alias>
<alias>egressive.org</alias>
<alias>www.egressive.net</alias>
<alias>egressive.net</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/dlane/logs/egressive.com</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/egressive</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/egressive</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

38
egstats/conf/far.conf Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>far.co.nz</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.far.co.nz</alias>
<alias>far.egressive.com</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/far/logs</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/far</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/far/www/stats</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

38
egstats/conf/ics2006.conf Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>ics2006.co.nz</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.ics2006.co.nz</alias>
<alias>ics2006.egressive.com</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/ics2006/logs</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/ics2006</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/ics2006</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

37
egstats/conf/openz.conf Normal file
View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>openz.org</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.openz.org</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/dlane/logs/openz.org</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/openz</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/openz</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

39
egstats/conf/oslnz.conf Normal file
View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>openstrategies.com</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.openstrategies.com</alias>
<alias>www.openstrategies.co.nz</alias>
<alias>openstrategies.co.nz</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>moe.kc</host>
<!-- path to the access log file -->
<path>/home/devel/logs/openstrategies.com</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/oslnz</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/oslnz</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

37
egstats/conf/osluk.conf Normal file
View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>openstrategies.co.uk</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.openstrategies.co.uk</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>openstrategies.co.uk</host>
<!-- path to the access log file -->
<path>/home/devel/logs/openstrategies.co.uk</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/osluk</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/osluk</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<domain>
<!-- default site name - must be FQDN -->
<name>stoptheferrymeadtower.org.nz</name>
<!-- legitmate names for the site -->
<aliases>
<alias>www.stoptheferrymeadtower.org.nz</alias>
</aliases>
<!-- IP Addresses to disregard in statistics -->
<skipHost>REGEX[^192\.168\.] REGEX[^10\.128\.] 203.97.50.115 203.97.51.110 REGEX[^*\.kc$]</skipHost>
<!-- remote server details, if any -->
<remote>
<!-- suitable domain name to remote host -->
<host>warhol.kc</host>
<!-- path to the access log file -->
<path>/home/jonathan/logs/stoptheferrymeadtower.org.nz</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user with passwordless ssh access from local,
who also has access to file -->
<user>root</user>
</remote>
<local>
<!-- path to the local mirror of the access log -->
<path>/home/sites/logs/stoptheferrymeadtower</path>
<!-- accesslog filename -->
<file>access_log</file>
<!-- user and group to whom resulting files should belong -->
<user>sites</user>
<group>sites</group>
</local>
<!-- the web-accessible directory into which the stats info should go -->
<statsPath>/home/sites/public_html/stats/stoptheferrymeadtower</statsPath>
<!-- the web-path to the icons directory -->
<iconPath>/icons</iconPath>
</domain>

124
egstats/egawstats Executable file
View file

@ -0,0 +1,124 @@
#!/bin/bash
#
# create static XHTML pages for statistics for a given awstats config
#
AWSDIR="/usr/share/awstats"
AWSTOOL="$AWSDIR/tools"
#AWSROOT="/var/www/cgi-bin/wwwroot"
CONFDIR="/etc/egscripts/egawstats/awstatsconf"
CMD="$AWSTOOL/awstats_buildstaticpages.pl"
#ARGS="-update -awstatsprog=/var/www/cgi-bin/awstats.pl"
ARGS="-update -awstatsprog=/var/www/cgi-bin/awstats.pl"
#
# set defaults
MODE="help"
CONF=""
RESULTS=""
LOG="/var/log/egawstats.log"
NICE="19"
#
# work out dates
thismonth() {
MM=`date +%m`
MONTH=`date +%B`
YEAR=`date +%Y`
}
#
# function to direct a message...
message() {
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
#
# work out dates
lastmonth() {
MM=`date -d "last month" +%m`
MONTH=`date -d "last month" +%B`
YEAR=`date -d "last month" +%Y`
}
#
# choose a default just to be safe
thismonth
#
# get command line args
# start log with a blank line...
insert_blank
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONF=$1
;;
--results|-r)
shift
RESULTS=$1
;;
--this)
thismonth
message "getting details for current month ($MONTH $YEAR)"
;;
--last)
lastmonth
message "getting details for last month ($MONTH $YEAR)"
;;
--help|?|-h)
MODE="help"
;;
esac
shift
done
#
# check for mode
message "$CONF and $RESULTS"
if [ -z $CONF -o -z $RESULTS ] ; then
MODE="help"
else
MODE="run"
fi
if test $MODE == "run" ; then
#message "using config in $CONFDIR/awstats.$CONF.conf, putting results into $RESULTS"
YEARDIR=$RESULTS/$YEAR
if ! test -d $YEARDIR ; then
message "creating new year directory: $RESULTS/$YEAR"
mkdir $YEARDIR
fi
# if test -d $YEARDIR ; then
# nice -n $NICE $CMD $ARGS -config=$CONF -month=all -year=$YEAR -dir=$YEARDIR 2>&1 > /dev/null
# # link the basic xml file to an index.html...
# ln -sf $YEARDIR/awstats.$CONF.html $YEARDIR/index.html
# fi
MONTHDIR=$YEARDIR/$MM
if ! test -d $MONTHDIR ; then
message "creating new month directory: $MONTHDIR"
mkdir $MONTHDIR
fi
if test -d $MONTHDIR ; then
# run the awstats command to build the files for that month
#message "running test on month $MM, year $YEAR"
nice -n $NICE $CMD $ARGS -config=$CONF -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null
# $CMD $ARGS -config=$CONF -month=$MM -year=$YEAR -dir=$MONTHDIR
# link the basic xml file to an index.html...
ln -sf $MONTHDIR/awstats.$CONF.html $MONTHDIR/index.html
else
message "Couldn't find $DIR! Exiting"
exit 1
fi
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config -r results_path --last | --this | -h}"
echo "-r or --results - the absolute path to the directory"
echo " to populate with the year/month/ XHTML results files"
echo "-c or --config - the AWSTATS configuration name, probably"
echo " in /etc/awstats - the name is awstats.[name].conf"
echo "-h or --help - this help message"
fi
exit 0

52
egstats/egawstats_all Executable file
View file

@ -0,0 +1,52 @@
#!/bin/bash
#
# create static XHTML pages for statistics for a given awstats config
#
DIR="/etc/egscripts/egstats"
CMD="$DIR/egawstats"
CONF="$DIR/conf"
CONFSUF="conf"
#
# set defaults
ARG=""
MODE="help"
LOG="/var/log/$0.log"
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--this)
ARG="--this"
;;
--last)
ARG="--last"
;;
--help|?|-h)
MODE="help"
;;
esac
shift
done
#
# check for mode
if [ -z $ARG ] ; then
MODE="help"
else
MODE="run"
fi
if test $MODE == "run" ; then
$CMD $ARG -c far.org.nz -r /home/sites/public_html/far/www/stats
$CMD $ARG -c ics2006.co.nz -r /home/sites/public_html/stats/ics2006
# $CMD $ARG -c davelane.org -r /home/dlane/public_html/davelane.org/stats
# $CMD $ARG -c cypress.co.nz -r /home/cypress/public_html/stats
# $CMD $ARG -c far.org.nz -r /home/far/public_html/stats
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {--last | --this | -h}"
echo "--last - last month's statistics"
echo "--this - the current month's statistics"
echo "-h or --help - this help message"
fi
exit 0

148
egstats/egawstatsindex Executable file
View file

@ -0,0 +1,148 @@
#!/bin/bash
#
# create and index for static XHTML pages of awstats statistics
#
YEARS="2003 2004 2005"
MS="1 2 3 4 5 6 7 8 9 10 11 12"
MONTH[1]=January
MONTH[2]=February
MONTH[3]=March
MONTH[4]=April
MONTH[5]=May
MONTH[6]=June
MONTH[7]=July
MONTH[8]=August
MONTH[9]=September
MONTH[10]=October
MONTH[11]=November
MONTH[12]=December
AWSDIR="/usr/local/awstats/"
AWSTOOL="$AWSDIR/tools"
AWSROOT="$AWSDIR/wwwroot"
CONFDIR="/etc/awstats"
CMD="$AWSTOOL/awstats_buildstaticpages.pl"
ARGS="-update -staticlinksext=html"
MODE="help"
CONFIG=""
RESULTDIR=""
LOG="/var/log/awstats-static.log"
NICE="19"
#
# functions to put content into an index.html file...
starthtml() {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 STRICT//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> " > $HTMLFILE
echo "<html>" >> $HTMLFILE
echo " <head>" >> $HTMLFILE
SITETITLE="Site statistics for $CONFIG"
echo " <title>$SITETITLE</title>" >> $HTMLFILE
echo " </head>" >> $HTMLFILE
echo " <body>" >> $HTMLFILE
echo " <h1>$SITETITLE</h1>" >> $HTMLFILE
echo " <p>Index of statistics by year and month</p>" >> $HTMLFILE
echo " <ul style=\"\">" >> $HTMLFILE
}
startyear() {
echo " <li style=\"\">Statistics for $YEAR:" >> $HTMLFILE
echo " <ul>" >> $HTMLFILE
}
addmonth() {
MONTHNAME=${MONTH[$M]}
echo "MONTHNAME = $MONTHNAME"
echo " <li style=\"\"><a href=\"$YEAR/$MM/index.html\">$MONTHNAME</a></li>" >> $HTMLFILE
}
endyear() {
echo " </ul>" >> $HTMLFILE
echo " </li>" >> $HTMLFILE
}
endhtml() {
echo " </ul>" >> $HTMLFILE
echo " </body>" >> $HTMLFILE
echo "</html>" >> $HTMLFILE
}
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONFIG=$1
;;
--results|-r)
shift
RESULTS=$1
;;
--help|?|-h)
shift
MODE="help"
;;
esac
shift
done
#
# check for mode
if test -z $CONFIG -o -z $RESULTS ; then
MODE="help"
else
MODE="run"
fi
if test $MODE == "run" ; then
DIRS=`/usr/bin/find $REPORTS -name "??" -type d`
echo "using config in $CONFDIR/awstats.$CONFIG.conf, putting results into $RESULTS"
if test -d $RESULTS ; then
HTMLFILE="$RESULTS/index.html"
starthtml
fi
for YEAR in $YEARS
do
startyear
YEARDIR=$RESULTS/$YEAR
if test ! -d $YEARDIR ; then
echo "creating new year directory: $RESULTS/$YEAR"
mkdir $YEARDIR
fi
for M in $MS
do
MM=$(echo $M|sed -e 's/^.$/0&/')
MONTHDIR=$RESULTS/$YEAR/$MM
if test ! -d $MONTHDIR ; then
echo "creating new month directory: $MONTHDIR"
mkdir $MONTHDIR
fi
addmonth
if test -d $DIR ; then
# run the awstats command to build the files for that month
nice -n $NICE $CMD $ARGS -config=$CONFIG -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null
# link the basic xml file to an index.html...
mv $MONTHDIR/awstats.$CONFIG.xml $MONTHDIR/index.html
echo "running test on month $MM, year $YEAR"
else
echo "Couldn't find $DIR! Exiting"
exit 1
fi
done
endyear
done
endhtml
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config -r results_path | -h}"
echo "-r or --results - the absolute path to the directory"
echo " to populate with the year/month/ XHTML results files"
echo "-c or --config - the AWSTATS configuration name, probably"
echo " in /etc/awstats - the name is awstats.[name].conf"
echo "-h or --help - this help message"
fi
exit 0

605
egstats/egstats.php Executable file
View file

@ -0,0 +1,605 @@
#!/usr/bin/php5
<?php
/**
* This set of scripts is indended to accomplish the following:
*
* For each of a number of configured "domains" on this or another
* server, this script will
* a. mirror (rsync) a designated HTTP common access_logs to a
* local access_log.
* b. if it does not already exist, create the appropriate AWStats
* configuration file, including global and Egressive-specific
* configuration defaults as required.
* c. if it has not be performed already, initialise the
* statistics database
* d. update the statistics database
* e. produce a series of HTML pages based on the statistics
* f. copy the relevant icon and graphics files into a suitable
* subdirectory so that they're available for the HTML pages to include
* g. put those HTML pages into a web-viewable directory appropriate to
* the month within the domain's directory
* h. create a sensible "index.html" page so that a browser clicking on
* that month directory sees the summary page for that month and can
* access the other, more specific pages linked in that summary
*/
/* PEAR_LIB_DIR PEAR library directory. */
define('PEAR_LIB_DIR', '/usr/share/pear');
// dummy error constant for this example
define('MYCLASS_ERROR_CODE', 1);
/* system constants */
define('EG_APP','egstats');
define('EG_DIR','/etc/egscripts/egstats');
define('DOMAIN_DIR',EG_DIR.'/conf');
define('DOMAIN_CONF_SUFFIX','conf');
// the rsync command
define('RSYNC','/usr/bin/rsync');
// rsync command flags
define('FLAGS','-e ssh --stats');
// the chown command
define('CHOWN','/bin/chown');
// AWStats related defines
define('AWSBIN','/var/www/cgi-bin/awstats.pl');
define('AWSDIR','/usr/share/awstats');
define('AWS_DB_DIR','/var/lib/awstats');
define('AWS_DB_SUFFIX','txt');
define('AWS_ARGS','-update');
define('AWS_TOOLS_DIR',AWSDIR.'/tools');
define('AWSALLBIN',AWS_TOOLS_DIR.'/awstats_buildstaticpages.pl');
define('AWSALL_ARGS','-update -awstatsprog='.AWSBIN);
// AWStats configuration defaults
define('AWSTATS_LOCAL_DEFAULTS','local_defaults.inc');
define('AWSTATS_GLOBAL_DEFAULTS','global_defaults.inc');
define('AWSCONF_DIR',EG_DIR.'/awstatsconf');
define('AWSCONF_PREFIX','awstats');
define('AWSCONF_SUFFIX','conf');
// XHTML output details
define('AWS_OUT_PREFIX','awstats');
define('AWS_OUT_SUFFIX','html');
define('AWS_OUT_INDEX','index.html');
/**
* Program includes go below this
*/
/* PHP ini set to local PEAR library */
ini_set('include_path', PEAR_LIB_DIR);
/* Require main PEAR class and PLUM classes. */
require_once('PEAR.php');
/* include the logging functionality */
require_once('Log.php');
/* include file reading/writing functionality */
require_once('File.php');
/* include command line argument processing functionality */
require_once('Console/Getopt.php');
/* include command line argument processing functionality */
require_once('Config.php');
/**
* Domain class - information related to a particular virtual domain
* requiring awstats reports (http://awstats.sourceforge.net)
*
* @author Dave Lane <dave@egressive.com>
* @copyright Copyright (C) 2005 Egressive Limited (www.egressive.com)
* @version $Id: egawstats.php 0 2005-08-18 08:07:26Z dave $
* @package egawstats
*/
class Domain extends PEAR {
/**
* @var array $domain a mixed array of "name" and "values"
* for the current domain.
* @access private
*/
private $domain = array();
/**
* @var array $domain_array two dimensional array containing arrays
* of parsed domains.
* @access private
*/
private $domain_array = array();
/**
* @var array $report_dates two dimensional array containing years and
* and months [yyyy][mm] for which the domain yields results.
* @access private
*/
private $report_dates = null;
/**
* @var object $logger - reference to a PEAR log object
* @access private
*/
private $logger = null;
/**
* @var string $short_args - one letter command line arguments
* obeys GNU args conventions - args take form -a or -b value or -ab value
* for multiple arguments
* @access private
*/
private $short_args = "psa";
/**
* @var string $long_args - full word command line arguments, more memorable
* obeys GNU args conventions - args take form --flag or --flagwithvalue=value
* @access private
*/
private $long_args = array('rebuildpages','rebuildstats','rebuildconfs');
/**
* @var array $options_array - array of command line arguments and values
* from the Console/Getopts PEAR class
* @access private
*/
private $options_array = array();
/**
* @var array $options - array of just the command line arguments and values
* @access private
*/
private $options = array();
public function __construct($logger) {
$this->logger = $logger;
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
//
// Error handling
//
// function callback
//$this->setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this,'handleError'));
$this->setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
}
/**
* get the command line arguments
*/
public function get_args() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
$cli_args = new Console_Getopt();
$args = $cli_args->readPHPArgv();
array_shift($args);
$this->options_array = $cli_args->getopt2($args,$this->short_args,$this->long_args);
$this->options = $this->options_array[0];
//print_r($this->options);
}
/**
* put the command line arguments into an array that's useful
* elsewhere in the code...
*/
public function process_args() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// first, get the command line arguments
$this->get_args();
//print_r($this->options);
if (count($this->options) and
(count($this->options_array[0]) or count($this->options_array[1]))) {
foreach($this->options as $option) {
list($key,$value) = $option;
if ($value) {
$this->logger->log('option['.$key.'] = '.$value,PEAR_LOG_DEBUG);
} else {
$this->logger->log('option '.$key.' specified',PEAR_LOG_DEBUG);
}
}
} else {
$this->logger->log('no command line options supplied',PEAR_LOG_DEBUG);
}
}
/**
* put the domain definitions in the configuration files into an
* array that's useful elsewhere in the code...
*/
public function process_configs() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
$conf_files = glob(DOMAIN_DIR.'/*.'.DOMAIN_CONF_SUFFIX);
//print_r($conf_files);
$config = new Config();
foreach ($conf_files as $conf_file) {
$conf =& $config->parseConfig($conf_file,"XML");
}
// assign the configuration info to the domain array
$this->domain_array = $conf->toArray();
}
/**
* run the rsync that synchronises the logs on the main machine to the
* copy on the machine running awstats
*/
private function sync_access_logs() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// the current domain is $this->domain...
// check to see that we actually have to sync a remote file for this
// domain...
if (isset($this->domain['remote']['file']) and
isset($this->domain['remote']['user'])) {
$command = RSYNC.' '.FLAGS.' '.$this->domain['remote']['user'].'@'.
$this->domain['remote']['host'].':'.$this->domain['remote']['path'].'/'.
$this->domain['remote']['file'].' '.$this->domain['local']['path'].'/'.
$this->domain['local']['file'];
if (!is_dir($this->domain['local']['path'])) {
$this->logger->log($this->domain['local']['path']." doesn't exist yet, ".
'creating it...',PEAR_LOG_INFO);
// if it's not there, make the dir (rwxr-xr-x)
if (!mkdir($this->domain['local']['path'],0755)) {
$this->logger->log('failed to create dir '.$this->domain['local']['path'].
': '.$command,PEAR_LOG_ERR);
return false;
}
// set appropriate file ownership
chown($this->domain['local']['path'],$this->domain['local']['user']);
chgrp($this->domain['local']['path'],$this->domain['local']['group']);
}
// run the command and capture the output...
$output = array();
$this->logger->log('rsyncing domain '.$this->domain['name'].
': '.$command,PEAR_LOG_INFO);
$return_value = exec($command,$output);
//print_r($output);
// if the rsync was successful, it'll return a value like this
if (strstr($return_value,"total size ")) {
$this->logger->log('rsync: success - '.$return_value.' ',PEAR_LOG_INFO);
$this->logger->log(' '.$output[11],PEAR_LOG_INFO);
$this->logger->log(' '.$output[12],PEAR_LOG_INFO);
}
else {
$this->logger->log('rsync: failed - '.$return_value.' ',PEAR_LOG_ERR);
return false;
}
}
// if we don't have a remote file, just move on to the next step...
return true;
}
/**
* generate a valid AWSTATs configuration file if it doesn't already exist
*/
private function create_awstats_config() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// the current domain is $this->domain...
// the filename for this domain's AWSTATs configuration file
$filename = AWSCONF_PREFIX.'.'.$this->domain['name'].'.'.AWSCONF_SUFFIX;
// add the path, too...
$fullname = AWSCONF_DIR.'/'.$filename;
// if it doesn't exist, then...
if (!file_exists($fullname)) {
// construct the conf file contents based on this template...
$file_content[] = "#";
$file_content[] = "# site specific settings for ".$this->domain['name'];
$file_content[] = "SiteDomain=\"".$this->domain['name']."\"";
if (is_array($this->domain['aliases']['alias'])) {
$aliases = implode(' ',$this->domain['aliases']['alias']);
} else {
$aliases = $this->domain['aliases']['alias'];
}
$aliases = $this->domain['name'].' '.$aliases;
$file_content[] = "HostAliases=\"".$aliases."\"";
$file_content[] = "SkipHosts=\"".$this->domain['skipHost']."\"";
$file_content[] = "LogFile=\"".$this->domain['local']['path']."/".
$this->domain['local']['file']."\"";
$file_content[] = "DirIcons=\"".$this->domain['iconPath']."\"";
$file_content[] = "#";
$file_content[] = "# local defaults";
$file_content[] = "Include \"includes/".AWSTATS_LOCAL_DEFAULTS."\"";
$file_content[] = "#";
$file_content[] = "# global defaults (true for all Awstats installs)";
$file_content[] = "Include \"includes/".AWSTATS_GLOBAL_DEFAULTS."\"";
foreach ($file_content as $index => $line) {
$no = $index + 1;
$this->logger->log('conf file '.$no.': '.$line,PEAR_LOG_DEBUG);
$file_content[$index] .= "\n";
}
// and then attempt to write it...
if (is_writable(AWSCONF_DIR)) {
// write the file with
if ($bytes = file_put_contents($fullname,$file_content)) {
$this->logger->log('wrote conf file: '.$fullname.
'('.$bytes.' bytes, '.count($file_content).' lines)',PEAR_LOG_INFO);
} else {
$this->logger->log('failed to write conf file: '
.$fullname.'!',PEAR_LOG_ERR);
}
} else {
$this->logger->log('awstats config directory'.AWSCONF_DIR.
' is unwritable!',PEAR_LOG_ERR);
}
} else {
$this->logger->log('conf file: '.$fullname.
' already exists.',PEAR_LOG_INFO);
}
return true;
}
/**
* run AWSTATs script to update stats in the database since last run
* or, if run for first time, initialise the database
*/
private function update_stats() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
$command = AWSBIN.' '.AWS_ARGS.' -config='.$this->domain['name'];
// run the command and capture the output...
$output = array();
$this->logger->log('updating stats for '.$this->domain['name'].
': '.$command,PEAR_LOG_INFO);
$return_value = exec($command,$output);
//print_r($output);
// if the rsync was successful, it'll return a value like this
if (strstr($return_value,"Found ")) {
$this->logger->log('update stats: success - '.
$return_value,PEAR_LOG_INFO);
}
else {
$this->logger->log('update stats: failed - '.
$output[2].' ',PEAR_LOG_ERR);
return false;
}
return true;
}
/**
* figure out the months for which AWSTATs are available
*/
private function get_stats_months() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
if ($this->report_dates == null) {
$files = glob(AWS_DB_DIR.'/*.'.AWS_DB_SUFFIX);
// the current domain is $this->domain...
$this->report_dates = array();
foreach ($files as $filename) {
if ($pos = strpos($filename,$this->domain['name'])) {
$start = $pos-5;
$length = 4;
$year = substr($filename,$start,$length);
$start = $pos-7;
$length = 2;
$month = substr($filename,$start,$length);
$this->logger->log('found file - '.
$filename.' '.$month.'/'.$year,PEAR_LOG_DEBUG);
$dates[$year] .= ','.$month;
}
}
//print_r($dates);
// sort them so they're in year -> month order...
ksort($dates);
foreach ($dates as $year => $months_string) {
$this->report_dates[$year] = array_slice(explode(',',$months_string),1);
}
//array_multisort($this->report_dates);
reset($this->report_dates);
//print_r($this->report_dates);
}
return true;
}
/**
* generate the AWSTATs output pages in XHTML format for
* the specified time period...
*/
private function produce_xhtml_pages() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// first make sure that the stats output directory is there
// if not, create it and set its ownership...
$statsdir = $this->domain['statsPath'];
if (!is_dir($statsdir)) {
$this->logger->log('making '.$statsdir,PEAR_LOG_INFO);
if (!mkdir($statsdir,0755)) {
$this->logger->log('failed to create dir '.$statsdir,PEAR_LOG_ERR);
return false;
}
// set appropriate file ownership
chown($statsdir,$this->domain['local']['user']);
chgrp($statsdir,$this->domain['local']['group']);
}
if ($this->get_stats_months()) {
//print_r($dates);
foreach ($this->report_dates as $year => $months) {
$yeardir = $this->domain['statsPath'].'/'.$year;
if (!is_dir($yeardir)) {
$this->logger->log('making '.$yeardir,PEAR_LOG_INFO);
if (!mkdir($yeardir,0755)) {
$this->logger->log('failed to create dir '.$yeardir,PEAR_LOG_ERR);
return false;
}
// set appropriate file ownership
chown($yeardir,$this->domain['local']['user']);
chgrp($yeardir,$this->domain['local']['group']);
} else {
$this->logger->log('found '.$yeardir,PEAR_LOG_INFO);
}
foreach ($months as $month) {
$monthdir = $yeardir.'/'.$month;
if (!is_dir($monthdir)) {
$this->logger->log('making '.$monthdir,PEAR_LOG_INFO);
if (!mkdir($monthdir,0755)) {
$this->logger->log('failed to create dir '.$monthdir,PEAR_LOG_ERR);
return false;
}
// set appropriate file ownership
chown($monthdir,$this->domain['local']['user']);
chgrp($monthdir,$this->domain['local']['group']);
} else {
$this->logger->log('found '.$monthdir,PEAR_LOG_INFO);
}
$currentmonth = date('m');
$currentyear = date('Y');
$index_page = $monthdir.'/index.html';
//$this->logger->log("year=$currentyear/$year, month=$currentmonth/$month",PEAR_LOG_DEBUG);
if (!is_link($index_page) or ($currentmonth == $month and $currentyear == $year)) {
// having found the monthdir, it's time to create the pages!
$command = AWSALLBIN.' '.AWSALL_ARGS.' -config='.$this->domain['name'].
' -month='.$month.' -year='.$year.
' -dir='.$monthdir.'';
$this->logger->log('generating stats output: '.$command,PEAR_LOG_INFO);
$output = array();
$return_value = exec($command,$output);
if (strstr($return_value,"Main HTML page is ")) {
$idx = count($output) - 2;
$this->logger->log('success: '.$output[$idx],PEAR_LOG_INFO);
$this->logger->log('creating link for index page',PEAR_LOG_INFO);
symlink($monthdir.'/'.AWS_OUT_PREFIX.'.'.$this->domain['name'].
'.'.AWS_OUT_SUFFIX,$index_page);
}
}
}
}
}
}
/**
* generate an XHMTL page with a basic index of statisics results for the relevant
* months...
*/
private function create_xhtml_index() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// if there are any months worth writing about...
if ($this->get_stats_months()) {
$currentmonth = date('m');
$currentdate = date('d-m-y');
//print_r($this->report_dates);
foreach ($this->report_dates as $year => $months) {
$yeardir = $this->domain['statsPath'].'/'.$year;
foreach ($months as $month) {
$monthdir = $yeardir.'/'.$month;
$index_page = $monthdir.'/index.html';
}
}
/* // the filename for this domain's AWSTATs configuration file
$filename = AWS_OUT_INDEX;
// add the path, too...
$fullname = $this->domain['statsPath'].'/'.$filename;
// if it doesn't exist, then...
if (!file_exists($fullname)) {
// construct the conf file contents based on this template...
$file_content[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$file_content[] = "# site specific settings for ".$this->domain['name'];
$file_content[] = "SiteDomain=\"".$this->domain['name']."\"";
if (is_array($this->domain['aliases']['alias'])) {
$aliases = implode(' ',$this->domain['aliases']['alias']);
} else {
$aliases = $this->domain['aliases']['alias'];
}
$aliases = $this->domain['name'].' '.$aliases;
$file_content[] = "HostAliases=\"".$aliases."\"";
$file_content[] = "SkipHosts=\"".$this->domain['skipHost']."\"";
$file_content[] = "LogFile=\"".$this->domain['local']['path']."/".
$this->domain['local']['file']."\"";
$file_content[] = "DirIcons=\"".$this->domain['iconPath']."\"";
$file_content[] = "#";
$file_content[] = "# local defaults";
$file_content[] = "Include \"includes/".AWSTATS_LOCAL_DEFAULTS."\"";
$file_content[] = "#";
$file_content[] = "# global defaults (true for all Awstats installs)";
$file_content[] = "Include \"includes/".AWSTATS_GLOBAL_DEFAULTS."\"";
foreach ($file_content as $index => $line) {
$no = $index + 1;
$this->logger->log('conf file '.$no.': '.$line,PEAR_LOG_DEBUG);
$file_content[$index] .= "\n";
}
// and then attempt to write it...
if (is_writable(AWSCONF_DIR)) {
// write the file with
if ($bytes = file_put_contents($fullname,$file_content)) {
$this->logger->log('wrote conf file: '.$fullname.
'('.$bytes.' bytes, '.count($file_content).' lines)',PEAR_LOG_INFO);
} else {
$this->logger->log('failed to write conf file: '
.$fullname.'!',PEAR_LOG_ERR);
}
} else {
$this->logger->log('awstats config directory'.AWSCONF_DIR.
' is unwritable!',PEAR_LOG_ERR);
}
} else {
$this->logger->log('conf file: '.$fullname.
' already exists.',PEAR_LOG_INFO);
}
return true;
*/
}
}
/**
* run the whole process...
*/
public function run() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// process command line argments, if any
$this->process_args();
// get domain configuration files...
$this->process_configs();
//$this->domain = $this->domain_array['root']['domain'][0];
foreach ($this->domain_array['root']['domain'] as $this->domain) {
// initialise this value
$this->report_dates = null;
// first check to see if there're any access records that need to be
// sync'd
$this->sync_access_logs();
// if it doesn't already exist, create a configuration file...
$this->create_awstats_config();
// update the statistics based on the current access records
// if it hasn't already been created, initialise the stats db
$this->update_stats();
// produce XHTML pages
$this->produce_xhtml_pages();
// and create an up-to-date index of the relevant reports...
$this->create_xhtml_index();
}
}
}
/**
* deal with errors in a uniform way...
*/
function handleError($error) {
global $logger;
//print 'egstats error: '.$error->getMessage().'\n';
$logger->log(EG_APP.' error: '.$error->getMessage(),'.',PEAR_LOG_ERR);
}
// initialise logging
$logger = &Log::singleton('console','','egstats.php');
$logger->log("***** Starting egstats.php *****",PEAR_LOG_DEBUG);
// set up default error handling
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
/**
* Program logic goes below this
*/
$conf_filename="";
$domain = new Domain($logger);
$domain->run();
// final logging message
$logger->log("===== Finishing egstats.php =====",PEAR_LOG_DEBUG);
?>

View file

@ -0,0 +1,71 @@
#!/bin/bash
#
SRC=warhol.kc
SRCPATH=/home/far/logs
DSTFILE=access_log
#
DSTPATH=/home/sites/logs/far
DSTFILE=access_log
DSTUSR=sites
DSTGRP=sites
#
RSYNC=/usr/bin/rsync
FLAGS="-e ssh --stats"
CHOWN=/bin/chown
#
LOG=/var/log/egsynchttpaccess.log
#
# get the access log file from the remote machine
do_rsync() {
message "running rsync of $SRCPATH/$SRCFILE on $SRC to $DSTPATH/$DSTFILE on the local machine"
$RSYNC $FLAGS root@$SRC:$SRCPATH/$SRCFILE $DSTPATH/$DSTFILE
message "setting permissions appropriately for $DSTUSR:$DSTGRP"
$CHOWN $DSTUSR:$DSTGRP $DSTPATH
$CHOWN $DSTUSR:$DSTGRP $DSTPATH/$DSTFILE
}
#
# run the awstats program to generate the static pages of statistics
AWFLAGS="-config=/etc/egawstats/conf/far.conf -update"
BSFLAGS=""
do_stats() {
}
#
# function to direct a message...
message() {
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
#
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONF=$1
;;
--help|?|-h)
MODE="help"
;;
esac
shift
done
MODE="run"
if test $MODE == "run" ; then
do_rsync
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config | -h}"
echo "-c or --config - the configuration file name (full path)"
echo "-h or --help - this help message"
fi
exit 0

View file

@ -0,0 +1,71 @@
#!/bin/bash
#
SRC=warhol.kc
SRCPATH=/home/far/logs
DSTFILE=access_log
#
DSTPATH=/home/sites/logs/far
DSTFILE=access_log
DSTUSR=sites
DSTGRP=sites
#
RSYNC=/usr/bin/rsync
FLAGS="-e ssh --stats"
CHOWN=/bin/chown
#
LOG=/var/log/egsynchttpaccess.log
#
# get the access log file from the remote machine
do_rsync() {
message "running rsync of $SRCPATH/$SRCFILE on $SRC to $DSTPATH/$DSTFILE on the local machine"
$RSYNC $FLAGS root@$SRC:$SRCPATH/$SRCFILE $DSTPATH/$DSTFILE
message "setting permissions appropriately for $DSTUSR:$DSTGRP"
$CHOWN $DSTUSR:$DSTGRP $DSTPATH
$CHOWN $DSTUSR:$DSTGRP $DSTPATH/$DSTFILE
}
#
# run the awstats program to generate the static pages of statistics
AWFLAGS="-config=/etc/egawstats/conf/far.conf -update"
BSFLAGS=""
do_stats() {
}
#
# function to direct a message...
message() {
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
#
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONF=$1
;;
--help|?|-h)
MODE="help"
;;
esac
shift
done
MODE="run"
if test $MODE == "run" ; then
do_rsync
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config | -h}"
echo "-c or --config - the configuration file name (full path)"
echo "-h or --help - this help message"
fi
exit 0

View file

@ -0,0 +1,71 @@
#!/bin/bash
#
SRC=warhol.kc
SRCPATH=/home/ics2006/logs
DSTFILE=access_log
#
DSTPATH=/home/sites/logs/ics2006
DSTFILE=access_log
DSTUSR=sites
DSTGRP=sites
#
RSYNC=/usr/bin/rsync
FLAGS="-e ssh --stats"
CHOWN=/bin/chown
#
LOG=/var/log/egsynchttpaccess.log
#
# get the access log file from the remote machine
do_rsync() {
message "running rsync of $SRCPATH/$SRCFILE on $SRC to $DSTPATH/$DSTFILE on the local machine"
$RSYNC $FLAGS root@$SRC:$SRCPATH/$SRCFILE $DSTPATH/$DSTFILE
message "setting permissions appropriately for $DSTUSR:$DSTGRP"
$CHOWN $DSTUSR:$DSTGRP $DSTPATH
$CHOWN $DSTUSR:$DSTGRP $DSTPATH/$DSTFILE
}
#
# run the awstats program to generate the static pages of statistics
AWFLAGS="-config=/etc/egscripts/egstats/awstatsconf/awstats.ics2006.co.nz.conf -update"
BSFLAGS=""
#do_stats() {
#
#}
#
# function to direct a message...
message() {
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
}
MODE="run"
#
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--config|-c)
shift
CONF=$1
;;
--help|?|-h)
MODE="help"
;;
esac
shift
done
if test $MODE == "run" ; then
do_rsync
else
echo "$0, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {-c config | -h}"
echo "-c or --config - the configuration file name (full path)"
echo "-h or --help - this help message"
fi
exit 0

150
egstats/php/egstats.php Executable file
View file

@ -0,0 +1,150 @@
#!/usr/bin/php5
<?php
/**
* This set of scripts is indended to accomplish the following:
*
* For each of a number of configured "domains" on this or another
* server, this script will
* a. mirror (rsync) a designated HTTP common access_logs to a
* local access_log.
* b. if it does not already exist, create the appropriate AWStats
* configuration file, including global and Egressive-specific
* configuration defaults as required.
* c. if it has not be performed already, initialise the
* statistics database
* d. update the statistics database
* e. produce a series of HTML pages based on the statistics
* f. copy the relevant icon and graphics files into a suitable
* subdirectory so that they're available for the HTML pages to include
* g. put those HTML pages into a web-viewable directory appropriate to
* the month within the domain's directory
* h. create a sensible "index.html" page so that a browser clicking on
* that month directory sees the summary page for that month and can
* access the other, more specific pages linked in that summary
*/
/* PEAR_LIB_DIR PEAR library directory. */
define('PEAR_LIB_DIR', '/usr/share/pear');
/* system constants */
define('EG_DIR','/etc/egscripts/egawstats');
define('EG_CONF',EG_DIR.'conf');
// the rsync command
define('RSYNC','/usr/bin/rsync');
// rsync command flags
define('FLAGS','-e ssh --stats');
// the chown command
define('CHOWN','/bin/chown');
// AWStats related defines
define('AWSBIN','/var/www/cgi-bin/awstats.pl');
define('AWSDIR','/usr/share/awstats');
define('AWSCONF_DIR',EG_DIR.'/awstatsconf');
define('AWSCONF_PREFIX','awstats');
define('AWSCONF_SUFFIX','conf');
define('AWS_ARGS','-update -awstatsprog='.AWSBIN);
/**
* Domain class - information related to a particular virtual domain
* requiring awstats reports (http://awstats.sourceforge.net)
*
* @author Dave Lane <dave@egressive.com>
* @copyright Copyright (C) 2005 Egressive Limited (www.egressive.com)
* @version $Id: egawstats.php 0 2005-08-18 08:07:26Z dave $
* @package egawstats
*/
class Domain {
/**
* @var array $domain a mixed array of "name" and "values"
* for the current domain.
* @access private
*/
private $domain = array();
/**
* @var array $domain_array two dimensional array containing arrays
* of parsed domains.
* @access private
*/
private $domain_array = array();
private $logger = null;
public function __construct($logger) {
$this->logger = $logger;
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
// domain info
$this->domain_array[0]["NAME"] = "far.org.nz";
$this->domain_array[0]["ALIASES"] = array('www.far.org.nz',
'far.egressive.com');
$this->domain_array[0]["SKIP_HOST"] = "REGEX[^192\.168\.] 203.97.50.115 203.97.51.110";
// source information
$this->domain_array[0]["SRC_HOST"] = "warhol.kc";
$this->domain_array[0]["SRC_PATH"] = "/home/far/logs";
$this->domain_array[0]["SRC_FILE"] = "access_log";
$this->domain_array[0]["SRC_USER"] = "root";
// destination information
$this->domain_array[0]["DST_HOST"] = ""; // leave blank for localhost
$this->domain_array[0]["DST_PATH"] = "/home/sites/logs/far";
$this->domain_array[0]["DST_FILE"] = "access_log";
$this->domain_array[0]["DST_USER"] = "sites";
$this->domain_array[0]["DST_GROUP"] = "sites";
}
/**
* print the state of the current class
*/
/*public function print() {
}*/
/**
* run the rsync that synchronises the logs on the main machine to the
* copy on the machine running awstats
*/
private function sync_logs() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
//$this->domain[]
/*if ($this->logger->log('testing logger',PEAR_LOG_NOTICE)) {
echo "logging worked\n";
} else {
echo "logging folded\n";
}*/
}
/**
* run the whole process...
*/
public function run() {
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
foreach ($this->domain_array as $this->domain) {
$this->sync_logs();
}
}
}
/* PHP ini set to local PEAR library */
ini_set('include_path', PEAR_LIB_DIR);
/* Require main PEAR class and PLUM classes. */
require_once('PEAR.php');
/* include the logging functionality */
require_once('Log.php');
/* include file reading/writing functionality */
require_once('File.php');
$logger = &Log::singleton('console','','egawstats.php');
$logger->log("***** Starting egawstats.php *****",PEAR_LOG_DEBUG);
$conf_filename="";
$domain = new Domain($logger);
$domain->run();
$logger->log("===== Finishing egawstats.php =====",PEAR_LOG_DEBUG);
?>