Ejemplo n.º 1
0
function vpsnet_call($params, $action, $id, $reqtype = "", $type = "virtual_machines", $data = "", $nojsonencode = "")
{
    $creds = vpsnet_GetCredentials();
    $url = "https://api.vps.net/" . $type;
    if ($id) {
        $url .= "/" . $id;
    }
    if ($action) {
        $url .= "/" . $action;
    }
    $url .= ".api10json";
    if ($reqtype == "GET" && $data && !is_array($data)) {
        $url .= "?" . $data;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, $creds['username'] . ":" . $creds['accesshash']);
    if ($reqtype == "GET") {
        curl_setopt($ch, CURLOPT_HTTPGET, 1);
    } else {
        if ($reqtype == "DELETE") {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        } else {
            if ($reqtype == "PUT") {
                curl_setopt($ch, CURLOPT_PUT, true);
                if (!is_null($data)) {
                    if ($nojsonencode) {
                        curl_setopt($ch, CURLOPT_INFILE, $data);
                        curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
                        curl_setopt($ch, CURLOPT_HTTPHEADER, array());
                    } else {
                        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
                    }
                }
            } else {
                curl_setopt($ch, CURLOPT_POST, 1);
                if (!is_null($data)) {
                    if ($nojsonencode) {
                        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                        curl_setopt($ch, CURLOPT_HTTPHEADER, array());
                    } else {
                        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
                    }
                }
            }
        }
    }
    $rtn = array();
    $rtn['response_body'] = curl_exec($ch);
    $rtn['info'] = curl_getinfo($ch);
    $rtn['success'] = "0";
    if ($rtn['info']['content_type'] == "application/json; charset=utf-8") {
        if ($rtn['info']['http_code'] == 200) {
            $rtn['response'] = json_decode($rtn['response_body'], true);
            $rtn['success'] = "1";
        } else {
            if ($rtn['info']['http_code'] == 422) {
                $rtn['errors'] = json_decode($rtn['response_body'], true);
            } else {
                if ($rtn['info']['http_code'] == 406) {
                    $rtn['errors'] = array("Login Failed");
                } else {
                    $rtn['errors'] = json_decode($rtn['response_body'], true);
                }
            }
        }
    }
    if (curl_error($ch)) {
        $rtn['errors'] = array("Curl Error: " . curl_errno($ch) . " - " . curl_error($ch));
    }
    curl_close($ch);
    logModuleCall("vpsnet", $action, $url . " - " . json_encode($data), $rtn, $rtn['response']);
    return $rtn;
}
Ejemplo n.º 2
0
 * @ Author   : MTIMER
 * @ Release on : 2013-12-24
 * @ Website  : http://www.mtimer.cn
 *
 * */
require "../../../init.php";
require "vpsnet.php";
if (!$_SESSION['uid']) {
    exit("Access Denied");
}
$result = select_query("tblhosting", "count(*)", array("id" => $serviceid, "userid" => $_SESSION['uid']));
$data = mysql_fetch_array($result);
if (!$data[0]) {
    exit("Access Denied");
}
$creds = vpsnet_GetCredentials();
$api = VPSNET::getinstance($creds['username'], $creds['accesshash']);
$result = select_query("mod_vpsnet", "", array("relid" => $serviceid));
while ($data = mysql_fetch_array($result)) {
    ${$data['setting']} = $data['value'];
}
if (!in_array($period, array("hourly", "daily", "weekly", "monthly"))) {
    $period = "hourly";
}
$postfields = new VirtualMachine();
$postfields->id = $netid;
try {
    if ($graph == "cpu") {
        $result = $postfields->showCPUGraph($period);
    } else {
        $result = $postfields->showNetworkGraph($period);