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

class DirectAdmin
{
    public 
$protocol null;
    public 
$host null;
    public 
$user=null;
    public 
$password null;
    public 
$error null;
    public 
$cookie null;
    public 
$fp=null;

    public function 
DirectAdmin($protocol,$host,$user,$password) {
        
$this->protocol=$protocol;
        
$this->host=$host;
        
$this->user=$user;
        
$this->password=$password;
        
$this->cookie="_da_".str_replace(" ","",microtime()).".cookie";

        
$this->logIn();
    }

    public function 
send($api,$query,$post) {
        global 
$full_home_path;

        if (
$post == "get") { $getAddon "?".$query; }

        
$this->fp curl_init(); 
        
curl_setopt($this->fpCURLOPT_URL$this->protocol."://".$this->host.":2222/".$api.$getAddon);
        
curl_setopt($this->fpCURL_HTTP_VERSION_1_11);
        if (
$post == "post") {
            
curl_setopt($this->fpCURLOPT_POST1);
            
curl_setopt($this->fpCURLOPT_POSTFIELDS$query);
        }
        
curl_setopt($this->fpCURLOPT_SSL_VERIFYPEER0);
        
curl_setopt($this->fpCURLOPT_SSL_VERIFYHOST0);
        
curl_setopt($this->fpCURLOPT_RETURNTRANSFER,1);
        
curl_setopt($this->fpCURLOPT_FAILONERROR0); 
        
curl_setopt($this->fpCURLOPT_COOKIEJAR$full_home_path."/_roottemp/".$this->cookie);
        
curl_setopt($this->fpCURLOPT_COOKIEFILE$full_home_path."/_roottemp/".$this->cookie);
        
curl_setopt($this->fpCURLOPT_TIMEOUT120);

        
$result curl_exec($this->fp);

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

        
curl_close($this->fp);  

        
$result=iconv("windows-1251""utf-8"$result);

        return 
$result;
    }

    public function 
logIn() {
        
$result $this->send("CMD_LOGIN","referer=/&username=$this->user&password=$this->password","post");

        if (
$this->checkLogin()) {
            return 
true
        } else {
            return 
false;
        }
    }

    public function 
checkLogin() {
        
$result $this->send("CMD_API_LOGIN_TEST","","post");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) { 
                return 
true
            } else { 
                
$this->error "logIn: Authentication error";
                return 
false
            }
        } else {
            return 
false;
        }
    }

    public function 
logOut() {
        global 
$full_home_path;

        
$result $this->send("CMD_LOGOUT","","get");

        @
unlink($full_home_path."/_roottemp/".$this->cookie);
    }

    public function 
