<?  

//
//  cP Account Creator Version 0.4 Beta Build 01
//  MODS
//  1.  Signup Email MOD
//  2.  Password Protected Directory and User Creation MOD
//  3.  Scripts Mod
//  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
//
//

if($auth==1){
include("config.php");
include("template/header.php");
error_reporting(E_ERROR | E_PARSE);




if($uninstall_forum==1){
$ck_domain_type=explode(".",$usr_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,$usr_subdomain);
  $dir_struct=$dir_st[1];
}
if($dom_type==0){
$dir_struct="/$email";
}


$public_html="public_html";
$root_dir=explode($public_html,$srcroot1);

$rt_dir="$root_dir[0]$public_html$dir_struct";

$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/trashit.html?dir=$rt_dir&file=forum";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "Forum Deleted.<br>";
}
$sql_usr="_$email";
$sql_usr1="$ownername$sql_usr";
mysql_close($conn);
$conn2  = mysql_connect($dbhost, $sql_usr1, $password) or die(mysql_error( ));
mysql_select_db($sql_usr1,$conn2) or die(mysql_error( ));
$get_items = 'DROP TABLE `phpbb_auth_access`, `phpbb_banlist`, `phpbb_categories`, `phpbb_config`, `phpbb_confirm`, `phpbb_disallow`, `phpbb_forum_prune`, `phpbb_forums`, `phpbb_groups`, `phpbb_posts`, `phpbb_posts_text`, `phpbb_privmsgs`, `phpbb_privmsgs_text`, `phpbb_ranks`, `phpbb_search_results`, `phpbb_search_wordlist`, `phpbb_search_wordmatch`, `phpbb_sessions`, `phpbb_smilies`, `phpbb_themes`, `phpbb_themes_name`, `phpbb_topics`, `phpbb_topics_watch`, `phpbb_user_group`, `phpbb_users`, `phpbb_vote_desc`, `phpbb_vote_results`, `phpbb_vote_voters`, `phpbb_words`';
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
if(!$get_items_res){
  echo "Database was not deleted<br>";
} else{
  echo "Database Deleted<br>";
}
$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));

$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/dumpit.html";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "Cleanup complete.<br>";
}

}


if($uninstall_siteframe==1){
$ck_domain_type=explode(".",$usr_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,$usr_subdomain);
  $dir_struct=$dir_st[1];
}
if($dom_type==0){
$dir_struct="/$email";
}


$public_html="public_html";
$root_dir=explode($public_html,$srcroot1);

$rt_dir="$root_dir[0]$public_html$dir_struct";
$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/trashit.html?dir=$rt_dir&file=web";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "SiteFrame Deleted.";
}
$sql_usr="_$email";
$sql_usr1="$ownername$sql_usr";
mysql_close($conn);
$conn2  = mysql_connect($dbhost, $sql_usr1, $password) or die(mysql_error( ));
mysql_select_db($sql_usr1,$conn2) or die(mysql_error( ));
$get_items = 'DROP TABLE `activity`, `categories`, `comments`, `doc_categories`, `docs`, `events`, `folders`, `group_members`, `groups`, `messages`, `notifications`, `obj_props`, `objs`, `permissions`, `poll_votes`, `properties`, `ratings`, `rss`, `schedule`, `sessions`, `subscriptions`, `templates`, `themes`, `trackback`, `triggers`, `users`';
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
if(!$get_items_res){
  echo "Database was not deleted<br>";
} else{
  echo "Database Deleted<br>";
}
$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));
$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/dumpit.html";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "Cleanup complete.<br>";
}

}

if($uninstall_guestbook==1){
$ck_domain_type=explode(".",$usr_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,$usr_subdomain);
  $dir_struct=$dir_st[1];
}
if($dom_type==0){
$dir_struct="/$email";
}


$public_html="public_html";
$root_dir=explode($public_html,$srcroot1);

$rt_dir="$root_dir[0]$public_html$dir_struct";

$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/trashit.html?dir=$rt_dir&file=guestbook";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "Guestbook Deleted.<br>";
}
$sql_usr="_$email";
$sql_usr1="$ownername$sql_usr";
mysql_close($conn);
$conn2  = mysql_connect($dbhost, $sql_usr1, $password) or die(mysql_error( ));
mysql_select_db($sql_usr1,$conn2) or die(mysql_error( ));
$get_items = 'DROP TABLE `countries`, `myphpguest`';
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
if(!$get_items_res){
  echo "Database was not deleted<br>";
} else{
  echo "Database Deleted<br>";
}
$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));

$deldir="http://$ownername:$reseller_pass@$host:2082/frontend/$cpmod/files/dumpit.html";
($fp = fopen($deldir, "r")) or die("Could not open file!");
if(!$fp){
    echo "Error:  Did not Delete Directory";
}else{
  echo "Cleanup complete.<br>";
}

}

if ($uinst_forum=="1"){
mysql_close($conn);
$sk_dir="web";

if($dom_type==0){
  $forum_path="/forum";
}else{
$forum_path="$path/forum";
}
$forum_server=$server;
include("inst_sql/forum_install.php");
$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));

   // set the various variables
   $ftproot = "/";
