Файл: _rootinc/niclv.inc.php
Строк: 1074
<?
class NICLV
{
public $url = null;
public $port = null;
public $user = null;
public $password = null;
public $error = null;
public $fp = null;
public $isConnected = false;
public function init($url,$port,$user,$password)
{
$this->user = $user;
$this->url = $url;
$this->port = $port;
$this->password = $password;
}
public function connect()
{
$socket = fsockopen("ssl://".$this->url, $this->port, $errno, $errstr, 10);
if (!$socket) {
$this->error = "connect: Error connecting to $this->url: $errstr (code $errno)";
return false;
} else {
$this->fp=$socket;
}
$result = $this->get();
if ($result[svID][0][value]) {
if ($this->login()) {
$this->isConnected = true;
return true;
}
else {
return false;
}
} else if (!$this->error) {
$this->error = "connect: Unable to get Hello message.";
return false;
} else {
$this->error = "connect: ".$this->error;
return false;
}
}
public function disconnect()
{
if ($this->isConnected) {
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<logout/>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
$this->send($xml);
$this->isConnected = false;
}
@fclose($this->fp);
}
public function get($print = 1)
{
if (@feof($this->fp)) {
$this->error = "get: Connection appears to have closed.";
return false;
}
$hdr = fread($this->fp, 4);
if (empty($hdr)) {
$this->error = "get: Error reading from server: $php_errormsg";
return false;
} else {
$unpacked = unpack('N', $hdr);
$answer = @fread($this->fp, ($unpacked[1] - 4));
if ($print) { print "nn".$answer."nn"; }
$res = toarray($answer,"epp",1);
if ($print) { print_r($res); }
return $res;
}
}
public function send($xml,$print = 1)
{
if ($print) { print "nn".$xml."nn"; }
return fwrite($this->fp, pack('N', (strlen($xml)+4)).$xml);
}
public function login()
{
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<login>
<clID>".$this->user."</clID>
<pw>".$this->password."</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
<svcExtension>
<extURI>http://www.nic.lv/epp/schema/lvdomain-ext-1.0</extURI>
<extURI>http://www.nic.lv/epp/schema/lvcontact-ext-1.0</extURI>
</svcExtension>
</svcs>
</login>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='login: Unable to send query.';
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[result][0][attributes][code] == "1000") {
return true;
} else {
$this->error = "login: Code ".$result[result][0][attributes][code].", ".$result[msg][0][value];
return false;
}
} else if (!$this->error) {
$this->error = "login: Unable to get result.";
return false;
} else {
$this->error = "login: ".$this->error;
return false;
}
}
}
public function createContact($name,$org,$street,$city,$oblast,$post,$country,$phone,$fax,$email,$pw)
{
if ($this->isConnected or $this->connect()) {
$contactid = generatePassword(15,0,0);
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd">
<contact:id>$contactid</contact:id>
<contact:postalInfo type="loc">
<contact:name>$name</contact:name>
<contact:addr>
<contact:street>$street</contact:street>
<contact:city>$city</contact:city>
<contact:sp>$oblast</contact:sp>
<contact:pc>$post</contact:pc>
<contact:cc>$country</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice x=''>$phone</contact:voice>
<contact:fax x=''>$fax</contact:fax>
<contact:email>$email</contact:email>
<contact:authInfo>
<contact:pw>$pw</contact:pw>
</contact:authInfo>
</contact:create>
</create>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='createContact: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[result][0][attributes][code] == "1000" and $result["contact:id"][0][value]) {
return $result["contact:id"][0][value];
} else {
$this->error = "createContact: Code ".$result[result][0][attributes][code].", ".$result[msg][0][value];
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "createContact: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "createContact: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function registerDomain($domain,$period,$ns1,$ns2,$ns3,$ns4,$ns1ip,$ns2ip,$ns3ip,$ns4ip,$contactId,$pw)
{
if ($this->isConnected or $this->connect()) {
if ($ns1) { $nscode .= "<domain:hostAttr>n<domain:hostName>$ns1</domain:hostName>n"; if ($ns1ip) { $nscode .= "<domain:hostAddr ip="v4">$ns1ip</domain:hostAddr>n"; } $nscode .= "</domain:hostAttr>n"; }
if ($ns2) { $nscode .= "<domain:hostAttr>n<domain:hostName>$ns2</domain:hostName>n"; if ($ns2ip) { $nscode .= "<domain:hostAddr ip="v4">$ns2ip</domain:hostAddr>n"; } $nscode .= "</domain:hostAttr>n"; }
if ($ns3) { $nscode .= "<domain:hostAttr>n<domain:hostName>$ns3</domain:hostName>n"; if ($ns3ip) { $nscode .= "<domain:hostAddr ip="v4">$ns3ip</domain:hostAddr>n"; } $nscode .= "</domain:hostAttr>n"; }
if ($ns4) { $nscode .= "<domain:hostAttr>n<domain:hostName>$ns4</domain:hostName>n"; if ($ns4ip) { $nscode .= "<domain:hostAddr ip="v4">$ns4ip</domain:hostAddr>n"; } $nscode .= "</domain:hostAttr>n"; }
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>$domain</domain:name>
<domain:period unit="y">".$period."</domain:period>
<domain:ns>
$nscode
</domain:ns>
<domain:registrant>$contactId</domain:registrant>
<domain:contact type="admin">$contactId</domain:contact>
<domain:contact type="tech">__DEFAULT__</domain:contact>
<domain:contact type="billing">__DEFAULT__</domain:contact>
<domain:authInfo>
<domain:pw>$pw</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='registerDomain: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[result][0][attributes][code] == "1000" or $result[result][0][attributes][code] == "1001") {
$this->disconnect();
return true;
} else {
$this->error = "registerDomain: Code ".$result[result][0][attributes][code].", ".$result[msg][0][value];
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "registerDomain: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "registerDomain: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function transferDomain($domain,$period,$contactId,$authinfo)
{
if ($this->isConnected or $this->connect()) {
if ($period) {
$periodTxt = "n<domain:period unit="y">".$period."</domain:period>";
}
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<transfer op="request">
<domain:transfer xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>$domain</domain:name>$periodTxt
<domain:authInfo>
<domain:pw>$authinfo</domain:pw>
</domain:authInfo>
</domain:transfer>
</transfer>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='transferDomain: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[result][0][attributes][code] == "1000" or $result[result][0][attributes][code] == "1001") {
$this->disconnect();
return true;
} else {
$this->error = "transferDomain: Code ".$result[result][0][attributes][code].", ".$result[msg][0][value];
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "transferDomain: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "transferDomain: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function renewDomain($domain,$period,$expdate)
{
if ($this->isConnected or $this->connect()) {
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<renew>
<domain:renew xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>$domain</domain:name>
<domain:curExpDate>$expdate</domain:curExpDate>
<domain:period unit="y">$period</domain:period>
</domain:renew>
</renew>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='renewDomain: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[epp][0][response][0][result][0][msg] == "Command completed successfully") {
$this->disconnect();
return true;
} else {
$this->error = "renewDomain: ".$result[epp][0][response][0][result][0][msg]." (".$result[epp][0][response][0][result][0][value][0]["oxrs:xcp"].")";
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "renewDomain: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "renewDomain: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function getNS($domain)
{
$d = new domain($domain);
$result = $d->info();
if (!$d->last_error) {
$result1 = mb_split("n", $result);
$nsFlag = 0;
while (list($index,$res) = each($result1)) {
if (!$nsFlag and (preg_match("/Current Nameservers:/ui",$res) or preg_match("/Name Servers:/ui",$res))) {
$nsFlag = 1;
} else if ($nsFlag) {
if (preg_match("/[a-zа-яёЁїЇіІєЄ0-9-]+.[a-zа-яёЁїЇіІєЄ0-9-]+/ui",$res)) {
$res = preg_replace("/ d+.d+.d+.d+/iu","",$res);
$res = trim($res);
$res = preg_replace("/.+$/ui","",$res);
$res = trim($res);
if ($res) {
$resultarray[] = $res;
}
} else if ($res) {
break;
}
}
}
return $resultarray;
} else {
$this->error = "getNS: $d->last_error";;
return false;
}
}
public function updateNS($domain,$ns1,$ns2,$ns3,$ns4,$oldns1,$oldns2,$oldns3,$oldns4)
{
$nscode = ""; $nscoderem = ""; $notRemedNS = array();
####################################################################################################################
if ($oldns1) { if ($oldns1 != $ns1 and $oldns1 != $ns2 and $oldns1 != $ns3 and $oldns1 != $ns4) { $nscoderem = $nscoderem."n<domain:hostObj>".$oldns1."</domain:hostObj>"; } else { $notRemedNS[] = $oldns1; } }
if ($oldns2) { if ($oldns2 != $ns1 and $oldns2 != $ns2 and $oldns2 != $ns3 and $oldns2 != $ns4) { $nscoderem = $nscoderem."n<domain:hostObj>".$oldns2."</domain:hostObj>"; } else { $notRemedNS[] = $oldns2; } }
if ($oldns3) { if ($oldns3 != $ns1 and $oldns3 != $ns2 and $oldns3 != $ns3 and $oldns3 != $ns4) { $nscoderem = $nscoderem."n<domain:hostObj>".$oldns3."</domain:hostObj>"; } else { $notRemedNS[] = $oldns3; } }
if ($oldns4) { if ($oldns4 != $ns1 and $oldns4 != $ns2 and $oldns4 != $ns3 and $oldns4 != $ns4) { $nscoderem = $nscoderem."n<domain:hostObj>".$oldns4."</domain:hostObj>"; } else { $notRemedNS[] = $oldns4; } }
if ($nscoderem) { $nscoderem = "<domain:rem>n<domain:ns>".$nscoderem."n</domain:ns>n</domain:rem>"; }
####################################################################################################################
if ($ns1 and !@in_array($ns1,$notRemedNS)) { $nscode = $nscode."n<domain:hostObj>$ns1</domain:hostObj>"; }
if ($ns2 and !@in_array($ns2,$notRemedNS)) { $nscode = $nscode."n<domain:hostObj>$ns2</domain:hostObj>"; }
if ($ns3 and !@in_array($ns3,$notRemedNS)) { $nscode = $nscode."n<domain:hostObj>$ns3</domain:hostObj>"; }
if ($ns4 and !@in_array($ns4,$notRemedNS)) { $nscode = $nscode."n<domain:hostObj>$ns4</domain:hostObj>"; }
if ($nscode) { $nscode = "<domain:add>n<domain:ns>".$nscode."n</domain:ns>n</domain:add>"; }
####################################################################################################################
if ($this->isConnected or $this->connect()) {
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<update>
<domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>$domain</domain:name>
$nscode
$nscoderem
</domain:update>
</update>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='updateNS: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if (preg_match("/Command completed successfully/ui", $result[epp][0][response][0][result][0][msg])) {
$this->disconnect();
return true;
} else {
$this->error = "updateNS: ".$result[epp][0][response][0][result][0][msg]." (".$result[epp][0][response][0][result][0][value][0]["oxrs:xcp"].")";
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "updateNS: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "updateNS: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function createNS($ns,$ip)
{
if ($this->isConnected or $this->connect()) {
$xml = "<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<create>
<host:create xmlns:host="urn:ietf:params:xml:ns:host-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:host-1.0 host-1.0.xsd">
<host:name>$ns</host:name>
<host:addr ip="v4">$ip</host:addr>
</host:create>
</create>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='createNS: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if (preg_match("/Command completed successfully/ui", $result[epp][0][response][0][result][0][msg])) {
$this->disconnect();
return true;
} else {
$this->error = "createNS: ".$result[epp][0][response][0][result][0][msg]." (".$result[epp][0][response][0][result][0][value][0]["oxrs:xcp"].")";
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "createNS: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "createNS: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function deleteNS($ns,$ip)
{
if ($this->isConnected or $this->connect()) {
$xml = "<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<delete>
<host:delete xmlns:host="urn:ietf:params:xml:ns:host-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:host-1.0 host-1.0.xsd">
<host:name>$ns</host:name>
<host:addr ip="v4">$ip</host:addr>
</host:delete>
</delete>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='deleteNS: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if (preg_match("/Command completed successfully/ui", $result[epp][0][response][0][result][0][msg])) {
$this->disconnect();
return true;
} else {
$this->error = "deleteNS: ".$result[epp][0][response][0][result][0][msg]." (".$result[epp][0][response][0][result][0][value][0]["oxrs:xcp"].")";
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "deleteNS: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "deleteNS: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
public function updateContact($contactId,$name,$org,$street,$city,$oblast,$post,$country,$phone,$email,$pw)
{
if ($this->isConnected or $this->connect()) {
$xml = "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<update>
<contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd">
<contact:id>$contactId</contact:id>
<contact:chg>
<contact:postalInfo type="loc">
<contact:name>$name</contact:name>
<contact:org>$org</contact:org>
<contact:addr>
<contact:street>$street</contact:street>
<contact:city>$city</contact:city>
<contact:sp>$oblast</contact:sp>
<contact:pc>$post</contact:pc>
<contact:cc>$country</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>$phone</contact:voice>
<contact:email>$email</contact:email>
<contact:authInfo>
<contact:pw>$pw</contact:pw>
</contact:authInfo>
<contact:disclose flag="0">
<contact:voice />
<contact:email />
</contact:disclose>
</contact:chg>
</contact:update>
</update>
<clTRID>".time()."</clTRID>
</command>
</epp>
";
if(!$this->send($xml)) {
$this->error='updateContact: Unable to send query.';
$this->disconnect();
return false;
} else {
$result = $this->get();
if (is_array($result)) {
if ($result[epp][0][response][0][result][0][msg] == "Command completed successfully") {
return true;
} else {
$this->error = "updateContact: ".$result[epp][0][response][0][result][0][msg]." (".$result[epp][0][response][0][result][0][value][0]["oxrs:xcp"].")";
$this->disconnect();
return false;
}
} else if (!$this->error) {
$this->error = "updateContact: Unable to get result.";
$this->disconnect();
return false;
} else {
$this->error = "updateContact: ".$this->error;
$this->disconnect();
return false;
}
}
} else {
$this->disconnect();
return false;
}
}
}
?>