View Single Post
  #1  
Old 9th October 2010, 11:53
e100 e100 is offline
Junior Member
 
Join Date: Sep 2010
Posts: 12
Thanks: 1
Thanked 5 Times in 1 Post
Lightbulb use jawstats / mawstats with ispconfig

Its 4:45AM so blame any bugs on lack of sleep

The script is designed to be called by ispconfig cron as if it was the awstats_buildstaticpages.pl. No changes are required to ispconfig other than editing the awstats_buildstaticpages.pl setting in the panel.

This setup works with ispconfig 3.0.3, just follow the directions that are documented in the script and you should have a painless transition from static awstats to jawstats goodness. This is assuming you have awstats setup and working with ispconfig 3 already.

Enjoy!


Code:
#!/bin/bash

#Location of your jawstats:
JAWSTATS=/usr/local/ispcjawstats/jawstats/

#Location of your awstats config files, should match setting in ispconfig 3
AWSTATSCONFIG=/etc/awstats

#Location of old awstats data directory
OLDDIR=/var/lib/awstats/

#Optional Setting
DANGEROUS="no"
# Setting this to "YES" allows the script to delete the old static awstats html files.
#
# This is the only option that should result in anything being deleted
# However, as with any script use this option and this script at your own risk.
# No warranties implied, infact this script may delete all of your data 
# and make your hair fall out.
#
# Always make a backup and I hope you find this script useful
# 
##
## Do not edit below this line
##
#####################################################################################
## Many thanks to everyone who has contributed to ispconfig
## -e100
#####################################################################################
# SETUP
#
# 1. Create a directory to hold this script
#    I placed my script in /usr/local/ispcjawstats
#    ie mkdir /usr/local/ispcjawstats   
# 2. Put this script in that directory
# 3. Make this script executible
#    ie chmod 555 /usr/local/ispcjawstats/ispcjawstats.sh
# 4. Create your jawstats "source" folder. This is the folder that this script
#    will copy from to install jawstats for each site that is configured for awstats
#    in ispconfig 3
#    ie mkdir /usr/local/ispcjawstats/jawstats
# 5. Put jawstats into this folder
# 6. Set the JAWSTATS variable above to match the location of your jawstats folder
# 7. Set the AWSTATS variable above to match the location if your awstats config folder
#       This should match what you have set in ispconfig 3
# 8. delete the config.dist.php in the jawstats folder
# 9. create a file named "version" in the jawstats folder.
#    If the contents of this file is changed
#    this script will update jawstats in your customers stats folder
#    I put "0.7" inside of version to denote the version.
#    The contents of this file do not matter, changing the contents triggers the update.
# 10.Create a config.php in the jawstats directory that looks like this:
:<<StartCopyNextLineStopBeforeYouSeeThisAgain
<?php

  // core config parameters
  $sDefaultLanguage      = "en-gb";
  $sConfigDefaultView    = "thismonth.all";
  $bConfigChangeSites    = false;
  $bConfigUpdateSites    = false;
  $sUpdateSiteFilename   = "xml_update.php";

  // individual site configuration
  $aConfig["<DOMAIN>"] = array(
    "statspath"   => "<PATH>",
    "statsname"   => "myformat[MM][YYYY].txt",
    "updatepath"  => "<AWSTATS>",
    "siteurl"     => "http://<DOMAIN>",
    "sitename"    => "<DOMAIN>",
    "theme"       => "default",
    "fadespeed"   => 250,
    "password"    => "",
    "includes"    => "",
    "language"    => "en-gb"
  );

