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

class GFX
{
    public 
$url null;
    public 
$user null;
    public 
$password null;
    public 
$registrar null;
    public 
$error null;
    public 
$cltrid null;

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

    public function 
send($script,$params) {
        if (!
$this->cltrid) { 
            
$fp curl_init();
            
curl_setopt($fpCURLOPT_URL$this->url.$script);
            
curl_setopt($fpCURLOPT_RETURNTRANSFERtrue);
            
curl_setopt($fpCURLOPT_SSL_VERIFYPEERfalse);
            
curl_setopt($fpCURLOPT_SSL_VERIFYHOSTfalse);
            
curl_setopt($fpCURLOPT_HEADER1);
            
curl_setopt($fpCURLOPT_NOBODY1);
            
curl_setopt($fpCURLOPT_FAILONERRORfalse); 
            
curl_setopt($fpCURLOPT_TIMEOUT120);

            
$headers curl_exec($fp);

            if (
curl_errno($fp)) {
                
$this->error "cURL Error ".curl_errno($fp).": ".curl_error($fp);
                
curl_close($fp);
                return 
false;
            } else {
                
curl_close($fp);
                
preg_match("/id=(d+)/",$headers,$arr);

                if (
$arr[1] > 0) {
                    
$this->cltrid $arr[1];
                } else {
                    
$this->error "send: cant get Cookie ID.";
                    return 
false;
                }
            }
        }

        if (
$this->cltrid) {
            
$params json_encode($params);

            
$fp curl_init();
            
curl_setopt($fpCURLOPT_URL$this->url.$script);
            
curl_setopt($fpCURLOPT_RETURNTRANSFERtrue);
            
curl_setopt($fpCURLOPT_POSTtrue);
            
curl_setopt($fpCURLOPT_POSTFIELDS$params);
            
curl_setopt($fpCURLOPT_SSL_VERIFYPEERfalse);
            
curl_setopt($fpCURLOPT_SSL_VERIFYHOSTfalse);
            
curl_setopt($fpCURLOPT_FAILONERRORfalse); 
            
curl_setopt($fpCURLOPT_TIMEOUT120);
            
curl_setopt($fpCURLOPT_HTTPHEADER, array(
                            
"Accept: application/json, text/javascript, */*",
                            
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
                            
"Cookie: MYLANGID=ru; id=".$this->cltrid,
                            
"Content-length: ".strlen($params)
                        ));
            
$result curl_exec($fp);

            
preg_match("/([.*])/",$result,$arr);
            
$result $arr[1];

            if (
curl_errno($fp)) {
                
$this->error "cURL Error ".curl_errno($fp).": ".curl_error($fp);
                
curl_close($fp);
                return 
false;
            } else {
                
curl_close($fp);
                
$result json_decode($result,true);

                return 
$result[0][response];
            }
        } else {
            
$this->error "send: no cltrid";
            return 
false;
        }
    }

    public function 
signin() {
        
$params = array(
                array( 
                    
'method' => 'signin',
                    
'args' => array(
                            
$this->user,
                            
$this->password
                        
),
                    
'jsonrpc2' => '1.0',
                    
'chksum' => md5('1.0'.'signin')
                )
            );

        
$result $this->send("client",$params);

        if (
$result) {
            if (
$result[code] == "2000") {
                
$this->cltrid $result[cltrid];

                return 
true;
            } else {
                
$this->error "signin error code: ".$result[code];
            }
        } else {
            return 
false;
        }
        
    }

    public function 
signout() {
        
$params = array(
                array( 
                    
'method' => 'signout',
                    
'args' => array(
                            
$this->cltrid
                        
),
                    
'jsonrpc2' => '1.0',
                    
'chksum' => md5('1.0'.'signout')
                )
            );

        
$result $this->send("client",$params);

        if (
$result) {
            if (
$result[code] == "2000") {
                return 
true;
            } else {
                
$this->error "signout error code: ".$result[code];
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
contact_add($name,$org,$street,$city,$sp,$pc,$country,$phone,$fax,$email) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            
$params = array(
                    array( 
                        
'method' => 'contact_add',
                        
'args' => array(
                                
$this->cltrid,
                                array(
                                    
'name' => $name,
                                    
'org' => $org,
                                    
'street' => $street,
                                    
'city' => $city,
                                    
'sp' => $sp,
                                    
'pc' => $pc,
                                    
'cc' => $country,
                                    
'voice' => $phone,
                                    
'fax' => $fax,
                                    
'email' => $email
                                    
)
                            ),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'contact_add')
                    )
                );
        
            
$result $this->send("contact",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    
$contactid $this->getContactId($email);

                    if (
$contactid) {
                        return 
$contactid;
                    } else {
                        return 
false;
                    }
                } else {
                    
$this->error "contact_add error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
register_domain($domain,$zone,$period,$contactId,$ns1,$ns2,$ns3,$ns4) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain $idna->encode($domain); }
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$zone)) { $idna = new idna_convert(); $zone $idna->encode($zone); }

            
$zone '.'.$zone;
            
$extid $this->getext($zone);

