0

我有一个用于 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);

    } 

与帐户创建的第三个文件。

// 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>  
4

1 回答 1

0

我不会详细介绍,但快速浏览一下,我会发现几个可能的问题:

1) 您可能会在用户名或密码中使用特殊/保留字符,因此最好在将其用于 url 之前对其进行 urlencode

2) 一些 cPanel 需要会话,因此您还必须将会话 ID 插入 url。

3) 一些 cPanel 对 cUrl 调用很严格。我的意思是你应该有一个带有标题、cookie 等的“完整”curl 调用......否则 cUrl 将不起作用。

于 2013-07-17T06:08:23.453 回答