diff --git a/modules/registrars/cozaepp/cozaepp.php b/modules/registrars/cozaepp/cozaepp.php index 372ab9f75f0fdb1a43aa4cfec43f42eeac32d314..5fb4bf5f0a2e41b742dffe7a24b64445bfa7bfe6 100644 --- a/modules/registrars/cozaepp/cozaepp.php +++ b/modules/registrars/cozaepp/cozaepp.php @@ -44,8 +44,6 @@ function cozaepp_getConfigArray() { $configarray = array( "Username" => array( "Type" => "text", "Size" => "20", "Description" => "Enter your username here" ), "Password" => array( "Type" => "password", "Size" => "20", "Description" => "Enter your password here" ), - "Server" => array( "Type" => "text", "Size" => "20", "Description" => "Enter EPP Server Address" ), - "Port" => array( "Type" => "text", "Size" => "20", "Description" => "Enter EPP Server Port" ), "SSL" => array( "Type" => "yesno" ), "Certificate" => array( "Type" => "text", "Description" => "Path of certificate .pem" ) ); @@ -72,7 +70,7 @@ function cozaepp_GetNameservers($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Get list of nameservers for domain $result = $client->request($xml = ' @@ -168,7 +166,7 @@ function cozaepp_SaveNameservers($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab list of current nameservers $request = $client->request( $xml = ' @@ -284,13 +282,13 @@ function cozaepp_SaveRegistrarLock($params) { } # Function to retrieve an available contact id -function _cozaepp_CheckContact($prehash) { - $prehash = $prehash . time() . rand(0, 1000000); +function _cozaepp_CheckContact($domain) { + $prehash = $domain . time() . rand(0, 1000000); $contactid = substr(md5($prehash), 0,15); # Get client instance and check for available contact id try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); $contactAvailable = 0; $count = 0; @@ -425,7 +423,7 @@ function cozaepp_RegisterDomain($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Send registration $request = $client->request($xml = ' @@ -562,7 +560,7 @@ function cozaepp_TransferDomain($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Initiate transfer $request = $client->request($xml = ' @@ -661,7 +659,7 @@ function cozaepp_RenewDomain($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Send renewal request $request = $client->request($xml = ' @@ -739,7 +737,7 @@ function _getContactDetails($domain, $client = null) { # Get client instance try { if (!isset($client)) { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); } # Grab domain info @@ -961,7 +959,7 @@ function cozaepp_SaveContactDetails($params) { # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' @@ -1081,7 +1079,7 @@ function cozaepp_RegisterNameserver($params) { # Grab client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Register nameserver $request = $client->request($xml = ' @@ -1146,7 +1144,7 @@ function cozaepp_ModifyNameserver($params) { # Grab client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Modify nameserver $request = $client->request($xml = ' @@ -1207,7 +1205,7 @@ function cozaepp_DeleteNameserver($params) { # Grab client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # If we were given hostname. blow away all of the stuff behind it and allow us to remove hostname $nameserver = preg_replace('/\.\.\S+/','',$nameserver); @@ -1289,8 +1287,48 @@ function _cozaepp_ackpoll($client,$msgid) { } } +# Helper function to centrally provide data and information about different SLDs. +function _cozaepp_SldLookup($domain) { + # TLD server data provided by ZACR + $tldservers = array( + 'co.za' => array( + 'fqdn' => 'epp.coza.net.za', + 'port' => 3121, + 'additional_contacts' => false + ), + 'org.za' => array( + 'fqdn' => 'org-epp.registry.net.za', + 'port' => 3121, + 'additional_contacts' => true + ), + 'web.za' => array( + 'fqdn' => 'web-epp.registry.net.za', + 'port' => 3121, + 'additional_contacts' => true + ), + 'net.za' => array( + 'fqdn' => 'net-epp.registry.net.za', + 'port' => 3121, + 'additional_contacts' => true + ), + ); + + if (!is_null($domain)) { + foreach ($tldservers as $tld => $data) { + if (preg_match("/$tld$/i", $domain)) { + return $data; + } + } + + throw new Exception('SLD lookup failed to find: '.$domain); + + } else { # defaults to co.za server. + return $tldservers['co.za']; + } +} + # Function to create internal COZA EPP request -function _cozaepp_Client() { +function _cozaepp_Client($domain=null) { # Setup include dir $include_path = ROOTDIR . '/modules/registrars/cozaepp'; set_include_path($include_path . PATH_SEPARATOR . get_include_path()); @@ -1300,13 +1338,14 @@ function _cozaepp_Client() { # Grab module parameters $params = getregistrarconfigoptions('cozaepp'); + + # Set server address and port based on parsed domain name + $_server = _cozaepp_SldLookup($domain); + # Check if module parameters are sane if (empty($params['Username']) || empty($params['Password'])) { throw new Exception('System configuration error(1), please contact your provider'); } - if ($params['Server'] != 'regphase3.dnservices.co.za' && $params['Server'] != 'epp.coza.net.za') { - throw new Exception('System configuration error(2), please contact your provider'); - } # Create SSL context $context = stream_context_create(); @@ -1328,7 +1367,7 @@ function _cozaepp_Client() { $client = new Net_EPP_Client(); # Connect - $res = $client->connect($params['Server'], $params['Port'], 10, $use_ssl, $context); + $res = $client->connect($_server['fqdn'], $_server['port'], 10, $use_ssl, $context); # Perform login $request = $client->request($xml = ' @@ -1371,7 +1410,7 @@ function cozaepp_TransferSync($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' <epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" @@ -1436,10 +1475,10 @@ function cozaepp_RecreateContact($params) { $tld = $params["tld"]; $sld = $params["sld"]; $domain = strtolower("$sld.$tld"); - + # Get client instance try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Fetching contact details $contact = _getContactDetails($domain, $client); @@ -1552,7 +1591,7 @@ function cozaepp_Sync($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' <epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" @@ -1645,7 +1684,7 @@ function cozaepp_RequestDelete($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' @@ -1692,7 +1731,7 @@ function cozaepp_ApproveTransfer($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' @@ -1739,7 +1778,7 @@ function cozaepp_CancelTransferRequest($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = ' @@ -1786,7 +1825,7 @@ function cozaepp_RejectTransfer($params) { # Grab domain info try { - $client = _cozaepp_Client(); + $client = _cozaepp_Client($domain); # Grab domain info $request = $client->request($xml = '