<?php

$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die ("Could not connect");

@mysql_select_db(DB_NAME, $link);

$r = mysql_query("select password from blogusers where username='$blog_user_name'",$link);

list($passw) = mysql_fetch_row($r);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://".$sitemainhost.$sitedomain.":2082/frontend/".$cpaneltheme."/ftp/doaddftp.html");
curl_setopt($ch, CURLOPT_USERPWD, "$cpanel_admin_login" . ":" . "$cpanel_admin_password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=$blog_user_name&password=$passw&homedir=/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);



$ftps = ftp_connect("ftp.YOURDOMAIN.com");
ftp_login($ftps,$blog_user_name . "@YOURDOMAIN.com",$passw);
ftp_mkdir($ftps,"$blog_user_name");
ftp_site($ftps,"chmod 0777 $blog_user_name");

// Create Files

require_once("virtualadmin.php");

$fp = fopen("$blog_user_name"."/wp-comments-post.php","w");
fwrite($fp,"<?php chdir(\"../\"); require_once(\"wp-comments-post.php\"); ?>");
fclose($fp);

$fp = fopen("$blog_user_name"."/wp-commentsrss2.php","w");
fwrite($fp,"<?php chdir(\"../\"); require_once(\"wp-commentsrss2.php\"); ?>");
fclose($fp);

$fp = fopen("$blog_user_name"."/wp-login.php","w");
fwrite($fp,"<?php chdir(\"../\"); require_once(\"wp-login.php\"); ?>");
fclose($fp);

$fp = fopen("$blog_user_name"."/wp-register.php","w");
fwrite($fp,"<?php chdir(\"../\"); require_once(\"wp-register.php\"); ?>");
fclose($fp);

$fp = fopen("$blog_user_name"."/index.php","w");
fwrite($fp,"<?php chdir(\"../\"); require_once(\"index.php\"); ?>");
fclose($fp);

// Edit permissions

ftp_site($ftps,"chmod 0755 $blog_user_name");

ftp_quit($ftps);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://".$sitemainhost.$sitedomain.":2082/frontend/".$cpaneltheme."/ftp/doaddftp.html");
curl_setopt($ch, CURLOPT_USERPWD, "$cpanel_admin_login" . ":" . "$cpanel_admin_password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=$blog_user_name&password=$passw&homedir=/$blog_user_name");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);

?>
