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

class AVDESK6
{
    public 
$url = null;
    public 
$user = null;
    public 
$password = null;
    public 
$error = null;

    public function 
init($url,$user,$password)
    {
        
$this->url=$url;
        
$this->user=$user;
        
$this->password=$password;
    }

    public function 
send($api, $request)
    {
        
$fp = curl_init(); 
        
curl_setopt($fp, CURLOPT_URL, $this->url.$api);
        
curl_setopt($fp, CURL_HTTP_VERSION_1_1, 1);
        
curl_setopt($fp, CURLOPT_USERPWD, $this->user.":".$this->password);  
        
curl_setopt($fp, CURLOPT_POST, 1);
        
curl_setopt($fp, CURLOPT_POSTFIELDS, $request);
        
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
        
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 0);
        
curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
        
curl_setopt($fp, CURLOPT_TIMEOUT, 120);

        
$result = curl_exec($fp);

        
curl_close($fp);  

        return 
$result;
    }



    public function 
createStation($id,$password,$rate,$expires,$name,$description,$email)
    {
        
$result = $this->send("api/3.0/stations/add.ds","id=$id&password=$password&rate=$rate&expires=$expires&name=$name&description=$description&email=$email");
        
$result = $this->parseResult($result);

        if (
$result["drweb-avdesk-api"][0][attributes][status] == "true") {
            
$res[url] = $result[url][0][value];
            
$res[grace_period] = $result[station][0][attributes][grace_period];

            return 
$res;
        } 
        else if (
$result["drweb-avdesk-api"][0][attributes][status] == "false") {
            
$this->error = "createStation: Code ".$result[errno][0][value].", ".$result[message][0][value];
            return 
false;
        } 
        else {
            
$this->error = "createStation: No output";
            return 
false;
        }
    }

    public function 
renewStation($id,$expires)
    {
        
$result = $this->send("api/3.0/stations/change.ds","id=$id&expires=$expires");
        
$result = $this->parseResult($result);

        if (
$result["drweb-avdesk-api"][0][attributes][status] == "true") {
            return 
true;
        } 
        else if (
$result["drweb-avdesk-api"][0][attributes][status] == "false") {
            
$this->error = "renewStation: Code ".$result[errno][0][value].", ".$result[message][0][value];
            return 
false;
        } 
        else {
            
$this->error = "renewStation: No output";
            return 
false;
        }
    }

    public function 
deleteStation($id)
    {
        
$result = $this->send("api/3.0/stations/delete.ds","id=$id");
        
$result = $this->parseResult($result);

        if (
$result["drweb-avdesk-api"][0][attributes][status] == "true") {
            return 
true;
        } 
        else if (
$result["drweb-avdesk-api"][0][attributes][status] == "false") {
            
$this->error = "deleteStation: Code ".$result[errno][0][value].", ".$result[message][0][value];
            return 
false;
        } 
        else {
            
$this->error = "deleteStation: No output";
            return 
false;
        }
    }

    public function 
getStationInfo($id)
    {
        
$result = $this->send("api/3.0/stations/info.ds","id=$id");
        
$result = $this->parseResult($result);

        if (
$result["drweb-avdesk-api"][0][attributes][status] == "true") {
            return 
$result;
        } 
        else if (
$result["drweb-avdesk-api"][0][attributes][status] == "false") {
            
$this->error = "getStationInfo: Code ".$result[errno][0][value].", ".$result[message][0][value];
            return 
false;
        } 
        else {
            
$this->error = "getStationInfo: No output";
            return 
false;
        }
    }

    public function 
getStationStats($id)
    {
        
$result = $this->send("api/3.0/stations/statistics.ds","id=$id");
        
$result = $this->parseResult($result);

        if (
$result["drweb-avdesk-api"][0][attributes][status] == "true") {
            return 
$result;
        } 
        else if (
$result["drweb-avdesk-api"][0][attributes][status] == "false") {
            
$this->error = "getStationStats: Code ".$result[errno][0][value].", ".$result[message][0][value];
            return 
false;
        } 
        else {
            
$this->error = "getStationStats: No output";
            return 
false;
        }
    }

    public function 
parseResult($input)
    {
        
$input = preg_replace("/<![CDATA[/ui","",$input);
        
$input = preg_replace("/]]>/ui","",$input);

        
$input = preg_replace("/<?xml version="1.0" encoding="utf-8"?>/ui","<xml>",$input);
        
$input .= "</xml>";

        return 
toarray($input,"xml",1);
    }
}
?>
Онлайн: 0
Реклама