From df4a5e9ecc9e7d46b793893cd66c627981700e9b Mon Sep 17 00:00:00 2001 From: Lee Reichardt Date: Thu, 25 Mar 2021 15:28:13 +1300 Subject: [PATCH 1/6] RS Build of OpenSRS package --- .gitignore | 1 + README.md | 11 ---- .../domains/bulkchange/SimpleTransfer.php | 64 +++++++++++++++++++ opensrs/domains/bulkchange/SimpleTransfer.php | 50 +++++++++++++++ 4 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 opensrs/backwardcompatibility/dataconversion/domains/bulkchange/SimpleTransfer.php create mode 100644 opensrs/domains/bulkchange/SimpleTransfer.php diff --git a/.gitignore b/.gitignore index 38b9d733..00f728c7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tags /vendor/ composer.lock .vagrant +.DS_Store diff --git a/README.md b/README.md index b974b650..defa8b28 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,6 @@ of the OpenSRS API. Not only does it give a starting point in developing an application to allow for quick integration, but also incorporates new communication markup languages such as JSON and YAML. -## Support -Our support team will be able to help with general connectivity issues outlined -in: (http://domains.opensrs.guide/docs/troubleshooting) - -If you find a bug in the sample provided with this toolkit, please contact -OpenSRS Support with the XML output and response. We will not, however, be able -to troubleshoot PHP configuration with your web host nor additional PHP code -that you developed. Should you require assistance on those matters, please work -with a website developer. - Requirements ------------ @@ -101,4 +91,3 @@ var_dump($osrsHandler); [OpenSRS API Documentation Page](http://www.opensrs.com/site/resources/documentation/api) [OpenSRS/osrs-toolkit-php Wiki](https://github.com/OpenSRS/osrs-toolkit-php/wiki) - diff --git a/opensrs/backwardcompatibility/dataconversion/domains/bulkchange/SimpleTransfer.php b/opensrs/backwardcompatibility/dataconversion/domains/bulkchange/SimpleTransfer.php new file mode 100644 index 00000000..5859b930 --- /dev/null +++ b/opensrs/backwardcompatibility/dataconversion/domains/bulkchange/SimpleTransfer.php @@ -0,0 +1,64 @@ + 'data->cookie' + // this will map ->data->cookie in the + // original object to ->cookie in the + // new format + // + // example 2: + // ['attributes']['domain'] = 'data->domain' + // this will map ->data->domain in the original + // to ->attributes->domain in the new format + protected $newStructure = array( + 'attributes' => array( + 'domain_list' => 'data->domain_list', + 'domain_name' => 'data->domain_name', + 'auth_info' => 'data->auth_info', + + 'reg_domain' => 'data->reg_domain', + 'reg_username' => 'data->reg_username', + 'reg_password' => 'data->reg_password', + + 'nameserver_list' => 'data->nameserver_list', + 'dns_template' => 'data->dns_template' + ) + ); + + public function convertDataObject($dataObject, $newStructure = null) + { + $p = new parent(); + + if (is_null($newStructure)) { + $newStructure = $this->newStructure; + } + + $newDataObject = $p->convertDataObject($dataObject, $newStructure); + + if(isset($newDataObject->attributes->domain_name)){ + if (!is_array($newDataObject->attributes->domain_list)) { + $newDataObject->attributes->domain_list = array(//domain list can't be empty, so fill it with the single domain we have. + array( + 'domain_name' => $newDataObject->attributes->domain_name, + 'auth_info' => $newDataObject->attributes->auth_info + ) + ); + } + } + + return $newDataObject; + } +} diff --git a/opensrs/domains/bulkchange/SimpleTransfer.php b/opensrs/domains/bulkchange/SimpleTransfer.php new file mode 100644 index 00000000..5b3ca720 --- /dev/null +++ b/opensrs/domains/bulkchange/SimpleTransfer.php @@ -0,0 +1,50 @@ + array( + 'domain_list', + 'domain_name', + 'auth_info', + ), + ); + + public function __construct($formatString, $dataObject, $returnFullResponse = true) + { + parent::__construct(); + + $this->_formatHolder = $formatString; + + if(empty($dataObject->attributes->domain_list)){//if it's empty, lets try populate with the individual domain so it works. + $dataObject->attributes->domain_list = array( + array( + 'domain_name' => $dataObject->attributes->domain_name, + 'auth_info' => $dataObject->attributes->auth_info + ) + ); + } + + $this->_validateObject($dataObject); + + $this->send($dataObject, $returnFullResponse); + } + + public function __destruct() + { + parent::__destruct(); + } +} From ddfffa9f1d20a85f72333c2c99eeb7bb1057c390 Mon Sep 17 00:00:00 2001 From: Lee Reichardt Date: Fri, 2 Jul 2021 12:16:31 +1200 Subject: [PATCH 2/6] Added in verify end point for AU domains --- opensrs/RequestFactory.php | 7 +- opensrs/domains/verify/VerifyTldData.php | 39 +++++++++++ .../domains/verify/VerifyTldDataTest.php | 64 +++++++++++++++++++ 3 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 opensrs/domains/verify/VerifyTldData.php create mode 100644 tests/unit/opensrs/domains/verify/VerifyTldDataTest.php diff --git a/opensrs/RequestFactory.php b/opensrs/RequestFactory.php index f4984eb8..f6ff7d08 100644 --- a/opensrs/RequestFactory.php +++ b/opensrs/RequestFactory.php @@ -87,6 +87,7 @@ class RequestFactory 'persquery' => 'domains\personalnames\PersonalNamesQuery', 'perssuregister' => 'domains\personalnames\PersonalNamesSURegister', 'persupdate' => 'domains\personalnames\PersonalNamesUpdate', + 'verifytlddata' => 'domains\verify\VerifyTldData', 'pubcreate' => 'publishing\Create', 'pubdelete' => 'publishing\Delete', 'pubdisable' => 'publishing\Disable', @@ -132,7 +133,7 @@ class RequestFactory 'mailsetdomaindisabledstatus' => 'mail\SetDomainDisabledStatus', 'mailsetdomainmailboxlimits' => 'mail\SetDomainMailboxLimits', 'accountgetbalance' => 'account\GetBalance' - ); + ); public static function build($func, $type, $dataObject) { @@ -144,11 +145,11 @@ public static function build($func, $type, $dataObject) $route = self::$RequestRoutes[$routeKey]; } - $class = '\opensrs\\'.$route; + $class = '\opensrs\\' . $route; if (class_exists($class)) { if (!isset($dataObject->attributes)) { - $dataconversionRoute = '\opensrs\backwardcompatibility\dataconversion\\'.$route; + $dataconversionRoute = '\opensrs\backwardcompatibility\dataconversion\\' . $route; if (class_exists($dataconversionRoute)) { $dc = new $dataconversionRoute(); diff --git a/opensrs/domains/verify/VerifyTldData.php b/opensrs/domains/verify/VerifyTldData.php new file mode 100644 index 00000000..3d66234e --- /dev/null +++ b/opensrs/domains/verify/VerifyTldData.php @@ -0,0 +1,39 @@ + array( + 'data', + ), + ); + + public function __construct($formatString, $dataObject, $returnFullResponse = true) + { + parent::__construct(); + + $this->_formatHolder = $formatString; + + $this->_validateObject($dataObject); + + $this->send($dataObject, $returnFullResponse); + } + + public function __destruct() + { + parent::__destruct(); + } +} diff --git a/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php b/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php new file mode 100644 index 00000000..78d7c485 --- /dev/null +++ b/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php @@ -0,0 +1,64 @@ + array( + 'type' => 'tld_data', + ), + ); + + /** + * Valid submission should complete with no + * exception thrown. + * + * + * @group validsubmission + */ + public function testValidSubmission() + { + $data = json_decode(json_encode($this->validSubmission)); + + $data->attributes->domain = 'phptest' . time() . '.com'; + $data->attributes->type = 'tld_data'; + $data->attributes->as_subreseller = 'katkinson'; + + $ns = new GetDomain('array', $data); + + $this->assertTrue($ns instanceof GetDomain); + } + + /** + * Valid submission should complete with no + * exception thrown. + * + * + * @group validsubmission + */ + public function testValidLiveSubmission() + { + $data = array( + 'func' => 'lookupGetDomain', + + 'attributes' => array( + 'domain' => 'phptest' . time() . '.com', + 'type' => 'all_info', + ), + ); + + $request = new Request(); + $ns = $request->process('array', $data); + + $this->assertTrue($ns instanceof GetDomain); + $this->assertTrue($ns->resultRaw['is_success'] == 1); + } +} From dc33279a3ff67d26509e957c5eb2d7d1cd2930bc Mon Sep 17 00:00:00 2001 From: Lee Reichardt Date: Fri, 2 Jul 2021 13:24:46 +1200 Subject: [PATCH 3/6] Reset readme, and removed test file --- README.md | 10 +++ .../domains/verify/VerifyTldDataTest.php | 64 ------------------- 2 files changed, 10 insertions(+), 64 deletions(-) delete mode 100644 tests/unit/opensrs/domains/verify/VerifyTldDataTest.php diff --git a/README.md b/README.md index defa8b28..905b654e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,16 @@ of the OpenSRS API. Not only does it give a starting point in developing an application to allow for quick integration, but also incorporates new communication markup languages such as JSON and YAML. +## Support +Our support team will be able to help with general connectivity issues outlined +in: (http://domains.opensrs.guide/docs/troubleshooting) + +If you find a bug in the sample provided with this toolkit, please contact +OpenSRS Support with the XML output and response. We will not, however, be able +to troubleshoot PHP configuration with your web host nor additional PHP code +that you developed. Should you require assistance on those matters, please work +with a website developer. + Requirements ------------ diff --git a/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php b/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php deleted file mode 100644 index 78d7c485..00000000 --- a/tests/unit/opensrs/domains/verify/VerifyTldDataTest.php +++ /dev/null @@ -1,64 +0,0 @@ - array( - 'type' => 'tld_data', - ), - ); - - /** - * Valid submission should complete with no - * exception thrown. - * - * - * @group validsubmission - */ - public function testValidSubmission() - { - $data = json_decode(json_encode($this->validSubmission)); - - $data->attributes->domain = 'phptest' . time() . '.com'; - $data->attributes->type = 'tld_data'; - $data->attributes->as_subreseller = 'katkinson'; - - $ns = new GetDomain('array', $data); - - $this->assertTrue($ns instanceof GetDomain); - } - - /** - * Valid submission should complete with no - * exception thrown. - * - * - * @group validsubmission - */ - public function testValidLiveSubmission() - { - $data = array( - 'func' => 'lookupGetDomain', - - 'attributes' => array( - 'domain' => 'phptest' . time() . '.com', - 'type' => 'all_info', - ), - ); - - $request = new Request(); - $ns = $request->process('array', $data); - - $this->assertTrue($ns instanceof GetDomain); - $this->assertTrue($ns->resultRaw['is_success'] == 1); - } -} From 553dff7affad026e3ac587b1ad8edfe1f5502a4f Mon Sep 17 00:00:00 2001 From: Lee Reichardt Date: Tue, 6 Jul 2021 10:19:51 +1200 Subject: [PATCH 4/6] Fixed php7.4 deprecation notices Deprecated: Array and string offset access syntax with curly braces is deprecated in opensrs/osrs-toolkit-php/opensrs/Base.php on line 267 Deprecated: Array and string offset access syntax with curly braces is deprecated in opensrs/osrs-toolkit-php/opensrs/Base.php on line 267 Deprecated: Array and string offset access syntax with curly braces is deprecated in opensrs/osrs-toolkit-php/opensrs/Base.php on line 271 --- opensrs/Base.php | 66 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/opensrs/Base.php b/opensrs/Base.php index 4d3a2168..a7453300 100644 --- a/opensrs/Base.php +++ b/opensrs/Base.php @@ -35,7 +35,7 @@ class Base * openSRS_base object constructor. * * Closes an existing socket connection, if we have one - * + * * @since 3.1 */ public function __construct() @@ -66,7 +66,7 @@ public function __destruct() private function _verifySystemProperties() { if (!function_exists('version_compare') || version_compare('4.3', phpversion(), '>=')) { - $error_message = 'PHP version must be v4.3+ (current version is '.phpversion().') to use "SSL" encryption'; + $error_message = 'PHP version must be v4.3+ (current version is ' . phpversion() . ') to use "SSL" encryption'; throw new Exception($error_message); } elseif (!function_exists('openssl_open')) { $error_message = 'PHP must be compiled using --with-openssl to use "SSL" encryption'; @@ -79,15 +79,15 @@ private function _verifySystemProperties() * * @param string $request Raw XML request * - * @return string $data Raw XML response - * + * @return string $data Raw XML response + * * @since 3.1 */ public function send_cmd($request) { // make or get the socket filehandle if (!$this->init_socket()) { - throw new Exception('oSRS Error - Unable to establish socket: ('.$this->_socketErrorNum.') '.$this->_socketErrorMsg); + throw new Exception('oSRS Error - Unable to establish socket: (' . $this->_socketErrorNum . ') ' . $this->_socketErrorMsg); } $this->send_data($request); @@ -106,7 +106,7 @@ public function send_cmd($request) * Method to initialize a socket connection to the OpenSRS server. * * @return bool True if connected - * + * * @since 3.1 */ private function init_socket() @@ -114,7 +114,7 @@ private function init_socket() if ($this->is_connected()) { return true; } - $this->_socket = fsockopen(CRYPT_TYPE.'://'.OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout); + $this->_socket = fsockopen(CRYPT_TYPE . '://' . OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout); if (!$this->_socket) { return false; } else { @@ -126,7 +126,7 @@ private function init_socket() * Method to check if a socket connection exists. * * @return bool True if connected - * + * * @since 3.4 */ public function is_connected() @@ -136,7 +136,7 @@ public function is_connected() /** * Method to close the socket connection. - * + * * @since 3.4 */ private function close_socket() @@ -148,7 +148,7 @@ private function close_socket() /** * Method to read data from the buffer stream. - * + * * @return string XML response * * @since 3.1 @@ -163,7 +163,7 @@ private function read_data() $data = $buf; } if (!empty($this->osrs_debug)) { - print_r('
'.htmlentities($data).'
'); + print_r('
' . htmlentities($data) . '
'); } return $data; @@ -171,17 +171,17 @@ private function read_data() /** * Method to send data. - * + * * @param string $message XML request * - * @return string $message XML response + * @return string $message XML response * * @since 3.1 */ private function send_data($message) { if (!empty($this->osrs_debug)) { - print_r('
'.htmlentities($message).'
'); + print_r('
' . htmlentities($message) . '
'); } return $this->writeData($this->_socket, $message); @@ -198,12 +198,12 @@ private function writeData(&$fh, $msg) $header = ''; $len = strlen($msg); - $signature = md5(md5($msg.OSRS_KEY).OSRS_KEY); - $header .= 'POST / HTTP/1.0'.CRLF; - $header .= 'Content-Type: text/xml'.CRLF; - $header .= 'X-Username: '.OSRS_USERNAME.CRLF; - $header .= 'X-Signature: '.$signature.CRLF; - $header .= 'Content-Length: '.$len.CRLF.CRLF; + $signature = md5(md5($msg . OSRS_KEY) . OSRS_KEY); + $header .= 'POST / HTTP/1.0' . CRLF; + $header .= 'Content-Type: text/xml' . CRLF; + $header .= 'X-Username: ' . OSRS_USERNAME . CRLF; + $header .= 'X-Signature: ' . $signature . CRLF; + $header .= 'Content-Length: ' . $len . CRLF . CRLF; fputs($fh, $header); fputs($fh, $msg, $len); @@ -212,8 +212,8 @@ private function writeData(&$fh, $msg) /** * Reads header data. * - * @param int socket handle - * @param int timeout for read + * @param int socket handle + * @param int timeout for read * * @return hash hash containing header key/value pairs */ @@ -253,8 +253,8 @@ private function readHeader($fh, $timeout = 5) /** * Reads data from a socket. * - * @param int socket handle - * @param int timeout for read + * @param int socket handle + * @param int timeout for read * * @return mixed buffer with data, or an error for a short read */ @@ -264,11 +264,11 @@ private function readData(&$fh, $timeout = 5) /* PHP doesn't have timeout for fread ... we just set the timeout for the socket */ socket_set_timeout($fh, $timeout); $header = $this->readHeader($fh, $timeout); - if (!$header || !isset($header{'content-length'}) || (empty($header{'content-length'}))) { + if (!$header || !isset($header['content-length']) || (empty($header['content-length']))) { throw new Exception('oSRS Error - UNEXPECTED ERROR: No Content-Length header provided! Please make sure IP is whitelisted in RWI.'); } - $len = (int) $header{'content-length'}; + $len = (int)$header['content-length']; $line = ''; while (strlen($line) < $len) { $line .= fread($fh, $len); @@ -302,13 +302,13 @@ public function convertArray2Formatted($type = '', $data = '') } /** - * Get configured tlds for domain call - * Will use (in order of preference)... - * 1. selected tlds - * 2. supplied default tlds + * Get configured tlds for domain call + * Will use (in order of preference)... + * 1. selected tlds + * 2. supplied default tlds * 3. included default tlds. - * - * @return array tlds + * + * @return array tlds */ public function getConfiguredTlds() { @@ -345,7 +345,7 @@ public function setDataObject($format, $dataObject) /** * Does the dataObject have a domain set? - * + * * @return bool */ public function hasDomain() From aee8a3a21081b5637e252cd8c8e7ccc715d7fe7d Mon Sep 17 00:00:00 2001 From: Andy Richdale Date: Thu, 31 Mar 2022 11:53:20 +1300 Subject: [PATCH 5/6] Set DNSSEC endpoint --- opensrs/RequestFactory.php | 1 + opensrs/domains/dnssec/DnsSecSet.php | 40 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 opensrs/domains/dnssec/DnsSecSet.php diff --git a/opensrs/RequestFactory.php b/opensrs/RequestFactory.php index f6ff7d08..d0edcdb3 100644 --- a/opensrs/RequestFactory.php +++ b/opensrs/RequestFactory.php @@ -88,6 +88,7 @@ class RequestFactory 'perssuregister' => 'domains\personalnames\PersonalNamesSURegister', 'persupdate' => 'domains\personalnames\PersonalNamesUpdate', 'verifytlddata' => 'domains\verify\VerifyTldData', + 'dnssecset' => 'domains\dnssec\DnsSecSet', 'pubcreate' => 'publishing\Create', 'pubdelete' => 'publishing\Delete', 'pubdisable' => 'publishing\Disable', diff --git a/opensrs/domains/dnssec/DnsSecSet.php b/opensrs/domains/dnssec/DnsSecSet.php new file mode 100644 index 00000000..9f931e5b --- /dev/null +++ b/opensrs/domains/dnssec/DnsSecSet.php @@ -0,0 +1,40 @@ + array( + 'dnssec', + ), + 'domain' + ); + + public function __construct($formatString, $dataObject, $returnFullResponse = true) + { + parent::__construct(); + + $this->_formatHolder = $formatString; + + $this->_validateObject($dataObject); + + $this->send($dataObject, $returnFullResponse); + } + + public function __destruct() + { + parent::__destruct(); + } +} From 57bb2d5c2e80ba1a9341d42899c11822a6b811f4 Mon Sep 17 00:00:00 2001 From: Andy Richdale Date: Mon, 4 Apr 2022 14:11:57 +1200 Subject: [PATCH 6/6] Add modifyXML function so commands can do custom modifications, dnssec modifications --- opensrs/Base.php | 12 ++++++++++++ opensrs/domains/dnssec/DnsSecSet.php | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/opensrs/Base.php b/opensrs/Base.php index a7453300..464ba1c3 100644 --- a/opensrs/Base.php +++ b/opensrs/Base.php @@ -390,6 +390,8 @@ public function send($dataObject, $returnFullResponse = true) // Flip Array to XML $xmlCMD = $this->_opsHandler->encode(json_decode(json_encode($dataObject), true)); + $xmlCMD = $this->modifyXml($xmlCMD); + // Send XML $XMLresult = $this->send_cmd($xmlCMD); @@ -496,4 +498,14 @@ public function isValidField($value) return $isValid; } + + /** + * Use this to customise the XML sent to the API + * + * @param string $xml + * @return string + */ + protected function modifyXml($xml) { + return $xml; + } } diff --git a/opensrs/domains/dnssec/DnsSecSet.php b/opensrs/domains/dnssec/DnsSecSet.php index 9f931e5b..1f24e4ff 100644 --- a/opensrs/domains/dnssec/DnsSecSet.php +++ b/opensrs/domains/dnssec/DnsSecSet.php @@ -22,8 +22,15 @@ class DnsSecSet extends Base 'domain' ); + const DNSSEC_EMPTY_ARRAY = 'emptyarray'; + public function __construct($formatString, $dataObject, $returnFullResponse = true) { + if (empty($dataObject->attributes->dnssec)) { + // We need to set this special "emptyarray" here so it can be encoded properly, it will be removed later + $dataObject->attributes->dnssec = [self::DNSSEC_EMPTY_ARRAY]; + } + parent::__construct(); $this->_formatHolder = $formatString; @@ -37,4 +44,12 @@ public function __destruct() { parent::__destruct(); } + + /** + * @inheritDoc + */ + protected function modifyXml($xml) { + // Remove special "emptyarray" here + return str_replace('' . self::DNSSEC_EMPTY_ARRAY. '', '', $xml); + } }