How To Display AWStats Publicly in Linux Server?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Shane
    Senior Member
    • Jun 2006
    • 264

    How To Display AWStats Publicly in Linux Server?

    Hello All,

    In order to display AWStats publicly one need to use script to accomplish this. Below mentioned is sample code for the same:

    <?php

    $user = 'username'; //your cpanel username
    $pass = 'password'; //your cpanel password
    $domain = 'website.com'; //do not include 'http://' or 'www.'

    /*
    NO NEED TO TOUCH ANYTHING BELOW HERE
    */

    //retrieves the file, either .pl or .png
    function getFile($fileQuery){
    global $user, $pass, $domain;
    return file_get_contents("http://$user:$pass@$domain:2082/".$fileQuery,'r');
    }

    //it's a .png file...
    if(strpos($_SERVER['QUERY_STRING'],'.png')!==false) {
    $fileQuery = $_SERVER['QUERY_STRING'];
    }
    //probably first time to access page...
    elseif(empty($_SERVER['QUERY_STRING'])){
    $fileQuery = "awstats.pl?config=$domain";
    }
    //otherwise, all other accesses
    else {
    $fileQuery = 'awstats.pl?'.$_SERVER['QUERY_STRING'];
    }

    //now get the file
    $file = getFile($fileQuery);

    //check again to see if it was a .png file
    //if it's not, replace the links
    if(strpos($_SERVER['QUERY_STRING'],'.png')===false) {
    $file = str_replace('awstats.pl', basename($_SERVER['PHP_SELF']), $file);
    $file = str_replace('="/images','="'.basename($_SERVER['PHP_SELF']).'?images',$file);
    }
    //if it is a png, output appropriate header
    else {
    header("Content-type: image/png");
    }

    //output the file
    echo $file;
    ?>

    Note: This script requires cPanel username and password in the php file which is a security risk.Thus, users are requested to use this script at their own risk. We will not provide any support for any issues arising out of the usage of this script.

    Thanks,

    Shane G.
    AccuWebHosting.Com
Working...
X