Difference between revisions of "API CLASS FILE"

From VMPanel
Jump to: navigation, search
Line 1: Line 1:
=== Step 1 === <!--T:8-->
 
  
<!--T:9-->
 
Copy the following code into your '''extensions''' directory under ''Code/Code.php'' file.
 
</translate>
 
  
<source lang="php" enclose="div">
+
''' PHP Code '''
<?php
+
if( !defined( 'MEDIAWIKI' ) ) {
+
        echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
+
        die( -1 );
+
}
+
$wgExtensionCredits['other'][] = array(
+
        'path'          => __FILE__,
+
        'name'          => 'Code',
+
        'version'        => '0.9',
+
        'author'        => 'Paul Grinberg',
+
        'url'            => 'https://www.mediawiki.org/wiki/Extension:Code',
+
        'description'    => 'Allows syntax highlighting using GeSHi'
+
);
+
  
$wgHooks['ParserFirstCallInit'][] = 'efCodeExtensionInit';
+
<?php
 +
//////////////////////////////////////////////////////////////
 +
//===========================================================
 +
// VMPanel_API.php
 +
//===========================================================
 +
// VMPanel - Cyber Group
 +
// Version : 1.0
 +
// ----------------------------------------------------------
 +
// Started by: mahdi8492
 +
// Date:      14th Sep 2016
 +
// Time:      18:00 hrs
 +
// Site:      http://www.vmpanel.ir/ (VMPanel)
 +
// ----------------------------------------------------------
 +
// Please Read the Terms of use at http://www.vmpanel.ir/
 +
// ----------------------------------------------------------
 +
//===========================================================
 +
// (c)Cyber Group.
 +
//===========================================================
 +
//////////////////////////////////////////////////////////////
 +
