Вход Регистрация
Файл: _rootinc/vdsmanager.inc.php
Строк: 208
<?

class VDSManager
{
    public 
$protocol null;
    public 
$host null;
    public 
$folder "manager";
    public 
$user null;
    public 
$password null;
    public 
$error null;

    public function 
init($protocol,$host,$user,$password,$folder='') {
        
$this->protocol $protocol;
        
$this->host $host;
        
$this->user $user;
        
$this->password $password;
        if (
$folder) {$this->folder $folder;}
    }

    public function 
connect($query) {
        
$fp curl_init(); 
        
curl_setopt($fpCURLOPT_URL$this->protocol."://".$this->host."/".$this->folder."/".$query);
        
curl_setopt($fpCURLOPT_SSL_VERIFYPEER0);
        
curl_setopt($fpCURLOPT_SSL_VERIFYHOST0);
        
curl_setopt($fpCURLOPT_FAILONERROR0); 
        
curl_setopt($fpCURLOPT_RETURNTRANSFER,1);
        
curl_setopt($fpCURLOPT_TIMEOUT120);

        
$result curl_exec($fp);

        if (@
curl_errno($fp)) {
            
$this->error "cURL Error ".@curl_errno($fp).": ".@curl_error($fp);
            return 
false;
        }

        
curl_close($fp);  

        return 
$result;
    }

    public function 
createVDS($serverName$serverIP$rootPassword$tarif$os$ispLicense$extns$backup$owner) {
        if (!
$owner) { $owner $this->user; }

        
$package $this->getPackage($tarif);

        if (
is_array($package)) {
            while (list(
$k$v) = @each($package)) {
                if (
$k == "disktempl" and $os) { $v $os; }
                
$queryAddon .= "$k=$v&";
            }

            
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&owner=".$owner."&func=vds.edit&sok=ok&id=auto&name=$serverName&ip=$serverIP&passwd=$rootPassword&vdspreset=".urlencode($tarif)."&ispmgr=$ispLicense&extns=$extns&backup=$backup&$queryAddon");

            if(
$xmlstr=='')    {
                
$this->error='createVDS: No output.';
                return 
false;
            } else {
                
$xmlArray toarray($xmlstr,"doc",1);

                if (isset(
$xmlArray[ok][0])) {
                    return 
$xmlArray[ip][0][value];
                } else if (isset(
$xmlArray[error][0])) {
                    
$this->error "createVDS: ".$this->getError($xmlArray[error][0]);
                    return 
false;
                } else {
                    
$this->error "createVDS: unknown error";
                    return 
false;
                }
            }
        }
    }

    public function 
suspendVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.disable&elid=$elid&");

        if(
$xmlstr=='')    {
            
$this->error='suspendVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[ok][0])) {
                return 
true;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "suspendVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "suspendVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
unSuspendVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.enable&elid=$elid&");

        if(
$xmlstr=='')    {
            
$this->error='unSuspendVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[ok][0])) {
                return 
true;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "unSuspendVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "unSuspendVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
terminateVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.delete&elid=$elid&");

        if(
$xmlstr=='')    {
            
$this->error='terminateVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[ok][0])) {
                return 
true;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "terminateVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "terminateVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
restartVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.reboot&elid=$elid&");

        if(
$xmlstr=='')    {
            
$this->error='restartVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[ok][0])) {
                return 
true;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "restartVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "restartVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
reinstallVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.reinstall&elid=$elid&");

        if(
$xmlstr=='')    {
            
$this->error='reinstallVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[ok][0])) {
                return 
true;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "reinstallVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "reinstallVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
getPackages() {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vdspreset&");

        if(
$xmlstr=='') {
            
$this->error='getPackages: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[name][0][value])) {
                while (list(
$i,$v) = each($xmlArray[name])) {
                    while (list(
$ii,$vv) = each($v)) {
                        
$resArray[] = $vv;
                    }
                }

                return 
$resArray;
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "getPackages: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "getPackages: unknown error";
                return 
false;
            }
        }
    }

    public function 
getPackage($package) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vdspreset.edit&elid=".urlencode($package)."&");

        if(
$xmlstr=='') {
            
$this->error='getPackage: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[name][0][value])) {
                
$resArray[disk] = $xmlArray[disk][0][value];
                
$resArray[mem] = $xmlArray[mem][0][value];
                
$resArray[bmem] = $xmlArray[bmem][0][value];
                
$resArray[cpu] = $xmlArray[cpu][0][value];
                
$resArray[proc] = $xmlArray[proc][0][value];
                
$resArray[desc] = $xmlArray[desc][0][value];
                
$resArray[traf] = $xmlArray[traf][0][value];
                
$resArray[disktempl] = $xmlArray[disktempl][0][value];
                
$resArray[ncpu] = $xmlArray[ncpu][0][value];
                
$resArray[config] = $xmlArray[config][0][value];

                return 
$resArray;

            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "getPackage: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "getPackage: unknown error";
                return 
false;
            }
        }
    }

    public function 
getVDS($elid) {
        
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.edit&elid=$elid&");

        if(
$xmlstr=='') {
            
$this->error='getVDS: No output.';
            return 
false;
        } else {
            
$xmlArray toarray($xmlstr,"doc",1);

            if (isset(
$xmlArray[name][0][value])) {
                while (list(
$i,$v) = each($xmlArray)) {
                    
$resArray[$i] = $v[0][value];
                }
    
                return 
$resArray;
    
            } else if (isset(
$xmlArray[error][0])) {
                
$this->error "getVDS: ".$this->getError($xmlArray[error][0]);
                return 
false;
            } else {
                
$this->error "getVDS: unknown error";
                return 
false;
            }
        }
    }

    public function 
changePackage($acctUser,$newPackage) {

        
$vds $this->getVDS($acctUser);
        
$package $this->getPackage($newPackage);

        if (
is_array($package) and is_array($vds)) {
            
$vds[vdspreset] = urlencode($newPackage);

            
reset($package);
            while (list(
$i,$v) = each($package)) {
                
$vds[$i] = $v;
            }

            
reset($vds);
            while (list(
$i,$v) = each($vds)) {
                
$params $params."$i=$v&";
            }

            
$xmlstr $this->connect("vdsmgr?authinfo=".$this->user.":".$this->password."&out=xml&func=vds.edit&sok=yes&$params");

            if(
$xmlstr=='')    {
                
$this->error='changePackage: No output.';
                return 
false;
            } else {
                
$xmlArray toarray($xmlstr,"doc",1);

                if (isset(
$xmlArray[ok][0])) {
                    return 
true;
                } else if (isset(
$xmlArray[error][0])) {
                    
$this->error "changePackage: ".$this->getError($xmlArray[error][0]);
                    return 
false;
                } else {
                    
$this->error "changePackage: unknown error";
                    return 
false;
                }
            }
        }
    }    

    public function 
getError($errorArray) {
        
$error "Code: ".$errorArray[attributes][code].". ";
        if (
$errorArray[attributes][obj]) { $error $error."Object: ".$errorArray[attributes][obj].". "; }
        if (
$errorArray[attributes][val]) { $error $error."Val: ".$errorArray[attributes][val].". "; }
        if (
$errorArray[value]) { $error $error."Error: ".$errorArray[value]."."; }

        return 
$error;
    }
}
?>
Онлайн: 3
Реклама