IT.COM

[TUTORIAL] Get Awstats outside of cpanel

Spaceship Spaceship
Watch
Impact
6
Here is a more secure version of getting your awstats outside of cpanel.

Demo

Rep Appreciated

First Create a file called;

awconfig.php

enter this into it (edit to suit your domain)

PHP:
<?

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

$config_domain = 'onebuckdirectory.com'; //The Domain You want the Awstats to show (can be altered in browser) 

$dynamic_images = true; //Ignore at the moment
$image_directory = './awstats_images/'; //Ignore at the moment! 

?>

Then create a second file called index.php

Put This code in (no need to edit anything)

PHP:
<?


require ('awconfig.php');

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

$requesting_image = (strpos($_SERVER['QUERY_STRING'],'.png')===false)?false:true;

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

$file = get_file($fileQuery);

//check again to see if it was a .png file
//if it's not, replace the links
if(!$requesting_image)
{
  $file = str_replace('awstats.pl', basename($_SERVER['PHP_SELF']), $file);

  if($dynamic_images)
  {
    $imgsrc_search = '="/images';
    $imgsrc_replace = '="'.basename($_SERVER['PHP_SELF']).'?images';
  }
  else
  {
    $imgsrc_search = 'src="/images/awstats/';
    $imgsrc_replace = 'src="'.$image_directory;
  }

  $file = str_replace($imgsrc_search, $imgsrc_replace, $file);
  $file = str_replace($spam_words, 'SPAM', $file);
}
else //if it is a png, output appropriate header
{
  header("Content-type: image/png");
}

//output the file
echo $file;
?>

Then upload both to your webserver in an awstats directory and away you go, i will soon do a version where the config is outside the public_html folder.

Marcvs
 
Last edited:
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Wow.
I really need this.
i'll try this if it'll work
rep added
 
0
•••
if you get an error just reply here and ill bug check it!

updated to!
 
0
•••
Shows this for a PNG file:
Code:
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/stats/index.php:1) in /home/user/public_html/stats/index.php on line 60
 
0
•••
0
•••
0
•••
hmm :S

anyone else got this problem...

ill finish of the dynamic images one which is morre advanced but harder to do
 
0
•••
Hi Marcvs,

How do you make the Awstats to 'Update Now'?. Thanks.
 
0
•••
eNOOBz said:
Hi Marcvs,

How do you make the Awstats to 'Update Now'?. Thanks.

Step 1: Go to /tmp/awstats/

Step 2: Edit awstats.yourdomain.com.conf and change AllowToUpdateStatsFromBrowser=0 to AllowToUpdateStatsFromBrowser=1

Step 3: Goto Awstats and use the Update Now button/link which will now appear
 
1
•••
Thanks polurNET but my hosting admin has just do that for me. Anyway thanks for the tip.
 
0
•••
0
•••
PolurNET said:
Step 1: Go to /tmp/awstats/

Step 2: Edit awstats.yourdomain.com.conf and change AllowToUpdateStatsFromBrowser=0 to AllowToUpdateStatsFromBrowser=1

Step 3: Goto Awstats and use the Update Now button/link which will now appear
That is very useful.

Thanks for sharing.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back