我有使用cPanel api 1开发的php脚本whm模块,但现在无法像磁盘使用/带宽使用一样获得列表cPanel。
info("Diskspace and Bandwidth usage of master resellers");
sort($masters);
echo "\r\n <table class=\"table table-bordered table-hover table-stripped\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\" width=\"100%\">\r\n <thead>\r\n <tr>\r\n <th class=\"xtbl_label\">Domain Name</th>\r\n <th class=\"xtbl_label\">Username</th>\r\n <th class=\"xtbl_label\">Diskspace</th>\r\n <th class=\"xtbl_label\">Bandwidth</th>\r\n </tr></thead>\r\n <tbody>";
foreach( $masters as $master )
{
$filename = "mr/" . $master;
$output = connect("/xml-api/accountsummary?user=" . $master);
$domain = $output["accountsummary"]["acct"]["domain"];
$ini = new iniParser($filename);
$resellers = $ini->get("Resellers", "usernames");
$allowed_diskspace = $ini->get("Master", "diskspace");
$allowed_bandwidth = $ini->get("Master", "bandwidth");
$resellers = explode(" ", $resellers);
foreach( $resellers as $username )
{
$output = connect("/xml-api/resellerstats?reseller=" . $username);
$disk = $output["resellerstats"]["result"]["diskused"];
$band = $output["resellerstats"]["result"]["totalbwused"];
if( is_numeric($disk) )
{
$total_disk = $total_disk + $disk;
}
if( is_numeric($band) )
{
$total_bw = $total_bw + $band;
}
}
if( $allowed_diskspace < $total_disk )
{
if( is_numeric($allowed_diskspace) )
{
$total_disk = "<font color=red><b>" . $total_disk . "</b></font>";
}
}
if( $allowed_bandwidth < $total_bw )
{
if( is_numeric($allowed_bandwidth) )
{
$total_bw = "<font color=red><b>" . $total_bw . "</b></font>";
}
}
获取服务器负载不起作用
function GetServerLoad()
{
$data = connect("/xml-api/loadavg");
echo $data["loadavg"]["one"] . " - " . $data["loadavg"]["five"] . " - " . $data["loadavg"]["fifteen"];
}
访问哈希不起作用
function connect($request, $hash = "")
{
if( !is_file("/root/.accesshash") )
{
exec("/usr/local/cpanel/whostmgr/bin/whostmgr setrhash");
}
$hash = file_get_contents("/root/.accesshash");
$hash = preg_replace("/(\n|\r|\\s)/", "", $hash);
if( !$hash )
{
$hash = @file_get_contents("/var/cpanel/key");
}
if( function_exists("curl_setopt") )
{
$result = connect_curl($request, $hash);
}
else
{
$result = connect_fsock($request, $hash);
}
return $result;
}
function connect_curl($request, $hash)
{
if( !$hash )
{
if( !is_file("/root/.accesshash") )
{
system("/usr/local/cpanel/whostmgr/bin/whostmgr setrhash");
}
}
$hash = file_get_contents("/root/.accesshash");
$hash = preg_replace("/(\n|\r|\\s)/", "", $hash);
if( !$hash )
{
$hash = @file_get_contents("/var/cpanel/key");
}
$result = connect_curl_whm($request, $hash);
if( $result["cpanelresult"]["data"]["reason"] == "Access denied" )
{
echo "Please setup your <a href=changehash.php> Remote Access Key</a>";
}
return $result;
}
function connect_curl_whm($request, $hash)
{
$serverip = "localhost";
$cleanaccesshash = preg_replace("'(\r|\n)'", "", $hash);
$authstr = "root:" . $cleanaccesshash;
$cpanelaccterr = "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, "https://" . $serverip . ":2087" . $request);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlheaders[0] = "Authorization: WHM " . $authstr;
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlheaders);
$data = curl_exec($ch);
curl_close($ch);
$data = xml2array($data);
return $data;
}
function connect_fsock($request, $hash)
{
$result = connect_fsock_whm($request, $hash);
if( $result["cpanelresult"]["data"]["reason"] == "Access denied" )
{
echo "Please setup your <a href=changehash.php> Remote Access Key</a>";
}
return $result;
}
由于我的开发人员插件未处于活动状态,因此我在这里需要帮助,要将此功能更改为cPanel api 2或UAPI
非常感谢您的帮助:)