Файл: _rootinc/namecheap.inc.php
Строк: 778
<?
class NAMECHEAP
{
private $timeout = 30;
private $host = null;
private $user = null;
private $password = null;
private $log = null;
private $userip = null;
public $error = null;
private $answer = null;
private $answerArray = null;
public function init($host,$user,$password,$log,$userip) {
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->log = $log;
$this->userip = $userip;
}
private function send($requestArray) {
$this->slog("n<<< Send Requestn");
$this->slog($requestArray, MODE_CLIENT);
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->host."xml.response?".http_build_query($requestArray));
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_HEADER, false);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
$this->answer = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp); $this->slog($this->error); return false;
}
$this->slog("n>>> Got Responsen");
$this->slog($this->answer, MODE_SERVER);
curl_close($fp);
if ($this->answer) {
$this->answerArray = xmlToArrayL($this->answer);
if (is_array($this->answerArray)) {
return true;
} else {
$this->error = "::: send: ".$requestArray[Command].": bad response ($this->answer)"; $this->slog($this->error); return false;
}
} else {
$this->error = "::: send: ".$requestArray[Command].": no output"; $this->slog($this->error); return false;
}
}
private function slog($str, $mode = MODE_INFO) {
if ($this->log) {
switch($mode) {
case MODE_INFO: $mode = "I"; break;
case MODE_CLIENT: $mode = "C"; break;
case MODE_SERVER: $mode = "S"; break;
}
if (is_array($str)) {
ob_start();
var_export($str);
$str = ob_get_clean();
}
if (is_string($str)) {
$str = explode("n", $str);
}
if (is_array($str)) {
foreach($str as $tmp) {
if (function_exists("posix_getpid")) { $pid = @posix_getpid(); }
else if (function_exists("getmypid")) { $pid = @getmypid(); }
$dt = date("Y-m-d H:i:s");
$tmp = sprintf("%s [%5s] %s: %sn", $dt, $pid, $mode, $tmp);
@error_log($tmp, 3, "./_rootlogs/".date("Ymd")."_namecheap.log");
}
}
}
}
public function registerDomain($DomainName, $Years, $ns1, $ns2, $ns3, $ns4, $AddFreeWhoisguard, $PromotionCode, $OrganizationName, $FirstName, $LastName, $Address1, $City, $StateProvince, $PostalCode, $Country, $Phone, $Fax, $Email)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); $IdnCode = "rus"; } else { $IdnCode = ""; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns1)) { $idna = new idna_convert(); $ns1 = $idna->encode($ns1); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns2)) { $idna = new idna_convert(); $ns2 = $idna->encode($ns2); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns3)) { $idna = new idna_convert(); $ns3 = $idna->encode($ns3); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns4)) { $idna = new idna_convert(); $ns4 = $idna->encode($ns4); }
$ns = "$ns1,$ns2"; if ($ns3) { $ns .= ",$ns3"; } if ($ns4) { $ns .= ",$ns4"; }
if ($AddFreeWhoisguard) { $AddFreeWhoisguard = "yes"; } else { $AddFreeWhoisguard = "no"; }
$_req[Command] = "namecheap.domains.create";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[DomainName] = $DomainName;
$_req[Years] = $Years;
$_req[PromotionCode] = $PromotionCode;
$_req[IdnCode] = $IdnCode;
$_req[Nameservers] = $ns;
$_req[AddFreeWhoisguard] = $AddFreeWhoisguard;
$_req[WGEnabled] = $AddFreeWhoisguard;
$_req[RegistrantOrganizationName] = $OrganizationName;
$_req[RegistrantFirstName] = $FirstName;
$_req[RegistrantLastName] = $LastName;
$_req[RegistrantAddress1] = $Address1;
$_req[RegistrantCity] = $City;
$_req[RegistrantStateProvince] = $StateProvince;
$_req[RegistrantPostalCode] = $PostalCode;
$_req[RegistrantCountry] = $Country;
$_req[RegistrantPhone] = $Phone;
$_req[RegistrantFax] = $Fax;
$_req[RegistrantEmailAddress] = $Email;
$_req[TechOrganizationName] = $OrganizationName;
$_req[TechFirstName] = $FirstName;
$_req[TechLastName] = $LastName;
$_req[TechAddress1] = $Address1;
$_req[TechCity] = $City;
$_req[TechStateProvince] = $StateProvince;
$_req[TechPostalCode] = $PostalCode;
$_req[TechCountry] = $Country;
$_req[TechPhone] = $Phone;
$_req[TechFax] = $Fax;
$_req[TechEmailAddress] = $Email;
$_req[AdminOrganizationName] = $OrganizationName;
$_req[AdminFirstName] = $FirstName;
$_req[AdminLastName] = $LastName;
$_req[AdminAddress1] = $Address1;
$_req[AdminCity] = $City;
$_req[AdminStateProvince] = $StateProvince;
$_req[AdminPostalCode] = $PostalCode;
$_req[AdminCountry] = $Country;
$_req[AdminPhone] = $Phone;
$_req[AdminFax] = $Fax;
$_req[AdminEmailAddress] = $Email;
$_req[AuxBillingOrganizationName] = $OrganizationName;
$_req[AuxBillingFirstName] = $FirstName;
$_req[AuxBillingLastName] = $LastName;
$_req[AuxBillingAddress1] = $Address1;
$_req[AuxBillingCity] = $City;
$_req[AuxBillingStateProvince] = $StateProvince;
$_req[AuxBillingPostalCode] = $PostalCode;
$_req[AuxBillingCountry] = $Country;
$_req[AuxBillingPhone] = $Phone;
$_req[AuxBillingFax] = $Fax;
$_req[AuxBillingEmailAddress] = $Email;
$_req[BillingFirstName] = $FirstName;
$_req[BillingLastName] = $LastName;
$_req[BillingAddress1] = $Address1;
$_req[BillingCity] = $City;
$_req[BillingStateProvince] = $StateProvince;
$_req[BillingPostalCode] = $PostalCode;
$_req[BillingCountry] = $Country;
$_req[BillingPhone] = $Phone;
$_req[BillingFax] = $Fax;
$_req[BillingEmailAddress] = $Email;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: registerDomain: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function transferDomain($DomainName, $Years, $EPPCode, $PromotionCode)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
$_req[Command] = "namecheap.domains.transfer.create";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[DomainName] = $DomainName;
$_req[Years] = $Years;
$_req[PromotionCode] = $PromotionCode;
$_req[EPPCode] = $EPPCode;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: transferDomain: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function renewDomain($DomainName, $Years, $PromotionCode)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
$_req[Command] = "namecheap.domains.renew";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[DomainName] = $DomainName;
$_req[Years] = $Years;
$_req[PromotionCode] = $PromotionCode;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: renewDomain: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function updateContactsDomain($DomainName, $OrganizationName, $FirstName, $LastName, $Address1, $City, $StateProvince, $PostalCode, $Country, $Phone, $Fax, $Email)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
$_req[Command] = "namecheap.domains.setContacts";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[DomainName] = $DomainName;
$_req[RegistrantOrganizationName] = $OrganizationName;
$_req[RegistrantFirstName] = $FirstName;
$_req[RegistrantLastName] = $LastName;
$_req[RegistrantAddress1] = $Address1;
$_req[RegistrantCity] = $City;
$_req[RegistrantStateProvince] = $StateProvince;
$_req[RegistrantPostalCode] = $PostalCode;
$_req[RegistrantCountry] = $Country;
$_req[RegistrantPhone] = $Phone;
$_req[RegistrantFax] = $Fax;
$_req[RegistrantEmailAddress] = $Email;
$_req[TechOrganizationName] = $OrganizationName;
$_req[TechFirstName] = $FirstName;
$_req[TechLastName] = $LastName;
$_req[TechAddress1] = $Address1;
$_req[TechCity] = $City;
$_req[TechStateProvince] = $StateProvince;
$_req[TechPostalCode] = $PostalCode;
$_req[TechCountry] = $Country;
$_req[TechPhone] = $Phone;
$_req[TechFax] = $Fax;
$_req[TechEmailAddress] = $Email;
$_req[AdminOrganizationName] = $OrganizationName;
$_req[AdminFirstName] = $FirstName;
$_req[AdminLastName] = $LastName;
$_req[AdminAddress1] = $Address1;
$_req[AdminCity] = $City;
$_req[AdminStateProvince] = $StateProvince;
$_req[AdminPostalCode] = $PostalCode;
$_req[AdminCountry] = $Country;
$_req[AdminPhone] = $Phone;
$_req[AdminFax] = $Fax;
$_req[AdminEmailAddress] = $Email;
$_req[AuxBillingOrganizationName] = $OrganizationName;
$_req[AuxBillingFirstName] = $FirstName;
$_req[AuxBillingLastName] = $LastName;
$_req[AuxBillingAddress1] = $Address1;
$_req[AuxBillingCity] = $City;
$_req[AuxBillingStateProvince] = $StateProvince;
$_req[AuxBillingPostalCode] = $PostalCode;
$_req[AuxBillingCountry] = $Country;
$_req[AuxBillingPhone] = $Phone;
$_req[AuxBillingFax] = $Fax;
$_req[AuxBillingEmailAddress] = $Email;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: updateContactsDomain: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function getNS($DomainName)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
$DomainName = @mb_split(".",$DomainName); $SLD = $DomainName[0]; unset($DomainName[0]); $TLD = @join(".",$DomainName);
$_req[Command] = "namecheap.domains.dns.getList";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[SLD] = $SLD;
$_req[TLD] = $TLD;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
$res = array();
if ($this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][0]) { $res[] = $this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][0]; }
if ($this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][1]) { $res[] = $this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][1]; }
if ($this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][2]) { $res[] = $this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][2]; }
if ($this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][3]) { $res[] = $this->answerArray[ApiResponse][CommandResponse][DomainDNSGetListResult][Nameserver][3]; }
if (count($res) > 0) {
return $res;
} else {
$this->error = "::: getNS: no DNS-servers in response";
$this->slog($this->error);
return false;
}
} else {
$this->error = "::: getNS: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function getHostIP($DomainName, $Nameserver)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$Nameserver)) { $idna = new idna_convert(); $Nameserver = $idna->encode($Nameserver); }
$DomainName = @mb_split(".",$DomainName); $SLD = $DomainName[0]; unset($DomainName[0]); $TLD = @join(".",$DomainName);
$_req[Command] = "namecheap.domains.ns.getInfo";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[SLD] = $SLD;
$_req[TLD] = $TLD;
$_req[Nameserver] = $Nameserver;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return $this->answerArray[ApiResponse][CommandResponse][DomainNSInfoResult_attr][IP];
} else {
$this->error = "::: getHostIP: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function createHost($DomainName, $Nameserver, $IP)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$Nameserver)) { $idna = new idna_convert(); $Nameserver = $idna->encode($Nameserver); }
$DomainName = @mb_split(".",$DomainName); $SLD = $DomainName[0]; unset($DomainName[0]); $TLD = @join(".",$DomainName);
$_req[Command] = "namecheap.domains.ns.create";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[SLD] = $SLD;
$_req[TLD] = $TLD;
$_req[Nameserver] = $Nameserver;
$_req[IP] = $IP;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: createHost: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function updateHostIP($DomainName, $Nameserver, $OldIP, $IP)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$Nameserver)) { $idna = new idna_convert(); $Nameserver = $idna->encode($Nameserver); }
$DomainName = @mb_split(".",$DomainName); $SLD = $DomainName[0]; unset($DomainName[0]); $TLD = @join(".",$DomainName);
$_req[Command] = "namecheap.domains.ns.update";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[SLD] = $SLD;
$_req[TLD] = $TLD;
$_req[Nameserver] = $Nameserver;
$_req[OldIP] = $OldIP;
$_req[IP] = $IP;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: updateHostIP: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
public function updateNS($DomainName, $ns1, $ns2, $ns3, $ns4, $ns1ip, $ns2ip, $ns3ip, $ns4ip)
{
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$DomainName)) { $idna = new idna_convert(); $DomainName = $idna->encode($DomainName); $IdnCode = "rus"; } else { $IdnCode = ""; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns1)) { $idna = new idna_convert(); $ns1 = $idna->encode($ns1); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns2)) { $idna = new idna_convert(); $ns2 = $idna->encode($ns2); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns3)) { $idna = new idna_convert(); $ns3 = $idna->encode($ns3); }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$ns4)) { $idna = new idna_convert(); $ns4 = $idna->encode($ns4); }
$ns = "$ns1,$ns2"; if ($ns3) { $ns .= ",$ns3"; } if ($ns4) { $ns .= ",$ns4"; }
if ($ns1 and $ns1ip) {
$oldIP = $this->getHostIP($DomainName, $ns1);
if ($oldIP and ($oldIP != $ns1ip)) { if (!$this->updateHostIP($DomainName, $ns1, $oldIP, $ns1ip)) { return false; } }
else if (!$oldIP) { if (!$this->createHost($DomainName, $ns1, $ns1ip)) { return false; } }
}
if ($ns2 and $ns2ip) {
$oldIP = $this->getHostIP($DomainName, $ns2);
if ($oldIP and ($oldIP != $ns2ip)) { if (!$this->updateHostIP($DomainName, $ns2, $oldIP, $ns2ip)) { return false; } }
else if (!$oldIP) { if (!$this->createHost($DomainName, $ns2, $ns2ip)) { return false; } }
}
if ($ns3 and $ns3ip) {
$oldIP = $this->getHostIP($DomainName, $ns3);
if ($oldIP and ($oldIP != $ns3ip)) { if (!$this->updateHostIP($DomainName, $ns3, $oldIP, $ns3ip)) { return false; } }
else if (!$oldIP) { if (!$this->createHost($DomainName, $ns3, $ns3ip)) { return false; } }
}
if ($ns4 and $ns4ip) {
$oldIP = $this->getHostIP($DomainName, $ns4);
if ($oldIP and ($oldIP != $ns4ip)) { if (!$this->updateHostIP($DomainName, $ns4, $oldIP, $ns4ip)) { return false; } }
else if (!$oldIP) { if (!$this->createHost($DomainName, $ns4, $ns4ip)) { return false; } }
}
$DomainName = @mb_split(".",$DomainName); $SLD = $DomainName[0]; unset($DomainName[0]); $TLD = @join(".",$DomainName);
$_req[Command] = "namecheap.domains.dns.setCustom";
$_req[ApiUser] = $this->user; $_req[ApiKey] = $this->password; $_req[UserName] = $this->user; $_req[ClientIp] = $this->userip;
$_req[SLD] = $SLD;
$_req[TLD] = $TLD;
$_req[Nameservers] = $ns;
if (!$this->send($_req)) { return false; }
if ($this->answerArray[ApiResponse_attr][Status] == "OK") {
return true;
} else {
$this->error = "::: updateNS: ".$this->answerArray[ApiResponse][Errors][Error_attr][Number].", ".$this->answerArray[ApiResponse][Errors][Error];
$this->slog($this->error);
return false;
}
}
}
?>