class VMPanel_API {
 +
var $apiusernme = '';
 +
var $apipassword = '';
 +
var $ip = '';
 +
var $port = 873;
 +
var $protocol = 'http';
 +
var $error = array();
 +
/**
 +
* Contructor
 +
*
 +
* @param        string $ip IP of the VMPanel
 +
* @param        string $apiusername The API Username of your VMPanel
 +
* @param        string $apipassword The API Password of your VMPanel
 +
* @param        int $port (Optional) The port to connect to. Port 873 is the default.(Other Ports : 2021 , 2022 , 2023 , 2082 , 2222 )
 +
* @return      NULL
 +
*/
 +
function VMPanel_API($ip, $apiusernme, $apipassword, $port = 873){
 +
$this->apiusernme = $apiusernme;
 +
$this->apipassword = $apipassword;
 +
$this->ip = $ip;
 +
$this->port = $port;
  
function efCodeExtensionInit(Parser &$parser) {
+
}
    $parser->setHook( "Code", "efCodeExtensionRenderCode" );
+
/**
    return true;
+
* Unserializes a string
}
+
*
 +
* @param        string $str The serialized string
 +
* @return      array The unserialized array on success OR false on failure
 +
*/
 +
public function _unserialize($str){
 +
$var = @unserialize($str);
 +
if(empty($var)){
 +
$str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str);
 +
 +
$var = @unserialize($str);
 +
}
 +
//If it is still empty false
 +
if(empty($var)){
 +
return false;
 +
}else{
 +
 +
return $var;
 +
}
 +
}
 +
public function cyberhttpPost($params)
 +
{
 +
$url = "http://".$this->ip.":".$this->port."/?loadapi=1&";
 +
  $postData = '';
 +
//create name value pairs seperated by &
 +
$params['api'] = true ;
 +
$params['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ;
 +
$params['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'] ;
 +
$params['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ;
 +
$params['SERVER_NAME'] = $_SERVER['SERVER_NAME'] ;
 +
$params['MODULE_VER'] = '2.7' ;
 +
foreach($params as $k => $v)
 +
{
 +
        $postData .= $k . '='.$v.'&';
 +
}
 +
$postData = rtrim($postData, '&');
 +
$ch = curl_init(); 
 +
    curl_setopt($ch,CURLOPT_URL,$url);
 +
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
 +
    curl_setopt($ch,CURLOPT_HEADER, false);
 +
    curl_setopt($ch, CURLOPT_POST, count($postData));
 +
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);   
 +
    $output=curl_exec($ch);
 +
    curl_close($ch);
 +
    return $output;
 +
}
 +
public function checklogin()
 +
    {
  
function efCodeExtensionRenderCode($input, $argv, $parser) {
+
$postfilds = array();
    global $wgShowHideDivi, $wgOut;
+
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'check' ;
  
    // default values
+
$data = $this->cyberhttpPost($postfilds);
    $language = 'text';
+
$data = $this->_unserialize($data);
    $showLineNumbers = false;
+
    $showDownloadLink = false;
+
if( $data['ok'] = true ){
     $source = $input;
+
return true ;
     $tabwidth = 4;
+
}
 +
 +
        return false ;
 +
     }
 +
 +
public function isolist()
 +
     {
 +
     
  
    foreach ($argv as $key => $value) {
+
$postfilds = array();
        switch ($key) {
+
$postfilds['user'] = $this->apiusernme ;
            case 'lang':
+
$postfilds['pass'] = $this->apipassword ;
                $language = $value;
+
$postfilds['action'] = 'isolist' ;
                break;
+
 
            case 'linenumbers':
+
$data = $this->cyberhttpPost($postfilds);
                $showLineNumbers = true;
+
$data = $this->_unserialize($data);
                break;
+
 
            case 'tabwidth':
+
        return $data ;
                $tabwidth = $value;
+
                break;
+
            case 'download':
+
                $showDownloadLink = true;
+
                break;
+
            case 'fileurl':
+
                $html = $parser->unstrip($parser->recursiveTagParse($value),$parser->mStripState);
+
                $i = preg_match('/<a.*?>(.*?)<\/a>/', $html, $matches);
+
                $url = $matches[1];
+
                //print("URL is '$url'");
+
                #$source = "file_get_contents disabled! Contact your wiki admin with questions.";
+
                $source =  file_get_contents($url);
+
                break;
+
            default :
+
                wfDebug( __METHOD__.": Requested '$key ==> $value'\n" );
+
                break;
+
        }
+
 
     }
 
     }
    if (!defined('GESHI_VERSION')) {
+
 
        include('geshi/geshi.php'); // include only once or else wiki dies
+
public function serverlist()
 +
    {
 +
     
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'serverlist' ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
$data = $this->_unserialize($data);
 +
 
 +
        return $data ;
 
     }
 
     }
    $geshi = new GeSHi($source, $language);
+
 
     $error = $geshi->error();           // die gracefully if errors found
+
 
    if ($error) {
+
public function createvps($useremail,$userpassword,$firstname,$lastname,$hostname,$server,$ram,$space,$cpumhz,$bandwidth,$vnc,$datastore,$useros,$cores='1',$nic_type='e1000',$osreinstall='0',$resouce_pools='')
         return "Code Extension Error: $error";
+
     {
 +
 
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'create' ;
 +
$postfilds['prefix'] = 'API' ; // Prefix For Create VPS
 +
 +
$data['email'] = $useremail ;
 +
$data['userpassword'] = $userpassword ;
 +
$data['firstname'] = $firstname ;
 +
$data['lastname'] = $lastname ;
 +
$data['hostname'] = $hostname ;
 +
$data['server'] = $server ;
 +
$data['ram'] = $ram ;
 +
$data['space'] = $space ;
 +
$data['cpu'] = $cpumhz ;
 +
$data['bandwidth'] = $bandwidth ;
 +
$data['os'] = '' ;
 +
$data['iso'] = '' ;
 +
if(!empty($vnc)){
 +
$data['vnc'] = 'on' ;
 +
}else{
 +
$data['vnc'] = '' ;
 +
}
 +
$data['ds'] = $datastore ;
 +
$data['useros'] = $useros ;
 +
$data['cores'] = $cores ;
 +
$data['nic_type'] = $nic_type ;
 +
$data['osreinstall'] = $osreinstall ;
 +
$data['resouce_pools'] = $resouce_pools ;
 +
 +
$postfilds['data'] = base64_encode(serialize($data)); ;
 +
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
 
 +
         return $data;
 
     }
 
     }
    $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); // always display line numbers
 
    $geshi->set_tab_width($tabwidth);
 
    $code = $geshi->parse_code();
 
    $code_pieces = preg_split('/\<ol/', $code );
 
  
     $output = '';
+
public function rebuildvps($vmid,$newos)
    $ol_tag = '<ol';
+
     {
    if (!$showLineNumbers) {
+
 
        // if not asked to show line numbers, then we should hide them. This is the preferred method
+
 
        // because this allows for a means of a block of code in the middle of a numbered list
+
$postfilds = array();
        $output .= "<style type='text/css'><!-- ol.codelinenumbers { list-style: none; margin-left: 0; padding-left: 0em;} --></style>";
+
$postfilds['user'] = $this->apiusernme ;
         $ol_tag = "<ol class='codelinenumbers'";
+
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'rebuild' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 +
$data['newos'] = $newos ;
 +
 +
$postfilds['data'] = base64_encode(serialize($data)); ;
 +
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
 
 +
         return $data;
 
     }
 
     }
    $output .= $code_pieces[0];
+
    if ($showDownloadLink) {
+
        $output .= "<a href=\"javascript:win3 = window.open('', 'code', 'width=320,height=210,scrollbars=yes');win3.document.writeln('$source');\"  style=\"float:right\">Download Code</a>\n";
+
public function getAllVmInfo()
 +
    {
 +
     
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'vpslist' ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
$data = $this->_unserialize($data);
 +
 
 +
        return $data ;
 
     }
 
     }
    $output .= $ol_tag . $code_pieces[1];
 
  
     return $output;
+
public function getSummaryInfo( $vmid )
}
+
     {
</source>
+
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'getsummary' ;
 +
$postfilds['datatype'] = 'array' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
 
 +
$data = $this->_unserialize($data);
 +
     
 +
        return $data;
 +
    }
 +
 
