<?
	require_once('../include/user.php');
	
	$user = $cp_user;
	$pass = $cp_pass;
	$url = $_SERVER['HTTP_HOST']; //do not include 'http://'

	function getFile($file){
		global $user, $pass, $url;
		return file_get_contents("http://".$user.":".urlencode($pass)."@".$url.":2082/tmp/".$user."/webalizer/".$file);
	}

	function changeLinks($subject, $type) {
		return preg_replace("/($type=\")(?!http)(.*?)\"/is","$1$PHP_SELF?$2\"", $subject);
	}

	if (!empty($_SERVER['QUERY_STRING'])) {

		$page = getFile($_SERVER['QUERY_STRING']);

		if (strpos($_SERVER['QUERY_STRING'],'.png') !== false) {
			header("Content-type: image/png");
		} else {
			$page = changeLinks($page, 'src');
		}
	
	} else {
		$page = getFile('index.html');
		$page = changeLinks($page, 'href');
		$page = changeLinks($page, 'src');
	}

	echo $page;

?>