Home >

Providing Server Statistics To Customers

You may want to give your clients access to server stats without giving them access to cPanel. Here are a couple of PHP scripts you can use for AWStats and Webalizer:

AWStats

<?php
//dv at josheli.com
$user = 'username';//your cpanel username
$pass = 'password';//your cpanel password
$domain = 'mydomain.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;
?>

Webalizer

<?php
//dv at josheli.com
$user = 'username';
$pass = 'password';
$url = 'www.mydomain.com';//do not include 'http://'
//retrieves the webalizer file, either .html or .png
function getFile($file){
global $user, $pass, $url;
return file_get_contents("http://$user:$pass@$url:2082/tmp/$user/webalizer/$file");
}
//alters links, either .html or .png
function changeLinks($subject, $type) {
return preg_replace("/($type=\")(?!http)(.*?)\"/is","$1$PHP_SELF?$2\"",$subject);
}
if(!empty($_SERVER['QUERY_STRING'])){

//get file (whether png or html)
$page = getFile($_SERVER['QUERY_STRING']); //if png, output appropriate header
if(strpos($_SERVER['QUERY_STRING'],'.png')!==false){
header("Content-type: image/png");
}
//change the .png src(s)
else {
$page = changeLinks($page, 'src');
}
}
else {
//get index
$page = getFile('index.html');
//change links
$page = changeLinks($page, 'href');
//change the usage.png src
$page = changeLinks($page, 'src');
}
//output it
echo $page;
?>


Email:  info@pittsites.com          Phone:  (916) 222-1573
Copyright © 2004 - 2006, Pitt Sites

x