我有一个ftp帐户创建者的API脚本。我不确定我做错了什么。那里有3个文件,一个是配置,一个是功能,另一个是带帐户创建者的APi。将所有文件放入服务器后,它不会创建帐户。有人会帮助我吗谢谢
第一个配置文件
/* 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 /”;
第二是功能
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);
}
创建帐户的第3个文件。
// 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)
?>
<head>
<title>cPanel FTP Account Creator</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>
<style>
input { border: 1px solid black; }
</style>
<form method="post" accept-charset="utf-8">
<label for="username">Username</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password</label>
<input type="password" name="password" value="" id="password">
<label for="email_address">Email Address</label>
<input type="text" name="email_address" value="" id="email_address">
<input type="hidden" name="ftp_quota" value="5" id="ftp_quota">
<input type="hidden" name="ftp_homedir" value="public_html/user_files/" id="ftp_homedir">
<input type="submit" name="submit" value="Sign Up" id="signup_submit">
</form>
</body>
</html>
答案 0 :(得分:0)
我不会详细介绍,但快速浏览一下,我看到了几个可能的问题:
1)您可以在用户名或密码中使用特殊/保留字符,因此在将其用于网址之前最好对其进行urlencode
2)有些cPanel需要会话,所以你也必须将会话ID插入到url中。
3)有些cPanel在cUrl调用中是严格的。我的意思是你应该用标题,cookie等进行“完整”的卷曲调用......否则cUrl将无效。