From 2e11d698ee284f7b436c6c0f6748c05dd0f1d52c Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:40:26 +0300 Subject: [PATCH] Create Tembo.php --- Tembo.php | 2619 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2619 insertions(+) create mode 100644 Tembo.php diff --git a/Tembo.php b/Tembo.php new file mode 100644 index 0000000..48c92a5 --- /dev/null +++ b/Tembo.php @@ -0,0 +1,2619 @@ + array( + 'verify_peer' => (bool)$params['verify_peer'], + 'verify_peer_name' => (bool)$params['verify_peer_name'], + 'verify_host' => (bool)$params['verify_host'], + 'cafile' => (string)$params['cafile'], + 'local_cert' => (string)$params['local_cert'], + 'local_pk' => (string)$params['local_pk'], + 'passphrase' => (string)$params['passphrase'], + 'allow_self_signed' => (bool)$params['allow_self_signed'], + 'min_tls_version' => $tls + ) + ); + if ($bind) { + $opts['socket'] = array('bindto' => $bindip); + } + $context = stream_context_create($opts); + $this->resource = stream_socket_client("tls://{$host}:{$port}", $errno, $errmsg, $timeout, STREAM_CLIENT_CONNECT, $context); + if (!$this->resource) { + throw new \exception("Cannot connect to server '{$host}': {$errmsg}"); + } + + return $this->readResponse(); + } + + /** + * readResponse + */ + public function readResponse() + { + $hdr = stream_get_contents($this->resource, 4); + if ($hdr === false) { + throw new \exception('Connection appears to have closed.'); + } + if (strlen($hdr) < 4) { + throw new \exception('Failed to read header from the connection.'); + } + $unpacked = unpack('N', $hdr); + $xml = fread($this->resource, ($unpacked[1] - 4)); + $xml = preg_replace('/>\n<", $xml); + $this->_response_log($xml); + return $xml; + } + + /** + * writeRequest + */ + public function writeRequest($xml) + { + $this->_request_log($xml); + if (fwrite($this->resource, pack('N', (strlen($xml) + 4)) . $xml) === false) { + throw new exception('Error writing to the connection.'); + } + $xml_string = $this->readResponse(); + libxml_use_internal_errors(true); + + $r = simplexml_load_string($xml_string, 'SimpleXMLElement', LIBXML_DTDLOAD | LIBXML_NOENT); + if ($r instanceof SimpleXMLElement) { + $r->registerXPathNamespace('e', 'urn:ietf:params:xml:ns:epp-1.0'); + $r->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'); + $r->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0'); + $r->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0'); + $r->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0'); + $r->registerXPathNamespace('rgp', 'urn:ietf:params:xml:ns:rgp-1.0'); + } + if (isset($r->response) && $r->response->result->attributes()->code >= 2000) { + throw new \exception($r->response->result->msg); + } + return $r; + } + + /** + * disconnect + */ + public function disconnect() + { + if (!fclose($this->resource)) { + throw new \exception('Error closing the connection.'); + } + $this->resource = null; + } + + /** + * wrapper for functions + */ + public function __call($func, $args) + { + if (!function_exists($func)) { + throw new \Exception("Call to undefined method Epp::$func()."); + } + + if ($func === 'connect') { + try { + $result = call_user_func_array($func, $args); + } catch (\ErrorException $e) { + throw new \Exception($e->getMessage()); + } + + if (!is_resource($this->resource)) { + throw new \Exception('An error occured while trying to connect to EPP server.'); + } + + $result = null; + } elseif (!is_resource($this->resource)) { + throw new EppNotConnectedException(); + } else { + array_unshift($args, $this->resource); + try { + $result = call_user_func_array($func, $args); + } catch (\ErrorException $e) { + throw new \Exception($e->getMessage()); + } + } + + return $result; + } + + /** + * login + */ + public function login($params = array()) + { + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ clID }}/'; + $to[] = htmlspecialchars($params['clID']); + $from[] = '/{{ pwd }}/'; + $to[] = htmlspecialchars($params['pw']); + if (isset($params['newpw']) && !empty($params['newpw'])) { + $from[] = '/{{ newpw }}/'; + $to[] = PHP_EOL . ' ' . htmlspecialchars($params['newpw']) . ''; + } else { + $from[] = '/{{ newpw }}/'; + $to[] = ''; + } + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($params['prefix'] . '-login-' . $microtime); + $xml = preg_replace($from, $to, ' + + + + {{ clID }} + {{ pwd }}{{ newpw }} + + 1.0 + en + + + urn:ietf:params:xml:ns:domain-1.0 + urn:ietf:params:xml:ns:contact-1.0 + urn:ietf:params:xml:ns:host-1.0 + + urn:ietf:params:xml:ns:secDNS-1.1 + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + if ($code == 1000) { + $this->isLoggedIn = true; + $this->prefix = $params['prefix']; + } + + $return = array( + 'code' => $code, + 'msg' => $r->response->result->msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * logout + */ + public function logout($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-logout-' . $microtime); + $xml = preg_replace($from, $to, ' + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + if ($code == 1500) { + $this->isLoggedIn = false; + } + + $return = array( + 'code' => $code, + 'msg' => $r->response->result->msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * hello + */ + public function hello() + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-hello-' . $microtime); + $xml = preg_replace($from, $to, ' + + +'); + $r = $this->writeRequest($xml); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $r->asXML(); + } + + /** + * hostCheck + */ + public function hostCheck($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['hostname']); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-host-check-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:host-1.0')->chkData; + + $i = 0; + foreach ($r->cd as $cd) { + $i++; + $hosts[$i]['name'] = (string)$cd->name; + $hosts[$i]['reason'] = (string)$cd->reason; + $hosts[$i]['avail'] = (int)$cd->name->attributes()->avail; + } + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'hosts' => $hosts + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * hostInfo + */ + public function hostInfo($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['hostname']); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-host-info-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:host-1.0')->infData[0]; + $name = (string)$r->name; + $addr = array(); + foreach ($r->addr as $ns) { + $addr[] = (string)$ns; + } + $status = array(); + $i = 0; + foreach ($r->status as $e) { + $i++; + $status[$i] = (string)$e->attributes()->s; + } + $clID = (string)$r->clID; + $crID = (string)$r->crID; + $crDate = (string)$r->crDate; + $upID = (string)$r->upID; + $upDate = (string)$r->upDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'status' => $status, + 'addr' => $addr, + 'clID' => $clID, + 'crID' => $crID, + 'crDate' => $crDate, + 'upID' => $upID, + 'upDate' => $upDate + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * hostCreate + */ + public function hostCreate($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['hostname']); + $from[] = '/{{ ip }}/'; + $to[] = htmlspecialchars($params['ipaddress']); + $from[] = '/{{ v }}/'; + $to[] = (preg_match('/:/', $params['ipaddress']) ? 'v6' : 'v4'); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-host-create-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ ip }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:host-1.0')->creData; + $name = (string)$r->name; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * hostUpdate + */ + public function hostUpdate($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['hostname']); + $from[] = '/{{ ip1 }}/'; + $to[] = htmlspecialchars($params['currentipaddress']); + $from[] = '/{{ v1 }}/'; + $to[] = (preg_match('/:/', $params['currentipaddress']) ? 'v6' : 'v4'); + $from[] = '/{{ ip2 }}/'; + $to[] = htmlspecialchars($params['newipaddress']); + $from[] = '/{{ v2 }}/'; + $to[] = (preg_match('/:/', $params['newipaddress']) ? 'v6' : 'v4'); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-host-update-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + {{ ip2 }} + + + {{ ip1 }} + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * hostDelete + */ + public function hostDelete($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['hostname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-host-delete-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * contactCheck + */ + public function contactCheck($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ id }}/'; + $id = $params['contact']; + $to[] = htmlspecialchars($id); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-contact-check-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ id }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:contact-1.0')->chkData; + + $i = 0; + foreach ($r->cd as $cd) { + $i++; + $contacts[$i]['id'] = (string)$cd->id; + $contacts[$i]['avail'] = (int)$cd->id->attributes()->avail; + $contacts[$i]['reason'] = (string)$cd->reason; + } + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'contacts' => $contacts + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * contactInfo + */ + public function contactInfo($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ id }}/'; + $to[] = htmlspecialchars($params['contact']); + $from[] = '/{{ authInfo }}/'; + $authInfo = (isset($params['authInfoPw']) ? "\n\n" : ''); + $to[] = $authInfo; + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-contact-info-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ id }} + {{ authInfo }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:contact-1.0')->infData[0]; + + foreach ($r->postalInfo as $e) { + $name = (string)$e->name; + $org = (string)$e->org; + $street1 = $street2 = $street3 = ''; + for ($i = 0; $i <= 2; $i++) { + ${'street' . ($i + 1)} = (string)$e->addr->street[$i]; + } + $city = (string)$e->addr->city; + $state = (string)$e->addr->sp; + $postal = (string)$e->addr->pc; + $country = (string)$e->addr->cc; + } + $id = (string)$r->id; + $status = array(); + $i = 0; + foreach ($r->status as $e) { + $i++; + $status[$i] = (string)$e->attributes()->s; + } + $roid = (string)$r->roid; + $voice = (string)$r->voice; + $fax = (string)$r->fax; + $email = (string)$r->email; + $clID = (string)$r->clID; + $crID = (string)$r->crID; + $crDate = (string)$r->crDate; + $upID = (string)$r->upID; + $upDate = (string)$r->upDate; + $authInfo = (string)$r->authInfo->pw; + + $return = array( + 'id' => $id, + 'roid' => $roid, + 'code' => $code, + 'status' => $status, + 'msg' => $msg, + 'name' => $name, + 'org' => $org, + 'street1' => $street1, + 'street2' => $street2, + 'street3' => $street3, + 'city' => $city, + 'state' => $state, + 'postal' => $postal, + 'country' => $country, + 'voice' => $voice, + 'fax' => $fax, + 'email' => $email, + 'clID' => $clID, + 'crID' => $crID, + 'crDate' => $crDate, + 'upID' => $upID, + 'upDate' => $upDate, + 'authInfo' => $authInfo + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * contactCreate + */ + public function contactCreate($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ type }}/'; + $to[] = htmlspecialchars($params['type']); + $from[] = '/{{ id }}/'; + $to[] = htmlspecialchars($params['id']); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['firstname'] . ' ' . $params['lastname']); + $from[] = '/{{ org }}/'; + $to[] = htmlspecialchars($params['companyname']); + $from[] = '/{{ street1 }}/'; + $to[] = htmlspecialchars($params['address1']); + $from[] = '/{{ street2 }}/'; + $to[] = htmlspecialchars($params['address2']); + $from[] = '/{{ street3 }}/'; + $street3 = (isset($params['address3']) ? $params['address3'] : ''); + $to[] = htmlspecialchars($street3); + $from[] = '/{{ city }}/'; + $to[] = htmlspecialchars($params['city']); + $from[] = '/{{ state }}/'; + $to[] = htmlspecialchars($params['state']); + $from[] = '/{{ postcode }}/'; + $to[] = htmlspecialchars($params['postcode']); + $from[] = '/{{ country }}/'; + $to[] = htmlspecialchars($params['country']); + $from[] = '/{{ phonenumber }}/'; + $to[] = htmlspecialchars($params['fullphonenumber']); + $from[] = '/{{ email }}/'; + $to[] = htmlspecialchars($params['email']); + $from[] = '/{{ authInfo }}/'; + $to[] = htmlspecialchars($params['authInfoPw']); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-contact-create-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ id }} + + {{ name }} + {{ org }} + + {{ street1 }} + {{ street2 }} + {{ street3 }} + {{ city }} + {{ state }} + {{ postcode }} + {{ country }} + + + {{ phonenumber }} + + {{ email }} + + {{ authInfo }} + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:contact-1.0')->creData; + $id = (string)$r->id; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'id' => $id + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * contactUpdate + */ + public function contactUpdate($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ type }}/'; + $to[] = htmlspecialchars($params['type']); + $from[] = '/{{ id }}/'; + $to[] = htmlspecialchars($params['id']); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['firstname'] . ' ' . $params['lastname']); + $from[] = '/{{ org }}/'; + $to[] = htmlspecialchars($params['companyname']); + $from[] = '/{{ street1 }}/'; + $to[] = htmlspecialchars($params['address1']); + $from[] = '/{{ street2 }}/'; + $to[] = htmlspecialchars($params['address2']); + $from[] = '/{{ street3 }}/'; + $street3 = (isset($params['address3']) ? $params['address3'] : ''); + $to[] = htmlspecialchars($street3); + $from[] = '/{{ city }}/'; + $to[] = htmlspecialchars($params['city']); + $from[] = '/{{ state }}/'; + $to[] = htmlspecialchars($params['state']); + $from[] = '/{{ postcode }}/'; + $to[] = htmlspecialchars($params['postcode']); + $from[] = '/{{ country }}/'; + $to[] = htmlspecialchars($params['country']); + $from[] = '/{{ voice }}/'; + $to[] = htmlspecialchars($params['fullphonenumber']); + $from[] = '/{{ email }}/'; + $to[] = htmlspecialchars($params['email']); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-contact-update-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ id }} + + + {{ name }} + {{ org }} + + {{ street1 }} + {{ street2 }} + {{ street3 }} + {{ city }} + {{ state }} + {{ postcode }} + {{ country }} + + + {{ voice }} + + {{ email }} + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * contactDelete + */ + public function contactDelete($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ id }}/'; + $to[] = htmlspecialchars($params['contact']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-contact-delete-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ id }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainCheck + */ + public function domainCheck($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $text = ''; + foreach ($params['domains'] as $name) { + $text .= '' . $name . '' . "\n"; + } + $from[] = '/{{ names }}/'; + $to[] = $text; + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-check-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ names }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->chkData; + + $i = 0; + foreach ($r->cd as $cd) { + $i++; + $domains[$i]['name'] = (string)$cd->name; + $domains[$i]['avail'] = (int)$cd->name->attributes()->avail; + $domains[$i]['reason'] = (string)$cd->reason; + } + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'domains' => $domains + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainCheckClaims + */ + public function domainCheckClaims($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-checkClaims-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + + + claims + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $phase = $r->response->extension->children('urn:ietf:params:xml:ns:launch-1.0')->chkData->phase; + $status = $r->response->extension->children('urn:ietf:params:xml:ns:launch-1.0')->chkData->cd->name->attributes()->exists; + $name = $r->response->extension->children('urn:ietf:params:xml:ns:launch-1.0')->chkData->cd->name; + $claimKey = $r->response->extension->children('urn:ietf:params:xml:ns:launch-1.0')->chkData->cd->claimKey; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'domain' => $name, + 'status' => $status, + 'phase' => $phase, + 'claimKey' => $claimKey + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainInfo + */ + public function domainInfo($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ domainname }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ authInfo }}/'; + $authInfo = (isset($params['authInfoPw']) ? "\n\n" : ''); + $to[] = $authInfo; + $from[] = '/{{ clTRID }}/'; + $microtime = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-info-' . $microtime); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ domainname }} + {{ authInfo }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->infData; + $name = (string)$r->name; + $roid = (string)$r->roid; + $status = array(); + $i = 0; + foreach ($r->status as $e) { + $i++; + $status[$i] = (string)$e->attributes()->s; + } + $registrant = (string)$r->registrant; + $contact = array(); + $i = 0; + foreach ($r->contact as $e) { + $i++; + $contact[$i]['type'] = (string)$e->attributes()->type; + $contact[$i]['id'] = (string)$e; + } + $ns = array(); + $i = 0; + foreach ($r->ns->hostObj as $hostObj) { + $i++; + $ns[$i] = (string)$hostObj; + } + $host = array(); + $i = 0; + foreach ($r->host as $hostname) { + $i++; + $host[$i] = (string)$hostname; + } + $clID = (string)$r->clID; + $crID = (string)$r->crID; + $crDate = (string)$r->crDate; + $upID = (string)$r->upID; + $upDate = (string)$r->upDate; + $exDate = (string)$r->exDate; + $trDate = (string)$r->trDate; + $authInfo = (string)$r->authInfo->pw; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'roid' => $roid, + 'status' => $status, + 'registrant' => $registrant, + 'contact' => $contact, + 'ns' => $ns, + 'host' => $host, + 'clID' => $clID, + 'crID' => $crID, + 'crDate' => $crDate, + 'upID' => $upID, + 'upDate' => $upDate, + 'exDate' => $exDate, + 'trDate' => $trDate, + 'authInfo' => $authInfo + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainUpdateNS + */ + public function domainUpdateNS($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-info-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->infData; + + $add = $rem = array(); + $i = 0; + foreach ($r->ns->hostObj as $ns) { + $i++; + $ns = (string)$ns; + if (!$ns) { + continue; + } + + $rem["ns{$i}"] = $ns; + } + + foreach ($params as $k => $v) { + if (!$v) { + continue; + } + + if (!preg_match("/^ns\d$/i", $k)) { + continue; + } + + if ($k0 = array_search($v, $rem)) { + unset($rem[$k0]); + } else { + $add[$k] = $v; + } + } + + if (!empty($add) || !empty($rem)) { + $from = $to = array(); + $text = ''; + foreach ($add as $k => $v) { + $text.= '' . $v . '' . "\n"; + } + + $from[] = '/{{ add }}/'; + $to[] = (empty($text) ? '' : "\n{$text}\n"); + $text = ''; + foreach ($rem as $k => $v) { + $text.= '' . $v . '' . "\n"; + } + + $from[] = '/{{ rem }}/'; + $to[] = (empty($text) ? '' : "\n{$text}\n"); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-updateNS-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ add }} + {{ rem }} + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainUpdateContact + */ + public function domainUpdateContact($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + if ($params['contacttype'] === 'registrant') { + $from[] = '/{{ add }}/'; + $to[] = ""; + $from[] = '/{{ rem }}/'; + $to[] = ""; + $from[] = '/{{ chg }}/'; + $to[] = "".htmlspecialchars($params['new_contactid'])."\n"; + } else { + $from[] = '/{{ add }}/'; + $to[] = "".htmlspecialchars($params['new_contactid'])."\n"; + $from[] = '/{{ rem }}/'; + $to[] = "".htmlspecialchars($params['old_contactid'])."\n"; + $from[] = '/{{ chg }}/'; + $to[] = ""; + } + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-updateContact-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ add }} + {{ rem }} + {{ chg }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainUpdateStatus + */ + public function domainUpdateStatus($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + if ($params['command'] === 'add') { + $from[] = '/{{ add }}/'; + $to[] = "\n"; + $from[] = '/{{ rem }}/'; + $to[] = ""; + } else if ($params['command'] === 'rem') { + $from[] = '/{{ add }}/'; + $to[] = ""; + $from[] = '/{{ rem }}/'; + $to[] = "\n"; + } + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-updateStatus-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ add }} + {{ rem }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainUpdateAuthinfo + */ + public function domainUpdateAuthinfo($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ authInfo }}/'; + $to[] = htmlspecialchars($params['authInfo']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-updateAuthinfo-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ authInfo }} + + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainUpdateDNSSEC + */ + public function domainUpdateDNSSEC($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + if ($params['command'] == 'add') { + $from[] = '/{{ add }}/'; + $to[] = " + + ".htmlspecialchars($params['keyTag_1'])." + ".htmlspecialchars($params['alg_1'])." + ".htmlspecialchars($params['digestType_1'])." + ".htmlspecialchars($params['digest_1'])." + + "; + $from[] = '/{{ rem }}/'; + $to[] = ""; + $from[] = '/{{ addrem }}/'; + $to[] = ""; + } else if ($params['command'] == 'rem') { + $from[] = '/{{ add }}/'; + $to[] = ""; + $from[] = '/{{ rem }}/'; + $to[] = " + + ".htmlspecialchars($params['keyTag_1'])." + ".htmlspecialchars($params['alg_1'])." + ".htmlspecialchars($params['digestType_1'])." + ".htmlspecialchars($params['digest_1'])." + + "; + $from[] = '/{{ addrem }}/'; + $to[] = ""; + } else if ($params['command'] == 'addrem') { + $from[] = '/{{ add }}/'; + $to[] = ""; + $from[] = '/{{ rem }}/'; + $to[] = ""; + $from[] = '/{{ addrem }}/'; + $to[] = " + + ".htmlspecialchars($params['keyTag_1'])." + ".htmlspecialchars($params['alg_1'])." + ".htmlspecialchars($params['digestType_1'])." + ".htmlspecialchars($params['digest_1'])." + + + + + ".htmlspecialchars($params['keyTag_2'])." + ".htmlspecialchars($params['alg_2'])." + ".htmlspecialchars($params['digestType_2'])." + ".htmlspecialchars($params['digest_2'])." + + "; + } + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-updateDNSSEC-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + + + {{ add }} + {{ rem }} + {{ addrem }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainTransfer + */ + public function domainTransfer($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + switch (htmlspecialchars($params['op'])) { + case 'request': + $from[] = '/{{ years }}/'; + $to[] = (int)($params['years']); + $from[] = '/{{ authInfoPw }}/'; + $to[] = htmlspecialchars($params['authInfoPw']); + $xmltype = 'req'; + break; + case 'query': + $from[] = '/{{ type }}/'; + $to[] = 'query'; + $xmltype = 'oth'; + break; + case 'cancel': + $from[] = '/{{ type }}/'; + $to[] = 'cancel'; + $xmltype = 'oth'; + break; + case 'reject': + $from[] = '/{{ type }}/'; + $to[] = 'reject'; + $xmltype = 'oth'; + break; + case 'approve': + $xmltype = 'apr'; + break; + default: + throw new EppException('Invalid value for transfer:op specified.'); + break; + } + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-transfer-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + if ($xmltype === 'req') { + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ years }} + + {{ authInfoPw }} + + + + {{ clTRID }} + + '); + + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->trnData; + $name = (string)$r->name; + $trStatus = (string)$r->trStatus; + $reID = (string)$r->reID; + $reDate = (string)$r->reDate; + $acID = (string)$r->acID; + $acDate = (string)$r->acDate; + $exDate = (string)$r->exDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'trStatus' => $trStatus, + 'reID' => $reID, + 'reDate' => $reDate, + 'acID' => $acID, + 'acDate' => $acDate, + 'exDate' => $exDate + ); + + } else if ($xmltype === 'apr') { + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + + '); + + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->Data; + $name = (string)$r->name; + $trStatus = (string)$r->trStatus; + $reID = (string)$r->reID; + $reDate = (string)$r->reDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'trStatus' => $trStatus, + 'reID' => $reID, + 'reDate' => $reDate + ); + + } else if ($xmltype === 'oth') { + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + + '); + + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + + } + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainCreate + */ + public function domainCreate($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ period }}/'; + $to[] = (int)($params['period']); + if (isset($params['nss'])) { + $text = ''; + foreach ($params['nss'] as $hostObj) { + $text .= '' . $hostObj . '' . "\n"; + } + $from[] = '/{{ hostObjs }}/'; + $to[] = $text; + } else { + $from[] = '/{{ hostObjs }}/'; + $to[] = ''; + } + $from[] = '/{{ registrant }}/'; + $to[] = htmlspecialchars($params['registrant']); + $text = ''; + foreach ($params['contacts'] as $contactType => $contactID) { + $text .= '' . $contactID . '' . "\n"; + } + $from[] = '/{{ contacts }}/'; + $to[] = $text; + $from[] = '/{{ authInfoPw }}/'; + $to[] = htmlspecialchars($params['authInfoPw']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-create-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ period }} + + {{ hostObjs }} + + {{ registrant }} + {{ contacts }} + + {{ authInfoPw }} + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->creData; + $name = (string)$r->name; + $crDate = (string)$r->crDate; + $exDate = (string)$r->exDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'crDate' => $crDate, + 'exDate' => $exDate + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainCreateDNSSEC + */ + public function domainCreateDNSSEC($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ period }}/'; + $to[] = (int)($params['period']); + if (isset($params['nss'])) { + $text = ''; + foreach ($params['nss'] as $hostObj) { + $text .= '' . $hostObj . '' . "\n"; + } + $from[] = '/{{ hostObjs }}/'; + $to[] = $text; + } else { + $from[] = '/{{ hostObjs }}/'; + $to[] = ''; + } + $from[] = '/{{ registrant }}/'; + $to[] = htmlspecialchars($params['registrant']); + $text = ''; + foreach ($params['contacts'] as $contactType => $contactID) { + $text .= '' . $contactID . '' . "\n"; + } + $from[] = '/{{ contacts }}/'; + $to[] = $text; + $from[] = '/{{ authInfoPw }}/'; + $to[] = htmlspecialchars($params['authInfoPw']); + if ($params['dnssec_records'] == 1) { + $from[] = '/{{ dnssec_data }}/'; + $to[] = " + ".htmlspecialchars($params['keyTag_1'])." + ".htmlspecialchars($params['alg_1'])." + ".htmlspecialchars($params['digestType_1'])." + ".htmlspecialchars($params['digest_1'])." + "; + } else if ($params['dnssec_records'] == 2) { + $from[] = '/{{ dnssec_data }}/'; + $to[] = " + ".htmlspecialchars($params['keyTag_1'])." + ".htmlspecialchars($params['alg_1'])." + ".htmlspecialchars($params['digestType_1'])." + ".htmlspecialchars($params['digest_1'])." + + + ".htmlspecialchars($params['keyTag_2'])." + ".htmlspecialchars($params['alg_2'])." + ".htmlspecialchars($params['digestType_2'])." + ".htmlspecialchars($params['digest_2'])." + "; + } + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-createDNSSEC-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ period }} + + {{ hostObjs }} + + {{ registrant }} + {{ contacts }} + + {{ authInfoPw }} + + + + + + {{ dnssec_data }} + + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->creData; + $name = (string)$r->name; + $crDate = (string)$r->crDate; + $exDate = (string)$r->exDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'crDate' => $crDate, + 'exDate' => $exDate + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainCreateClaims + */ + public function domainCreateClaims($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ period }}/'; + $to[] = (int)($params['period']); + if (isset($params['nss'])) { + $text = ''; + foreach ($params['nss'] as $hostObj) { + $text .= '' . $hostObj . '' . "\n"; + } + $from[] = '/{{ hostObjs }}/'; + $to[] = $text; + } else { + $from[] = '/{{ hostObjs }}/'; + $to[] = ''; + } + $from[] = '/{{ registrant }}/'; + $to[] = htmlspecialchars($params['registrant']); + $text = ''; + foreach ($params['contacts'] as $contactType => $contactID) { + $text .= '' . $contactID . '' . "\n"; + } + $from[] = '/{{ contacts }}/'; + $to[] = $text; + $from[] = '/{{ authInfoPw }}/'; + $to[] = htmlspecialchars($params['authInfoPw']); + $from[] = '/{{ noticeID }}/'; + $to[] = htmlspecialchars($params['noticeID']); + $from[] = '/{{ notAfter }}/'; + $to[] = htmlspecialchars($params['notAfter']); + $from[] = '/{{ acceptedDate }}/'; + $to[] = htmlspecialchars($params['acceptedDate']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-createClaims-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ period }} + + {{ hostObjs }} + + {{ registrant }} + {{ contacts }} + + {{ authInfoPw }} + + + + + claims + + {{ noticeID }} + {{ notAfter }} + {{ acceptedDate }} + + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->creData; + $name = (string)$r->name; + $crDate = (string)$r->crDate; + $exDate = (string)$r->exDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'crDate' => $crDate, + 'exDate' => $exDate + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainRenew + */ + public function domainRenew($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-renew-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->infData; + + $expDate = (string)$r->exDate; + $expDate = preg_replace("/^(\d+\-\d+\-\d+)\D.*$/", "$1", $expDate); + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ regperiod }}/'; + $to[] = htmlspecialchars($params['regperiod']); + $from[] = '/{{ expDate }}/'; + $to[] = htmlspecialchars($expDate); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-renew-' . $clTRID); + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + {{ expDate }} + {{ regperiod }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->renData; + $name = (string)$r->name; + $exDate = (string)$r->exDate; + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'name' => $name, + 'exDate' => $exDate + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainDelete + */ + public function domainDelete($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-delete-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainRestore + */ + public function domainRestore($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-restore-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + + + + + + + {{ clTRID }} + +'); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * domainReport + */ + public function domainReport($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ name }}/'; + $to[] = htmlspecialchars($params['domainname']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-domain-report-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + + {{ name }} + + + + + + + + Pre-delete registration data goes here. + Both XML and free text are allowed. + Post-restore registration data goes here. + Both XML and free text are allowed. + 2019-10-10T22:00:00.0Z + 2019-10-20T22:00:00.0Z + Registrant error. + This registrar has not restored the + Registered Name in order to assume the rights to use + or sell the Registered Name for itself or for any + third party. + The information in this report is + true to best of this registrars knowledge, and this + registrar acknowledges that intentionally supplying + false information in this report shall constitute an + incurable material breach of the + Registry-Registrar Agreement. + Supporting information goes + here. + + + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * pollReq + */ + public function pollReq() + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-poll-req-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + $messages = (int)($r->response->msgQ->attributes()->count ?? 0); + $last_id = (int)($r->response->msgQ->attributes()->id ?? 0); + $qDate = (string)($r->response->msgQ->qDate ?? ''); + $last_msg = (string)($r->response->msgQ->msg ?? ''); + + $return = array( + 'code' => $code, + 'msg' => $msg, + 'messages' => $messages, + 'last_id' => $last_id, + 'qDate' => $qDate, + 'last_msg' => $last_msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + /** + * pollAck + */ + public function pollAck($params = array()) + { + if (!$this->isLoggedIn) { + return array( + 'code' => 2002, + 'msg' => 'Command use error' + ); + } + + $return = array(); + try { + $from = $to = array(); + $from[] = '/{{ message }}/'; + $to[] = htmlspecialchars($params['msgID']); + $from[] = '/{{ clTRID }}/'; + $clTRID = str_replace('.', '', round(microtime(1), 3)); + $to[] = htmlspecialchars($this->prefix . '-poll-ack-' . $clTRID); + $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; + $to[] = ''; + $xml = preg_replace($from, $to, ' + + + + {{ clTRID }} + + '); + $r = $this->writeRequest($xml); + $code = (int)$r->response->result->attributes()->code; + $msg = (string)$r->response->result->msg; + + $return = array( + 'code' => $code, + 'msg' => $msg + ); + } catch (\Exception $e) { + $return = array( + 'error' => $e->getMessage() + ); + } + + return $return; + } + + public function _response_log($content) + { + $handle = fopen(dirname(__FILE__) . '/response.log', 'a'); + ob_start(); + echo "\n==================================\n"; + ob_end_clean(); + fwrite($handle, $content); + fclose($handle); + } + + public function _request_log($content) + { + $handle = fopen(dirname(__FILE__) . '/request.log', 'a'); + ob_start(); + echo "\n==================================\n"; + ob_end_clean(); + fwrite($handle, $content); + fclose($handle); + } +}