debug(true); * * // Check a domain name * $check = $srs->domain->check('domain.com'); * * if($srs->isError($check)) * die($check->Error('html')); * * if($check->avail) { * // Create a domain name * $create = $srs->domain->create( * 'domain.com', * array('ns1.example.com', 'ns2.example.com'), * 'registrant', * 'admin', * 'billing', * 'tech' * ); * * if($srs->isError($create)) * die($create->Error('html')); * * print 'OK'; * * } else { * print 'Domain not available'; * } * * // Logout and close connection * $srs->close(); * * // Get debug info * print $srs->debug(); * * ?> * */ if(version_compare(PHP_VERSION, '5.0.0', '<')) { die('PHP 5.0.0 or higer required'); } require_once('include/Unserializer.php'); require_once('XML/Serializer.php'); /** * Class for YourSRS EPP interface * */ class YourSRS { /** * Opbject var for singleton * * @var YourSRS */ static private $instance; /** * Object for base EPP commands * * @var Epp_Base */ public $epp; /** * Object to manage YourSRS domains * * @var Epp_Domain */ public $domain; /** * Object to manage YourSRS contacts * * @var Epp_Contact */ public $contact; /** * Create a new YourSRS instance * * @param string username * @param string password * @return YourSRS */ function YourSRS($user, $pass) { if(!defined('EPP_SERVER_NAME')) { die('Constante EPP_SERVER_NAME must be defined'); } if(!defined('EPP_SERVER_PORT')) { die('Constante EPP_SERVER_PORT must be defined'); } $this->epp = new Epp_Base($user, $pass); $this->domain = new Epp_Domain(&$this->epp); $this->contact = new Epp_Contact(&$this->epp); } /** * Get a singleton instance of YourSRS * * @param string username * @param string password * @return YourSRS */ static function Singleton($user, $pass) { if ( ! YourSRS::SingletonInstance()) { YourSRS::$instance = new YourSRS($user, $pass); } return YourSRS::$instance; } /** * Check if there is an Singleton instance * * @return bool */ static function SingletonInstance() { return isset(YourSRS::$instance); } /** * Check if a variabele is a EPP error object * * @param mixed mixed * @return bool */ static function isError($input) { if(is_object($input)) { return is_a($input, 'Epp_Result_Error'); } return false; } /** * Logout and close connection * * @return bool */ function close() { return $this->epp->close(); } /** * Return debug log * * @return string */ function debug($set = null) { if(isset($set)) { $this->epp->debug = $set; } else { return $this->epp->debug(); } } /** * Return total time of command execution * * @return double */ function debug_time() { return $this->epp->debug_time(); } } /** * Class to create and read XML/EPP documents * */ class Epp_XML { /** * PEAR XML Serializer * * @var XML_Serializer */ private $s; /** * PEAR XML Unserializer * * @var XML_Unserializer */ private $u; /** * The EPP parser * * @return Epp_XML */ function Epp_XML() { $this->s = new XML_Serializer(array( 'addDecl' => true, 'encoding' => 'UTF-8', 'indent' => ' ', 'indentAttributes' => '_auto', 'mode' => 'simplexml', 'rootName' => 'epp', 'scalarAsAttributes' => false, 'attributesArray' => '_attribute', 'contentName' => '_content', 'rootAttributes' => array( 'xmlns' => 'http://www.yoursrs.com/xml/epp/epp-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:domain' => 'http://www.yoursrs.com/xml/epp/domain-1.0', 'xmlns:contact' => 'http://www.yoursrs.com/xml/epp/contact-1.0', 'xsi:schemaLocation' => 'http://www.yoursrs.com/xml/epp/epp-1.0 epp-1.0.xsd http://www.yoursrs.com/xml/epp/domain-1.0 domain-1.0.xsd http://www.yoursrs.com/xml/epp/contact-1.0 contact-1.0.xsd' ), ) ); $this->u = new XML_Unserializer(array( 'complexType' => 'object', 'contentName' => '_content', 'parseAttributes' => true, 'attributesArray' => '_attribute', 'tagMap' => array( 'epp' => 'Epp_Result', ), ) ); } /** * Create an XML/EPP document from a hash * * @param hash $hash * @return string */ function getEpp($hash) { $status = $this->s->serialize($hash); if (PEAR::isError($status)) { return false; } return $this->s->getSerializedData(); } /** * Create a Epp_Result object from an XML/EPP document * * @param string $xml * @return Epp_Result */ function getHash($xml) { $status = $this->u->unserialize($xml); if (PEAR::isError($status)) { return false; } $result = $this->u->getUnserializedData(); $result->init(); return $result; } } /** * EPP base class, this class provides connection and session handling * */ class Epp_Base { /** * The username used to login * * @var string */ private $user = null; /** * The password used to login * * @var string */ private $pass = null; /** * The XML/EPP parser * * @var Epp_XML */ private $xml = null; /** * The socket to the EPP server * * @var resource */ private $fp = null; /** * Array to store debug data * * @var array */ private $_debug = array(); /** * The socket time out * * @var int */ private $timeout = 100; /** * Store debug data * * @var bool */ public $debug = true; /** * Connection Time out * * @var int */ private $conn_timeout = 100; /** * Constructor * * @param string username * @param string password * @return Epp_Base */ function Epp_Base($user, $pass) { $this->xml = new Epp_XML; $this->user = $user; $this->pass = $pass; } /** * Execute an EPP command * * @param hahs Command hash * @param bool Will not login if true * @return Epp_Result */ public function execute($msg, $nologin = false) { if(!$this->_isConnected()) { $result = $this->_connect(); if(YourSRS::isError($result)) return $result; if($nologin != true) { $result = $this->login(); if(YourSRS::isError($result)) return $result; } } $string = $this->xml->getEpp($msg); $start = $this->_getmicrotime(); $this->_writeEppString($string); $response = $this->_readEppString(); if(YourSRS::isError($response)) return $response; if($this->debug or defined('DEVELOP')) { $trace = debug_backtrace(); $this->_setDebug($string, $response, $trace[1]['line'], $trace[1]['file'], $this->_getmicrotime() - $start ); } $result = $this->xml->getHash($response); if($result->isSuccess()) return $result; else return $result->getError(); } public function executeRaw($msg, $nologin = false) { if(!$this->_isConnected()) { $result = $this->_connect(); if(YourSRS::isError($result)) return $result; if($nologin != true) { $result = $this->login(); if(YourSRS::isError($result)) return $result; } } $start = $this->_getmicrotime(); $this->_writeEppString($msg); $response = $this->_readEppString(); if(YourSRS::isError($response)) return $response; if($this->debug or defined('DEVELOP')) { $trace = debug_backtrace(); $this->_setDebug($msg, $response, $trace[1]['line'], $trace[1]['file'], $this->_getmicrotime() - $start ); } return $response; } /** * Connect to the EPP server * * @return bool true or error object */ private function _connect() { $errno = 0; $errstr = ''; $this->fp = @fsockopen(EPP_SERVER_NAME, EPP_SERVER_PORT , $errno, $errstr, $this->conn_timeout); if(isset($this->fp)) { if($this->_isConnected()) { $response = $this->_readEppString(); if(YourSRS::isError($response)) return $response; if(empty($response)) { $this->fp = null; $this->_log('Connection failed (' . $errno . ' ' . $errstr . ')'); return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } } else { $this->_log('Connection failed (' . $errno . ' ' . $errstr . ')'); return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } } else { $this->_log('Connection failed (' . $errno . ' ' . $errstr . ')'); return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } return true; } /** * Check if there is an connection to the server * * @return bool */ private function _isConnected() { return is_resource($this->fp) ? true : false; } /** * Logout and close the connection * * @return bool */ public function close() { if($this->_isConnected()) { $this->logout(); if(!@fclose($this->fp)) $this->_log('Failed to close socket'); } return true; } /** * Log an error * * @param string Log message * @param string Log data */ private function _log($message) { if(defined('EPP_LOGFILE')) { if($handle = @fopen(EPP_LOGFILE, 'a')) { if(@fwrite($handle, substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/')) . " " . date("d-m-Y H:i:s") . " (" . $this->user . ")\r\n" . $string)) { @fwrite($handle, "\r\n" . $message. "\r\n\r\n"); @fclose($handle); } } } } /** * Reset timeout * */ private function _control_socket_reset() { if($this->_isConnected()) @stream_set_timeout($this->fp, $this->timeout); } /** * Read string form EPP server * * @return string */ private function _readEppString() { if(!$this->_isConnected()) return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); $this->_control_socket_reset(); /* * Read the header */ if(!$buf = @fread($this->fp, 4)) { $info = stream_get_meta_data($this->fp); if($info['timed_out']) $this->_log('Connection timed out'); $this->_log('Failed to read message length'); return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } else { $this->_control_socket_reset(); if(strlen($buf) < 4) { $this->_log('Failed to read message length'); return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } else { $b0 = ord($buf[0]); $b1 = ord($buf[1]); $b2 = ord($buf[2]); $b3 = ord($buf[3]); $len = $b3 + 256 * ($b2 + 256 * ($b1 + 256 * $b0)); } } /* * Read the data */ if($len > 0) { $left = $len - 4; $data = null; do { $this->_control_socket_reset(); $chunk = @fread($this->fp, $left); if(isset($chunk)) { $data .= $chunk; $left = $left - strlen($chunk); } else { $info = stream_get_meta_data($this->fp); if($info['timed_out']) $this->_log('Connection timed out'); $this->_log('Failed to read message data'); break; } $this->_control_socket_reset(); if ($left <= 0) break; } while(true); if(is_null($data)) { return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed (time-out)', )); } return $data; } else return new Epp_Result_Error(array( 'code' => 2400, 'msg' => 'Command failed', 'error' => 'Connection failed', )); } /** * Write string to EPP server * * @param string epp message * @return bool */ private function _writeEppString($message) { if(!$this->_isConnected()) return false; /* * Calculate and write the header */ $len = strlen($message); $value = $len + 4; $b3 = $value % 256; $value = ($value - $b3)/256; $b2 = $value % 256; $value = ($value - $b2)/256; $b1 = $value % 256; $value = ($value - $b1)/256; $b0 = $value % 256; if(!@fwrite($this->fp, chr($b0).chr($b1).chr($b2).chr($b3), 4)) { $this->_log('Failed to write message length'); return false; } /* * Write the data */ if(!@fwrite($this->fp, $message)) { $this->_log('Failed to read message data'); return false; } return true; } /** * Login to the EPP server * * @return bool */ public function login() { if(!isset($this->user)) { return false; } if(!isset($this->pass)) { return false; } $result = $this->execute( array( 'command' => array( 'login' => array ( 'clID' => $this->user, 'pw' => $this->pass, 'options' => array( 'version' => '1.0', 'lang' => 'en', ) ), ), ), true); if(YourSRS::isError($result)) { return $result; } return true; } /** * Logout form EPP server * * @return bool */ public function logout() { if(!$this->_isConnected()) { return true; } $result = $this->execute( array( 'command' => array( 'logout' => null, ), )); if(YourSRS::isError($result)) { return $result; } return true; } /** * Change the password * * @param string new password * @return bool */ public function changePassword($newpw) { if(!isset($this->user)) { return false; } if(!isset($this->pass)) { return false; } $this->close(); $result = $this->execute( array( 'command' => array( 'login' => array ( 'clID' => $this->user, 'pw' => $this->pass, 'newPW' => $newpw, 'options' => array( 'version' => '1.0', 'lang' => 'en', ), ), ), ), true); if(YourSRS::isError($result)) { return $result; } return true; } /** * Get microtime * * @return float */ private function _getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } /** * Get debug data, HTML representation of EPP conversation * * @return string */ public function debug() { $res = ''; foreach ($this->_debug as $d) { $res .= "\n"; } $res .= '
EPP command executed in ".$d[3]." at line ".$d[2]." in ".$d[4]." seconds
".highlight_string($d[0],1)."
".highlight_string($d[1],1)."
'; return $res; } /** * Get the total time the EPP commands took * * @return float */ public function debug_time() { $time = 0; foreach ($this->_debug as $d) { $time = $time + $d[4]; } return $time; } /** * Add debug data * * @param string EPP message * @param string EPP response * @param int Line where command was executed * @param string File where command was executed * @param fload Time EPP command took */ private function _setDebug($out, $in, $line, $file, $time) { $this->_debug[] = array($out, $in, $line, $file, $time); } } /** * EPP Domain class, this class provides domain actions * */ class Epp_Domain { /** * Epp_Base object used to execute commands * * @var Epp_Base */ private $epp; /** * Constructor * * @param Epp_Base Epp_Base object used to execute commands * @return Epp_Domain */ function Epp_Domain($epp) { $this->epp = $epp; } /** * Check if a domain name exists * * @param string|array The domain name(s) to check * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [avail] => bool, optional, Only if 1 domain is checked, Availability of the domain name * [reason] => string, optional, Only if 1 domain is checked and the domain is not available a reason may be provided * [**domain**] => Array, For each checked domain a element with the result is created * ( * [avail] => bool, Availability of the domain name * [reason] => string, optional, If domain is not available a reason may be provided * ) * ) * * If the action fails an Epp_Result_Error object is returned. */ function check($name) { $result = $this->epp->execute( array( 'command' => array( 'check' => array( 'domain:check' => array( 'domain:name' => $name, ), ), ), )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); if(is_array($result->response->resData->{'domain:chkData'}->{'domain:cd'})) { foreach($result->response->resData->{'domain:chkData'}->{'domain:cd'} as $d) { $dom = $d->{'domain:name'}->_content; $r->{$dom} = array( 'avail' => $d->{'domain:name'}->_attribute['avail'], ); if(isset($d->{'domain:reason'})) $r->{$dom}['reason'] = $d->{'domain:reason'}; } } else { $dom = $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:name'}->_content; $r->{$dom} = array( 'avail' => $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:name'}->_attribute['avail'], ); $r->avail = $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:name'}->_attribute['avail']; if(isset( $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:reason'})) { $r->{$dom}['reason'] = $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:reason'}; $r->reason = $result->response->resData->{'domain:chkData'}->{'domain:cd'}->{'domain:reason'}; } } return $r; } /** * Query domain details * * @param string The domain to query * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [name] => string, The domain name * [roid] => string, The repository object identifier * [status] => string|array, The status of the domain, if the domain has more than 1 status an array is created * [registrant] => string, The registrant contact handle * [billing] => string, The billing contact handle * [tech] => string, The tech contact handle * [admin] => string, The admin contact handle * [ns] => Array, optional, Assigned name servers * ( * [0] => Array, Name server data * ( * [host] => string, Name server host * [addr] => string, optional, Name server IP address * ) * [1] => ... * ) * [template] => int, optional, the DNS template id * [records] => bool, optional, If true the domain has dns records but not attached to a template * [clID] => string, ID of the dealer that administrates the domein * [crID] => string, ID of the dealer that created the domain * [crDate] => timestamp, Creation date/time of the domain * [upID] => string, optional, ID of the dealer that last updated the domain * [upDate] => timestamp, optional, Date/time of last update on the domain * [exDate] => timestamp, Date/time of expiration * [pw] => string, optional, The Auth ID of the domain * [renew] => bool, optional, Is the domain automaticly renewed * [lock] => bool, optional, True if domain is locked * ) * * If the action fails an Epp_Result_Error object is returned. */ function info($name) { $result = $this->epp->execute( array( 'command' => array( 'info' => array( 'domain:info' => array( 'domain:name' => $name, ), ), ), )); if(YourSRS::isError($result)) { return $result; } $i = &$result->response->resData->{'domain:infData'}; $domain = $result->stdClass(); $domain->name = $i->{'domain:name'}; $domain->roid = $i->{'domain:roid'}; if(is_array($i->{'domain:status'})) { $domain->status = array(); foreach($i->{'domain:status'} as $status) array_push($domain->status, $status->_attribute['s']); } else $domain->status = $i->{'domain:status'}->_attribute['s']; $domain->registrant = $i->{'domain:registrant'}; foreach($i->{'domain:contact'} as $c) { $domain->{$c->_attribute['type']} = $c->_content; } if(isset($i->{'domain:ns'}->{'domain:hostAttr'})) { $domain->ns = array(); if (is_array($i->{'domain:ns'}->{'domain:hostAttr'})) { foreach($i->{'domain:ns'}->{'domain:hostAttr'} as $ns) { $n = array( 'host' => $ns->{'domain:hostName'} ); if(isset($ns->{'domain:hostAddr'})) $n['addr'] = $ns->{'domain:hostAddr'}; array_push($domain->ns, $n); } } else { $n = array( 'host' => $i->{'domain:ns'}->{'domain:hostAttr'}->{'domain:hostName'} ); if(isset($i->{'domain:ns'}->{'domain:hostAttr'}->{'domain:hostAddr'})) $n['addr'] = $i->{'domain:ns'}->{'domain:hostAttr'}->{'domain:hostAddr'}; array_push($domain->ns, $n); } } elseif(isset($i->{'domain:ns'}->{'domain:template'})) { $domain->template = $i->{'domain:ns'}->{'domain:template'}; } elseif(isset($i->{'domain:ns'}->{'domain:records'})) { $domain->records = $i->{'domain:ns'}->{'domain:records'}; } if (isset($i->{'domain:renew'})) $domain->renew = ($i->{'domain:renew'} == 'y'); if (isset($i->{'domain:lock'})) $domain->lock = true; $domain->clID = $i->{'domain:clID'}; //$domain->crID = $i->{'domain:crID'}; $domain->crDate = strtotime($i->{'domain:crDate'}); //$domain->upID = $i->{'domain:upID'}; if (isset($i->{'domain:upDate'})) $domain->upDate = strtotime($i->{'domain:upDate'}); $domain->exDate = strtotime($i->{'domain:exDate'}); if(isset($i->{'domain:authInfo'})) $domain->pw = $i->{'domain:authInfo'}->{'domain:pw'}; return $domain; } /** * Create a domain name * * @param string The domain to create * @param array Array of name servers * The name servers must be provided in an array: * - If the array key is an int the value is assumed to be the host name of the name server. * array('ns1.example.com', 'ns2.example.com') * - If the array key is not an int it is assumed to be the host name of the name server * and the value the IP adress. * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com' => '4.3.2.1') * - If the value is an array the assumed format is array('host' => 'ns2.example.com', ['addr' => '4.3.2.1']) * - These options may be mixed * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com') * * @param string The registrant handle * @param string The admin contact handle * @param string The billing contact handle * @param string The tech contact handle * @param bool Autorenew domain, optional, ignored if null, default dealer default * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [domain] => string, The domain name * [crDate] => timestamp, The creation date/time of the domain * ) * * If the action fails an Epp_Result_Error object is returned. */ function create($name, $ns, $registrant, $admin, $billing, $tech, $autorenew = null, $template = null, $template_link = null) { $command = array(); $command['domain:name'] = $name; if($template !== null){ $command['domain:ns'] = array(); $command['domain:ns']['domain:template'] = array('_content' => $template, '_attribute' => array('link' => ($template_link ? 'true' : 'false'))); } elseif ($ns) { $command['domain:ns'] = array(); $command['domain:ns']['domain:hostAttr'] = array(); if(is_array($ns)) { foreach($ns as $key => $value) { if (!empty($value)){ if(is_array($value)) { if(isset($value['addr'])) $command['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host'], 'domain:hostAddr' => $value['addr']); else $command['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host']); } elseif(is_int($key)) $command['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value); else $command['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $key, 'domain:hostAddr' => $value); } } } elseif (!empty($ns)) $command['domain:ns']['domain:hostAttr']['domain:hostName'] = $ns; } $command['domain:registrant'] = $registrant; $command['domain:contact'] = array(); $command['domain:contact'][] = array('_content' => $admin, '_attribute' => array('type' => 'admin')); $command['domain:contact'][] = array('_content' => $billing, '_attribute' => array('type' => 'billing')); $command['domain:contact'][] = array('_content' => $tech, '_attribute' => array('type' => 'tech')); if(isset($autorenew)) $command['domain:renew'] = $autorenew ? 'y' : 'n'; $result = $this->epp->execute( array( 'command' => array( 'create' => array( 'domain:create' => $command, ), ), )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); $r->domain = $result->response->resData->{'domain:creData'}->{'domain:name'}; $r->crDate = strtotime($result->response->resData->{'domain:creData'}->{'domain:crDate'}); $r->exDate = strtotime($result->response->resData->{'domain:creData'}->{'domain:exDate'}); return $r; } /** * Enter description here... * * @param string The domain to update * @param array The name server to add to the domain, optional, ignored if null * The name servers must be provided in an array: * - If the array key is an int the value is assumed to be the host name of the name server. * array('ns1.example.com', 'ns2.example.com') * - If the array key is not an int it is assumed to be the host name of the name server * and the value the IP adress. * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com' => '4.3.2.1') * - If the value is an array the assumed format is array('host' => 'ns2.example.com', ['addr' => '4.3.2.1']) * - These options may be mixed * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com') * * @param array The name server to remove, optional, ignored if null * The name servers must be provided in an array: * - If the array key is an int the value is assumed to be the host name of the name server. * array('ns1.example.com', 'ns2.example.com') * - If the array key is not an int it is assumed to be the host name of the name server * and the value the IP adress. * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com' => '4.3.2.1') * - If the value is an array the assumed format is array('host' => 'ns2.example.com', ['addr' => '4.3.2.1']) * - These options may be mixed * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com') * The name server is removed on basis of the host name so there is no need to specify the IP adresses * * @param string The admin contact handle, optional, ignored if null * @param string The billing contact handle, optional, ignored if null * @param string The rech contact handle, optional, ignored if null * @param bool Autorenew the domain, optional, ignored if null * - If true, autorenew will be enabled for this domain * - If false, autorenew will be disabled for this domain * - On other exept null, the autorenew setting will be removed so that the dealer default will be used * * @param bool $lock, optional, ignored if null * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function update($name, $ns_add = null, $ns_rem = null, $admin = null, $billing = null, $tech = null, $autorenew = null, $lock = null, $template = null, $template_link = null) { $command = array(); $command['domain:name'] = $name; /** * Name servers toevoegen */ if(isset($ns_add) and count($ns_add)) { $ns_continue = false; foreach($ns_add as $key => $value){ if (!empty($value)) $ns_continue = true; } if ($ns_continue){ if(!isset($command['domain:add'])) $command['domain:add'] = array(); $command['domain:add']['domain:ns'] = array(); $command['domain:add']['domain:ns']['domain:hostAttr'] = array(); if(is_array($ns_add)) { foreach($ns_add as $key => $value) { if (!empty($value)) { if(is_array($value)) { if(isset($value['addr'])) $command['domain:add']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host'], 'domain:hostAddr' => $value['addr']); else $command['domain:add']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host']); } elseif(is_int($key)) $command['domain:add']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value); else $command['domain:add']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $key, 'domain:hostAddr' => $value); } } } else $command['domain:add']['domain:ns']['domain:hostAttr']['domain:hostName'] = $ns_add; } } /** * Lock plaatsen */ if(isset($lock) and $lock === true) { if(!isset($command['domain:add'])) $command['domain:add'] = array(); $command['domain:add']['domain:lock'] = null; } /** * Name servers verwijderen */ if(isset($ns_rem) and count($ns_rem)) { if(!isset($command['domain:rem'])) $command['domain:rem'] = array(); $command['domain:rem']['domain:ns'] = array(); $command['domain:rem']['domain:ns']['domain:hostAttr'] = array(); if(is_array($ns_rem)) { foreach($ns_rem as $key => $value) if(is_array($value)) { $command['domain:rem']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host']); } elseif(is_int($key)) $command['domain:rem']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value); else $command['domain:rem']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $key); } else $command['domain:rem']['domain:ns']['domain:hostAttr']['domain:hostName'] = $ns_rem; } /** * Lock verwijderen */ if(isset($lock) and $lock === false) { if(!isset($command['domain:rem'])) $command['domain:rem'] = array(); $command['domain:rem']['domain:lock'] = null; } /** * Admin updaten */ if(isset($admin)) { if(!isset($command['domain:chg'])) $command['domain:chg'] = array(); $command['domain:chg']['domain:contact'][] = array('_content' => $admin, '_attribute' => array('type' => 'admin')); } /** * Billing updaten */ if(isset($billing)) { if(!isset($command['domain:chg'])) $command['domain:chg'] = array(); $command['domain:chg']['domain:contact'][] = array('_content' => $billing, '_attribute' => array('type' => 'billing')); } /** * Tech updaten */ if(isset($tech)) { if(!isset($command['domain:chg'])) $command['domain:chg'] = array(); $command['domain:chg']['domain:contact'][] = array('_content' => $tech, '_attribute' => array('type' => 'tech')); } /** * Auto renew updaten */ if(isset($autorenew)) { if(!isset($command['domain:chg'])) $command['domain:chg'] = array(); if($autorenew === true) $command['domain:chg']['domain:renew'] = 'y'; elseif($autorenew === false) $command['domain:chg']['domain:renew'] = 'n'; else $command['domain:chg']['domain:renew'] = null; } /** * Template updaten */ if(isset($template)) { if($template == -1) { $command['domain:chg']['domain:template'] = null; } else { $command['domain:chg']['domain:template'] = array('_content' => $template, '_attribute' => array('link' => (@$template_link ? 'true' : 'false'))); } } elseif(isset($template_link) and $template_link == false) { $command['domain:chg']['domain:template'] = array('_attribute' => array('link' => 'false')); } $result = $this->epp->execute( array( 'command' => array( 'update' => array( 'domain:update' => $command ), ), )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } /** * Renew a domain * * @param string The domain to renew * @param timestam The curren expiration date of the domain, accuracy in days * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [domain] => string, The domain name * [crDate] => timestamp, The new expiration date/time of the domain * ) * * If the action fails an Epp_Result_Error object is returned. */ function renew($name, $curExpDate) { $command = array(); $command['domain:name'] = $name; $command['domain:curExpDate'] = gmdate('Y-m-d', $curExpDate); $result = $this->epp->execute( array( 'command' => array( 'renew' => array( 'domain:renew' => $command, ), ), )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); $r->domain = $result->response->resData->{'domain:renData'}->{'domain:name'}; $r->exDate = strtotime($result->response->resData->{'domain:renData'}->{'domain:exDate'}); return $r; } /** * Transfer a domain * * @param string The domain to transfer * @param array Array of name servers * The name servers must be provided in an array: * - If the array key is an int the value is assumed to be the host name of the name server. * array('ns1.example.com', 'ns2.example.com') * - If the array key is not an int it is assumed to be the host name of the name server * and the value the IP adress. * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com' => '4.3.2.1') * - If the value is an array the assumed format is array('host' => 'ns2.example.com', ['addr' => '4.3.2.1']) * - These options may be mixed * array('ns1.example.com' => '1.2.3.4', 'ns2.example.com') * * @param string The registrant handle * @param string The admin contact handle * @param string The billing contact handle * @param string The tech contact handle * @param string The request type, "transfer" or "trade" * @param string optional, The auth code of the domain * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [domain] => string, The domain * [trStatus] => string, The status of the transfer * [reID] => string, The dealer ID that requested the transfer * [reData] => timestamp, The date/time the transfer was requested * [acID] => string, The dealer ID from witch the domain is transferd away, 'unknown' if not an YourSRS dealer * [acDate] => timestamp, The date/time the transfer will expire * ) * * If the action fails an Epp_Result_Error object is returned. */ function transfer($name, $ns, $registrant, $admin, $billing, $tech, $request_type, $auth = null, $template = null, $template_link = null) { $command = array(); $command['domain:name'] = $name; // $command['domain:request'] = array( '_attribute' => array( 'type' => $request_type ) ); if($template !== null){ $command['domain:request']['domain:ns'] = array(); $command['domain:request']['domain:ns']['domain:template'] = array('_content' => $template, '_attribute' => array('link' => ($template_link ? 'true' : 'false'))); } elseif ($ns) { $command['domain:request']['domain:ns'] = array(); $command['domain:request']['domain:ns']['domain:hostAttr'] = array(); if(is_array($ns)) { foreach($ns as $key => $value) { if (!empty($value)){ if(is_array($value)) { if(isset($value['addr'])) $command['domain:request']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host'], 'domain:hostAddr' => $value['addr']); else $command['domain:request']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value['host']); } elseif(is_int($key)) $command['domain:request']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $value); else $command['domain:request']['domain:ns']['domain:hostAttr'][] = array('domain:hostName' => $key, 'domain:hostAddr' => $value); } } } else $command['domain:request']['domain:ns']['domain:hostAttr']['domain:hostName'] = $ns; } $command['domain:request']['domain:registrant'] = $registrant; $command['domain:request']['domain:contact'] = array(); $command['domain:request']['domain:contact'] = array( array( '_attribute' => array( 'type'=> 'admin' ), $admin ), array( '_attribute' => array('type'=> 'billing'), $billing ), array( '_attribute' => array('type'=> 'tech'), $tech ) ); if(isset($auth) and $auth != '') { $command['domain:authInfo'] = array(); $command['domain:authInfo']['domain:pw'] = $auth; } $result = $this->epp->execute( array( 'command' => array( 'transfer' => array( '_attribute' => array( 'op' => 'request' ), 'domain:transfer' => $command ) ), )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); $r->domain = $result->response->resData->{'domain:trnData'}->{'domain:name'}; $r->trStatus = $result->response->resData->{'domain:trnData'}->{'domain:trStatus'}; $r->reID = $result->response->resData->{'domain:trnData'}->{'domain:reID'}; $r->reDate = strtotime($result->response->resData->{'domain:trnData'}->{'domain:reDate'}); $r->acID = $result->response->resData->{'domain:trnData'}->{'domain:acID'}; $r->acDate = strtotime($result->response->resData->{'domain:trnData'}->{'domain:acDate'}); return $r; } /** * Change the registrant of a domain * * @param string The domain do trade * @param string The registrant handle * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function trade($name, $registrant) { $command = array(); $command['domain:name'] = $name; $command['domain:registrant'] = $registrant; $result = $this->epp->execute( array( 'command' => array( 'trade' => array( '_content' => array( 'domain:trade' => $command, ), ), ), )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } /** * Reply to a transfer request * * @param string The domain name * @param string The autorisation code * @param bool true to approve the transfer, false to reject the transfer * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function transferRespond($name, $auth, $approve) { $command = array(); $command['domain:name'] = $name; if(isset($auth)) { $command['domain:authInfo'] = array(); $command['domain:authInfo']['domain:pw'] = $auth; } $result = $this->epp->execute( array( 'command' => array( 'transfer' => array( '_attribute' => array( 'op' => $approve ? 'approve' : 'reject', ), '_content' => array( 'domain:transfer' => $command ), ), ), ), true); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } /** * Cancel transfer * * @param string The domain name * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function transferCancel($name) { $command = array(); $command['domain:name'] = $name; if(isset($auth)) { $command['domain:authInfo'] = array(); //$command['domain:authInfo']['domain:pw'] = $auth; } $result = $this->epp->execute( array( 'command' => array( 'transfer' => array( '_attribute' => array( 'op' => 'cancel', ), 'domain:transfer' => array( 'domain:name' => $name ), ), ), )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } /** * Delete a domain * * @param string The domain to delete * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function delete($name) { $result = $this->epp->execute( array( 'command' => array( 'delete' => array( 'domain:delete' => array( 'domain:name' => $name, ), ), ), )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } } /** * EPP Contact class, this class provides contact actions * */ class Epp_Contact { private $epp; /** * Constructor * * @param Epp_Base Epp_Base object used to execute commands * @return Epp_Contact */ function Epp_Contact($epp) { $this->epp = $epp; } /** * Check if a contact handle exists * * @param string|array Contact handle(s) to check * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [avail] => bool, optional, Only if 1 handle is checked, Availability of the contact handle * [**handle**] => bool, For each checked handle a element with avaiability of the contact handle is created * ) * * If the action fails an Epp_Result_Error object is returned. */ function check($id) { $result = $this->epp->execute( array( 'command' => array( 'check' => array( 'contact:check' => array( 'contact:id' => $id, ), ), ), )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); if(is_array($result->response->resData->{'contact:chkData'}->{'contact:cd'})) { foreach($result->response->resData->{'contact:chkData'}->{'contact:cd'} as $c) { $contact = $c->{'contact:id'}->_content; $r->$contact = $c->{'contact:id'}->_attribute['avail']; } } else { $contact = $result->response->resData->{'contact:chkData'}->{'contact:cd'}->{'contact:id'}->_content; $r->$contact = $result->response->resData->{'contact:chkData'}->{'contact:cd'}->{'contact:id'}->_attribute['avail']; $r->avail = $result->response->resData->{'contact:chkData'}->{'contact:cd'}->{'contact:id'}->_attribute['avail']; } return $r; } /** * Query contact details * * @param string Contact handle to query * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [id] => string, The contact handle * [roid] => string, The repository object identifier * [status] => string|array, The status of the contact, if the contact has more than 1 status an array is created * [name] => string, The person name * [org] => string, optional, The orginisation * [street] => Array * ( * [0] => string, Street line * [1] => string, optional, Street line * [2] => string, optional, Street line * ) * * [city] => string, City * [sp] => string, optional, State or province * [pc] => string, Postal code * [cc] => string, Country code, ISO3166 format * [voice] => string, phone number, E164a format * [fax] => string, optional, Fax number, E164a format * [email] => string, E-mail address * [gender] => string, optional, Gender, male|female * [lang] => string, optional, Preferred language * [clID] => string, ID of the dealer that administrates the contact * [crID] => string, ID of the dealer that created the contact * [crDate] => timestamp, Creation date/time of the contact * [upDate] => timestamp, optional, Date/time of last update on the contact * ) * * If the action fails an Epp_Result_Error object is returned. */ function info($id) { $result = $this->epp->execute( array( 'command' => array( 'info' => array( 'contact:info' => array( 'contact:id' => $id, ), ), ), )); if(YourSRS::isError($result)) { return $result; } $i = &$result->response->resData->{'contact:infData'}; $contact = $result->stdClass(); $contact->id = $i->{'contact:id'}; $contact->roid = $i->{'contact:roid'}; if(is_array($i->{'contact:status'})) { $s = array(); foreach($i->{'contact:status'} as $status) array_push($s, $status->_attribute['s']); $contact->status = $s; } else $contact->status = $i->{'contact:status'}->_attribute['s']; $contact->name = $i->{'contact:postalInfo'}->{'contact:name'}; if(isset($i->{'contact:postalInfo'}->{'contact:org'})) $contact->org = $i->{'contact:postalInfo'}->{'contact:org'}; if(is_array($i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:street'})) $contact->street = $i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:street'}; else $contact->street = array($i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:street'}); $contact->city = $i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:city'}; if(isset($i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:sp'})) $contact->sp = $i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:sp'}; $contact->pc = $i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:pc'}; $contact->cc = $i->{'contact:postalInfo'}->{'contact:addr'}->{'contact:cc'}; $contact->voice = $i->{'contact:voice'}; if(isset($i->{'contact:fax'})) $contact->fax = $i->{'contact:fax'}; $contact->email = $i->{'contact:email'}; if (isset($i->{'contact:gender'})) $contact->gender = $i->{'contact:gender'}; if (isset($i->{'contact:lang'})) $contact->lang = $i->{'contact:lang'}; $contact->clID = $i->{'contact:clID'}; $contact->crDate = strtotime($i->{'contact:crDate'}); if(isset($i->{'contact:upDate'})) $contact->upDate = strtotime($i->{'contact:upDate'}); return $contact; } /** * Create a contact * * @param string Contact handle, currently not used, email address is used as handle * @param string The person name * @param String ignored if null, The orginisation * @param string|array Street line(s) * @param string City * @param string ignored if null, State of province * @param string Postal code * @param string Country code, ISO3166 format * @param string Email address * @param string Telephone number, E164a format * @param string optional, ignored if null, Fax number, E164a format * @param string optional, ignored if null, Preferred language * @param string optional, ignored if null, Gender, male|female * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * [id] => string, The contact handle * [crDate] => timestamp, Creation date/time of the contact * ) * * If the action fails an Epp_Result_Error object is returned. */ function create($id, $email, $name, $org, $street, $city, $sp, $pc, $cc, $voice, $fax = null, $gender = null, $lang = null) { $command = array(); $command['contact:id'] = $id; $command['contact:postalInfo'] = array(); $command['contact:postalInfo']['_attribute'] = array('type' => 'int'); $command['contact:postalInfo']['contact:name'] = $name; if(isset($org)) $command['contact:postalInfo']['contact:org'] = $org; $command['contact:postalInfo']['contact:addr'] = array(); if(is_array($street)) { foreach(array_keys($street) as $i) { if(!isset($street[$i]) or $street[$i] === '') { unset($street[$i]); } } } $command['contact:postalInfo']['contact:addr']['contact:street'] = $street; $command['contact:postalInfo']['contact:addr']['contact:city'] = $city; if(isset($sp)) $command['contact:postalInfo']['contact:addr']['contact:sp'] = $sp; $command['contact:postalInfo']['contact:addr']['contact:pc'] = $pc; $command['contact:postalInfo']['contact:addr']['contact:cc'] = $cc; $command['contact:voice'] = $voice; if(isset($fax)) $command['contact:fax'] = $fax; $command['contact:email'] = $email; if(isset($gender) or isset($lang)) { if(isset($gender)) $command['contact:gender'] = $gender; if(isset($lang)) $command['contact:lang'] = $lang; } $execute = array( 'create' => array( 'contact:create' => $command, ), ); $result = $this->epp->execute( array( 'command' => $execute, )); if(YourSRS::isError($result)) { return $result; } $r = $result->stdClass(); $r->id = $result->response->resData->{'contact:creData'}->{'contact:id'}; $r->crDate = strtotime($result->response->resData->{'contact:creData'}->{'contact:crDate'}); return $r; } /** * Update contact details * * If you want to delete an optional element from the contact details (org, sp, fax, lang, gender) * you can use false as value. * * If one of the elements street, city, sp, pc or cc is provided all of these elements mus be provided * * @param string Contact handle to update * @param string optional, ignored if null, The person name * @param String optional, ignored if null, The orginisation * @param string|array optional, ignored if null, Street line(s) * @param string optional, ignored if null, City * @param string optional, ignored if null, State of province * @param string optional, ignored if null, Postal code * @param string optional, ignored if null, Country code, ISO3166 format * @param string optional, ignored if null, Email address * @param string optional, ignored if null, Telephone number, E164a format * @param string optional, ignored if null, Fax number, E164a format * @param string optional, ignored if null, Preferred language * @param string optional, ignored if null, Gender, male|female * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function update($id = null, $name = null, $org = null, $street = null, $city = null, $sp = null, $pc = null, $cc = null, $email = null, $voice = null, $fax = null, $lang = null, $gender = null) { if(isset($street)) { if(is_array($street)) { foreach(array_keys($street) as $i) { if(!isset($street[$i]) or $street[$i] === '') { unset($street[$i]); } } } if(!count($street)) { unset($street); } } // controle of er tenminste 1 verandering is // $data_array = array('name', 'org', 'street', 'city', 'sp', 'pc', 'cc', 'email', 'voice', 'fax', 'lang', 'gender'); $continue = false; foreach ($data_array as $key){ if (isset($$key) && $key != null) $continue = true; } if ($continue) { $command = array(); if( isset($name) or isset($org) or isset($street) or isset($city) or isset($sp) or isset($pc) or isset($cc) ) { $command['contact:postalInfo'] = array(); $command['contact:postalInfo']['_attribute'] = array('type' => 'int'); if(isset($name)) $command['contact:postalInfo']['contact:name'] = $name; if(isset($org)) $command['contact:postalInfo']['contact:org'] = $org; if(isset($street) or isset($city) or isset($sp) or isset($pc) or isset($cc) ) { $command['contact:postalInfo']['contact:addr'] = array(); $command['contact:postalInfo']['contact:addr']['contact:street'] = $street; $command['contact:postalInfo']['contact:addr']['contact:city'] = $city; if(isset($sp)) $command['contact:postalInfo']['contact:addr']['contact:sp'] = $sp; $command['contact:postalInfo']['contact:addr']['contact:pc'] = $pc; $command['contact:postalInfo']['contact:addr']['contact:cc'] = $cc; } } if(isset($voice)) $command['contact:voice'] = $voice; if(isset($fax)) $command['contact:fax'] = $fax; if(isset($email)) $command['contact:email'] = $email; if(isset($gender)) $command['contact:gender'] = $gender; if(isset($lang)) $command['contact:lang'] = $lang; $execute = array( 'update' => array( 'contact:update' => array( 'contact:id' => $id, 'contact:chg' => $command, ), ), ); $result = $this->epp->execute( array( 'command' => $execute, )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } } /** * Delete a contact * * @param string Contact handle to delete * * @return stdObject|Epp_Result_Error * The result is a stdClass object with the folowing elements: * stdClass Object * ( * [code] => int, Result code * [msg] => string, Result code message * [svTRID] => string, Server request ID * ) * * If the action fails an Epp_Result_Error object is returned. */ function delete($id) { $result = $this->epp->execute( array( 'command' => array( 'delete' => array( 'contact:delete' => array( 'contact:id' => $id, ), ), ), )); if(YourSRS::isError($result)) { return $result; } return $result->stdClass(); } } /** * Object used to retrieve data from an EPP response * */ class Epp_Result { /** * Was the transaction successfull? * * @var bool */ private $_success = false; /** * The result code of the transaction * * @var int */ private $_code = null; /** * Error messages * * @var array */ private $_error = null; /** * The svTRID of the transaction * * @var string */ private $_svTRID = false; /** * The clTRID of the transaction * * @var unknown_type */ private $_clTRID = false; /** * After the object is created and the xml data is inserted this function is used to set the object paramentes * */ function init() { if(isset($this->response)) { if(isset($this->response->result)){ if(isset($this->response->result->_attribute)){ if(is_array($this->response->result->_attribute)) { if(isset($this->response->result->_attribute['code'])) { $this->_code = $this->response->result->_attribute['code']; if($this->response->result->_attribute['code'] == 1000 or $this->response->result->_attribute['code'] == 1001 or $this->response->result->_attribute['code'] == 1300 or $this->response->result->_attribute['code'] == 1301 or $this->response->result->_attribute['code'] == 1500) { $this->_success = true; } } if(is_array($this->response->result->msg)) { $errors = $this->response->result->msg; unset ($this->response->result->msg); $this->_msg = array_shift($errors); $this->_error = $errors; } else { $this->_msg = $this->response->result->msg; } } } } if(isset($this->response->trID)) { if(isset($this->response->trID->svTRID)) { $this->_svTRID = $this->response->trID->svTRID; } if(isset($this->response->trID->clTRID)) { $this->_clTRID = $this->response->trID->clTRID; } } } } /** * Was the transaction successfull * * @return bool */ function isSuccess() { return $this->_success; } /** * Get the EPP result code * * @return int */ function getCode() { return $this->_code; } /** * Get the error object * * @return Epp_Result_Error */ function getError() { return new Epp_Result_Error($this); } /** * Get the text version of the EPP result code * * @return unknown */ function getMsg() { return $this->_msg; } /** * Get the svTRID of the transaction * * @return string */ function getSvTRID() { return $this->_svTRID; } /** * Get the clTRID of the transaction * * @return string */ function getClTRID() { return $this->_clTRID; } /** * Get the error message(s) * * @return string|array */ function getErr() { return $this->_error; } /** * Get the base stdClass of the transaction * * @return unknown */ function stdClass() { $r = new stdClass(); $r->code = $this->getCode(); $r->msg = $this->getMsg(); $r->svTRID = $this->getSvTRID(); if($this->getClTRID()) $r->clTRID = $this->getClTRID(); return $r; } } /** * Class to store and display a failed transaction * */ class Epp_Result_Error { /** * The EPP result code * * @var int */ public $code; /** * The EPP result message * * @var string */ public $msg; /** * The error message(s) * * @var string|array */ public $error; /** * The svTRID of the transaction * * @var string */ public $svTRID; /** * The clTRID of the transaction * * @var string */ public $clTRID; /** * Constructor * * @param Epp_Result|array Data used to construct object, can be * - An Epp_Result object * - An array with the elements: * Array * ( * [code] => int, Epp Result code * [msg] => string, Epp Result meaage * [error] => string|array, optional, Error message(s) * [svTRID] => string, optional, Server request ID * [clTRID] => string, optional, Client request ID * ) * @return Epp_Result_Error */ function Epp_Result_Error($in) { if(is_object($in) and is_a($in, 'Epp_Result')) { $this->code = $in->getCode(); $this->msg = $in->getMsg(); if($in->getErr()) $this->error = $in->getErr(); if($in->getSvTRID()) $this->svTRID = $in->getSvTRID(); if($in->getClTRID()) $this->clTRID = $in->getClTRID(); } else { $this->code = $in['code']; $this->msg = $in['msg']; if(isset($in['error'])) $this->error = $in['error']; if(isset($in['svTRID'])) $this->svTRID = $in['svTRID']; if(isset($in['clTRID'])) $this->svTRID = $in['clTRID']; } } /** * Get the error in diffrent format's * * @param string Format * @return mixed Depending on the format * - html : A string with html code discribing the error */ public function Error($type) { if(!isset($this->code)) { return 'FATAL ERROR'; } switch ($type) { case 'html': $r = '** '.htmlentities($this->msg).' ('.$this->code; if(isset($this->svTRID)) $r .= '/'.htmlentities($this->svTRID); $r .= ') **'; if(isset($this->error)) { if(is_array($this->error)) { foreach($this->error as $error) $r .= '
'.htmlentities($error); } else { $r .= '
'.htmlentities($this->error); } } return $r; break; case 'stdObject': $r = new stdClass(); $r->code = $this->code; $r->msg = $this->msg; if(isset($this->error)) $r->error = $this->error; if(isset($this->svTRID)) $r->svTRID = $this->svTRID; if(isset($this->clTRID)) $r->clTRID = $this->clTRID; return $r; case 'text': $r = '** '.$this->msg.' ('.$this->code; if(isset($this->svTRID)) $r .= '/'.$this->svTRID; $r .= ') **'; if(isset($this->error)) { if(is_array($this->error)) { foreach($this->error as $error) $r .= "\n".htmlentities($error); } else { $r .= "\n".htmlentities($this->error); } } return $r; break; default: return 'FATAL ERROR'; break; } } } ?>