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

class HOSTMASTER
{
    public 
$controller true;
    public 
$url null;
    public 
$port null;
    public 
$user null;
    public 
$password null;
    public 
$error null;
    public 
$fp null;

    public function 
startup(&$controller)
    {
        
$this->controller =& $controller;
    }

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

    public function 
connect()
    {
        
$this->fp fsockopen("ssl://".$this->url$this->port$errno$errstr30);        #live url
#        $this->fp = fsockopen("ssl://rrp.hostmaster.net.ua", 6648, $errno, $errstr, 30);    #demo url

        
if ($errno == && $this->fp == false)
        {
            
$this->error="Socket Error: Could not initialize socket.";
            return 
false;
        }
        elseif (
$this->fp == false)
        {
            
$this->error="Socket Error #" $errno ": " $errstr;
            return 
false;
        }

        
$result $this->get();

        if (
preg_match("/version/ui",$result[0])) {
            if (
$this->login()) {
                return 
true;
            }
            else { 
                return 
false
            }
        } else {
            
$this->error "Unable to get Hello message.";
            return 
false;
        }
    }

    public function 
disconnect()
    {
        
fputs($this->fp"QUITn.n");
        
fclose($this->fp);
    }

    public function 
get($size "500")
    {
        
$result fread($this->fp$size);

        if (
$result == '') {
            
$this->error "Unable to get result.";
            return 
false;
        } else {
            return 
$this->parseResult($result);
        }
    }

    public function 
parseResult($result) {
        
$result mb_split("n",$result);

        
$resArray "";
        
$nserver 0;
        while (list(
$index,$res) = each($result)) {
            
$res=trim($res);

            if (
preg_match("/^(d{3})s+(.*)$/u",$res,$arr)) {
                
$resArray["rescode"] = $arr[1];
                
$resArray["restxt"] = $arr[2];
            } else if (
preg_match("/^([^:]+):s+([^:]+)$/u",$res,$arr)) {
                
$newIndex $arr[1];
                if (
$newIndex == "nserver") {$nserver++; $newIndex $newIndex.$nserver; }
                
$newValue $arr[2];
                
$resArray[$newIndex] = $newValue;
            } else if (
$res and $res != ".") {
                
$resArray[$index] = $res;
            }
        }
        return 
$resArray;
    }

    public function 
login()
    {
        
$query "SESSION OPENnuser: ".$this->user."npassword: ".$this->password."n.n";
        if(!
fputs($this->fp$query)) {
            
$this->error='Unable to send login query.'
            return 
false
        } else {
            
$result $this->get();

            if (
$result) {
                if (
$result["rescode"] == "200") {
                    return 
true;
                } else {
                    
$this->error "Login error: ".$result["rescode"]." ".$result["restxt"];
                    
$this->disconnect();
                    return 
false;
                }
            } else {
                
$this->error "Unable to get result for login.";
                return 
false;
            }
        }
    }

    public function 
registerDomain($domain,$ns1,$ns2,$ns3,$ns4,$nichandle)
    {
        if (
$this->connect()) {
            
$nslistcode "nserver: $ns1nnserver$ns2"; if ($ns3) {$nslistcode $nslistcode."nnserver: $ns3"; } if ($ns4) {$nslistcode $nslistcode."nnserver: $ns4"; }

            
$query "ADD DOMAINndomain: ".$domain."nadmin-c: ".$nichandle."ntech-c: ".$nichandle."n".$nslistcode."n.n";
            if(!
fputs($this->fp$query)) {
                
$this->error='Unable to send registerDomain query.'
                return 
false
            } else {
                
$result $this->get();
                if (
$result) {
                    if (
$result["rescode"] == "200") {
                        
$this->disconnect();
                        return 
true;
                    } else {
                        
$this->error "registerDomain error: ".$result["rescode"]." ".$result["restxt"];
                        
$this->disconnect();
                        return 
false;
                    }
                } else {
                    
$this->error "Unable to get result for registerDomain.";
                    
$this->disconnect();
                    return 
false;
                }
            }
        } else {
            return 
false;
        }
    }

    public function 
getYear($domain)
    {
        
$query "CHECK DOMAINndomain: $domainn.n";
        if(!
fputs($this->fp$query)) {
            
$this->error='Unable to send getYear query.'
            return 
false
        } else {
            
$result $this->get(3000);
            if (
$result) {
                if (
$result["rescode"] == "211") {
                    if (
preg_match("/OK-UNTIL/ui",$result["status"])) {
                        
preg_match("/^OK-UNTILs+(d{4})d+$/iu",$result["status"],$arr);
                        return 
$arr[1];
                    } else if (
preg_match("/HOLD-SINCE/ui",$result["status"])) {
                        
preg_match("/^HOLD-SINCEs+(d{4})d+$/iu",$result["status"],$arr);
                        return 
$arr[1];
                    }
                } else {
                    
$this->error "getYear error: ".$result["rescode"]." ".$result["restxt"];
                    return 
false;
                }
            } else {
                
$this->error "Unable to get result for getYear.";
                return 
false;
            }
        }
    }