createAccount($login$email$pwd$domain$tarif$userip) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        
$result $this->send("CMD_API_ACCOUNT_USER","action=create&add=Submit&username=$login&email=$email&passwd=$pwd&passwd2=$pwd&domain=$domain&package=$tarif&ip=$userip&notify=no","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "createAccount: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
createResellerAccount($login$email$pwd$domain$tarif) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        
$result $this->send("CMD_API_ACCOUNT_RESELLER","action=create&add=Submit&username=$login&email=$email&passwd=$pwd&passwd2=$pwd&domain=$domain&package=$tarif&ip=shared&notify=no","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "createResellerAccount: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
get_user_info($name) {
        
$result $this->send("CMD_API_SHOW_USER_CONFIG","user=$name","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
$result;
            } else {
                
$this->error "get_user_info: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
is_suspended_user($name) {
        
$info=$this->get_user_info($name);
        return (
$info['suspended']=='no')?false:true;
    }

    public function 
is_active_user($name) {
        return !
$this->is_suspended_user($name);
    }

    public function 
suspend_user($name) {
#        if($this->is_suspended_user($name)) return false;

        
$result $this->send("CMD_API_SELECT_USERS","select0=$name&dosuspend=1","post");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "suspend_user: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
activate_user($name) {
#        if($this->is_active_user($name)) return false;

        
$result $this->send("CMD_API_SELECT_USERS","select0=$name&dounsuspend=1","post");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "activate_user: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
set_language($name,$lng) {
        
$result $this->send("CMD_API_MODIFY_USER","action=single&user=$name&lvalue=$lng&language=1","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "set_language: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
set_package_user($name,$package) {
        
$result $this->send("CMD_API_MODIFY_USER","action=package&user=$name&package=$package","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "set_package_user: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
set_package_reseller($name,$package) {
        
$result $this->send("CMD_API_MODIFY_RESELLER","action=customize&user=$name&package=$package","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "set_package_reseller: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
add_domain_pointer($mainDomain,$domain) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$mainDomain)) {
            
$idna = new idna_convert();
            
$mainDomain $idna->encode($mainDomain);
        }

        
$result $this->send("CMD_API_DOMAIN_POINTER","domain=$mainDomain&action=add&from=$domain&alias=yes","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error] or ($result[text] == "Unable to add domain pointer" and $result[details] == "You cannot use that domain as a pointer. It already exists on the server")) {
                return 
true;
            } else {
                
$this->error "add_domain_pointer: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
delete_domain_pointer($mainDomain,$domain) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$mainDomain)) {
            
$idna = new idna_convert();
            
$mainDomain $idna->encode($mainDomain);
        }

        
$result $this->send("CMD_API_DOMAIN_POINTER","domain=$mainDomain&action=delete&select0=$domain","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "delete_domain_pointer: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
set_password($name,$pwd) {
        
$result $this->send("CMD_API_USER_PASSWD","username=$name&passwd=$pwd&passwd2=$pwd","post");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "set_password: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
get_users() {
        
$result $this->send("CMD_API_SHOW_USERS","","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
$result['list'];
            } else {
                
$this->error "get_users: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
get_packages() {
        
$result $this->send("CMD_API_PACKAGES_USER","","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
$result['list'];
            } else {
                
$this->error "get_packages: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
get_packages_reseller() {
        
$result $this->send("CMD_API_PACKAGES_RESELLER","","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
$result['list'];
            } else {
                
$this->error "get_packages_reseller: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
delete_user($name) {
        
$result $this->send("CMD_API_SELECT_USERS","select0=$name&delete=yes&confirmed=Confirm","post");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "delete_user: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }


    public function 
getDNS($domain,$ptr) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        
$result $this->send("CMD_API_DNS_CONTROL","domain=$domain&ptr=$ptr&urlencoded=yes","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$resultArray $this->parseDNSresult($result);

            if (
count($resultArray) > 0) {
                return 
$resultArray;
            } else {
                
$result $this->parseAPIresult($result);
                
$this->error "getDNS: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
deleteDNS($domain,$ptr,$key,$key2) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        
$result $this->send("CMD_API_DNS_CONTROL","domain=$domain&ptr=$ptr&action=select&$key=$key2","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "deleteDNS: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
createDNS($domain,$ptr,$name,$type,$addr,$prio) {
        if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) {
            
$idna = new idna_convert();
            
$domain $idna->encode($domain);
        }

        if (
$type == "MX") { $name $addr$addr $prio; }
        if (
$type == "NS") { $oldName=$name$name $addr$addr $oldName; }

        
$result $this->send("CMD_API_DNS_CONTROL","domain=$domain&ptr=$ptr&action=add&type=$type&name=$name&value=$addr","get");

        if (
preg_match("/DirectAdmin Login Page/ui",$result)) {
            
$this->error "Authentication error";
            return 
false;
        }

        if (
$result) {
            
$result $this->parseAPIresult($result);

            if (!
$result[error]) {
                return 
true;
            } else {
                
$this->error "createDNS: ".$result[error]." ".$result[details];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
parseDNSresult($results) {
        
$results = @mb_split("n",$results);

        
$cnt=0;
        while (list(
$k,$line) = @each($results)) {
            if (
$line) {
                
preg_match("/^(w+)=/i",$line,$res);
                if (
$res[1]) {
                    
$type $res[1];
                    
$line preg_replace("/^$type=/i","",$line);
                    
$elements = @mb_split("&",$line);
                    
$typeCnt 0;
                    while (list(
$kk,$element) = @each($elements)) {
                        
$element=@mb_split("=",$element);

                        if (
$element[0] and $element[1]) {
                            
$resArray[$cnt][type] = $type;

                            
$resArray[$cnt][key] = mb_strtolower($type)."recs".$typeCnt;
                            
$resArray[$cnt][key2] = urlencode("name=".urldecode($element[0])."&value=".urldecode($element[1]));

                            if (
$type == "NS") {
                                
$resArray[$cnt][key2] = urlencode("name=".urldecode($element[1])."&value=".urldecode($element[0]));
                                
$resArray[$cnt][name] = urldecode($element[1]);
                                
$resArray[$cnt][addr] = urldecode($element[0]);
                            } else if (
$type == "MX") {
                                
$resArray[$cnt][prio] = urldecode($element[1]);
                                
$resArray[$cnt][addr] = urldecode($element[0]);
                            } else {
                                
$resArray[$cnt][name] = urldecode($element[0]);
                                
$resArray[$cnt][addr] = urldecode($element[1]);
                            }

                            
$cnt++;
                            
$typeCnt++;
                        }
                    }
                }
            }
        }
        return 
$resArray;
    }

    public function 
parseAPIresult($results) {
        if (!
preg_match("/<html>/iu",$results)) {
            
$results mb_split("&",$results);
            
$result_array = array();
            while (list(
$i,$result) = @each($results)) {
                
$result mb_split("=",$result);
                
$param $result[0];
                
$value $result[1];

                if (
preg_match("/[]$/u",$param)) {
                    
$param preg_replace("/[]$/u","",$param);
                    
$result_array[$param][] = $value;
                } else {
                    
$result_array[$param] = $value;
                }
            }
            return 
$result_array;
        }
    }
}
?>
Онлайн: 1
Реклама