 +
public function getGuestInfo( $vmid )
 +
    {
 +
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'getguestinfo' ;
 +
$postfilds['datatype'] = 'array' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
 
 +
$data = $this->_unserialize($data);
 +
 +
        return $data ;
 +
    }
 +
 
 +
public function getDataStoreInfo( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['datatype'] = 'array' ;
 +
$postfilds['action'] = 'getdatastore' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
 
 +
$data = $this->_unserialize($data);
 +
 +
        return $data ;
 +
    }
 +
//// Open VNC Ports On ESXI //////
 +
public function gdbserver( $vmid )
 +
    {
 +
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'gdbserver' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
 
 +
$data = $this->_unserialize($data);
 +
 +
if($data['status'] == 'action-success' ){
 +
return true;
 +
}
 +
 
 +
      return false;
 +
 
 +
    }
 +
 
 +
public function getvncconf( $vmid )
 +
    {
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'getvncconf' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
 +
 +
  $data = $this->_unserialize($data);
 +
 +
return $data ;
 +
    }
 +
 
 +
public function getnovnc( $vmid )
 +
    {
 +
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'novnc' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
return $data ;
 +
    }
 +
 
 +
public function enablevnc( $vmid )
 +
    {
 +
 
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'setvncconf' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['enabled'] == "TRUE"){
 +
return true;
 +
}
 +
return false;
 +
  }
 +
 
 +
 
 +
public function resetvncpass( $vmid )
 +
    {
 +
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'setvncpass' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['enabled'] == "TRUE"){
 +
return true;
 +
}
 +
return false;
 +
 
 +
    }
 +
 
 +