            if (
$extid) {
                
$ns_array = array($ns1,$ns2);
                if (
$ns3) { $ns_array[] = $ns3; }
                if (
$ns4) { $ns_array[] = $ns4; }

                if (
$this->registrar) {
                    
$contact_array = array($contactId,$this->registrar,$contactId,$contactId);
                } else {
                    
$contact_array = array($contactId,$contactId,$contactId,$contactId);
                }

                
$params = array(
                        array( 
                            
'method' => 'register_domain',
                            
'args' => array(
                                    
$this->cltrid,
                                    
$domain,
                                    
$zone,
                                    
$period,
                                    
$extid,
                                    
$contact_array,
                                    
$ns_array,
                                    
$this->cltrid
                                
),
                            
'jsonrpc2' => '1.0',
                            
'chksum' => md5('1.0'.'register_domain')
                        )
                    );

                
$result $this->send("domain",$params);

                if (
$result) {
                    if (
$result[code] == "2000") {
                        
$domainid $this->getDomainId($domain,$zone);

                        if (
$domainid) {
                            return 
$domainid;
                        } else {
                            return 
false;
                        }
                    } else {
                        
$this->error "register_domain error code: ".$result[code];
                        return 
false;
                    }
                } else {
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
renewdomain($domainId,$period) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            
$params = array(
                    array( 
                        
'method' => 'renewdomain',
                        
'args' => array(
                                
$this->cltrid,
                                
$domainId,
                                
$period
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'renewdomain')
                    )
                );

            
$result $this->send("domain",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    return 
true;
                } else {
                    
$this->error "renewdomain error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

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

            
$params = array(
                    array( 
                        
'method' => 'getall',
                        
'args' => array(
                                
$this->cltrid
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'getall')
                    )
                );
        
            
$result $this->send("domain",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    while (list(
$k,$v) = each($result[data])) {
                        if (
$v['domain_name'] == $domain and $v['domain_ext'] == $zone) {
                            
$domainid $v['domain_id'];
                        }
                    }

                    if (
$domainid) {
                        return 
$domainid;
                    } else {
                        
$this->error "getDomainId: cant find domain $domain$zone";
                        return 
false;
                    }
                } else {
                    
$this->error "getDomainId error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

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

            
$params = array(
                    array( 
                        
'method' => 'getext',
                        
'args' => array(
                                
$this->cltrid
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'getext')
                    )
                );

            
$result $this->send("domain",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    while (list(
$k,$v) = each($result[data])) {
                        if (
$v['ext_name'] == $zone) {
                            
$extid $v['ext_id'];
                            break;
                        }
                    }

                    if (
$extid) {
                        return 
$extid;
                    } else {
                        
$this->error "getext: not supported domain zone .$zone";
                        return 
false;
                    }
                } else {
                    
$this->error "getext error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
getContactId($email) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            
$params = array(
                    array( 
                        
'method' => 'getall',
                        
'args' => array(
                                
$this->cltrid
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'getall')
                    )
                );
        
            
$result $this->send("contact",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    while (list(
$k,$v) = each($result[data])) {
                        if (
$v['contact_email'] == $email) {
                            
$contactid $v['contact_id'];
                        }
                    }

                    if (
$contactid) {
                        return 
$contactid;
                    } else {
                        
$this->error "getContactdId: cant find contact for $email";
                        return 
false;
                    }
                } else {
                    
$this->error "getContactId error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
getNS($domainId) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            
$params = array(
                    array( 
                        
'method' => 'ns',
                        
'args' => array(
                                
$domainId,
                                
$this->cltrid
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'ns')
                    )
                );

            
$result $this->send("domain",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    
$ns_array $result[data]['domain_ns'];

                    if (
is_array($ns_array)) {
                        return 
$ns_array;
                    } else {
                        
$this->error "getNS: unknown error";
                        return 
false;
                    }
                } else {
                    
$this->error "getNS error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
updateNS($domainId,$ns1,$ns2,$ns3,$ns4) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns1)) { $idna = new idna_convert(); $domain $idna->encode($ns1); }
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns2)) { $idna = new idna_convert(); $domain $idna->encode($ns2); }
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns3)) { $idna = new idna_convert(); $domain $idna->encode($ns3); }
            if (
preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns4)) { $idna = new idna_convert(); $domain $idna->encode($ns4); }

            
$ns_array = array(0=>$ns1,1=>$ns2);
            if (
$ns3) { $ns_array[2] = $ns3; }
            if (
$ns4) { $ns_array[3] = $ns4; }

            
$params = array(
                    array( 
                        
'method' => 'ns_save',
                        
'args' => array(
                                
$domainId,
                                
$this->cltrid,
                                
$ns_array
                            
),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'ns_save')
                    )
                );

            
$result $this->send("domain",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    return 
true;
                } else {
                    
$this->error "updateNS error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }

    public function 
contact_save($contactid,$name,$org,$street,$city,$sp,$pc,$country,$phone,$fax,$email) {
        if (
$this->cltrid or (!$this->cltrid and $this->signin())) {
            
$params = array(
                    array( 
                        
'method' => 'contact_save',
                        
'args' => array(
                                
$contactid,
                                
$this->cltrid,
                                array(
                                    
'name' => $name,
                                    
'org' => $org,
                                    
'street' => $street,
                                    
'city' => $city,
                                    
'sp' => $sp,
                                    
'pc' => $pc,
                                    
'cc' => $country,
                                    
'voice' => $phone,
                                    
'fax' => $fax,
                                    
'email' => $email
                                
)
                            ),
                        
'jsonrpc2' => '1.0',
                        
'chksum' => md5('1.0'.'contact_save')
                    )
                );
        
            
$result $this->send("contact",$params);

            if (
$result) {
                if (
$result[code] == "2000") {
                    return 
true;
                } else {
                    
$this->error "contact_save error code: ".$result[code];
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }
    }
}
?>
Онлайн: 0
Реклама