0

这是我的 Vesta.php 我这样做是为了发送 API 请求并在内部使用它

<?php
require 'includes/Config.php';
class VestaAPI {
    private $_instance = null;
    public static function getInstance() {
        if ($_instance == null) {
            $_instance = new VestaAPI();
        }
        return $_instance;
    }
    public static function runCMD($cmd,$arg1 = "",$arg2 = "",$arg3 = "",$arg4 = "",$arg5 = "",$arg6 = "",$arg7 = "",$arg8 = "",$arg9 = "",$arg10 = ""){
    ini_set('max_execution_time', 30);
set_time_limit(30);
        // Server credentials
    $settings = Config::getInstance()->getSettings();
$vst_hostname = $settings["vestaLogin"]["Host"];
$vst_username = $settings["vestaLogin"]["Username"];
$vst_password = $settings["vestaLogin"]["Password"];
$vst_command = $cmd;


// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'cmd' => $vst_command,
    'arg1' => $arg1,
    'arg2' => $arg2
);
$postdata = http_build_query($postvars);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://' . $vst_hostname . ':81/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);   // cancel if below 1 byte/second
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 30);   // for a period of 30 seconds
 curl_setopt($post, CURLOPT_AUTOREFERER, true);
    curl_setopt($post, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($post, CURLOPT_TIMEOUT, 30 );
    curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
return curl_exec($curl);
    }
public static function arrayToXml($array, &$xml){
    foreach ($array as $key => $value) {
        if(is_array($value)){
            if(is_int($key)){
                $key = "e";
            }
            $label = $xml->addChild($key);
            arrayToXml($value, $label);
        }
        else {
            $xml->addChild($key, $value);
        }
    }
}
}

// to get your instance use

?>

但是当我尝试在此处运行此代码(暂停网站或取消暂停)时,我收到错误 500

<?php
require 'includes/Vesta.php';
if(isset($_POST["username"])){}else{die("ERROR 403");}
$output = VestaAPI::runCMD("v-suspend-user",$_POST["username"]);
if(strstr($output, "Error:")) {die($output);}else{
    die("Done!");
}
?>

但是如果我得到它有效的帐户数据我认为这一定是一个超时问题但这里是 php 错误日志

2016/02/15 00:53:55 [错误] 14102#0: *6 上游过早关闭连接,同时从上游读取响应标头,客户端:86.6.39.173,服务器:testing.DOMAIN.co.uk,请求:“POST /suspendUser.php HTTP/1.1”,上游:“ http://45.58.48.103:8080/suspendUser.php ”,主机:“testing.DOMAIN.co.uk”,引荐来源:“ http://testing.DOMAIN。 co.uk/ "

我已将我的域替换为 DOMAIN

4

1 回答 1

1

也许您从与vestacp 安装相同的服务器运行API 请求。发生这种情况是因为在暂停/取消暂停用户之后,vestacp Web 服务会重新启动。您必须设置 $arg2='no',以防止 Web 服务重新启动,并在以后重新启动它。

于 2016-04-03T14:11:00.397 回答