?>
StartCopyNextLineStopBeforeYouSeeThisAgain
#
# NOTE: if you are using mawstats you may need to add more options to the above configuration
# 11. Set the permissions on every file/folder inside the jawstats directory
#     to whatever you feel is appropriate for your server configuration.
#     These will be preserved when it copies.
#     I suggest the following:
#     everything  chown root:root
#     All directories chmod 555
#     All files chmod 444 except for config.php I made 644
#     This way your customers sites can read them but not change them.
# 12. In ispconfig 3 control panel go to System->Server Config
# 13. Select the server you installed this onto
# 14. Go to the web tab and change "awstats_buildstaticpages.pl script"
#     To the path to this script.
# 15. Make note of previous setting for "awstats data folder"
#     Set the variable OLDDIR to the current "awstats data folder" setting. 
# 16. Set the "awstats data folder" to [website_path]/web/stats/  
#
# Wait for the daily cron to run or run it yourself:
# /usr/local/ispconfig/server/cron_daily.sh
#
# point your browser to http://sitename/stats/ and log in as usual
#
# Happy JAWStats!
#
# NOTES:
# If you had awstats setup prior to installing this script and you
# setup the OLDDIR variable correctly this script will copy the
# previous awstats DB files for the site into the new 
# [website_path]/web/stats/ directory.
#
# If your awstats files are defined different than awstats[MM][YYYY]sitename.conf
# This script is likely to not work for you.
# The above example is how my debian ispconfig3 install is setup by default.
# Therefore this is how I have written the script to function.
# If your setup is different you will need to edit this script to make it work.
#
# If this jawstats config.php is ever missing, this script will re-create it
#
if [ ! -r "$JAWSTATS""/version" ]
then
  echo "Your JAWSTATS directory is missing or not configured properly"
  exit 1
fi

for i in $*
do
    case $i in
        -config=*)
        CONFIG=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
        ;;
        -lang=*)
        LANG=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
        ;;
        -dir=*)
        DIR=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
        ;;
    -awstatsprog=*)
        AWSTATS=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
                ;;
      esac
done

#Check if awstats config exists
if [ ! -r "$AWSTATSCONFIG""/awstats.""$CONFIG"".conf" ]
then
  echo "Your config file is missing!"
  exit 1
fi

#check if directory exists
if [ ! -r "$DIR" ]
then
  echo "Your destination directory is missing!"
  exit 1
fi

updateconfig()
{
#use sed to updateconfig
sed "s,<AWSTATS>,$AWSTATS,g" "$JAWSTATS""/config.php" \
|sed "s,<PATH>,$DIR/,g"|sed "s,<DOMAIN>,$CONFIG,g" >"$DIR""/config.php"
}

#Check if this script has ever installed JAWStats
if [ ! -r "$DIR""/version" ]
then
  #Attempt to copy the old awstats data files to new directory
  cp -pu "$OLDDIR""awstats"*"$CONFIG"".txt" "$OLDDIR""dnscachelastupdate.""$CONFIG"".hash" "$DIR"
  #Call function to update config here
  updateconfig
fi

#Check is jawstats needs updated in the destination directory
cmp "$JAWSTATS""/version" "$DIR""/version" &> /dev/null
if [ $? -eq 0 ]         # Test exit status of "cmp" command.
then
  #Jawstats is up to date
  #Check for config, if missing re-create it
  if [ ! -r "$DIR""/config.php" ]
  then
    #Call function to update config
    updateconfig
  fi 
else  
  #Jawstats is out of date, update it in user's directory.
  cp -Rpu "$JAWSTATS""/"* "$DIR""/"
  updateconfig
fi

#now lets update the stats!
#That is the whole purpose of this script, right?!

#Needed to keep perl from spitting out warnings on my system
LANG="en_US.UTF-8"
CMD="$AWSTATS""  -config='""$CONFIG""' -lang=""$LANG"" -update"
$CMD

#Now that JAWStats is installed lets create that html file that ispconfig 3 will want to rename

cat > "$DIR""/awstats.""$CONFIG"".html" <<index-html-output
<html>
<head>
<meta http-equiv="refresh" content="0;URL=index.php" />
<title>Page has moved</title>
</head>
<body>
If this page does not redirect automatically click <a href="index.php">here</a>
</body>
</html>
index-html-output



if [ "$DANGEROUS" == "YES" ]
then
  NAMES="allhosts.html allrobots.html browserdetail.html errors404.html keyphrases.html keywords.html lasthosts.html lastrobots.html osdetail.html refererpages.html refererse.html session.html unknownbrowser.html unknownip.html unknownos.html urldetail.html urlentry.html urlexit.html alldomains.html"
fi
  for ext in $NAMES
  do
    rm -f "$DIR""/awstats.""$CONFIG"".$ext"
  done
exit 0

Last edited by e100; 9th October 2010 at 19:14. Reason: Typo in the definition for config.php
Reply With Quote
Sponsored Links