$srcdir="skel_1/";
$srcroot="$srcroot1$srcdir";
   // connect to the destination FTP & enter appropriate directories both locally and remotely
   $ftpc = ftp_connect($host);
   $ftpr = ftp_login($ftpc,"$email@$domain",$password);
   if ((!$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
   if (!chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
   if (!ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }


$file3 = 'forum/config.php';
include("forum_config.php");

// Let's make sure the file exists and is writable first.
if (is_writable($file3)) {
$handle = fopen($file3, "w");
   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($file3, 'a')) {
         echo "Cannot open file ($file3)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $buffer) === FALSE) {
       echo "Cannot write to file ($file3)";
       exit;
   }

   echo "Success, wrote ($buffer) to file ($file3)";

   fclose($handle);

} else {
   echo "The file $filename is not writable";
}

      // start ftp'ing over the directory recursively
   ftpRec($srcrela);
}





if ($uinst_siteframe=="1"){
mysql_close($conn);
$sk_dir="forum";
$sf_path="$siteurl/web";
include("inst_sql/sf_install.php");


$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));
   // set the various variables
   $ftproot = "/";
$srcdir="skel_2/";
$srcroot="$srcroot1$srcdir";
   // connect to the destination FTP & enter appropriate directories both locally and remotely
   $ftpc = ftp_connect($host);
   $ftpr = ftp_login($ftpc,"$email@$domain",$password);
   if ((!$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
   if (!chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
   if (!ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }
$file4 = 'web/config.php';
include("sf_config.php");

// Let's make sure the file exists and is writable first.
if (is_writable($file4)) {
$handle = fopen($file4, "w");
   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($file4, 'a')) {
         echo "Cannot open file ($file4)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $buffer) === FALSE) {
       echo "Cannot write to file ($file4)";
       exit;
   }

   echo "Success, wrote to file ($file4)<br>";

   fclose($handle);

} else {
   echo "The file $filename is not writable";
}

      // start ftp'ing over the directory recursively
   ftpRec($srcrela);
}

if ($uinst_guestbook=="1"){
mysql_close($conn);
$sk_dir="forum";
$sf_path="$siteurl/guestbook";
include("inst_sql/guestbook_install.php");


$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));
   // set the various variables
   $ftproot = "/";
$srcdir="skel_3/";
$srcroot="$srcroot1$srcdir";
   // connect to the destination FTP & enter appropriate directories both locally and remotely
   $ftpc = ftp_connect($host);
   $ftpr = ftp_login($ftpc,"$email@$domain",$password);
   if ((!$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
   if (!chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
   if (!ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }
$file4 = 'guestbook/config.php';
include("guestbook_config.php");

// Let's make sure the file exists and is writable first.
if (is_writable($file4)) {
$handle = fopen($file4, "w");
   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($file4, 'a')) {
         echo "Cannot open file ($file4)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $buffer) === FALSE) {
       echo "Cannot write to file ($file4)";
       exit;
   }

   echo "Success, wrote to file ($file4)<br>";

   fclose($handle);

} else {
   echo "The file $filename is not writable";
}

      // start ftp'ing over the directory recursively
   ftpRec($srcrela);
}



   // close the FTP connection
   ftp_close($ftpc);
}



   function ftpRec($srcrela)
{
   global $srcroot;
   global $ftproot;
   global $ftpc;
   global $ftpr;
   global $sk_dir;


   // enter the local directory to be recursed through
   chdir($srcroot.$srcrela);

   // check if the directory exists & change to it on the destination
   if (!ftp_chdir($ftpc,$ftproot.$srcrela))
   {
       // remote directory doesn't exist so create & enter it
          ftp_mkdir    ($ftpc,$ftproot.$srcrela);
          ftp_chdir    ($ftpc,$ftproot.$srcrela);
   }

   if ($handle = opendir("."))
   {
      while (false !== ($fil = readdir($handle)))
      {
          if ($fil != "." && $fil != "..")
          {
              // check if it's a file or directory
              if (!is_dir($fil))
              {
                  // it's a file so upload it
                  ftp_put($ftpc, $ftproot.$srcrela.$fil, $fil, FTP_BINARY);
               }
               else
               {
                   // it's a directory so recurse through it
                   if ($fil == $sk_dir)
                   {
                           // I want the script to ignore any directories named "templates"
                           // and therefore, not recurse through them and upload their contents
                   }
                   else
                   {
                       ftpRec($srcrela.$fil."/");
                       chdir("../");
                   }
               }
         }
     }
     closedir($handle);
   }
}



function ftp_rmAll($conn_id,$dst_dir){
    $ar_files = ftp_nlist($conn_id, $dst_dir);
    if (is_array($ar_files)){ // makes sure there are files
        for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
            $st_file = $ar_files[$i];
            if (ftp_size($conn_id, $st_file) == -1){ // check if it is a directory
                ftp_rmAll($conn_id, $st_file); // if so, use recursion
            } else {
                ftp_delete($conn_id, $st_file); // if not, delete the file
            }
        }
    }
    ftp_rmdir($conn_id, $dst_dir); // delete empty directories
}










?>