public function poweroff( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'poweroff' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 
 +
public function poweron( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'poweron' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 
 +
public function resetvps( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'reset' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 +
public function suspend( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'suspend' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 +
public function unsuspend( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'unsuspend' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 +
public function rebootos( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'reboot' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 
 +
 +
public function shutdownos( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'shutdown' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 
 +
public function mountvmtool( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'vmtool' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 
 +
public function getstate( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'getstatus' ;
 +
$postfilds['datatype'] = 'array' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if(!empty($data)){
 +
return $data ;
 +
}
 +
 
 +
        return false;
 +
    }
 +
 +
public function getvminfo( $vmid )
 +
    {
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'importantinfo' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if(empty($data)){
 +
return true ;
 +
}
 +
$vminfoArr = array( );
 +
       
 +
        $info = array( );
 +
        $info['vmid'] = $vmid;
 +
        $info['memorySize'] = intval( $data['ram'] );
 +
        $info['memoryUsage'] = intval( $data['memoryUsage'] );
 +
        $info['cpuMax'] = intval( $data['cpu'] );
 +
$info['bootTime'] = $data['bootTime'];
 +
       
 +
        $info['os'] = $data['os'];
 +
        $info['osFullName'] = trim( $data['os_name'] );
 +
        $info['hostname'] = $data['hostname'];
 +
$info['vmPathName'] = $data['vmPathName'];
 +
        $info['ip'] = $data['ip'];
 +
 +
        $info['powerState'] = strtolower( trim( $data['powerstate'] ) );
 +
        $info['cpuUsage'] = intval( $data['cpuUsage'] );
 +
        $info['uptime'] = intval( $data['uptime'] );
 +
 
 +
        $info['hd'] = $data['disks']['size'];
 +
        $info['hardUsage'] = $data['hardUsage'];
 +
        $info['hardFree'] = round($info['hd']-$info['hardUsage']);
 +
        $info['hardNums'] = $data['hardNums'];
 +
 
 +
        return $info;
 +
    }
 +
 
 +
public function terminatevps( $vmid )
 +
    {
 +
 
 +
$postfilds = array();
 +
$postfilds['user'] = $this->apiusernme ;
 +
$postfilds['pass'] = $this->apipassword ;
 +
$postfilds['action'] = 'terminate' ;
 +
$postfilds['vmid'] = $vmid ;
 +
 
 +
$data = $this->cyberhttpPost($postfilds);
 +
  $data = $this->_unserialize($data);
 +
 +
if($data['status'] == "action-success"){
 +
return true ;
 +
}
 +
 
 +
        return $data['status'];
 +
    }
 +
 +
} // Class Ends
  
<translate>
+
?>

Revision as of 15:56, 14 September 2016


PHP Code

<?php
//////////////////////////////////////////////////////////////
//===========================================================
// VMPanel_API.php
//===========================================================
// VMPanel - Cyber Group
// Version : 1.0
// ----------------------------------------------------------
// Started by: mahdi8492
// Date:       14th Sep 2016
// Time:       18:00 hrs
// Site:       http://www.vmpanel.ir/ (VMPanel)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.vmpanel.ir/
// ----------------------------------------------------------
//===========================================================
// (c)Cyber Group.
//===========================================================
//////////////////////////////////////////////////////////////
class VMPanel_API {

var $apiusernme = ; var $apipassword = ; var $ip = ; var $port = 873; var $protocol = 'http'; var $error = array(); /** * Contructor * * @param string $ip IP of the VMPanel * @param string $apiusername The API Username of your VMPanel * @param string $apipassword The API Password of your VMPanel * @param int $port (Optional) The port to connect to. Port 873 is the default.(Other Ports : 2021 , 2022 , 2023 , 2082 , 2222 ) * @return NULL */ function VMPanel_API($ip, $apiusernme, $apipassword, $port = 873){ $this->apiusernme = $apiusernme; $this->apipassword = $apipassword; $this->ip = $ip; $this->port = $port;

} /** * Unserializes a string * * @param string $str The serialized string * @return array The unserialized array on success OR false on failure */

public function _unserialize($str){

$var = @unserialize($str); if(empty($var)){ $str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'._strlen('$2').':\"$2\";'", $str);

$var = @unserialize($str); } //If it is still empty false if(empty($var)){ return false; }else{

return $var; } }

public function cyberhttpPost($params)

{ $url = "http://".$this->ip.":".$this->port."/?loadapi=1&";

 	$postData = ;

//create name value pairs seperated by & $params['api'] = true ; $params['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ; $params['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'] ; $params['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ; $params['SERVER_NAME'] = $_SERVER['SERVER_NAME'] ; $params['MODULE_VER'] = '2.7' ; foreach($params as $k => $v) {

       $postData .= $k . '='.$v.'&'; 

} $postData = rtrim($postData, '&'); $ch = curl_init();

   curl_setopt($ch,CURLOPT_URL,$url);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
   curl_setopt($ch,CURLOPT_HEADER, false); 
   curl_setopt($ch, CURLOPT_POST, count($postData));
   curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    
   $output=curl_exec($ch);
   curl_close($ch);
   return $output;

}

public function checklogin()
   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'check' ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if( $data['ok'] = true ){ return true ; }

       return false ;
   }

public function isolist()

   {
      

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'isolist' ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

       return $data ;
   }

public function serverlist()

   {
      

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'serverlist' ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

       return $data ;
   }


public function createvps($useremail,$userpassword,$firstname,$lastname,$hostname,$server,$ram,$space,$cpumhz,$bandwidth,$vnc,$datastore,$useros,$cores='1',$nic_type='e1000',$osreinstall='0',$resouce_pools=)

   {


$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'create' ; $postfilds['prefix'] = 'API' ; // Prefix For Create VPS

$data['email'] = $useremail ; $data['userpassword'] = $userpassword ; $data['firstname'] = $firstname ; $data['lastname'] = $lastname ; $data['hostname'] = $hostname ; $data['server'] = $server ; $data['ram'] = $ram ; $data['space'] = $space ; $data['cpu'] = $cpumhz ; $data['bandwidth'] = $bandwidth ; $data['os'] =  ; $data['iso'] =  ; if(!empty($vnc)){ $data['vnc'] = 'on' ; }else{ $data['vnc'] =  ; } $data['ds'] = $datastore ; $data['useros'] = $useros ; $data['cores'] = $cores ; $data['nic_type'] = $nic_type ; $data['osreinstall'] = $osreinstall ; $data['resouce_pools'] = $resouce_pools ;

$postfilds['data'] = base64_encode(serialize($data)); ;


$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);


       return $data;
   }

public function rebuildvps($vmid,$newos)

   {


$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'rebuild' ; $postfilds['vmid'] = $vmid ;

$data['newos'] = $newos ;

$postfilds['data'] = base64_encode(serialize($data)); ;


$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);


       return $data;
   }


public function getAllVmInfo()

   {
      

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'vpslist' ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

       return $data ;
   }

public function getSummaryInfo( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'getsummary' ; $postfilds['datatype'] = 'array' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds);

$data = $this->_unserialize($data);

       return $data;
   }

public function getGuestInfo( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'getguestinfo' ; $postfilds['datatype'] = 'array' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds);

$data = $this->_unserialize($data);

       return $data ;
   }

