<?
//
//  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( ));

if($banned==1) {
$get_items="SELECT * FROM banned WHERE $b_field='$b_entry'";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));

if(mysql_num_rows($get_items_res)>=1)  {
echo "Already in the banned list <a href=admin.php>Go Back</a>";
}else {

$put_items="INSERT INTO banned SET $b_field='$b_entry'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Success updating record.  <a href=admin.php>Go Back</a>";
}
}

if($rem_ban==1) {
$get_items="DELETE FROM banned WHERE $b_field='$b_entry'";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
echo "Removed $b_entry from the banned list <a href=view_ban.php>Go Back</a>";
}

if($updt_user==1) {
$put_items="UPDATE email_users SET first_name='$first_name', last_name='$last_name', email='$alt_email' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Success updating record.  <a href=admin.php>Go Back</a>";

}
if($updt_admin==1) {
$put_items="UPDATE email_users SET username='$username' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Success updating record.  <a href=admin.php>Go Back</a>";

}

if($del_pop==1) {
$get_items="SELECT * FROM email_users WHERE id='$id'&&username='$email' ";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
	while ($items = mysql_fetch_array ($get_items_res)) {
		$cp_sub_dom=$items[sub_domain];
		$approved=$items[approved];
}

if($approved==1) {
$put_items="DELETE FROM email_users WHERE id='$id'&&username='$email' ";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));

$request = "/frontend/$cpmod/mail/realdelpop.html?email=$email&domain=$domain&password=$password&quota=$quota"; 
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$request = "/frontend/$cpmod/ftp/realdodelftp.html?login=$email";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$request = "/frontend/$cpmod/subdomain/dodeldomain.html?domain=$cp_sub_dom";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$request = "/frontend/x/addoncgi/dokill.html?addonname=$add_on&url=$scriptdir1$scriptdir2";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

//$script="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/addoncgi/dokill.html?addonname=phpBB&url=$scriptdir1$scriptdir2";
//($fp = fopen("$script", "r")) or die("Could not open file!");
//if(!$fp){
//    echo "Error:  Forum Deletion Failed.";
//}else{
//}


$ck_domain_type=explode(".",$cp_sub_dom);
$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_sub_dom);
  $dir_st1=explode("/$email",$dir_st[1]);
  $dir_struct="$dir_st1[0]";
}

if($dom_type==0){
$dir_struct="";

}
$root_dir=explode("public_html",$srcroot);
$rt_dir="$root_dir[0]public_html$dir_struct";

//$request= "/frontend/$cpmod/files/trashit.html?dir=$rt_dir&file=$email";
//$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/trashit.html?dir=$rt_dir&file=$email";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}




$db_user1=$ownername;

$db_user2="_" ;

$db_user3=$email;
$request = "/frontend/$cpmod/sql/deldb.html?db=$db_user1$db_user2$db_user3"; 
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$request = "/frontend/$cpmod/sql/deluser.html?user=$db_user1$db_user2$db_user3"; 
$result = deluser($host,$port,$ownername,$reseller_pass,$request);



echo "Success deleting user <a href=admin.php>Go Back</a>";
}else{
$put_items="DELETE FROM email_users WHERE id='$id'&&username='$email' ";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Success deleting user <a href=admin.php>Go Back</a>";
}
}
if($chg_pass==1) {
$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( ));

$request = "/frontend/$cpmod/mail/dopasswdpop.html?email=$email&domain=$domain&password=$password&quota=$quota"; 
$result = chgpass($host,$port,$ownername,$reseller_pass,$request,$email,$domain,$password,$quota);

$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 "Password updated";
}
if($admin_pass==1) {
$put_items="UPDATE email_users SET password=password('$password'), raw_pwd='$password', WHERE username='$username'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Record updated <a href=index.php> Login</a>";
}
if($updt_config==1) {
$put_items="UPDATE config SET auto_create='$u_auto',sub_domain='$u_sub',ftp_user='$u_ftp',database_user='$u_db',stor_lmt_enab='$u_str_lmt',stor_lmt='$u_str', ftp_lmt='$u_ftp_lmt', sub_name1='$u_sub_name1', sub_name2='$u_sub_name2', sub_name3='$u_sub_name3', sub_name4='$u_sub_name4' WHERE id='$u_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
echo "Record updated <a href=view_settings.php>Settings</a>";
}

