<?  

//  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");
$get_items="SELECT * FROM email_users WHERE username='$email' && password=password('$pass')";
$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)) {
		$quota = $items[quota];
		$cp_email = $items[cp_email];
}




if($change_pass==1){
if ($password!=$password1) {
echo "New Passwords do not match <a href=poppass.php>Go Back</a>";
} else {

$put_items="UPDATE email_users SET password=password('$password'), raw_pwd='$password' WHERE username='$email'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));

// Comment out here to End for manual password change approval.
$request = "/frontend/$cpmod/mail/dopasswdpop.html?email=$email&domain=$domain&password=$password&quota=$quota";
$result = cprq($host,$port,$ownername,$reseller_pass,$request);
$show = strip_tags($result);

if ($debugon==1) {
echo "$show<br><br>";
}

$ftppwd="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/ftp/dopasswdftp.html?acct=$email&password=$password";
($fp = fopen($ftppwd, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not change password";
}
$sqlusr="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/sql/adduser.html?user=$email&pass=$password";
($fp = fopen($sqlusr, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Database username may be corrupted contact the administrator";
}

echo " Your password was successfully changed.  An email has been sent to the account owners email address";

$recipient=$admin_email; 

$subject="User $email has changed their password"; 

$msg="Username $email has their password to $password"; 

$mailheaders="From:  Site Admin <admin@$domain>\n"; 

mail ($recipient, $subject, $msg, $mailheaders); 



$get_items="SELECT * FROM email_users WHERE username='$email'";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
	while ($items = mysql_fetch_array ($get_items_res)) {
		$alt_email = $items[email];
}



$recipient=$alt_email; 

$subject="Your $domain email password change"; 

$msg="The password for account name $email at $domain has been changed to $password.  If you didn't request this change please contact $admin_email immediately";

$mailheaders="From:  $domain Site Admin <$admin_email>\n"; 

mail ($recipient, $subject, $msg, $mailheaders); 

}
?><FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> </FORM><?
}


if($add_forward==1){

$request = "/dowebmailforward.cgi?fwd=$email_forward";
$result = cprq($host,$port_mail,$cp_email,$pass,$request);
$show = strip_tags($result);

if ($debugon==1) {
echo "$show<br><br>";
}
?><FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> </FORM><?
}

if($del_forward==1){
//$request = "/frontend/x2/mail/dodelfwd.html?email=$cp_email=$fwd";
//$result = cprq($host,$port,$ownername,$reseller_pass,$request);
//$request = "/dowebmailforward.cgi?action=$action&fwd=$fwd";
//$result = cprq($host,$port_mail,$cp_email,$pass,$request);

$mailusr="http://$ownername:$reseller_pass@$host:$port/frontend/$cpmod/mail/dodelfwd.html?email=$cp_email=$fwd";
($fp = fopen($mailusr, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  The forwarder to $fwd has NOT been deleted";
}else{
  echo "The forwarder to $fwd has been deleted";
}

//$show = strip_tags($result);

if ($debugon==1) {
echo "$show<br><br>";
}
?><FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> </FORM><?
}

}else{
  echo "ERROR INVALID USERNAME/PASSWORD";
}
exit;

function cprq($host,$port,$ownername,$reseller_pass,$request)  {



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

if(!$sock)

{

print('Socket error');

exit();

}

$authstr = "$ownername:$reseller_pass";

$pass = base64_encode($authstr);

$in  = "GET $request\r\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;

}
?>
