Перенос cPanel api 1 в cPanel Api 2 / uapi - PullRequest
0 голосов
/ 01 декабря 2018

У меня есть php скрипт, модуль wm разработан с cPanel api 1, но теперь не работает, чтобы получить как использование диска / использование полосы пропускания, так и получить список 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"];
}

Access Hash не работает

    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

Большое спасибо за любую помощь:)

...