From fea0e8dbc47b444483b86714c26af757dc051a04 Mon Sep 17 00:00:00 2001 From: Aaron Shavolian <49081082+ashavolian@users.noreply.github.com> Date: Wed, 16 Nov 2022 12:59:01 -0500 Subject: [PATCH 1/7] Added namecheap registrar adapter Notes: getting EPP code is not supported through namecheap API. Changing nameserver settings seems broken atm: always confirms success even when the api call fails --- src/library/Registrar/Adapter/Namecheap.php | 750 ++++++++++++++++++++ 1 file changed, 750 insertions(+) create mode 100644 src/library/Registrar/Adapter/Namecheap.php diff --git a/src/library/Registrar/Adapter/Namecheap.php b/src/library/Registrar/Adapter/Namecheap.php new file mode 100644 index 000000000..80e0ebc59 --- /dev/null +++ b/src/library/Registrar/Adapter/Namecheap.php @@ -0,0 +1,750 @@ + null, + 'api-key' => null, + 'username' => null, + 'ip' => null, + ); + + public function isKeyValueNotEmpty($array, $key) + { + $value = isset($array[$key]) ? $array[$key] : ''; + if (strlen(trim($value)) == 0) { + return false; + } + return true; + } + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if (isset($options['api-user-id']) && !empty($options['api-user-id'])) { + $this->config['api-user-id'] = $options['api-user-id']; + unset($options['api-user-id']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "Reseller ID" at "Configuration -> Domain registration".'); + } + + if (isset($options['api-key']) && !empty($options['api-key'])) { + $this->config['api-key'] = $options['api-key']; + unset($options['api-key']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "API Key" at "Configuration -> Domain registration".'); + } + + if (isset($options['username']) && !empty($options['username'])) { + $this->config['username'] = $options['username']; + unset($options['username']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "Username" at "Configuration -> Domain registration".'); + } + + if (isset($options['ip']) && !empty($options['ip'])) { + $this->config['ip'] = $options['ip']; + unset($options['ip']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Namecheap via API. Namecheap requires your server IP in order to work.', + 'form' => array( + 'api-user-id' => array( + 'text', array( + 'label' => 'Reseller ID', + 'description' => 'Namecheap Reseller ID. You can get this at Namecheap control panel' + ), + ), + 'api-key' => array( + 'password', array( + 'label' => 'API Key', + 'description' => 'You can get this at Namecheap control panel', + 'required' => false, + ), + ), + 'username' => array( + 'text', array( + 'label' => 'Namecheap UserName', + 'description' => 'You can get this at Namecheap control panel', + 'required' => false, + ), + ), + 'ip' => array( + 'text', array( + 'label' => 'Server IP address', + 'description' => 'IP address of this server. Ensure that this IP is whitelisted under your NameCheap settings', + 'required' => false, + ), + ), + ), + ); + } + + /** + * Tells what TLDs can be registered via this adapter + * @return string[] + */ + public function getTlds() + { + $params = array( + 'Command' => 'namecheap.domains.getTldList' + ); + + $result = $this->_makeRequest($params); + $strTlds = array(); + $xmlTlds = $result->CommandResponse->Tlds; + foreach ($xmlTlds->tld as $tld) { + array_push($strTlds, '.' . $tld['Name']); + } + return $strTlds; + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'DomainList' => strtolower($domain->getSld()) . $domain->getTld(), + 'Command' => 'namecheap.domains.check' + ); + + $result = $this->_makeRequest($params); + + error_log('AVAILABLE ATTR: ' . $result->CommandResponse->DomainCheckResult['Available']); + + if (isset($result->CommandResponse->DomainCheckResult['Available']) && $result->CommandResponse->DomainCheckResult['Available'] == 'true') { + error_log('DOMAIN AVAILABLE: true'); + return true; + } + error_log('DOMAIN AVAILABLE: false'); + return false; + } + + /** + * Perform call to Api + * @param array $params + * @param string $method + * @return object + * @throws Registrar_Exception + */ + protected function _makeRequest($params = array(), $method = 'GET') + { + $params = $this->includeAuthorizationParams($params); + + $opts = array( + CURLOPT_CONNECTTIMEOUT => 30, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 60, + CURLOPT_URL => $this->_getApiUrl(), + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0, + ); + + if ($method == 'POST') { + $opts[CURLOPT_POST] = 1; + $opts[CURLOPT_POSTFIELDS] = $this->_formatParams($params); + $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL] . '?' . $opts[CURLOPT_POSTFIELDS]); + } else { + $opts[CURLOPT_URL] = $opts[CURLOPT_URL] . '?' . $this->_formatParams($params); + $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL]); + } + + $ch = curl_init(); + curl_setopt_array($ch, $opts); + $data = curl_exec($ch); + if ($data === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + curl_close($ch); + + $this->getLog()->info('API RESULT: ' . $data); + + error_log('API RESULT: ' . $data); + + $result = simplexml_load_string($data); + + // error_log('RESULT ARRAY 1: '.implode("\n", $result)); + + if (isset($result['status']) && $result['status'] == 'error') { + throw new Registrar_Exception($result['error'], 102); + } + + if (isset($result['status']) && $result['status'] == 'Failed') { + throw new Registrar_Exception($result['actionstatusdesc'], 103); + } + + return $result; + } + + /** + * Convert params to resellerClub format + * @see http://manage.resellerclub.com/kb/answer/755 + * @param array $params + * @return string + */ + private function _formatParams($params) + { + foreach ($params as $key => &$param) { + if (is_bool($param)) { + $param = ($param) ? 'true' : 'false'; + } + } + + $params = http_build_query($params); + return $params; + } + + /** + * Api URL + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) { + return 'https://api.sandbox.namecheap.com/xml.response'; + } + return 'https://api.namecheap.com/xml.response'; + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * @param array $params + * @return array + */ + public function includeAuthorizationParams(array $params) + { + return array_merge(array( + 'ApiUser' => $this->config['api-user-id'], + 'ApiKey' => $this->config['api-key'], + 'UserName' => $this->config['username'], + 'ClientIp' => $this->config['ip'], + ), $params); + } + + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyNs(Registrar_Domain $domain) + { + // get NS info + $params = array( + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld($with_dot = false), + 'NameServers' => $domain->getNs1() . ',' . $domain->getNs2() . ',' . $domain->getNs3() . ',' . $domain->getNs4(), + 'Command' => 'namecheap.domains.dns.setCustom', + ); + + $result = $this->_makeRequest($params); + + error_log('AFTER NS MODIFY: ' . $domain->__toString()); + + // TODO + // problem here: fossbilling doesn't display our error and will display 'nameservers updates' evern when this fails + + if (!isset($result->CommandResponse->DomainDNSSetCustomResult['Updated']) && $result->CommandResponse->DomainDNSSetCustomResult['Updated'] != 'true') { + throw new Registrar_Exception($message = 'Could not update NameServers'); + } + return True; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyContact(Registrar_Domain $domain) + { + $params = array( + 'Command' => 'namecheap.domains.setContacts', + 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), + ); + + // Set contact data + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $c = $domain->getContactRegistrar(); + + if ($contactType == 'Admin' && $domain->getContactAdmin()) { + $c = $domain->getContactAdmin(); + } + + if ($contactType == 'Tech' && $domain->getContactTech()) { + $c = $domain->getContactTech(); + } + + if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { + $c = $domain->getContactBilling(); + } + + $params[$contactType . 'FirstName'] = $c->getFirstName(); + $params[$contactType . 'LastName'] = $c->getLastName(); + $params[$contactType . 'EmailAddress'] = $c->getEmail(); + $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); + $params[$contactType . 'Address1'] = $c->getAddress1(); + $params[$contactType . 'Address2'] = $c->getAddress2(); + $params[$contactType . 'City'] = $c->getCity(); + $params[$contactType . 'StateProvince'] = $c->getState(); + $params[$contactType . 'Country'] = $c->getCountry(); + $params[$contactType . 'PostalCode'] = $c->getZip(); + } + $result = $this->_makeRequest($params); + return $result->CommandResponse->DomainSetContactResult['IsSuccess'] == 'true'; + } + + /** + * relying on domain->getEpp() to return user's input for Epp code + * @return bool + * @throws Registrar_Exception + */ + public function transferDomain(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Years' => '1', + 'EPPCode' => $domain->getEpp(), + 'Command' => 'namecheap.domains.transfer.create' + ); + + $result = $this->_makeRequest($params); + + error_log('TRANSFER ATTR: ' . $result->CommandResponse->DomainTransferCreateResult['Transfer']); + + if (isset($result->CommandResponse->DomainTransferCreateResult['Transfer']) && $result->CommandResponse->DomainTransferCreateResult['Transfer'] == 'true') { + error_log('DOMAIN TRANSFER: true'); + return true; + } + error_log('DOMAIN TRANSFER: false'); + return false; + } + + /** + * Should return details of registered domain + * If domain is not registered should throw Registrar_Exception + * @return Registrar_Domain + * @throws Registrar_Exception + */ + public function getDomainDetails(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getInfo' + ); + + $result = $this->_makeRequest($params); + + $domain->setRegistrationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->CreatedDate); + $domain->setExpirationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->ExpiredDate); + $domain->setPrivacyEnabled((string)$result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled']); + + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getContacts' + ); + + $result = $this->_makeRequest($params); + + error_log('INFO ATTR: ' . (string)$result->CommandResponse->DomainContactsResult); + + if (!isset($result->CommandResponse->DomainContactsResult)) { + throw new Registrar_Exception($message = "API ERROR: could not retrieve domain details"); + } + + $contacts = $result->CommandResponse->DomainContactsResult; + // create new Domain obj to return + $newDomain = new Registrar_Domain(); + + // set SLD and TLD + $newDomain->setSld($domain->getSld()); + $newDomain->setTld($domain->getTld()); + + $registrarContact = new Registrar_Domain_Contact(); + $adminContact = new Registrar_Domain_Contact(); + $techContact = new Registrar_Domain_Contact(); + $billingContact = new Registrar_Domain_Contact(); + + // Set contact data on our Domain obj using info from our API call + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $contactApi = $contacts->Registrant; + $contact = $registrarContact; + + if ($contactType == 'Admin') { + $contactApi = $contacts->Admin; + $contact = $adminContact; + } + if ($contactType == 'Tech') { + $contactApi = $contacts->Tech; + $contact = $techContact; + } + if ($contactType == 'AuxBilling') { + $contactApi = $contacts->AuxBilling; + $contact = $billingContact; + } + + $contact->setFirstName((string)$contactApi->FirstName); + $contact->setLastName((string)$contactApi->LastName); + $contact->setEmail((string)$contactApi->EmailAddress); + $contact->setTel((string)$contactApi->Phone); + $contact->setAddress1((string)$contactApi->Address1); + $contact->setAddress2((string)$contactApi->Address2); + $contact->setCity((string)$contactApi->City); + $contact->setState((string)$contactApi->StateProvince); + $contact->setCountry((string)$contactApi->Country); + $contact->setZip((string)$contactApi->PostalCode); + } + + $newDomain->setContactRegistrar($registrarContact); + $newDomain->setContactAdmin($adminContact); + $newDomain->setContactTech($techContact); + $newDomain->setContactBilling($billingContact); + + // get NS info + $params = array( + 'SLD' => $newDomain->getSld(), + 'TLD' => $newDomain->getTld($with_dot = false), + 'Command' => 'namecheap.domains.dns.getList', + ); + + $result = $this->_makeRequest($params); + + $NsArr = array(); + $xmlNsList = $result->CommandResponse->DomainDNSGetListResult; + foreach ($xmlNsList->Nameserver as $Nameserver) { + $NsArr[] = $Nameserver; + } + + for ($i = 1; $i <= 4; $i++) { + if (isset($NsArr[$i - 1])) { + $newDomain->{'setNs' . $i}((string)$NsArr[$i - 1]); + } + } + + error_log('DOMAIN OBJ FIELDS: ' . $newDomain->__toString()); + + return $newDomain; + } + + + /** + * Should return domain transfer code + * + * @return string + * @throws Registrar_Exception + */ + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception($message = 'This feature is unavailable through the Namecheap API. Please contact your administrator.'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function registerDomain(Registrar_Domain $domain) + { + + $params = array( + 'Command' => 'namecheap.domains.create', + 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), + 'Years' => $domain->getRegistrationPeriod(), + ); + + if ($domain->getNs1()) { + // Add nameservers + $nsList = array(); + $nsList[] = $domain->getNs1(); + $nsList[] = $domain->getNs2(); + if ($domain->getNs3()) { + $nsList[] = $domain->getNs3(); + } + if ($domain->getNs4()) { + $nsList[] = $domain->getNs4(); + } + $params['Nameservers'] = implode(',', $nsList); + } + + // Set contact data + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $c = $domain->getContactRegistrar(); + + if ($contactType == 'Admin' && $domain->getContactAdmin()) { + $c = $domain->getContactAdmin(); + } + + if ($contactType == 'Tech' && $domain->getContactTech()) { + $c = $domain->getContactTech(); + } + + if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { + $c = $domain->getContactBilling(); + } + + $params[$contactType . 'FirstName'] = $c->getFirstName(); + $params[$contactType . 'LastName'] = $c->getLastName(); + $params[$contactType . 'EmailAddress'] = $c->getEmail(); + $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); + $params[$contactType . 'Address1'] = $c->getAddress1(); + $params[$contactType . 'Address2'] = $c->getAddress2(); + $params[$contactType . 'City'] = $c->getCity(); + $params[$contactType . 'StateProvince'] = $c->getState(); + $params[$contactType . 'Country'] = $c->getCountry(); + $params[$contactType . 'PostalCode'] = $c->getZip(); + } + $params['AddFreeWhoisguard'] = 'yes'; + + if ($domain->getTld() == '.us') { + $params['RegistrantPurpose'] = 'P3'; + $params['RegistrantNexus'] = 'C11'; + } + + if ($domain->getTld() == '.eu') { + $params['EUAgreeWhoisPolicy'] = 'YES'; + $params['EUAgreeDeletePolicy'] = 'YES'; + } + // passport for swedish identification + if ($domain->getTld() == '.nu') { + $params['NUOrgNo'] = $domain->getContactRegistrar()->getDocumentNr(); + } + + // need to check if user is a canadian resident or if coorporation is registered in canada + // if ($domain->getTld() == '.ca') { + // $params['CIRALegalType'] = 'CCT'; + // $params['EUAgreeDeletePolicy'] = 'YES'; + // } + + if ($domain->getTld() == '.co.uk' || $domain->getTld() == '.me.uk' || $domain->getTld() == '.org.uk') { + if ($domain->getContactRegistrar()->getCountry() == 'UK') { + $params['COUKLegalType'] = 'IND'; + } else { + $params['COUKLegalType'] = 'FIND'; + } + + $params['COUKRegisteredfor'] = $domain->getContactRegistrar()->getName(); + } + + // unsure how to handle this + // if ($domain->getTld() == '.com.au' || $domain->getTld() == '.net.au' || $domain->getTld() == '.org.au') { + // $params['COMAURegistrantId'] = ''; + // $params['COMAURegistrantIdType'] = ''; + // } + + // .de domains require an admin address in Germany + // if ($domain->getTld() == '.de') { + // //confirm here that the admin address is in fact germany + // $params['DEConfirmAddress'] = 'DE'; + // $params['DEAgreeDelete'] = 'Yes'; + // } + + if ($domain->getTld() == '.fr') { + $params['FRLegalType'] = 'Individual'; + $params['FRRegistrantBirthDate'] = $domain->getContactRegistrar()->getBirthday(); + $params['FRRegistrantBirthplace'] = $domain->getContactRegistrar()->getCountry(); + } + + error_log('REGISTER API PARAMS: ' . implode("\n", $params)); + + $result = $this->_makeRequest($params); + + error_log('REGISTER API RESULT: ' . $result); + + return (isset($result->CommandResponse->DomainCreateResult['Registered']) + && ($result->CommandResponse->DomainCreateResult['Registered'] == 'true')); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'Command' => 'namecheap.domains.renew', + 'DomainName' => $domain->getName(), + 'Years' => $domain->getRegistrationPeriod(), + ); + + $result = $this->_makeRequest($params); + + return (isset($result->CommandResponse->DomainRenewResult['Renew']) + && ($result->CommandResponse->DomainRenewResult['Renew'] == 'true')); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function deleteDomain(Registrar_Domain $domain) + { + } + + /** + * @return string[] + * @throws Registrar_Exception + */ + private function getPrivacyInfo(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getInfo' + ); + + $result = $this->_makeRequest($params); + + if (isset($result->CommandResponse->DomainGetInfoResult->Whoisguard)) { + return array( + 'enabled' => $result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled'] == 'True', + 'id' => (string)$result->CommandResponse->DomainGetInfoResult->Whoisguard->ID + ); + } + throw new Registrar_Exception($message = 'Could not retrieve privacy info on this domain.'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function enablePrivacyProtection(Registrar_Domain $domain) + { + $privacyInfo = $this->getPrivacyInfo($domain); + + if($privacyInfo['enabled']) { + return True; + } + + $params = array( + 'WhoisguardID' => $privacyInfo['id'], + 'ForwardedToEmail' => $domain->getContactRegistrar()->getEmail(), + 'Command' => 'namecheap.whoisguard.enable' + ); + + $result = $this->_makeRequest($params); + + return isset($result->CommandResponse->WhoisguardEnableResult['isSuccess']) + && $result->CommandResponse->WhoisguardEnableResult['isSuccess'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function disablePrivacyProtection(Registrar_Domain $domain) + { + $privacyInfo = $this->getPrivacyInfo($domain); + + if(!$privacyInfo['enabled']) { + return True; + } + + $params = array( + 'WhoisguardID' => $privacyInfo['id'], + 'Command' => 'namecheap.whoisguard.disable' + ); + + $result = $this->_makeRequest($params); + + return isset($result->CommandResponse->WhoisguardDisableResult['isSuccess']) + && $result->CommandResponse->WhoisguardDisableResult['isSuccess'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function getLock(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getRegistrarLock' + ); + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'])) { + throw new Registrar_Exception($message = 'API ERROR: could not get lock status on domain'); + } + return $result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function lock(Registrar_Domain $domain) + { + if ($this->getLock($domain) == 'true') { + return True; + } + + $params = array( + 'DomainName' => $domain->getName(), + 'LockAction' => 'LOCK', + 'Command' => 'namecheap.domains.setRegistrarLock' + ); + + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { + throw new Registrar_Exception($message = 'API ERROR: could not set lock status on domain'); + } + if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { + $domain->setLocked('true'); + return True; + } + return False; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function unlock(Registrar_Domain $domain) + { + if ($this->getLock($domain) == 'false') { + return True; + } + + $params = array( + 'DomainName' => $domain->getName(), + 'LockAction' => 'UNLOCK', + 'Command' => 'namecheap.domains.setRegistrarLock' + ); + + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { + throw new Registrar_Exception($message = 'API ERROR: could not set lock status on domain'); + } + if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { + $domain->setLocked('false'); + return True; + } + return False; + } + + /** + * Checks if tld is compatible with namecheaps transfer api and + * if the domain is not available for registration (meaning hopefully the client owns it) + * @return bool + * @throws Registrar_Exception + */ + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + return in_array($domain->getTld(), array( + '.biz', '.ca', '.cc', '.co', '.co.uk', '.com', '.com.es', + '.com.pe', '.es', '.in', '.info', '.me', '.me.uk', '.mobi', '.net', '.net.pe', + '.nom.es', '.org', '.org.es', '.org.pe', '.org.uk', '.pe', '.tv', '.us' + )) + && !$this->isDomainAvailable($domain); + } +} From ae7996048b9f26e489f5debfcda02a498eddba3f Mon Sep 17 00:00:00 2001 From: Aaron Shavolian <49081082+ashavolian@users.noreply.github.com> Date: Fri, 18 Nov 2022 16:11:22 -0500 Subject: [PATCH 2/7] added namecheap adapter with clouDns support --- .../Registrar/Adapter/NamecheapClouDns.php | 867 ++++++++++++++++++ 1 file changed, 867 insertions(+) create mode 100644 src/library/Registrar/Adapter/NamecheapClouDns.php diff --git a/src/library/Registrar/Adapter/NamecheapClouDns.php b/src/library/Registrar/Adapter/NamecheapClouDns.php new file mode 100644 index 000000000..62b188a60 --- /dev/null +++ b/src/library/Registrar/Adapter/NamecheapClouDns.php @@ -0,0 +1,867 @@ + null, + 'api-key' => null, + 'username' => null, + 'ip' => null, + 'clouDns-id' => null, + 'clouDns-password' => null + + ); + + public function isKeyValueNotEmpty($array, $key) + { + $value = isset($array[$key]) ? $array[$key] : ''; + if (strlen(trim($value)) == 0) { + return false; + } + return true; + } + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if (isset($options['api-user-id']) && !empty($options['api-user-id'])) { + $this->config['api-user-id'] = $options['api-user-id']; + unset($options['api-user-id']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Reseller ID" at "Configuration -> Domain registration".'); + } + + if (isset($options['api-key']) && !empty($options['api-key'])) { + $this->config['api-key'] = $options['api-key']; + unset($options['api-key']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "API Key" at "Configuration -> Domain registration".'); + } + + if (isset($options['username']) && !empty($options['username'])) { + $this->config['username'] = $options['username']; + unset($options['username']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Username" at "Configuration -> Domain registration".'); + } + + if (isset($options['ip']) && !empty($options['ip'])) { + $this->config['ip'] = $options['ip']; + unset($options['ip']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); + } + + if (isset($options['clouDns-id']) && !empty($options['clouDns-id'])) { + $this->config['clouDns-id'] = $options['clouDns-id']; + unset($options['clouDns-id']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); + } + + if (isset($options['clouDns-password']) && !empty($options['clouDns-password'])) { + $this->config['clouDns-password'] = $options['clouDns-password']; + unset($options['clouDns-password']); + } else { + throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Namecheap via API. Namecheap requires your server IP in order to work.', + 'form' => array( + 'api-user-id' => array( + 'text', array( + 'label' => 'Namecheap Reseller ID', + 'description' => 'Namecheap Reseller ID. You can get this at Namecheap control panel', + 'required' => true, + ), + ), + 'api-key' => array( + 'password', array( + 'label' => ' Namecheap API Key', + 'description' => 'You can get this at Namecheap control panel', + 'required' => true, + ), + ), + 'username' => array( + 'text', array( + 'label' => 'Namecheap UserName', + 'description' => 'You can get this at Namecheap control panel', + 'required' => true, + ), + ), + 'ip' => array( + 'text', array( + 'label' => 'Server IP address', + 'description' => 'IP address of this server. Ensure that this IP is whitelisted under your NameCheap settings', + 'required' => true, + ), + ), + 'clouDns-id' => array( + 'text', array( + 'label' => 'ClouDns Api user ID', + 'description' => 'Login to your ClouDns Account. Go to Reseller API. The table API users indicates all your API users', + 'required' => true, + ), + ), + 'clouDns-password' => array( + 'text', array( + 'label' => 'ClouDns Api user Password', + 'description' => 'This is the password associated with the ClouDns user entered above', + 'required' => true, + ), + ), + ), + ); + } + + /** + * Tells what TLDs can be registered via this adapter + * @return string[] + */ + public function getTlds() + { + $params = array( + 'Command' => 'namecheap.domains.getTldList' + ); + + $result = $this->_makeRequest($params); + $strTlds = array(); + $xmlTlds = $result->CommandResponse->Tlds; + foreach ($xmlTlds->tld as $tld) { + array_push($strTlds, '.' . $tld['Name']); + } + return $strTlds; + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'DomainList' => strtolower($domain->getSld()) . $domain->getTld(), + 'Command' => 'namecheap.domains.check' + ); + + $result = $this->_makeRequest($params); + + error_log('AVAILABLE ATTR: ' . $result->CommandResponse->DomainCheckResult['Available']); + + if (isset($result->CommandResponse->DomainCheckResult['Available']) && $result->CommandResponse->DomainCheckResult['Available'] == 'true') { + error_log('DOMAIN AVAILABLE: true'); + return true; + } + error_log('DOMAIN AVAILABLE: false'); + return false; + } + + /** + * Perform call to Api + * @param array $params + * @param string $method + * @return object + * @throws Registrar_Exception + */ + protected function _makeRequest($params = array(), $method = 'GET', $customUrl = null) + { + $params = $this->includeAuthorizationParams($params); + + $opts = array( + CURLOPT_CONNECTTIMEOUT => 30, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 60, + CURLOPT_URL => $customUrl ?? $this->_getApiUrl(), + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0, + ); + + if ($method == 'POST') { + $opts[CURLOPT_POST] = 1; + $opts[CURLOPT_POSTFIELDS] = $this->_formatParams($params); + $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL] . '?' . $opts[CURLOPT_POSTFIELDS]); + } else { + $opts[CURLOPT_URL] = $opts[CURLOPT_URL] . '?' . $this->_formatParams($params); + $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL]); + } + + $ch = curl_init(); + curl_setopt_array($ch, $opts); + $data = curl_exec($ch); + if ($data === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + curl_close($ch); + + $this->getLog()->info('API RESULT: ' . $data); + + error_log('API RESULT: ' . $data); + + $result = simplexml_load_string($data); + + // error_log('RESULT ARRAY 1: '.implode("\n", $result)); + + if (isset($result['status']) && $result['status'] == 'error') { + throw new Registrar_Exception($result['status'], 102); + } + + if (isset($result['status']) && $result['status'] == 'Failed') { + throw new Registrar_Exception($result['status'], 103); + } + + return $result; + } + + /** + * Convert params to resellerClub format + * @see http://manage.resellerclub.com/kb/answer/755 + * @param array $params + * @return string + */ + private function _formatParams($params) + { + foreach ($params as $key => &$param) { + if (is_bool($param)) { + $param = ($param) ? 'true' : 'false'; + } + } + + $params = http_build_query($params); + return $params; + } + + /** + * Api URL + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) { + return 'https://api.sandbox.namecheap.com/xml.response'; + } + return 'https://api.namecheap.com/xml.response'; + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * @param array $params + * @return array + */ + public function includeAuthorizationParams(array $params) + { + return array_merge(array( + 'ApiUser' => $this->config['api-user-id'], + 'ApiKey' => $this->config['api-key'], + 'UserName' => $this->config['username'], + 'ClientIp' => $this->config['ip'], + ), $params); + } + + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyNs(Registrar_Domain $domain) + { + // get NS info + $params = array( + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld($with_dot = false), + 'NameServers' => $domain->getNs1() . ',' . $domain->getNs2() . ',' . $domain->getNs3() . ',' . $domain->getNs4(), + 'Command' => 'namecheap.domains.dns.setCustom', + ); + + $result = $this->_makeRequest($params); + + error_log('AFTER NS MODIFY: ' . $domain->__toString()); + + // TODO + // problem here: fossbilling doesn't display our error and will display 'nameservers updates' evern when this fails + + if (!isset($result->CommandResponse->DomainDNSSetCustomResult['Updated']) && $result->CommandResponse->DomainDNSSetCustomResult['Updated'] != 'true') { + throw new Registrar_Exception('Could not update NameServers'); + } + return True; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyContact(Registrar_Domain $domain) + { + $params = array( + 'Command' => 'namecheap.domains.setContacts', + 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), + ); + + // Set contact data + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $c = $domain->getContactRegistrar(); + + if ($contactType == 'Admin' && $domain->getContactAdmin()) { + $c = $domain->getContactAdmin(); + } + + if ($contactType == 'Tech' && $domain->getContactTech()) { + $c = $domain->getContactTech(); + } + + if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { + $c = $domain->getContactBilling(); + } + + $params[$contactType . 'FirstName'] = $c->getFirstName(); + $params[$contactType . 'LastName'] = $c->getLastName(); + $params[$contactType . 'EmailAddress'] = $c->getEmail(); + $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); + $params[$contactType . 'Address1'] = $c->getAddress1(); + $params[$contactType . 'Address2'] = $c->getAddress2(); + $params[$contactType . 'City'] = $c->getCity(); + $params[$contactType . 'StateProvince'] = $c->getState(); + $params[$contactType . 'Country'] = $c->getCountry(); + $params[$contactType . 'PostalCode'] = $c->getZip(); + } + $result = $this->_makeRequest($params); + return $result->CommandResponse->DomainSetContactResult['IsSuccess'] == 'true'; + } + + /** + * relying on domain->getEpp() to return user's input for Epp code + * @return bool + * @throws Registrar_Exception + */ + public function transferDomain(Registrar_Domain $domain) + { + $nameservers = $this->clouDnsRegisterDomainZone($domain); + $params = array( + 'DomainName' => $domain->getName(), + 'Years' => '1', + 'EPPCode' => $domain->getEpp(), + 'Command' => 'namecheap.domains.transfer.create' + ); + + $result = $this->_makeRequest($params); + + error_log('TRANSFER ATTR: ' . $result->CommandResponse->DomainTransferCreateResult['Transfer']); + + if (isset($result->CommandResponse->DomainTransferCreateResult['Transfer']) && $result->CommandResponse->DomainTransferCreateResult['Transfer'] == 'true') { + error_log('DOMAIN TRANSFER: true'); + $this->setNsToClouDns($domain, $nameservers); + return True; + } + error_log('DOMAIN TRANSFER: false'); + throw new Registrar_Exception("Domain transfer could not be completed. Please contact your administrator"); + } + + /** + * Should return details of registered domain + * If domain is not registered should throw Registrar_Exception + * @return Registrar_Domain + * @throws Registrar_Exception + */ + public function getDomainDetails(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getInfo' + ); + + $result = $this->_makeRequest($params); + + $domain->setRegistrationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->CreatedDate); + $domain->setExpirationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->ExpiredDate); + $domain->setPrivacyEnabled((string)$result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled']); + + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getContacts' + ); + + $result = $this->_makeRequest($params); + + error_log('INFO ATTR: ' . (string)$result->CommandResponse->DomainContactsResult); + + if (!isset($result->CommandResponse->DomainContactsResult)) { + throw new Registrar_Exception("Could not retrieve domain details"); + } + + $contacts = $result->CommandResponse->DomainContactsResult; + // create new Domain obj to return + $newDomain = new Registrar_Domain(); + + // set SLD and TLD + $newDomain->setSld($domain->getSld()); + $newDomain->setTld($domain->getTld()); + + $registrarContact = new Registrar_Domain_Contact(); + $adminContact = new Registrar_Domain_Contact(); + $techContact = new Registrar_Domain_Contact(); + $billingContact = new Registrar_Domain_Contact(); + + // Set contact data on our Domain obj using info from our API call + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $contactApi = $contacts->Registrant; + $contact = $registrarContact; + + if ($contactType == 'Admin') { + $contactApi = $contacts->Admin; + $contact = $adminContact; + } + if ($contactType == 'Tech') { + $contactApi = $contacts->Tech; + $contact = $techContact; + } + if ($contactType == 'AuxBilling') { + $contactApi = $contacts->AuxBilling; + $contact = $billingContact; + } + + $contact->setFirstName((string)$contactApi->FirstName); + $contact->setLastName((string)$contactApi->LastName); + $contact->setEmail((string)$contactApi->EmailAddress); + $contact->setTel((string)$contactApi->Phone); + $contact->setAddress1((string)$contactApi->Address1); + $contact->setAddress2((string)$contactApi->Address2); + $contact->setCity((string)$contactApi->City); + $contact->setState((string)$contactApi->StateProvince); + $contact->setCountry((string)$contactApi->Country); + $contact->setZip((string)$contactApi->PostalCode); + } + + $newDomain->setContactRegistrar($registrarContact); + $newDomain->setContactAdmin($adminContact); + $newDomain->setContactTech($techContact); + $newDomain->setContactBilling($billingContact); + + // get NS info + $params = array( + 'SLD' => $newDomain->getSld(), + 'TLD' => $newDomain->getTld($with_dot = false), + 'Command' => 'namecheap.domains.dns.getList', + ); + + $result = $this->_makeRequest($params); + + $NsArr = array(); + $xmlNsList = $result->CommandResponse->DomainDNSGetListResult; + foreach ($xmlNsList->Nameserver as $Nameserver) { + $NsArr[] = $Nameserver; + } + + for ($i = 1; $i <= 4; $i++) { + if (isset($NsArr[$i - 1])) { + $newDomain->{'setNs' . $i}((string)$NsArr[$i - 1]); + } + } + + error_log('DOMAIN OBJ FIELDS: ' . $newDomain->__toString()); + + return $newDomain; + } + + + /** + * This feature is unavailable through namecheaps API + * @return string + * @throws Registrar_Exception + */ + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception('This feature is unavailable through the Namecheap API. Please contact your administrator'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function registerDomain(Registrar_Domain $domain) + { + $params = array( + 'Command' => 'namecheap.domains.create', + 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), + 'Years' => $domain->getRegistrationPeriod(), + ); + + if ($domain->getNs1()) { + // Add nameservers + $nsList = array(); + $nsList[] = $domain->getNs1(); + $nsList[] = $domain->getNs2(); + if ($domain->getNs3()) { + $nsList[] = $domain->getNs3(); + } + if ($domain->getNs4()) { + $nsList[] = $domain->getNs4(); + } + $params['Nameservers'] = implode(',', $nsList); + } else { + $params['Nameservers'] = $this->clouDnsRegisterDomainZone($domain); + } + + // Set contact data + foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { + $c = $domain->getContactRegistrar(); + + if ($contactType == 'Admin' && $domain->getContactAdmin()) { + $c = $domain->getContactAdmin(); + } + + if ($contactType == 'Tech' && $domain->getContactTech()) { + $c = $domain->getContactTech(); + } + + if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { + $c = $domain->getContactBilling(); + } + + $params[$contactType . 'FirstName'] = $c->getFirstName(); + $params[$contactType . 'LastName'] = $c->getLastName(); + $params[$contactType . 'EmailAddress'] = $c->getEmail(); + $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); + $params[$contactType . 'Address1'] = $c->getAddress1(); + $params[$contactType . 'Address2'] = $c->getAddress2(); + $params[$contactType . 'City'] = $c->getCity(); + $params[$contactType . 'StateProvince'] = $c->getState(); + $params[$contactType . 'Country'] = $c->getCountry(); + $params[$contactType . 'PostalCode'] = $c->getZip(); + } + $params['AddFreeWhoisguard'] = 'yes'; + + if ($domain->getTld() == '.us') { + $params['RegistrantPurpose'] = 'P3'; + $params['RegistrantNexus'] = 'C11'; + } + + if ($domain->getTld() == '.eu') { + $params['EUAgreeWhoisPolicy'] = 'YES'; + $params['EUAgreeDeletePolicy'] = 'YES'; + } + // passport for swedish identification + if ($domain->getTld() == '.nu') { + $params['NUOrgNo'] = $domain->getContactRegistrar()->getDocumentNr(); + } + + // need to check if user is a canadian resident or if coorporation is registered in canada + // if ($domain->getTld() == '.ca') { + // $params['CIRALegalType'] = 'CCT'; + // $params['EUAgreeDeletePolicy'] = 'YES'; + // } + + if ($domain->getTld() == '.co.uk' || $domain->getTld() == '.me.uk' || $domain->getTld() == '.org.uk') { + if ($domain->getContactRegistrar()->getCountry() == 'UK') { + $params['COUKLegalType'] = 'IND'; + } else { + $params['COUKLegalType'] = 'FIND'; + } + + $params['COUKRegisteredfor'] = $domain->getContactRegistrar()->getName(); + } + + // unsure how to handle this + // if ($domain->getTld() == '.com.au' || $domain->getTld() == '.net.au' || $domain->getTld() == '.org.au') { + // $params['COMAURegistrantId'] = ''; + // $params['COMAURegistrantIdType'] = ''; + // } + + // .de domains require an admin address in Germany + // if ($domain->getTld() == '.de') { + // //confirm here that the admin address is in fact germany + // $params['DEConfirmAddress'] = 'DE'; + // $params['DEAgreeDelete'] = 'Yes'; + // } + + if ($domain->getTld() == '.fr') { + $params['FRLegalType'] = 'Individual'; + $params['FRRegistrantBirthDate'] = $domain->getContactRegistrar()->getBirthday(); + $params['FRRegistrantBirthplace'] = $domain->getContactRegistrar()->getCountry(); + } + + error_log('REGISTER API PARAMS: ' . implode("\n", $params)); + + $result = $this->_makeRequest($params); + + error_log('REGISTER API RESULT: ' . $result); + + if (isset($result->CommandResponse->DomainCreateResult['Registered']) && ($result->CommandResponse->DomainCreateResult['Registered'] == 'true')){ + return True; + } + + throw new Registrar_Exception('Could not register domain.'); + + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'Command' => 'namecheap.domains.renew', + 'DomainName' => $domain->getName(), + 'Years' => $domain->getRegistrationPeriod(), + ); + + $result = $this->_makeRequest($params); + + return (isset($result->CommandResponse->DomainRenewResult['Renew']) + && ($result->CommandResponse->DomainRenewResult['Renew'] == 'true')); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function deleteDomain(Registrar_Domain $domain) + { + } + + /** + * @return string[] + * @throws Registrar_Exception + */ + private function getPrivacyInfo(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getInfo' + ); + + $result = $this->_makeRequest($params); + + if (isset($result->CommandResponse->DomainGetInfoResult->Whoisguard)) { + return array( + 'enabled' => $result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled'] == 'True', + 'id' => (string)$result->CommandResponse->DomainGetInfoResult->Whoisguard->ID + ); + } + throw new Registrar_Exception('Could not retrieve privacy info on this domain'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function enablePrivacyProtection(Registrar_Domain $domain) + { + $privacyInfo = $this->getPrivacyInfo($domain); + + if ($privacyInfo['enabled']) { + return True; + } + + $params = array( + 'WhoisguardID' => $privacyInfo['id'], + 'ForwardedToEmail' => $domain->getContactRegistrar()->getEmail(), + 'Command' => 'namecheap.whoisguard.enable' + ); + + $result = $this->_makeRequest($params); + + return isset($result->CommandResponse->WhoisguardEnableResult['isSuccess']) + && $result->CommandResponse->WhoisguardEnableResult['isSuccess'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function disablePrivacyProtection(Registrar_Domain $domain) + { + $privacyInfo = $this->getPrivacyInfo($domain); + + if (!$privacyInfo['enabled']) { + return True; + } + + $params = array( + 'WhoisguardID' => $privacyInfo['id'], + 'Command' => 'namecheap.whoisguard.disable' + ); + + $result = $this->_makeRequest($params); + + return isset($result->CommandResponse->WhoisguardDisableResult['isSuccess']) + && $result->CommandResponse->WhoisguardDisableResult['isSuccess'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function getLock(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Command' => 'namecheap.domains.getRegistrarLock' + ); + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'])) { + throw new Registrar_Exception('API ERROR: could not get lock status on domain'); + } + return $result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'] == 'true'; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function lock(Registrar_Domain $domain) + { + if ($this->getLock($domain) == 'true') { + return True; + } + + $params = array( + 'DomainName' => $domain->getName(), + 'LockAction' => 'LOCK', + 'Command' => 'namecheap.domains.setRegistrarLock' + ); + + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { + throw new Registrar_Exception('API ERROR: could not set lock status on domain'); + } + if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { + $domain->setLocked('true'); + return True; + } + return False; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function unlock(Registrar_Domain $domain) + { + if ($this->getLock($domain) == 'false') { + return True; + } + + $params = array( + 'DomainName' => $domain->getName(), + 'LockAction' => 'UNLOCK', + 'Command' => 'namecheap.domains.setRegistrarLock' + ); + + $result = $this->_makeRequest($params); + if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { + throw new Registrar_Exception('API ERROR: could not set lock status on domain'); + } + if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { + $domain->setLocked('false'); + return True; + } + return False; + } + + /** + * Checks if tld is compatible with namecheaps transfer api and + * if the domain is not available for registration (meaning hopefully the client owns it) + * @return bool + * @throws Registrar_Exception + */ + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + return in_array($domain->getTld(), array( + '.biz', '.ca', '.cc', '.co', '.co.uk', '.com', '.com.es', + '.com.pe', '.es', '.in', '.info', '.me', '.me.uk', '.mobi', '.net', '.net.pe', + '.nom.es', '.org', '.org.es', '.org.pe', '.org.uk', '.pe', '.tv', '.us' + )) + && !$this->isDomainAvailable($domain); + } + + // ClouDns config below + + /** + * Should return details of registered domain + * If domain is not registered should throw Registrar_Exception + * @return string + * @throws Registrar_Exception + */ + private function clouDnsRegisterDomainZone(Registrar_Domain $domain) + { + $url = 'https://api.cloudns.net/dns/register.xml'; + + $params = array( + 'auth-id' => $this->config['clouDns-id'], + 'auth-password' => $this->config['clouDns-password'], + 'domain-name' => $domain->getName(), + 'zone-type' => 'master', + ); + + $result = $this->_makeRequest($params, 'POST', $url); + + if (!(string)$result->status == 'Success') { + throw new Registrar_Exception('Could not create zone at ClouDns'); + } + + error_log('CLOUDNS REGISTER RESULT: ' . $result); + + $url = 'https://api.cloudns.net/dns/records.xml'; + + $params = array( + 'auth-id' => $this->config['clouDns-id'], + 'auth-password' => $this->config['clouDns-password'], + 'domain-name' => $domain->getName(), + ); + + $result = $this->_makeRequest($params, 'GET', $url); + + error_log('CLOUDNS RECORDS RESULT: ' . $result); + + if(!isset($result->item)){ + throw new Registrar_Exception('Could not retrieve records from ClouDns'); + } + + $records = array(); + foreach ($result->item as $item) { + $records[] = $item->record; + } + return implode(',', $records); + } + + /** + * Should return details of registered domain + * If domain is not registered should throw Registrar_Exception + * @return bool + * @throws Registrar_Exception + */ + private function setNsToClouDns(Registrar_Domain $domain, String $records) + { + // get NS info + $params = array( + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld($with_dot = false), + 'NameServers' => $records, + 'Command' => 'namecheap.domains.dns.setCustom', + ); + + $result = $this->_makeRequest($params); + + error_log('AFTER NS MODIFY: ' . $domain->__toString()); + + if (!isset($result->CommandResponse->DomainDNSSetCustomResult['Updated']) && $result->CommandResponse->DomainDNSSetCustomResult['Updated'] != 'true') { + throw new Registrar_Exception('Could create DNS records. Please contact your administrator'); + } + return True; + } +} From 034213574db4633223d37fff296411be7d0f2708 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Tue, 27 Dec 2022 15:42:21 -0800 Subject: [PATCH 3/7] Fix spelling of function --- src/library/Registrar/Adapter/Namecheap.php | 2 +- src/library/Registrar/Adapter/NamecheapClouDns.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library/Registrar/Adapter/Namecheap.php b/src/library/Registrar/Adapter/Namecheap.php index 80e0ebc59..e63f9f668 100644 --- a/src/library/Registrar/Adapter/Namecheap.php +++ b/src/library/Registrar/Adapter/Namecheap.php @@ -738,7 +738,7 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract * @return bool * @throws Registrar_Exception */ - public function isDomainCanBeTransfered(Registrar_Domain $domain) + public function isDomaincanBeTransferred(Registrar_Domain $domain) { return in_array($domain->getTld(), array( '.biz', '.ca', '.cc', '.co', '.co.uk', '.com', '.com.es', diff --git a/src/library/Registrar/Adapter/NamecheapClouDns.php b/src/library/Registrar/Adapter/NamecheapClouDns.php index 62b188a60..56ae6f93e 100644 --- a/src/library/Registrar/Adapter/NamecheapClouDns.php +++ b/src/library/Registrar/Adapter/NamecheapClouDns.php @@ -779,7 +779,7 @@ class Registrar_Adapter_NamecheapClouDns extends Registrar_AdapterAbstract * @return bool * @throws Registrar_Exception */ - public function isDomainCanBeTransfered(Registrar_Domain $domain) + public function isDomaincanBeTransferred(Registrar_Domain $domain) { return in_array($domain->getTld(), array( '.biz', '.ca', '.cc', '.co', '.co.uk', '.com', '.com.es', From ae93b8af8c166142eac2f4c780ff8e203a7bbaa2 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Tue, 27 Dec 2022 15:46:20 -0800 Subject: [PATCH 4/7] Add exception to deleteDomain --- src/library/Registrar/Adapter/Namecheap.php | 4 +++- src/library/Registrar/Adapter/NamecheapClouDns.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/library/Registrar/Adapter/Namecheap.php b/src/library/Registrar/Adapter/Namecheap.php index e63f9f668..7e3658066 100644 --- a/src/library/Registrar/Adapter/Namecheap.php +++ b/src/library/Registrar/Adapter/Namecheap.php @@ -585,11 +585,13 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract } /** - * @return bool + * TODO: Implement this correctly. + * * @throws Registrar_Exception */ public function deleteDomain(Registrar_Domain $domain) { + throw new Registrar_Exception('Domain deletion is not implemented in the NameCheap adapter. Please contact your system administrator.'); } /** diff --git a/src/library/Registrar/Adapter/NamecheapClouDns.php b/src/library/Registrar/Adapter/NamecheapClouDns.php index 56ae6f93e..1f60ba225 100644 --- a/src/library/Registrar/Adapter/NamecheapClouDns.php +++ b/src/library/Registrar/Adapter/NamecheapClouDns.php @@ -626,11 +626,13 @@ class Registrar_Adapter_NamecheapClouDns extends Registrar_AdapterAbstract } /** - * @return bool + * TODO: Implement this correctly. + * * @throws Registrar_Exception */ public function deleteDomain(Registrar_Domain $domain) { + throw new Registrar_Exception('Domain deletion is not implemented in the NameCheap adapter. Please contact your system administrator.'); } /** From 171931d6f975c281ac8e08c57ed639e3c91eb263 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Thu, 29 Dec 2022 11:28:51 -0800 Subject: [PATCH 5/7] Formatting --- src/library/Registrar/Adapter/Namecheap.php | 14 +++++++------- src/library/Registrar/Adapter/NamecheapClouDns.php | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/library/Registrar/Adapter/Namecheap.php b/src/library/Registrar/Adapter/Namecheap.php index 7e3658066..c8b1cd0d3 100644 --- a/src/library/Registrar/Adapter/Namecheap.php +++ b/src/library/Registrar/Adapter/Namecheap.php @@ -609,9 +609,9 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract if (isset($result->CommandResponse->DomainGetInfoResult->Whoisguard)) { return array( - 'enabled' => $result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled'] == 'True', - 'id' => (string)$result->CommandResponse->DomainGetInfoResult->Whoisguard->ID - ); + 'enabled' => $result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled'] == 'True', + 'id' => (string)$result->CommandResponse->DomainGetInfoResult->Whoisguard->ID + ); } throw new Registrar_Exception($message = 'Could not retrieve privacy info on this domain.'); } @@ -624,7 +624,7 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract { $privacyInfo = $this->getPrivacyInfo($domain); - if($privacyInfo['enabled']) { + if ($privacyInfo['enabled']) { return True; } @@ -636,7 +636,7 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract $result = $this->_makeRequest($params); - return isset($result->CommandResponse->WhoisguardEnableResult['isSuccess']) + return isset($result->CommandResponse->WhoisguardEnableResult['isSuccess']) && $result->CommandResponse->WhoisguardEnableResult['isSuccess'] == 'true'; } @@ -648,7 +648,7 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract { $privacyInfo = $this->getPrivacyInfo($domain); - if(!$privacyInfo['enabled']) { + if (!$privacyInfo['enabled']) { return True; } @@ -659,7 +659,7 @@ class Registrar_Adapter_Namecheap extends Registrar_AdapterAbstract $result = $this->_makeRequest($params); - return isset($result->CommandResponse->WhoisguardDisableResult['isSuccess']) + return isset($result->CommandResponse->WhoisguardDisableResult['isSuccess']) && $result->CommandResponse->WhoisguardDisableResult['isSuccess'] == 'true'; } diff --git a/src/library/Registrar/Adapter/NamecheapClouDns.php b/src/library/Registrar/Adapter/NamecheapClouDns.php index 1f60ba225..26686d3ba 100644 --- a/src/library/Registrar/Adapter/NamecheapClouDns.php +++ b/src/library/Registrar/Adapter/NamecheapClouDns.php @@ -599,12 +599,11 @@ class Registrar_Adapter_NamecheapClouDns extends Registrar_AdapterAbstract error_log('REGISTER API RESULT: ' . $result); - if (isset($result->CommandResponse->DomainCreateResult['Registered']) && ($result->CommandResponse->DomainCreateResult['Registered'] == 'true')){ + if (isset($result->CommandResponse->DomainCreateResult['Registered']) && ($result->CommandResponse->DomainCreateResult['Registered'] == 'true')) { return True; } - + throw new Registrar_Exception('Could not register domain.'); - } /** @@ -830,7 +829,7 @@ class Registrar_Adapter_NamecheapClouDns extends Registrar_AdapterAbstract error_log('CLOUDNS RECORDS RESULT: ' . $result); - if(!isset($result->item)){ + if (!isset($result->item)) { throw new Registrar_Exception('Could not retrieve records from ClouDns'); } From 4e58df788d9210bcb30672ca56b3076758f36087 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Thu, 29 Dec 2022 11:47:56 -0800 Subject: [PATCH 6/7] Remove the ClouDNS file We've decided we don't want it in the core software --- .../Registrar/Adapter/NamecheapClouDns.php | 868 ------------------ 1 file changed, 868 deletions(-) delete mode 100644 src/library/Registrar/Adapter/NamecheapClouDns.php diff --git a/src/library/Registrar/Adapter/NamecheapClouDns.php b/src/library/Registrar/Adapter/NamecheapClouDns.php deleted file mode 100644 index 26686d3ba..000000000 --- a/src/library/Registrar/Adapter/NamecheapClouDns.php +++ /dev/null @@ -1,868 +0,0 @@ - null, - 'api-key' => null, - 'username' => null, - 'ip' => null, - 'clouDns-id' => null, - 'clouDns-password' => null - - ); - - public function isKeyValueNotEmpty($array, $key) - { - $value = isset($array[$key]) ? $array[$key] : ''; - if (strlen(trim($value)) == 0) { - return false; - } - return true; - } - - public function __construct($options) - { - if (!extension_loaded('curl')) { - throw new Registrar_Exception('CURL extension is not enabled'); - } - - if (isset($options['api-user-id']) && !empty($options['api-user-id'])) { - $this->config['api-user-id'] = $options['api-user-id']; - unset($options['api-user-id']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Reseller ID" at "Configuration -> Domain registration".'); - } - - if (isset($options['api-key']) && !empty($options['api-key'])) { - $this->config['api-key'] = $options['api-key']; - unset($options['api-key']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "API Key" at "Configuration -> Domain registration".'); - } - - if (isset($options['username']) && !empty($options['username'])) { - $this->config['username'] = $options['username']; - unset($options['username']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Username" at "Configuration -> Domain registration".'); - } - - if (isset($options['ip']) && !empty($options['ip'])) { - $this->config['ip'] = $options['ip']; - unset($options['ip']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); - } - - if (isset($options['clouDns-id']) && !empty($options['clouDns-id'])) { - $this->config['clouDns-id'] = $options['clouDns-id']; - unset($options['clouDns-id']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); - } - - if (isset($options['clouDns-password']) && !empty($options['clouDns-password'])) { - $this->config['clouDns-password'] = $options['clouDns-password']; - unset($options['clouDns-password']); - } else { - throw new Registrar_Exception('Domain registrar "NamecheapClouDns" is not configured properly. Please update configuration parameter "Server IP Address" at "Configuration -> Domain registration".'); - } - } - - public static function getConfig() - { - return array( - 'label' => 'Manages domains on Namecheap via API. Namecheap requires your server IP in order to work.', - 'form' => array( - 'api-user-id' => array( - 'text', array( - 'label' => 'Namecheap Reseller ID', - 'description' => 'Namecheap Reseller ID. You can get this at Namecheap control panel', - 'required' => true, - ), - ), - 'api-key' => array( - 'password', array( - 'label' => ' Namecheap API Key', - 'description' => 'You can get this at Namecheap control panel', - 'required' => true, - ), - ), - 'username' => array( - 'text', array( - 'label' => 'Namecheap UserName', - 'description' => 'You can get this at Namecheap control panel', - 'required' => true, - ), - ), - 'ip' => array( - 'text', array( - 'label' => 'Server IP address', - 'description' => 'IP address of this server. Ensure that this IP is whitelisted under your NameCheap settings', - 'required' => true, - ), - ), - 'clouDns-id' => array( - 'text', array( - 'label' => 'ClouDns Api user ID', - 'description' => 'Login to your ClouDns Account. Go to Reseller API. The table API users indicates all your API users', - 'required' => true, - ), - ), - 'clouDns-password' => array( - 'text', array( - 'label' => 'ClouDns Api user Password', - 'description' => 'This is the password associated with the ClouDns user entered above', - 'required' => true, - ), - ), - ), - ); - } - - /** - * Tells what TLDs can be registered via this adapter - * @return string[] - */ - public function getTlds() - { - $params = array( - 'Command' => 'namecheap.domains.getTldList' - ); - - $result = $this->_makeRequest($params); - $strTlds = array(); - $xmlTlds = $result->CommandResponse->Tlds; - foreach ($xmlTlds->tld as $tld) { - array_push($strTlds, '.' . $tld['Name']); - } - return $strTlds; - } - - public function isDomainAvailable(Registrar_Domain $domain) - { - $params = array( - 'DomainList' => strtolower($domain->getSld()) . $domain->getTld(), - 'Command' => 'namecheap.domains.check' - ); - - $result = $this->_makeRequest($params); - - error_log('AVAILABLE ATTR: ' . $result->CommandResponse->DomainCheckResult['Available']); - - if (isset($result->CommandResponse->DomainCheckResult['Available']) && $result->CommandResponse->DomainCheckResult['Available'] == 'true') { - error_log('DOMAIN AVAILABLE: true'); - return true; - } - error_log('DOMAIN AVAILABLE: false'); - return false; - } - - /** - * Perform call to Api - * @param array $params - * @param string $method - * @return object - * @throws Registrar_Exception - */ - protected function _makeRequest($params = array(), $method = 'GET', $customUrl = null) - { - $params = $this->includeAuthorizationParams($params); - - $opts = array( - CURLOPT_CONNECTTIMEOUT => 30, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TIMEOUT => 60, - CURLOPT_URL => $customUrl ?? $this->_getApiUrl(), - CURLOPT_SSL_VERIFYHOST => 0, - CURLOPT_SSL_VERIFYPEER => 0, - ); - - if ($method == 'POST') { - $opts[CURLOPT_POST] = 1; - $opts[CURLOPT_POSTFIELDS] = $this->_formatParams($params); - $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL] . '?' . $opts[CURLOPT_POSTFIELDS]); - } else { - $opts[CURLOPT_URL] = $opts[CURLOPT_URL] . '?' . $this->_formatParams($params); - $this->getLog()->debug('API REQUEST: ' . $opts[CURLOPT_URL]); - } - - $ch = curl_init(); - curl_setopt_array($ch, $opts); - $data = curl_exec($ch); - if ($data === false) { - $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); - $this->getLog()->err($e); - curl_close($ch); - throw $e; - } - curl_close($ch); - - $this->getLog()->info('API RESULT: ' . $data); - - error_log('API RESULT: ' . $data); - - $result = simplexml_load_string($data); - - // error_log('RESULT ARRAY 1: '.implode("\n", $result)); - - if (isset($result['status']) && $result['status'] == 'error') { - throw new Registrar_Exception($result['status'], 102); - } - - if (isset($result['status']) && $result['status'] == 'Failed') { - throw new Registrar_Exception($result['status'], 103); - } - - return $result; - } - - /** - * Convert params to resellerClub format - * @see http://manage.resellerclub.com/kb/answer/755 - * @param array $params - * @return string - */ - private function _formatParams($params) - { - foreach ($params as $key => &$param) { - if (is_bool($param)) { - $param = ($param) ? 'true' : 'false'; - } - } - - $params = http_build_query($params); - return $params; - } - - /** - * Api URL - * @return string - */ - private function _getApiUrl() - { - if ($this->isTestEnv()) { - return 'https://api.sandbox.namecheap.com/xml.response'; - } - return 'https://api.namecheap.com/xml.response'; - } - - public function isTestEnv() - { - return $this->_testMode; - } - - /** - * @param array $params - * @return array - */ - public function includeAuthorizationParams(array $params) - { - return array_merge(array( - 'ApiUser' => $this->config['api-user-id'], - 'ApiKey' => $this->config['api-key'], - 'UserName' => $this->config['username'], - 'ClientIp' => $this->config['ip'], - ), $params); - } - - - /** - * @return bool - * @throws Registrar_Exception - */ - public function modifyNs(Registrar_Domain $domain) - { - // get NS info - $params = array( - 'SLD' => $domain->getSld(), - 'TLD' => $domain->getTld($with_dot = false), - 'NameServers' => $domain->getNs1() . ',' . $domain->getNs2() . ',' . $domain->getNs3() . ',' . $domain->getNs4(), - 'Command' => 'namecheap.domains.dns.setCustom', - ); - - $result = $this->_makeRequest($params); - - error_log('AFTER NS MODIFY: ' . $domain->__toString()); - - // TODO - // problem here: fossbilling doesn't display our error and will display 'nameservers updates' evern when this fails - - if (!isset($result->CommandResponse->DomainDNSSetCustomResult['Updated']) && $result->CommandResponse->DomainDNSSetCustomResult['Updated'] != 'true') { - throw new Registrar_Exception('Could not update NameServers'); - } - return True; - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function modifyContact(Registrar_Domain $domain) - { - $params = array( - 'Command' => 'namecheap.domains.setContacts', - 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), - ); - - // Set contact data - foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { - $c = $domain->getContactRegistrar(); - - if ($contactType == 'Admin' && $domain->getContactAdmin()) { - $c = $domain->getContactAdmin(); - } - - if ($contactType == 'Tech' && $domain->getContactTech()) { - $c = $domain->getContactTech(); - } - - if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { - $c = $domain->getContactBilling(); - } - - $params[$contactType . 'FirstName'] = $c->getFirstName(); - $params[$contactType . 'LastName'] = $c->getLastName(); - $params[$contactType . 'EmailAddress'] = $c->getEmail(); - $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); - $params[$contactType . 'Address1'] = $c->getAddress1(); - $params[$contactType . 'Address2'] = $c->getAddress2(); - $params[$contactType . 'City'] = $c->getCity(); - $params[$contactType . 'StateProvince'] = $c->getState(); - $params[$contactType . 'Country'] = $c->getCountry(); - $params[$contactType . 'PostalCode'] = $c->getZip(); - } - $result = $this->_makeRequest($params); - return $result->CommandResponse->DomainSetContactResult['IsSuccess'] == 'true'; - } - - /** - * relying on domain->getEpp() to return user's input for Epp code - * @return bool - * @throws Registrar_Exception - */ - public function transferDomain(Registrar_Domain $domain) - { - $nameservers = $this->clouDnsRegisterDomainZone($domain); - $params = array( - 'DomainName' => $domain->getName(), - 'Years' => '1', - 'EPPCode' => $domain->getEpp(), - 'Command' => 'namecheap.domains.transfer.create' - ); - - $result = $this->_makeRequest($params); - - error_log('TRANSFER ATTR: ' . $result->CommandResponse->DomainTransferCreateResult['Transfer']); - - if (isset($result->CommandResponse->DomainTransferCreateResult['Transfer']) && $result->CommandResponse->DomainTransferCreateResult['Transfer'] == 'true') { - error_log('DOMAIN TRANSFER: true'); - $this->setNsToClouDns($domain, $nameservers); - return True; - } - error_log('DOMAIN TRANSFER: false'); - throw new Registrar_Exception("Domain transfer could not be completed. Please contact your administrator"); - } - - /** - * Should return details of registered domain - * If domain is not registered should throw Registrar_Exception - * @return Registrar_Domain - * @throws Registrar_Exception - */ - public function getDomainDetails(Registrar_Domain $domain) - { - $params = array( - 'DomainName' => $domain->getName(), - 'Command' => 'namecheap.domains.getInfo' - ); - - $result = $this->_makeRequest($params); - - $domain->setRegistrationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->CreatedDate); - $domain->setExpirationTime((string)$result->CommandResponse->DomainGetInfoResult->DomainDetails->ExpiredDate); - $domain->setPrivacyEnabled((string)$result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled']); - - $params = array( - 'DomainName' => $domain->getName(), - 'Command' => 'namecheap.domains.getContacts' - ); - - $result = $this->_makeRequest($params); - - error_log('INFO ATTR: ' . (string)$result->CommandResponse->DomainContactsResult); - - if (!isset($result->CommandResponse->DomainContactsResult)) { - throw new Registrar_Exception("Could not retrieve domain details"); - } - - $contacts = $result->CommandResponse->DomainContactsResult; - // create new Domain obj to return - $newDomain = new Registrar_Domain(); - - // set SLD and TLD - $newDomain->setSld($domain->getSld()); - $newDomain->setTld($domain->getTld()); - - $registrarContact = new Registrar_Domain_Contact(); - $adminContact = new Registrar_Domain_Contact(); - $techContact = new Registrar_Domain_Contact(); - $billingContact = new Registrar_Domain_Contact(); - - // Set contact data on our Domain obj using info from our API call - foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { - $contactApi = $contacts->Registrant; - $contact = $registrarContact; - - if ($contactType == 'Admin') { - $contactApi = $contacts->Admin; - $contact = $adminContact; - } - if ($contactType == 'Tech') { - $contactApi = $contacts->Tech; - $contact = $techContact; - } - if ($contactType == 'AuxBilling') { - $contactApi = $contacts->AuxBilling; - $contact = $billingContact; - } - - $contact->setFirstName((string)$contactApi->FirstName); - $contact->setLastName((string)$contactApi->LastName); - $contact->setEmail((string)$contactApi->EmailAddress); - $contact->setTel((string)$contactApi->Phone); - $contact->setAddress1((string)$contactApi->Address1); - $contact->setAddress2((string)$contactApi->Address2); - $contact->setCity((string)$contactApi->City); - $contact->setState((string)$contactApi->StateProvince); - $contact->setCountry((string)$contactApi->Country); - $contact->setZip((string)$contactApi->PostalCode); - } - - $newDomain->setContactRegistrar($registrarContact); - $newDomain->setContactAdmin($adminContact); - $newDomain->setContactTech($techContact); - $newDomain->setContactBilling($billingContact); - - // get NS info - $params = array( - 'SLD' => $newDomain->getSld(), - 'TLD' => $newDomain->getTld($with_dot = false), - 'Command' => 'namecheap.domains.dns.getList', - ); - - $result = $this->_makeRequest($params); - - $NsArr = array(); - $xmlNsList = $result->CommandResponse->DomainDNSGetListResult; - foreach ($xmlNsList->Nameserver as $Nameserver) { - $NsArr[] = $Nameserver; - } - - for ($i = 1; $i <= 4; $i++) { - if (isset($NsArr[$i - 1])) { - $newDomain->{'setNs' . $i}((string)$NsArr[$i - 1]); - } - } - - error_log('DOMAIN OBJ FIELDS: ' . $newDomain->__toString()); - - return $newDomain; - } - - - /** - * This feature is unavailable through namecheaps API - * @return string - * @throws Registrar_Exception - */ - public function getEpp(Registrar_Domain $domain) - { - throw new Registrar_Exception('This feature is unavailable through the Namecheap API. Please contact your administrator'); - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function registerDomain(Registrar_Domain $domain) - { - $params = array( - 'Command' => 'namecheap.domains.create', - 'DomainName' => strtolower($domain->getSld()) . $domain->getTld(), - 'Years' => $domain->getRegistrationPeriod(), - ); - - if ($domain->getNs1()) { - // Add nameservers - $nsList = array(); - $nsList[] = $domain->getNs1(); - $nsList[] = $domain->getNs2(); - if ($domain->getNs3()) { - $nsList[] = $domain->getNs3(); - } - if ($domain->getNs4()) { - $nsList[] = $domain->getNs4(); - } - $params['Nameservers'] = implode(',', $nsList); - } else { - $params['Nameservers'] = $this->clouDnsRegisterDomainZone($domain); - } - - // Set contact data - foreach (array('Registrant', 'Admin', 'Tech', 'AuxBilling') as $contactType) { - $c = $domain->getContactRegistrar(); - - if ($contactType == 'Admin' && $domain->getContactAdmin()) { - $c = $domain->getContactAdmin(); - } - - if ($contactType == 'Tech' && $domain->getContactTech()) { - $c = $domain->getContactTech(); - } - - if ($contactType == 'AuxBilling' && $domain->getContactBilling()) { - $c = $domain->getContactBilling(); - } - - $params[$contactType . 'FirstName'] = $c->getFirstName(); - $params[$contactType . 'LastName'] = $c->getLastName(); - $params[$contactType . 'EmailAddress'] = $c->getEmail(); - $params[$contactType . 'Phone'] = '+' . $c->getTelCc() . '.' . $c->getTel(); - $params[$contactType . 'Address1'] = $c->getAddress1(); - $params[$contactType . 'Address2'] = $c->getAddress2(); - $params[$contactType . 'City'] = $c->getCity(); - $params[$contactType . 'StateProvince'] = $c->getState(); - $params[$contactType . 'Country'] = $c->getCountry(); - $params[$contactType . 'PostalCode'] = $c->getZip(); - } - $params['AddFreeWhoisguard'] = 'yes'; - - if ($domain->getTld() == '.us') { - $params['RegistrantPurpose'] = 'P3'; - $params['RegistrantNexus'] = 'C11'; - } - - if ($domain->getTld() == '.eu') { - $params['EUAgreeWhoisPolicy'] = 'YES'; - $params['EUAgreeDeletePolicy'] = 'YES'; - } - // passport for swedish identification - if ($domain->getTld() == '.nu') { - $params['NUOrgNo'] = $domain->getContactRegistrar()->getDocumentNr(); - } - - // need to check if user is a canadian resident or if coorporation is registered in canada - // if ($domain->getTld() == '.ca') { - // $params['CIRALegalType'] = 'CCT'; - // $params['EUAgreeDeletePolicy'] = 'YES'; - // } - - if ($domain->getTld() == '.co.uk' || $domain->getTld() == '.me.uk' || $domain->getTld() == '.org.uk') { - if ($domain->getContactRegistrar()->getCountry() == 'UK') { - $params['COUKLegalType'] = 'IND'; - } else { - $params['COUKLegalType'] = 'FIND'; - } - - $params['COUKRegisteredfor'] = $domain->getContactRegistrar()->getName(); - } - - // unsure how to handle this - // if ($domain->getTld() == '.com.au' || $domain->getTld() == '.net.au' || $domain->getTld() == '.org.au') { - // $params['COMAURegistrantId'] = ''; - // $params['COMAURegistrantIdType'] = ''; - // } - - // .de domains require an admin address in Germany - // if ($domain->getTld() == '.de') { - // //confirm here that the admin address is in fact germany - // $params['DEConfirmAddress'] = 'DE'; - // $params['DEAgreeDelete'] = 'Yes'; - // } - - if ($domain->getTld() == '.fr') { - $params['FRLegalType'] = 'Individual'; - $params['FRRegistrantBirthDate'] = $domain->getContactRegistrar()->getBirthday(); - $params['FRRegistrantBirthplace'] = $domain->getContactRegistrar()->getCountry(); - } - - error_log('REGISTER API PARAMS: ' . implode("\n", $params)); - - $result = $this->_makeRequest($params); - - error_log('REGISTER API RESULT: ' . $result); - - if (isset($result->CommandResponse->DomainCreateResult['Registered']) && ($result->CommandResponse->DomainCreateResult['Registered'] == 'true')) { - return True; - } - - throw new Registrar_Exception('Could not register domain.'); - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function renewDomain(Registrar_Domain $domain) - { - $params = array( - 'Command' => 'namecheap.domains.renew', - 'DomainName' => $domain->getName(), - 'Years' => $domain->getRegistrationPeriod(), - ); - - $result = $this->_makeRequest($params); - - return (isset($result->CommandResponse->DomainRenewResult['Renew']) - && ($result->CommandResponse->DomainRenewResult['Renew'] == 'true')); - } - - /** - * TODO: Implement this correctly. - * - * @throws Registrar_Exception - */ - public function deleteDomain(Registrar_Domain $domain) - { - throw new Registrar_Exception('Domain deletion is not implemented in the NameCheap adapter. Please contact your system administrator.'); - } - - /** - * @return string[] - * @throws Registrar_Exception - */ - private function getPrivacyInfo(Registrar_Domain $domain) - { - $params = array( - 'DomainName' => $domain->getName(), - 'Command' => 'namecheap.domains.getInfo' - ); - - $result = $this->_makeRequest($params); - - if (isset($result->CommandResponse->DomainGetInfoResult->Whoisguard)) { - return array( - 'enabled' => $result->CommandResponse->DomainGetInfoResult->Whoisguard['Enabled'] == 'True', - 'id' => (string)$result->CommandResponse->DomainGetInfoResult->Whoisguard->ID - ); - } - throw new Registrar_Exception('Could not retrieve privacy info on this domain'); - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function enablePrivacyProtection(Registrar_Domain $domain) - { - $privacyInfo = $this->getPrivacyInfo($domain); - - if ($privacyInfo['enabled']) { - return True; - } - - $params = array( - 'WhoisguardID' => $privacyInfo['id'], - 'ForwardedToEmail' => $domain->getContactRegistrar()->getEmail(), - 'Command' => 'namecheap.whoisguard.enable' - ); - - $result = $this->_makeRequest($params); - - return isset($result->CommandResponse->WhoisguardEnableResult['isSuccess']) - && $result->CommandResponse->WhoisguardEnableResult['isSuccess'] == 'true'; - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function disablePrivacyProtection(Registrar_Domain $domain) - { - $privacyInfo = $this->getPrivacyInfo($domain); - - if (!$privacyInfo['enabled']) { - return True; - } - - $params = array( - 'WhoisguardID' => $privacyInfo['id'], - 'Command' => 'namecheap.whoisguard.disable' - ); - - $result = $this->_makeRequest($params); - - return isset($result->CommandResponse->WhoisguardDisableResult['isSuccess']) - && $result->CommandResponse->WhoisguardDisableResult['isSuccess'] == 'true'; - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function getLock(Registrar_Domain $domain) - { - $params = array( - 'DomainName' => $domain->getName(), - 'Command' => 'namecheap.domains.getRegistrarLock' - ); - $result = $this->_makeRequest($params); - if (!isset($result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'])) { - throw new Registrar_Exception('API ERROR: could not get lock status on domain'); - } - return $result->CommandResponse->DomainGetRegistrarLockResult['RegistrarLockStatus'] == 'true'; - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function lock(Registrar_Domain $domain) - { - if ($this->getLock($domain) == 'true') { - return True; - } - - $params = array( - 'DomainName' => $domain->getName(), - 'LockAction' => 'LOCK', - 'Command' => 'namecheap.domains.setRegistrarLock' - ); - - $result = $this->_makeRequest($params); - if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { - throw new Registrar_Exception('API ERROR: could not set lock status on domain'); - } - if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { - $domain->setLocked('true'); - return True; - } - return False; - } - - /** - * @return bool - * @throws Registrar_Exception - */ - public function unlock(Registrar_Domain $domain) - { - if ($this->getLock($domain) == 'false') { - return True; - } - - $params = array( - 'DomainName' => $domain->getName(), - 'LockAction' => 'UNLOCK', - 'Command' => 'namecheap.domains.setRegistrarLock' - ); - - $result = $this->_makeRequest($params); - if (!isset($result->CommandResponse->DomainSetRegistrarLockResult['IsSuccess'])) { - throw new Registrar_Exception('API ERROR: could not set lock status on domain'); - } - if ($result->CommandResponse->DomainGetRegistrarLockResult['IsSuccess'] == 'true') { - $domain->setLocked('false'); - return True; - } - return False; - } - - /** - * Checks if tld is compatible with namecheaps transfer api and - * if the domain is not available for registration (meaning hopefully the client owns it) - * @return bool - * @throws Registrar_Exception - */ - public function isDomaincanBeTransferred(Registrar_Domain $domain) - { - return in_array($domain->getTld(), array( - '.biz', '.ca', '.cc', '.co', '.co.uk', '.com', '.com.es', - '.com.pe', '.es', '.in', '.info', '.me', '.me.uk', '.mobi', '.net', '.net.pe', - '.nom.es', '.org', '.org.es', '.org.pe', '.org.uk', '.pe', '.tv', '.us' - )) - && !$this->isDomainAvailable($domain); - } - - // ClouDns config below - - /** - * Should return details of registered domain - * If domain is not registered should throw Registrar_Exception - * @return string - * @throws Registrar_Exception - */ - private function clouDnsRegisterDomainZone(Registrar_Domain $domain) - { - $url = 'https://api.cloudns.net/dns/register.xml'; - - $params = array( - 'auth-id' => $this->config['clouDns-id'], - 'auth-password' => $this->config['clouDns-password'], - 'domain-name' => $domain->getName(), - 'zone-type' => 'master', - ); - - $result = $this->_makeRequest($params, 'POST', $url); - - if (!(string)$result->status == 'Success') { - throw new Registrar_Exception('Could not create zone at ClouDns'); - } - - error_log('CLOUDNS REGISTER RESULT: ' . $result); - - $url = 'https://api.cloudns.net/dns/records.xml'; - - $params = array( - 'auth-id' => $this->config['clouDns-id'], - 'auth-password' => $this->config['clouDns-password'], - 'domain-name' => $domain->getName(), - ); - - $result = $this->_makeRequest($params, 'GET', $url); - - error_log('CLOUDNS RECORDS RESULT: ' . $result); - - if (!isset($result->item)) { - throw new Registrar_Exception('Could not retrieve records from ClouDns'); - } - - $records = array(); - foreach ($result->item as $item) { - $records[] = $item->record; - } - return implode(',', $records); - } - - /** - * Should return details of registered domain - * If domain is not registered should throw Registrar_Exception - * @return bool - * @throws Registrar_Exception - */ - private function setNsToClouDns(Registrar_Domain $domain, String $records) - { - // get NS info - $params = array( - 'SLD' => $domain->getSld(), - 'TLD' => $domain->getTld($with_dot = false), - 'NameServers' => $records, - 'Command' => 'namecheap.domains.dns.setCustom', - ); - - $result = $this->_makeRequest($params); - - error_log('AFTER NS MODIFY: ' . $domain->__toString()); - - if (!isset($result->CommandResponse->DomainDNSSetCustomResult['Updated']) && $result->CommandResponse->DomainDNSSetCustomResult['Updated'] != 'true') { - throw new Registrar_Exception('Could create DNS records. Please contact your administrator'); - } - return True; - } -} From 3e5fcef67756834d8bac0053a8152dbf1df71f39 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Thu, 29 Dec 2022 11:48:49 -0800 Subject: [PATCH 7/7] Delete srsx.php --- src/library/Registrar/Adapter/srsx.php | 601 ------------------------- 1 file changed, 601 deletions(-) delete mode 100644 src/library/Registrar/Adapter/srsx.php diff --git a/src/library/Registrar/Adapter/srsx.php b/src/library/Registrar/Adapter/srsx.php deleted file mode 100644 index 4e3c7941f..000000000 --- a/src/library/Registrar/Adapter/srsx.php +++ /dev/null @@ -1,601 +0,0 @@ -config['resellerId'] = $options['resellerId']; - unset($options['resellerId']); - } else { - throw new Registrar_Exception('Domain registrar "SRSX" is not configured properly. Please update configuration parameter "SRSX Reseller ID" at "Configuration -> Domain registration".'); - } - - if(isset($options['apiUsername']) && !empty($options['apiUsername'])) { - $this->config['apiUsername'] = $options['apiUsername']; - unset($options['apiUsername']); - } else { - throw new Registrar_Exception('Domain registrar "SRSX" is not configured properly. Please update configuration parameter "SRSX Username" at "Configuration -> Domain registration".'); - } - - if(isset($options['apiPassword']) && !empty($options['apiPassword'])) { - $this->config['apiPassword'] = $options['apiPassword']; - unset($options['apiPassword']); - } else { - throw new Registrar_Exception('Domain registrar "SRSX" is not configured properly. Please update configuration parameter "ResellerClub API Key" at "Configuration -> Domain registration".'); - } - - - - - } - - public static function getConfig() - { - return array( - 'label' => 'Manages domains on SRSX via API. ResellerClub requires your server IP in order to work. Login to the ResellerClub control panel (the url will be in the email you received when you signed up with them) and then go to Settings > API and enter the IP address of the server where FOSSBilling is installed to authorize it for API access.', - 'form' => array( - - 'resellerId' => array('text', array( - 'label' => 'RESELLER ID', - 'description'=> 'You can get this at ResellerClub control panel, go to Settings -> API' - ), - ), - - 'apiUsername' => array('text', array( - 'label' => 'Username Reseller. You can get this at ResellerClub control panel Settings > Personal information > Primary profile > Reseller ID', - 'description'=> 'SRSX Reseller UserName' - ), - ), - - 'apiPassword' => array('password', array( - 'label' => 'Password Reseller. You can get this at ResellerClub control panel Settings > Personal information > Primary profile > Reseller ID', - 'description'=> 'SRSX Password ID' - ), - ), - - ), - ); - } - - #still not fixed - public function synchInfo() { - # Get domain information - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $domaininfoResult = $this->_callApi("domain/info",$postfields); - if (sprintf($domaininfoResult->result->resultCode)==1000) { - # Get domain ID - $domainid = $this->getDomainId(); - # Update status - $status = sprintf($domaininfoResult->resultData->status); - if (strtolower($status)=="active") { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("status"=>"Active"))) { - $this->addInfo("Status has been updated to Active"); - } - } else { - if (in_array(strtolower($status),array("awaiting document","active*","verifying","validating","document approved"))) { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("status"=>"Pending Registration"))) { - $this->addInfo("Status has been updated to Pending Registration"); - } - } - } - if (in_array(strtolower($status),array("active","active*"))) { - # Update start date - $startdate = sprintf($domaininfoResult->resultData->enddate); - if ($startdate!="1970-01-01") { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("date_created"=>$startdate))) { - $this->addInfo("Start date has been updated"); - } - } - # Update expiry date - $expirydate = sprintf($domaininfoResult->resultData->enddate); - if ($expirydate!="1970-01-01") { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("expires"=>$expirydate))) { - $this->addInfo("Expiry date has been updated"); - } - } - # Update NS - $ns = array(); - for ($i=1;$i<=8;$i++) { - $nsItem = "ns{$i}"; - if (sprintf($domaininfoResult->resultData->$nsItem)) { - $ns[] = sprintf($domaininfoResult->resultData->$nsItem); - } - } - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("nameservers"=>implode("|",$ns)))) { - $this->addInfo("Nameservers has been updated"); - } - } - return true; - } else { - $this->addError(sprintf($domaininfoResult->result->resultMsg)); - return false; - } - } - - //its fixed for check - public function isDomainAvailable(Registrar_Domain $domain) - { - $params = array( - 'domain' => $domain->getName(), - ); - - $domaincheckResult = $this->_callApi("domain/check",$params); - if (sprintf($domaincheckResult->result->resultCode)==1000) { - return true; - } else { - return false; - } - } - - //for register domain -- still not fixed - public function registerDomain(Registrar_Domain $domain) - { - - $c = $domain->getContactRegistrar(); - $company = $c->getCompany(); - if (!isset($company) || strlen(trim($company)) == 0 ){ - $company = 'N/A'; - } - $phoneNum = $c->getTel(); - $phoneNum = preg_replace( "/[^0-9]/", "", $phoneNum); - $phoneNum = substr($phoneNum, 0, 12); - - # check if available on srsx - $postfields = array( - "user_username" => $c->getEmail() - ); - $userinfoResult = $this->_callApi("user/info",$postfields); - if (sprintf($userinfoResult->result->resultCode)!=1000) { - # create new user - $postfields = array( - "user_username" => $c->getEmail(), - "user_password" => $c->getPassword(), - "fname" => $c->getFirstName(), - "lname" => $c->getLastName(), - "company" => $company, - "address" => $c->getAddress1(), - "address2" => $c->getAddress2(), - "city" => $c->getCity(), - "province" => $c->getState(), - "country" => $c->getCountry(), - "postal_code" => $c->getZip(), - "phone" => $phoneNum - - ); - $usercreate = $this->_callApi("user/create",$postfields); - if (sprintf($usercreate->result->resultCode)!=1000) { - $this->addError("User create: ".sprintf($usercreate->result->resultMsg)); - return false; - } - } - # Get domain ID - $domainid = $this->getDomainId(); - # Register domain - #$this->client_data wut by timothy? - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"], - "api_id" => $domainid, - "periode" => $this->options["numyears"], - "fname" => $this->client_data["firstname"], - "lname" => $this->client_data["lastname"], - "company" => $this->client_data["companyname"], - "address1" => $this->client_data["address1"], - "address2" => $this->client_data["address2"], - "city" => $this->client_data["city"], - "state" => $this->client_data["state"], - "postcode" => $this->client_data["postcode"], - "country" => $this->client_data["country"], - "phonenumber" => $this->client_data["phonenumber"], - "handphone" => $this->client_data["phonenumber"], - "email" => $this->client_data["email"], - "user_username" => $this->client_data["email"], - "user_fname" => $this->client_data["firstname"], - "user_lname" => $this->client_data["lastname"], - "user_email" => $this->client_data["email"], - "user_company" => $this->client_data["companyname"], - "user_address" => $this->client_data["address1"], - "user_address2" => $this->client_data["address2"], - "user_city" => $this->client_data["city"], - "user_province" => $this->client_data["state"], - "user_phone" => $this->client_data["phonenumber"], - "user_country" => $this->client_data["country"], - "user_postal_code" => $this->client_data["postcode"], - "randomhash" => $this->randomhash(64) - ); - # NS - for ($i=1;$i<=4;$i++) { - if ($this->options["ns{$i}"] || $this->details["ns{$i}"]) { - $nameserver[] = $this->options["ns{$i}"] ? $this->options["ns{$i}"] : $this->details["ns{$i}"]; - } - } - $registerResult = $this->_callApi("domain/register",$postfields); - if (sprintf($registerResult->result->resultCode)==1000) { - $this->addInfo("Domain has been registered"); - return true; - } else { - if (preg_match("#upload required documents#",sprintf($registerResult->result->resultMsg))) { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("status"=>"Pending Registration"))) { - $this->addInfo("Domain has been registered, but domain name activation is waiting for documents to be uploaded"); - return true; - } - } elseif (sprintf($registerResult->result->resultMsg)=="Order with the same ID already created") { - if (Capsule::table("hb_domains")->where("id",$domainid)->update(array("status"=>"Pending Registration"))) { - $this->addInfo("Domain has been registered, please Synchronize this order"); - return true; - } - } else { - $this->addError("Domain create: ".sprintf($registerResult->result->resultMsg)); - } - return false; - } - } - - #still not fixed - public function modifyNs(Registrar_Domain $domain) - { - $ns = array(); - $ns[] = $domain->getNs1(); - $ns[] = $domain->getNs2(); - if($domain->getNs3()) { - $ns[] = $domain->getNs3(); - } - if($domain->getNs4()) { - $ns[] = $domain->getNs4(); - } - - $params = array( - 'order-id' => $this->_getDomainOrderId($domain), - 'ns' => $ns, - ); - - $result = $this->_callApi('domain/updatens', $params, 'POST'); - return ($result['status'] == 'Success'); - } - - #still not fixed - public function modifyContact(Registrar_Domain $domain) - { - $customer = $this->_getCustomerDetails($domain); - $cdetails = $this->_getDefaultContactDetails($domain, $customer['customerid']); - $contact_id = $cdetails['Contact']['registrant']; - - $c = $domain->getContactRegistrar(); - - $required_params = array( - 'contact-id' => $contact_id, - 'name' => $c->getName(), - 'company' => $c->getCompany(), - 'email' => $c->getEmail(), - 'address-line-1' => $c->getAddress1(), - 'city' => $c->getCity(), - 'zipcode' => $c->getZip(), - 'phone-cc' => $c->getTelCc(), - 'phone' => $c->getTel(), - 'country' => $c->getCountry(), - ); - - $optional_params = array( - 'address-line-2' => $c->getAddress2(), - 'address-line-3' => $c->getAddress3(), - 'state' => $c->getState(), - ); - - $params = array_merge($optional_params, $required_params); - $result = $this->_callApi('domain/editcontact', $params, 'POST'); - return ($result['status'] == 'Success'); - } - - public function transferDomain(Registrar_Domain $domain) - { - - # Get EPP Code - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $geteppResult = $this->_callApi("domain/getepp",$postfields); - if (sprintf($geteppResult->result->resultCode)==1000) { - # Transfer domain - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"], - "transfersecret" => base64_encode(sprintf($geteppResult->resultData->epp)), - "periode" => $this->options["numyears"], - "ns1" => $this->options["ns1"] ? $this->options["ns1"] : $this->details["ns1"], - "ns2" => $this->options["ns2"] ? $this->options["ns2"] : $this->details["ns2"], - "ns3" => $this->options["ns3"] ? $this->options["ns3"] : $this->details["ns3"], - "ns4" => $this->options["ns4"] ? $this->options["ns4"] : $this->details["ns4"], - "fname" => $this->client_data["firstname"], - "lname" => $this->client_data["lastname"], - "companyname" => $this->client_data["companyname"], - "address1" => $this->client_data["address1"], - "address2" => $this->client_data["address2"], - "city" => $this->client_data["city"], - "state" => $this->client_data["state"], - "postcode" => $this->client_data["postcode"], - "country" => $this->client_data["country"], - "phonenumber" => $this->client_data["phonenumber"], - "handphone" => $this->client_data["phonenumber"], - "email" => $this->client_data["email"], - "user_username" => $this->client_data["email"], - "user_fname" => $this->client_data["firstname"], - "user_lname" => $this->client_data["lastname"], - "user_email" => $this->client_data["email"], - "user_company" => $this->client_data["companyname"], - "user_address" => $this->client_data["address1"], - "user_address2" => $this->client_data["address2"], - "user_city" => $this->client_data["city"], - "user_province" => $this->client_data["state"], - "user_phone" => $this->client_data["phonenumber"], - "user_country" => $this->client_data["country"], - "user_postal_code" => $this->client_data["postcode"], - ); - $domaintransferResult = $this->_callApi("domain/transfer",$postfields); - if (sprintf($domaintransferResult->result->resultCode)==1000) { - $this->addInfo("Domain has been transferred"); - return true; - } else { - $this->addError(sprintf($domaintransferResult->result->resultMsg)); - } - } else { - $this->addError(sprintf($geteppResult->result->resultMsg)); - } - return false; - } - - - public function renewDomain(Registrar_Domain $domain) - { - # Get EPP Code - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"], - "periode" => $this->options['numyears'] - ); - $renewdomainResult = $this->_callApi("domain/getepp",$postfields); - if (sprintf($renewdomainResult->result->resultCode)==1000) { - $this->addInfo("Domain has been renewed"); - return true; - } else { - $this->addError(sprintf($renewdomainResult->result->resultMsg)); - } - return false; - } - - public function getEpp(Registrar_Domain $domain) - { - # Get EPP Code - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $domaingeteppResult = $this->_callApi("domain/getepp",$postfields); - if (sprintf($domaingeteppResult->result->resultCode)==1000) { - $domainid = $this->getDomainId(); - Capsule::table("hb_domains")->where("id",$domainid)->update(array("epp_code"=>sprintf($domaingeteppResult->resultData->epp))); - $this->addInfo("EPP Code: ".sprintf($domaingeteppResult->resultData->epp)); - return true; - } else { - $this->addError(sprintf($domaingeteppResult->result->resultMsg)); - return false; - } - } - - public function lock(Registrar_Domain $domain) - { - $params = array( - 'order-id' => $this->_getDomainOrderId($domain), - ); - - $domaincheckResult = $this->_callApi("domain/lock",$params); - if (sprintf($domaincheckResult->result->resultCode)==1000) { - return true; - } else { - return false; - } - } - - public function unlock(Registrar_Domain $domain) - { - $params = array( - 'order-id' => $this->_getDomainOrderId($domain), - ); - - $domaincheckResult = $this->_callApi("domain/unlock",$params); - if (sprintf($domaincheckResult->result->resultCode)==1000) { - return true; - } else { - return false; - } - } - - public function Cancel(Registrar_Domain $domain) { - # Cancel domain - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $domaincancelResult = $this->_callApi("domain/cancel",$postfields); - if (sprintf($domaincancelResult->result->resultCode)==1000) { - $this->addInfo("Domain has been cancelled"); - return true; - } else { - $this->addError(sprintf($domaincancelResult->result->resultMsg)); - return false; - } - } - - private function _getCustomerDetails() - { - # Get contact information - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $contactinfoResult = $this->_callApi("contact/info",$postfields); - if (sprintf($contactinfoResult->result->resultCode)==1000) { - $contact = array( - "contactid" => sprintf($contactinfoResult->resultData->contactid), - "userid" => sprintf($contactinfoResult->resultData->userid), - "nickhandle" => sprintf($contactinfoResult->resultData->nickhandle), - "firstname" => sprintf($contactinfoResult->resultData->fname), - "lastname" => sprintf($contactinfoResult->resultData->lname), - "email" => sprintf($contactinfoResult->resultData->email), - "companyname" => sprintf($contactinfoResult->resultData->company), - "address1" => sprintf($contactinfoResult->resultData->address1), - "address2" => sprintf($contactinfoResult->resultData->address2), - "address3" => sprintf($contactinfoResult->resultData->address3), - "city" => sprintf($contactinfoResult->resultData->city), - "state" => sprintf($contactinfoResult->resultData->state), - "phonenumber" => sprintf($contactinfoResult->resultData->phonenumber), - "fax" => sprintf($contactinfoResult->resultData->fax), - "country" => sprintf($contactinfoResult->resultData->country), - "postcode" => sprintf($contactinfoResult->resultData->postcode), - ); - return $contact; - } else { - $this->addError(sprintf($contactinfoResult->result->resultMsg)); - return false; - } - } - - private function _createCustomer() - { - # Get contact information - $postfields = array( - "domain" => $this->options["sld"].".".$this->options["tld"] - ); - $contactinfoResult = $this->_callApi("contact/info",$postfields); - if (sprintf($contactinfoResult->result->resultCode)==1000) { - # Update contact information - $postfields = array( - "contactid" => sprintf($contactinfoResult->resultData->contactid), - "fname" => $this->options['firstname'], - "lname" => $this->options['lastname'], - "email" => $this->options["email"], - "company" => $this->options['companyname'], - "address" => $this->options['address1'], - "address2" => $this->options["address2"], - "city" => $this->options["city"], - "province" => $this->options["state"], - "country" => $this->options["country"], - "postal_code" => $this->options["postcode"], - "phone" => $this->options["phonenumber"], - ); - $contactupdateResult = $this->_callApi("contact/create",$postfields); - if ($contactupdateResult) { - $this->addInfo("Contact has been updated"); - return true; - } else { - $this->addError(sprintf($contactupdateResult->result->resultMsg)); - return false; - } - } else { - $this->addError(sprintf($contactinfoResult->result->resultMsg)); - return false; - } - } - - private function _getDefaultContactDetails(Registrar_Domain $domain, $customerid) - { - $params = array( - 'customer-id' => $customerid, - 'type' => 'Contact', - ); - - return $this->_callApi('contact/info', $params, 'POST'); - } - - private function removeCustomer($params) - { - $required_params = array( - 'customer-id' => '', - ); - $params = $this->_checkRequiredParams($required_params, $params); - $result = $this->_callApi('contact/delete', $params, 'POST'); - return ($result == 'true'); - } - - private function _hasCompletedOrder(Registrar_Domain $domain) - { - try { - $orderid = $this->_getDomainOrderId($domain); - $params = array( - 'order-id' => $orderid, - 'options' => 'All', - ); - $data = $this->_callApi('domain/info', $params); - } catch(Exception $e) { - return false; - } - - return ($data['currentstatus'] == 'Active'); - } - - protected function _callApi($query=true,$postfields=true) { - - - if ($query && is_array($postfields)) { - # Get URL - $apiUrl = "https://srb{$this->config["resellerId"]}.srs-x.com"; - # Basic authentication - $postfields["username"] = $this->config["apiUsername"]; - $postfields["password"] = hash('sha256',$this->config["apiPassword"]); - - # CURL - $ch = curl_init(); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_URL, "{$apiUrl}/api/{$query}"); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields)); - $apiXml = curl_exec($ch); - curl_close($ch); - $apiResult = simplexml_load_string($apiXml); - - //$this->logmessage("error","API_URL: {$apiUrl}/api/{$query}\nAPI_Postfields:\n".print_r($this->protectField($postfields),true)."API_Response:\n".print_r($apiXml,true)); - return $apiResult; - echo json_encode($apiResult); - - } - return false; - } - - - protected function randomhash($length=6) { - $base = 'ABCDEFGHKLMNOPQRSTWXYZ123456789'; - $max = strlen($base)-1; - $randomResult = ""; - mt_srand((double)microtime()*1000000); - while (strlen($randomResult)<$length) { - $randomResult .= $base[random_int(0,$max)]; - } - return $randomResult; - } - -}