LeaseWeb API Implementation using PHP ~ Curl


if($_REQUEST['secretkey']!=='' && $_REQUEST['secretkey']=='SECRETKEY' && $_REQUEST['serverid']!=='' && $_REQUEST['startDate']!=='' && $_REQUEST['endDate']!=='' && $_REQUEST['datatype']!=='' )
{

//now we need to make sure that the customer can only see data to his own servers. For this I am going to extract his active servers id's
$username = "USERNAME";
$password = "PASSWORD";
$server = "127.0.0.1";
$db = "test_db";

mysql_connect($server,$username,$password)or die(mysql_error());
mysql_select_db($db);

//Using WHMCS DB table structure
$rec = mysql_query("SELECT domain FROM tblhosting WHERE userid=USERID and domainstatus='Active' and id = '".$_REQUEST['serverid']."'");

if(mysql_num_rows($rec)>0)
{
$row = mysql_fetch_array($rec);
$name = $row["domain"];


$sid = "SERVERID";


if(!empty($sid))
{
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.leaseweb.com/v1/bareMetals/".$sid."/networkUsage/".$_REQUEST['datatype']."?dateFrom=".$_REQUEST['startDate']."&dateTo=".$_REQUEST['endDate'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-lsw-auth: 253e507a-cc0d-421b-9757-77695dad7f33",
"Accept: image/png"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

$imgData = base64_encode($response);
$img = "<img src= 'data:image/jpeg;base64, $imgData' />";
print($img);

unset($sid);

}
else
{
echo "null";
}


//

}
else
{
echo "invalid";
exit();
}

}
else
{
echo "invalid";
exit();
}

Leave a Reply

Your email address will not be published. Required fields are marked *