- 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)
Then create a second file called index.php
Put This code in (no need to edit anything)
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
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: