SolusVM API PHP Script

The client API is a http based API that allows you and your clients to interact directly with a virtual server with security and ease. The client API can be disabled at any time and access is only granted with a key and hash on a per vps basis.Currently available options are:

solus_php_script

Here is the script:

<?php
/**
 *    A php script to show you information of your vps run by solusvm.
 *    by Fahad Ahammed
 */
set_time_limit(180);
$serv_array = array(
    array(//VPS-1
        'api_server' => 'https://vps1.domain.com:5656', //panel login page
        'api_key'    => 'AAAAA-BBBBB-CCCCC', //Replace by yours
        'api_hash'   => '1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a', //Replace by yours

    ),
    array(//VPS-2
        'api_server' => 'https://vps2.domain.com:5656', //panel login page
        'api_key'    => 'AAAAA-BBBBB-CCCCC', //Replace by yours
        'api_hash'   => '1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a', //Replace by yours

);

define('URL_FORMAT', '%s/api/client/command.php?key=%s&hash=%s&action=info&ipaddr=true&bw=true&mem=true&hdd=true&status=true'); //url key hash

foreach ($serv_array as $server) {
$url = sprintf(URL_FORMAT, $server['api_server'], $server['api_key'], $server[api_hash]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);

$data = curl_exec($ch);
curl_close($ch);

preg_match("/<hostname>(.*)</hostname>/", $data, $hostname);
preg_match("/<vmstat>(.*)</vmstat>/", $data, $vmstat);
preg_match("/<ipaddr>(.*)</ipaddr>/", $data, $ipaddr);
preg_match("/<hdd>(.*),(.*),(.*),(.*)</hdd>/", $data, $hdd);
preg_match("/<bw>(.*),(.*),(.*),(.*)</bw>/", $data, $bw);
preg_match("/<mem>(.*),(.*),(.*),(.*)</mem>/", $data, $mem);

$hdd[2] = format_bytes($hdd[2]);
$mem[2] = format_bytes($mem[2]);
$bw[2] = format_bytes($bw[2]);

echo "<strong>Server: </strong>$hostname[1]<br />n";
echo "<strong>Status: </strong>$vmstat[1]<br />n";
echo "<strong>IP: </strong>$ipaddr[0]<br />n";
echo "<strong>HDD used: </strong>$hdd[2], $hdd[4]%<br />n";
echo "<strong>Memory used: </strong>$mem[2], $mem[4]%<br />n";
echo "<strong>Bandwidth used: </strong>$bw[2], $bw[4]%<br />n";
echo "<hr />";
}

function format_bytes($size) {
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
return round($size, 2).$units[$i];
}

?>

 

From above image , you are seeing some button to reboot, shutdown, boot, reload. They are just html links having desired pattern of solusvm.

Links are:

Shutdown

https://vps1.domain.com:5656/api/client/command.php?key=AAAAA-BBBBB-CCCCC&hash=1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a&action=shutdown

Reboot

https://vps1.domain.com:5656/api/client/command.php?key=AAAAA-BBBBB-CCCCC&hash=1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a&action=reboot

Boot

https://vps1.domain.com:5656/api/client/command.php?key=AAAAA-BBBBB-CCCCC&hash=1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a&action=boot

Reload

https://vps1.domain.com:5656/api/client/command.php?key=AAAAA-BBBBB-CCCCC&hash=1a1a1a1a1a1a1a1a1a1aa1a1a1a1a1a1aa1a1a1a&action=reload

Just replace your api key and hash and url of solusvm.

Thank You.