HI every one,
I have a API script for ftp Account creator. I’m not sure what am i doing wrong. There are 3 file there , one is config, one is function and the other is APi with account creator. after putting all file in the server it doesnt create the account. would anybody will help me out . Thank You
First config file:
[PHP] /* cPanel Options */
$cpanel_user = " cpanel username";
$cpanel_pass = “Cpanel password”;
$cpanel_domain = ‘127.0.0.1’; // if this doesn’t work, you might not want to use it.
$cpanel_skin = ‘x3’;
$cpanel_default_ftp_quota = 5; // MB
$url = “http://$cpanel_user:$cpanel_pass@$cpanel_domain:2082/frontend/$cpanel_skin/”;
[/PHP]
2nd is Function
[PHP] function cPanel($action,$function,$args) {
global $MESSAGES, $url;
$url .= "$function?";
$url_args = array();
foreach($args as $key => $value) {
$url_args[] = "$key=$value";
}
$url .= implode("&",$url_args);
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($ch);
curl_close($ch);
if ($result === FALSE) {
$status = 'error';
$message = $result;
} else {
$status='success';
$message=$MESSAGES[$action];
}
return array($status, $message);
}[/PHP]
3rd file with account creation.
[PHP] // the options mentioned in part one are set here
include_once ‘config.php’;
$url = “http://$cpanel_user:$cpanel_pass@$cpanel_domain”;
$url .= “:2082/frontend/$cpanel_skin/”;
if(isset($_REQUEST['format'])) {
$format=$_REQUEST['format'];
} else {
$format='html';
}
// other stuff (including the emailUser function you'll see called below)
function addUser($user,$pass,$email_address) {
// we need to add the user to our database
// for other purposes
}
function createAccount(
$ftp_user, $ftp_pass, $email_address, $ftp_homedir, $ftp_quota) {
global $base_dir, $source_dir;
$error=addUser($ftp_user, $ftp_pass, $email_address);
if (!$error) {
$ftp_homedir .= $ftp_user;
$copy_dir = $base_dir . $ftp_user;
$cpanel_results = cPanel('signup','ftp/doaddftp.html',
array('login'=>$ftp_user,'password'=>$ftp_pass,
'quota'=>$ftp_quota,'homedir'=>$ftp_homedir)
);
$error = $cpanel_results[0];
if ($error!='error') {
recursive_copy($source_dir,$copy_dir);
}
if($error!='error') {
return emailUser($email_address,'signup','');
} else {
return $cpanel_results;
}
} else {
return array('error', $error);
}
}
$message = Null;
if(isset($_REQUEST['submit']) ) {
switch ($_REQUEST['submit']) {
case $signup_button:
$args = createAccount(
$_REQUEST['username'],$_REQUEST['password'],
$_REQUEST['email_address'],$_REQUEST['ftp_homedir'],
$_REQUEST['ftp_quota']);
break;
// other cases snipped
default:
$args = array(Null,Null);
}
$message_class = $args[0];
$message = $args[1];
}
if ($message) {
if ($format!='html') {
die($message);
} else {
$message="<div id=\"message\" class=\"$message_class\">$message</div>";
}
}
// generate html form here
// $message is included and styled to display
// above the form in red (error) or green (success)
?>
cPanel FTP Account Creator input { border: 1px solid black; } Username Password Email Address [/PHP]