if($acct_suspend==1) {
$ck_domain_type=explode(".",$cp_sub_dom);
$domain_type=explode(".",$domain);

if($ck_domain_type[0]==$domain_type[0]){
$sus_path=explode("$domain/",$cp_sub_dom);
$put_items="UPDATE email_users SET act_sub='0' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));

$request = "/frontend/$cpmod/mime/addredirect.html?type=temp&path=$sus_path[1]&url=$domain$script_directory$suspend";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$ftppwd="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/ftp/dopasswdftp.html?acct=$cp_username&password=$reseller_pass";
($fp = fopen($ftppwd, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not reset Password";
}


$sqlusr="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/sql/adduser.html?user=$cp_username&pass=$reseller_pass";

($fp = fopen($sqlusr, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Database username may be corrupted contact the administrator";
}

$result_detdir = detdir($cp_sub_dom);
$resource_name="Account+is+Suspended";
//$prodir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/htaccess/changepro.html?protected=1&resname=$resource_name&dir=$result_detdir&action=Save";
//($fp = fopen($prodir, "r")) or die("Could not open file!");
//if(!$fp){
//    echo "Error:  Database username may be corrupted contact the administrator";
//}
$request = "/frontend/$cpmod/htaccess/changepro.html?protected=1&resname=$resource_name&dir=$result_detdir&action=Save";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$show = strip_tags($result);

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


$request = "/frontend/$cpmod/mail/dopasswdpop.html?email=$cp_username&domain=$domain&password=$reseller_pass&quota=$quota";
$result = chgpass($host,$port,$ownername,$reseller_pass,$request,$email,$domain,$password,$quota);




echo "Account Suspended <a href=admin.php>Go back.</a>";

}else{
$put_items="UPDATE email_users SET act_sub='0' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
$req_underscore="_";
$dom_rew=explode($domain,$cp_sub_dom);
$dom_rewri=explode(".",$dom_rew[0]);
$dom_rewrite=implode("_",$dom_rewri);
$redir_sub="$dom_rewrite$domain";

$redir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/subdomain/saveredirect.html?domain=$redir_sub&url=http%3A%2F%2F$domain$script_directory$suspend";
($fp = fopen($redir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not store redirect";
}

$ftppwd="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/ftp/dopasswdftp.html?acct=$cp_username&password=$reseller_pass";
($fp = fopen($ftppwd, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not reset Password";
}

$sqlusr="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/sql/adduser.html?user=$cp_username&pass=$reseller_pass";
($fp = fopen($sqlusr, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Database username may be corrupted contact the administrator";
}
$request = "/frontend/$cpmod/mail/dopasswdpop.html?email=$cp_username&domain=$domain&password=$reseller_pass&quota=$quota";
$result = chgpass($host,$port,$ownername,$reseller_pass,$request,$email,$domain,$password,$quota);



echo "Subdomain Account Suspended <a href=admin.php>Go back.</a>";
}
}

if($acct_unsuspend==1) {
$ck_domain_type=explode(".",$cp_sub_dom);
$domain_type=explode(".",$domain);

if($ck_domain_type[0]==$domain_type[0]){
$sus_path=explode("$domain",$cp_sub_dom);
$put_items="UPDATE email_users SET act_sub='1' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));

$rmredir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/mime/delredirect.html?path=$sus_path[1]";
($fp = fopen($rmredir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did Remove Redirect";
}

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

$result_detdir = detdir($cp_sub_dom);
$resource_name="Account+is+Suspend";
//$prodir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/htaccess/changepro.html?protected=1&resname=$resource_name&dir=$result_detdir&action=Save";
//echo "<br>$prodir";
//($fp = fopen($prodir, "r")) or die("Could not open file!");
//if(!$fp){
//    echo "Error:  Database username may be corrupted contact the administrator";
//}
$request = "/frontend/$cpmod/htaccess/changepro.html?protected=0&resname=$resource_name&dir=$result_detdir&action=Save";
$result = deluser($host,$port,$ownername,$reseller_pass,$request);

$show = strip_tags($result);

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




$request = "/frontend/$cpmod/mail/dopasswdpop.html?email=$cp_username&domain=$domain&password=$password&quota=$quota";
$result = chgpass($host,$port,$ownername,$reseller_pass,$request,$email,$domain,$password,$quota);



echo "Account UnSuspended <a href=admin.php>Go back.</a>";

}else{

$put_items="UPDATE email_users SET act_sub='1' WHERE id='$cp_id'";
$put_items_res=mysql_query($put_items)  or die(mysql_error( ));
$req_underscore="_";
$dom_rew=explode($domain,$cp_sub_dom);
$dom_rewri=explode(".",$dom_rew[0]);
$dom_rewrite=implode("_",$dom_rewri);
$redir_sub="$dom_rewrite$domain";

$rmredir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/subdomain/donoredirect.html?domain=$redir_sub";
($fp = fopen($rmredir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not remove redirect";
}

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



echo "Subdomain Account UnSuspended <a href=admin.php>Go back.</a>";
}

}
exit;

function deluser($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);
$confirm= fgets ($sock,128);
}
fclose( $sock );
}

function chgpass($host,$port,$ownername,$reseller_pass,$request,$email,$domain,$password,$quota)  {

$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);
$confirm= fgets ($sock,128);
}
fclose( $sock );

}

function detdir($cp_sub_dom)  {
global $domain,$srcroot1;



$sus_path=explode("$domain/",$cp_sub_dom);

$prot_p=explode("/",$srcroot1);

$prot_pa=explode("/",$sus_path[1]);

$prot_pa0=$prot_pa[0];
$prot_pa1=$prot_pa[1];
if($prot_pa1==""){
  $prot_path_b="/$prot_pa0";
}else{
  $prot_path_b="/$prot_pa0/$prot_pa1";
}
$prot_path_a="/$prot_p[1]/$prot_p[2]/$prot_p[3]";
$prot_path="$prot_path_a$prot_path_b";
$prot_resname="account++is+suspended";

$result_detdir=$prot_path;



return $result_detdir;


}

?>