public function getDataStoreInfo( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['datatype'] = 'array' ; $postfilds['action'] = 'getdatastore' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds);

$data = $this->_unserialize($data);

       return $data ;
   }

//// Open VNC Ports On ESXI ////// public function gdbserver( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'gdbserver' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds);

$data = $this->_unserialize($data);

if($data['status'] == 'action-success' ){ return true; }

      return false;
   }

public function getvncconf( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'getvncconf' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds);


$data = $this->_unserialize($data);

return $data ;

   }

public function getnovnc( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'novnc' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

return $data ;

   }

public function enablevnc( $vmid )

   {


$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'setvncconf' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['enabled'] == "TRUE"){ return true; } return false;

  	}


public function resetvncpass( $vmid )

   {


$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'setvncpass' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['enabled'] == "TRUE"){ return true; } return false;

   }

public function poweroff( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'poweroff' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function poweron( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'poweron' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function resetvps( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'reset' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function suspend( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'suspend' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function unsuspend( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'unsuspend' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function rebootos( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'reboot' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }


public function shutdownos( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'shutdown' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function mountvmtool( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'vmtool' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return false;
   }

public function getstate( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'getstatus' ; $postfilds['datatype'] = 'array' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if(!empty($data)){ return $data ; }

       return false;
   }

public function getvminfo( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'importantinfo' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if(empty($data)){ return true ; } $vminfoArr = array( );

       $info = array( );
       $info['vmid'] = $vmid;
       $info['memorySize'] = intval( $data['ram'] );
       $info['memoryUsage'] = intval( $data['memoryUsage'] );
       $info['cpuMax'] = intval( $data['cpu'] );

$info['bootTime'] = $data['bootTime'];

       $info['os'] = $data['os'];
       $info['osFullName'] = trim( $data['os_name'] );
       $info['hostname'] = $data['hostname'];

$info['vmPathName'] = $data['vmPathName'];

       $info['ip'] = $data['ip'];
       $info['powerState'] = strtolower( trim( $data['powerstate'] ) );
       $info['cpuUsage'] = intval( $data['cpuUsage'] );
       $info['uptime'] = intval( $data['uptime'] );
       $info['hd'] = $data['disks']['size'];
       $info['hardUsage'] = $data['hardUsage'];
       $info['hardFree'] = round($info['hd']-$info['hardUsage']);
       $info['hardNums'] = $data['hardNums'];
       return $info;
   }

public function terminatevps( $vmid )

   {

$postfilds = array(); $postfilds['user'] = $this->apiusernme ; $postfilds['pass'] = $this->apipassword ; $postfilds['action'] = 'terminate' ; $postfilds['vmid'] = $vmid ;

$data = $this->cyberhttpPost($postfilds); $data = $this->_unserialize($data);

if($data['status'] == "action-success"){ return true ; }

       return $data['status'];
   }

} // Class Ends

?>