<?  

//  cP Account Creator Version 0.4 Beta Build 01
//  Copyright (C) 2004 Brian Freeman
//  All Rights Reserved.
//
//  This script set is distributed as is with absolutely no warranty.
//  Users of this script set agree to use at their own risk.
//  Questions or comments?  Contact webmaster@freemans-web.com
//
//

require("../config.php");



//$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
//mysql_select_db($dbname,$conn) or die(mysql_error( ));


$get_items="SELECT * FROM email_users WHERE username='$email' && password='$sess'";


$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
if (mysql_num_rows($get_items_res)==1)  {
	while ($items = mysql_fetch_array ($get_items_res)) {
		$cp_email = $items[cp_email];
		$raw_pwd = $items[raw_pwd];
		$password = $items[password];
		$cp_subdomain = $items[sub_domain];
                $cp_username = $items[username];
		$alt_email = $items[email];
$ck_domain_type=explode(".",$cp_subdomain);
$domain_type=explode(".",$domain);
if($ck_domain_type[0]==$domain_type[0]){
$dom_type=1;

}else{
$dom_type=0;
}
if($dom_type==1){
  $dir_st=explode($domain,$cp_subdomain);
  $dir_struct=$dir_st[1];
$net2ftp_dir=explode("/$cp_username",$dir_struct);

$net2ftp_dirstr=explode("/",$net2ftp_dir[0]);
}

if($dom_type==0){
$dir_struct="/$cp_username";
}




}
include("template/header.php");

if($view==""){
$request="/frontend/$cpmod/diskusage/index.html?showtree=public_html$dir_struct";
$result=cprq($host,$port,$ownername,$reseller_pass,$request);
$usage_raw_st= strip_tags($result);
$usage_form_st=explode('public_html',$usage_raw_st);
$usage_out_st= str_replace($dir_struct, "", $usage_form_st[1]);
$usage_form1_st=explode("Meg",$usage_out_st);

$request="/frontend/$cpmod/stats/bandwidth.html";
$result=cprq($host,$port,$ownername,$reseller_pass,$request);
$usage_raw_bw= strip_tags($result);
$usage_form_bw=explode("$cp_subdomain",$usage_raw_bw);
$usage_form1_bw=explode("Meg",$usage_form_bw[1]);

$request="/frontend/x/mail/pops.html?extras=disk";
$result=cprq($host,$port,$ownername,$reseller_pass,$request);
$usage_raw_e= strip_tags($result);
$usage_form_e=explode("$email+$domain",$usage_raw_e);
$usage_form1_e=explode("Meg",$usage_form_e[1]);

$request="/webmailforward.cgi";
$result=cprq($host,$port_mail,$cp_email,$raw_pwd,$request);
$email_fwd= strip_tags($result);
$email_fwd_e=explode("A copy of your mail is currently being forwarded to:",$email_fwd);
$email_fwd_d=explode("Forward a copy of your mail to: ",$email_fwd_e[1]);
$email_fwd_list=explode("Delete",$email_fwd_d[0]);

//$sql_usr="_$email";
//$sql_usr1="$ownername$sql_usr";
//$dbh=mysql_connect ("localhost", $sql_usr1, $raw_pwd) or die ('I cannot connect to the database because: ' . mysql_error());
//if(!$dbh){
//  echo "Cannot Connect to Database";
//}else{
//  echo "Connected to Database";
//}

include("template/client_access.php");
}

if($view==1){
$request="/awstats.pl?config=$cp_subdomain&lang=en&framename=mainright";
$result=cprq($host,$port,$ownername,$reseller_pass,$request);
$show_result=strip_tags($result, '<table><td><tr><body><head><option>');
$show_clean=explode("Summary",$show_result);

echo "<center><h2>Summary</h2><h3>$cp_subdomain</h3></center>";
echo $show_clean[1];
echo "<FORM><INPUT TYPE=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"> </FORM>";

}

if($view==2){
$request="/frontend/$cpmod/diskusage/index.html?showtree=public_html/$dir_struct";
$result=cprq($host,$port,$ownername,$reseller_pass,$request);
$usage_raw_st= strip_tags($result,'<table><td><tr><body><head>');
$usage_form_st=explode('Space Used',$usage_raw_st);
$usage_form_st1= explode('[ Go Back ]',$usage_form_st[1]);

echo "</tr><tr></tr><td>Directory</td><td>Space Used</td></tr>$usage_form_st1[0]";
echo "<FORM><INPUT TYPE=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"> </FORM>";
}

if($view==3){
  phpinfo();
}

include("template/footer.php");
}else{
  echo"Username or Password Incorrect";
}


//  End 
function cprq($host,$port,$ownername,$reseller_pass,$request)  {
global $email,$cpmod;



$sock = fsockopen($host,$port);

if(!$sock)

{

print('Socket error');

exit();

}

$authstr = "$ownername:$reseller_pass";

$pass = base64_encode($authstr);
//$in  = "GET $request\r\n";
$in  = "GET $request\n";

$in .= "HTTP/1.0\r\n";

$in .= "Host:$domain\r\n";

$in .= "Authorization: Basic $pass\r\n";

$in .= "\r\n";





   fputs($sock, $in);

   while (!feof($sock))  {

// fgets ($sock,128);

$result .= fgets ($sock,128);

}

fclose( $sock );

return $result;


}

?>