    public function 
renewDomain($domain,$period)
    {
        if (
$this->connect()) {
            
$currYear intval($this->getYear($domain));
            if (
$currYear) {
                
$untilYear $currYear $period;

                
$query "RENEWndomain: $domainnuntil$untilYearn.n";
                if(!
fputs($this->fp$query)) {
                    
$this->error='Unable to send renewDomain query.'
                    return 
false
                } else {
                    
$result $this->get();
                    if (
$result) {
                        if (
$result["rescode"] == "200") {
                            
$this->disconnect();
                            return 
true;
                        } else {
                            
$this->error "renewDomain error: ".$result["rescode"]." ".$result["restxt"];
                            
$this->disconnect();
                            return 
false;
                        }
                    } else {
                        
$this->error "Unable to get result for renewDomain.";
                        
$this->disconnect();
                        return 
false;
                    }
                }
            } else {
                
$this->error "Unable to get Year.";
                
$this->disconnect();
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
getNS($domain)
    {
        if (
$this->connect()) {
            
$query "CHECK DOMAINndomain: $domainn.n";
            if(!
fputs($this->fp$query)) {
                
$this->error='Unable to send getNS query.'
                return 
false
            } else {
                
$result $this->get("3000");
    
                if (
$result) {
                    if (
$result["rescode"] == "211") {
                        if (
$result["nserver1"]) {$resultarray[]=$result["nserver1"];}
                        if (
$result["nserver2"]) {$resultarray[]=$result["nserver2"];}
                        if (
$result["nserver3"]) {$resultarray[]=$result["nserver3"];}
                        if (
$result["nserver4"]) {$resultarray[]=$result["nserver4"];}

                        
$this->disconnect();
                        return 
$resultarray;
                    } else {
                        
$this->error "getNS error: ".$result["rescode"]." ".$result["restxt"];
                        
$this->disconnect();
                        return 
false;
                    }
                } else {
                    
$this->error "Unable to get result for getNS.";
                    
$this->disconnect();
                    return 
false;
                }
            }
        } else {
            return 
false;
        }
    }

    public function 
updateNS($domain,$ns1,$ns2,$ns3,$ns4)
    {
        if (
$this->connect()) {
            
$nslistcode "nserver: $ns1nnserver$ns2"; if ($ns3) {$nslistcode $nslistcode."nnserver: $ns3"; } if ($ns4) {$nslistcode $nslistcode."nnserver: $ns4"; }

            
$query "MODTECHndomain: $domainnnserver: -%n$nslistcoden.n";
            if(!
fputs($this->fp$query)) {
                
$this->error='Unable to send updateNS query.'
                return 
false
            } else {
                
$result $this->get();
                if (
$result) {
                    if (
$result["rescode"] == "200") {
                        
$this->disconnect();
                        return 
true;
                    } else {
                        
$this->error "updateNS error: ".$result["rescode"]." ".$result["restxt"];
                        
$this->disconnect();
                        return 
false;
                    }
                } else {
                    
$this->error "Unable to get result for updateNS.";
                    
$this->disconnect();
                    return 
false;
                }
            }
        } else {
            return 
false;
        }
    }

    public function 
createNichandle($person,$org,$address,$city,$country,$phone,$fax,$email)
    {
        if (
$this->connect()) {

            if (
$fax) {$fax "nfax: $fax";}
            
            if (
$person) { $qaddon "nperson: $person"; }
            else if (
$org) { $qaddon "norganization: $orgnorg-id: N/A"; }

            
$query "ADD PERSONnnic-hdl: AUTONIC$qaddonnaddress$addressnaddress$citynaddress$countrynphone$phone$faxne-mail: $emailnremark: SVAI.net Domain Registratorn.n";

            if(!
fputs($this->fp$query)) {
                
$this->error='Unable to send createNichandle query.'
                return 
false
            } else {
                
$result $this->get();
                if (
$result) {
                    if (
$result["rescode"] == "200") {
                        
$this->disconnect();
                        if (
$result["nic-hdl"]) {
                            return 
$result["nic-hdl"];
                        } else {
                            
$this->error "createNichandle error: can't get created nic-handle";
                            return 
false;
                        }
                    } else {
                        
$this->error "createNichandle error: ".$result["rescode"]." ".$result["restxt"];
                        
$this->disconnect();
                        return 
false;
                    }
                } else {
                    
$this->error "Unable to get result for createNichandle.";
                    
$this->disconnect();
                    return 
false;
                }
            }
        } else {
            return 
false;
        }
    }
}
?>
Онлайн: 5
Реклама