AWStats without cPanel

AWStats logoThe following script displays AWStats for a site, without the need to log in via cPanel, and without needing to know the cPanel username and password. There are many situations where this is useful. If you're a web developer with business clients, you'll know that most business people can be classified into one of three types:

  1. those who don't know much about computers, and are afraid of breaking them;
  2. those who know a bit about computers, and use some intelligence to try things out; and
  3. those who think they know more than they actually do, and barge in clicking everything until their site breaks

This script is great for people in category (a), who often get overwhelmed and confused by all the options in cPanel. People in category (b) might be ok with cPanel, but this script is handy if they just want to look at their web stats. People in category (c) should be kept away from cPanel at all costs!

Although the script can be used without any password, I'd still recommend putting it into a password-protected directory to stop every man and his dog from playing with your statistics.

<?php
// For this script to show the graphics correctly, they must be uploaded to your server.
// The graphics from AWStats v6.8 are available from this page, or you can
// download a copy of the AWStats package from http://awstats.sourceforge.net/
// Within the package is the directory wwwroot/icon/
// FTP all the folders in this directory to a folder on your server.
 
// To view the stats for an addon or subdomain, just append to the URL:
//  ?config=subdomain.yourdomain.com.au
 
 
// Required settings
$Domain 'yourdomain.com.au'// change this to your own domain
$UserId 'username';          // change this to your cpanel username
$Secret 'password';          // change this to your cpanel password
$ImageDir='awstats_images';    // location of the AWStats graphics
 
// Optional settings
$DefaultLanguage 'en';
$HideLanguages   false;
$HideAwstatsLogo false;
$CustomLogo      '';
$CustomAltTitle  '';
$CustomUrl       '';
 
// ------------------------------------------------------
 
$SayDomain=(isset($_GET['config'])) ?  $_GET['config'] : $Domain;
if(
0==count($_GET))
    { 
$qs="config=$Domain&lang=$DefaultLanguage&framename=mainright"; }
else
    {
    
$qs ''
    foreach (
$_GET as $key=>$value
        { 
$value urlencode(stripslashes($value)); $qs.="$key=$value&"; }
    
$qs=substr($qs,0,-1);
    }
 
$Secret=rawurlencode($Secret);
$Stats file_get_contents("http://$UserId:$Secret@$Domain:2082/awstats.pl?$qs");
$Stats=str_replace('<form name="FormDateFilter"'"<center><h2>Web statistics for $SayDomain</h2></center>\r\n<form name=\"FormDateFilter\""$Stats);
$Stats=str_replace('awstats.pl'$_SERVER['PHP_SELF'], $Stats);
if(
substr($ImageDir,-1)<>'/'$ImageDir.='/';
$Stats=str_replace('/images/awstats/'$ImageDir$Stats);
$Stats=str_replace('framename=index''framename=mainright'$Stats);
$Stats=str_replace('name="framename" value="index"''name="framename" value="mainright"'$Stats);
$Stats=str_replace('target="mainright"'''$Stats);
if(
$HideLanguages$Stats=preg_replace('/<td align="right" rowspan="2">(<a .*<\/a>).*<br \/><a .*<\/td>/Us''<td align="right" rowspan="2">$1</td>'$Stats1);
if(
$HideAwstatsLogo or $CustomLogo<>'')
    {
    
$Img="<img src=\"$CustomLogo\" border=\"0\" alt=\"$CustomAltTitle\" title=\"$CustomAltTitle\" />";
    
$Logo=(''==$CustomUrl) ? $Img "<a href=\"$CustomUrl\" target=\"_blank\">$Img</a>";
    if(
''==$CustomLogo$Logo='&nbsp;';
    
$Stats=preg_replace('/<td align="right" rowspan="2">(<a .*<\/a>)/Us''<td align="right" rowspan="2">'.$Logo$Stats1);
    }
echo 
$Stats;
?>

If you want to use this script, remember to also grab the images that go with it (link below) or get them from the AWStats package on Sourceforge.

awstats-images
Filename:

awstats_images.zip

File date: 

2009-09-27


Write a comment

  • Required fields are marked with *.