diff --git a/bb-library/Payment/Adapter/Ccavenue.php b/bb-library/Payment/Adapter/Ccavenue.php index cd6db5c..110af16 100644 --- a/bb-library/Payment/Adapter/Ccavenue.php +++ b/bb-library/Payment/Adapter/Ccavenue.php @@ -120,21 +120,38 @@ public function recurrentPayment(Payment_Invoice $invoice) public function getTransaction($data, Payment_Invoice $invoice) { $ipn = $data['post']; + + $Order_Id = $ipn['Order_Id']; + $Amount = $ipn['Amount']; + $AuthDesc = $ipn['AuthDesc']; + $Merchant_Id = $ipn['Merchant_Id']; + $Checksum = $ipn['Checksum']; - //@todo - $response = new Payment_Transaction(); - $response->setType(Payment_Transaction::TXTYPE_PAYMENT); - $response->setId(uniqid()); - $response->setAmount($invoice->getTotalWithTax()); - $response->setCurrency($invoice->getCurrency()); - $response->setStatus(Payment_Transaction::STATUS_COMPLETE); - return $response; + $tx = new Payment_Transaction(); + $tx->setType(Payment_Transaction::TXTYPE_PAYMENT); + $tx->setId($Checksum); + $tx->setAmount($Amount); + $tx->setCurrency($invoice->getCurrency()); + + if ($AuthDesc == 'Y') { + $tx->setStatus(Payment_Transaction::STATUS_COMPLETE); + } + + return $tx; } public function isIpnValid($data, Payment_Invoice $invoice) { $ipn = $data['post']; - return true; + + $WorkingKey = $this->getParam('workingkey'); + $Merchant_Id = $ipn['Merchant_Id']; + $Amount = $ipn['Amount']; + $OrderId = $ipn['Order_Id']; + $AuthDesc = $ipn['AuthDesc']; + $CheckSum = $ipn['Checksum']; + $sum = getchecksum($Merchant_Id, $Amount, $OrderId, $AuthDesc, $WorkingKey); + return ($CheckSum == $sum); } } diff --git a/bb-library/Registrar/Adapter/CNic.php b/bb-library/Registrar/Adapter/CNic.php new file mode 100644 index 0000000..00701aa --- /dev/null +++ b/bb-library/Registrar/Adapter/CNic.php @@ -0,0 +1,415 @@ + null, + 'password' => null + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "CentralNIC" is not configured properly. Please update configuration parameter "CentralNIC Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "CentralNIC" is not configured properly. Please update configuration parameter "CentralNIC password" at "Configuration -> Domain registration".'); + } + //@todo + //require_once 'Registrar/CNic/Toolkit.php'; + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on CentralNIC via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'CentralNIC Username', + 'description'=>'CentralNIC Username' + ), + ), + 'password' => array('password', array( + 'label' => 'CentralNIC password', + 'description'=>'CentralNIC password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + $query = new CNic_Toolkit('suffixes'); + return $this->_request($query)->suffixes(); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $query = new CNic_Toolkit('search', $domain->getSld()); + + $query->set('suffixlist', array($domain->getTld())); + + return !$this->_request($query)->is_registered($domain->getTld()); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + $this->getLog()->debug('Checking if domain can be transfered: ' . $domain->getName()); + return true; + } + + public function modifyNs(Registrar_Domain $domain) + { + $query = new CNic_Toolkit( + 'modify', + $domain->getName(), + 1, + $this->config['user'], + $this->config['password'] + ); + + $nsList = array(); + $nsList[] = $domain->getNs1(); + $nsList[] = $domain->getNs2(); + $nsList[] = $domain->getNs3(); + $nsList[] = $domain->getNs4(); + + $query->set('dns', array( + 'drop' => 'all', + 'add' => $nsList + )); + + return (bool) $this->_request($query); + } + + public function modifyContact(Registrar_Domain $domain) + { + $query = new CNic_Toolkit( + 'modify_handle', + 1, + $this->config['user'], + $this->config['password'] + ); + + $userid = $this->_getHandleId($domain); + $c = $domain->getContactRegistrar(); + + $query->set('handle', $userid); + $query->set('name', $c->getName()); + $query->set('company', $c->getCompany()); + $query->set('street1', $c->getAddress1()); + $query->set('street2', $c->getAddress2()); + $query->set('city', $c->getCity()); + $query->set('sp', $c->getCountry()); + $query->set('postcode', $c->getZip()); + $query->set('country', $c->getCountry()); + $query->set('phone', $c->getTelCc() . '.' . $c->getTel()); + $query->set('fax', $c->getFaxCc() . '.' . $c->getFax()); + $query->set('email', $c->getEmail()); + + return (bool) $this->_request($query); + } + + public function transferDomain(Registrar_Domain $domain) + { + $query = new CNic_Toolkit( + 'start_transfer', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('domains', array($domain->getName())); + $query->set('authinfo', array($this->_getEpp($domain))); + + return (bool) $this->_request($query); + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $query = new CNic_Toolkit('whois', $domain->getName()); + + $response = $this->_request($query); + + return $this->_createDomainObj($response, $domain); + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $userid = $this->_createHandle($domain); + + $query = new CNic_Toolkit( + 'register', + $domain->getName(), + 1, + $this->config['user'], + $this->config['password'] + ); + + $nsList = array(); + $nsList[] = $domain->getNs1(); + $nsList[] = $domain->getNs2(); + $nsList[] = $domain->getNs3(); + $nsList[] = $domain->getNs4(); + + $query->set('registrant', 'John Doe, Example Company Ltd.'); + $query->set('chandle', $userid); + $query->set('thandle', $userid); + $query->set('bhandle', $userid); + $query->set('ahandle', $userid); + $query->set('dns', $nsList); + $query->set('period', $domain->getRegistrationPeriod()); + + return (bool) $this->_request($query); + } + + public function renewDomain(Registrar_Domain $domain) + { + $query = new CNic_Toolkit( + 'issue_renewals', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('period', $domain->getRegistrationPeriod()); + $query->set('domains', array($domain->getName())); + + return (bool) $this->_request($query); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + $query = new CNic_Toolkit('whois', $domain->getName()); + + $contact = $this->_request($query)->response('chandle'); + + // Request for privacy settings change + $query = new CNic_Toolkit( + 'modify_handle', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('handle', $contact['userid']); + $query->set('visible', 1); + + return (bool) $this->_request($query); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + $query = new CNic_Toolkit('whois', $domain->getName()); + + $contact = $this->_request($query)->response('chandle'); + + // Request for privacy settings change + $query = new CNic_Toolkit( + 'modify_handle', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('handle', $contact['userid']); + $query->set('visible', 0); + + return (bool) $this->_request($query); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception('Epp code retrieval is not implemented'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain locking is not implemented'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain unlocking is not implemented'); + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * Creates domain object from received data array. + * @param array $result + * @param Registrar_Domain $domain + * @return Registrar_Domain + */ + private function _createDomainObj($response, Registrar_Domain $domain) + { + $contact = $response->response('chandle'); + $nameservers = $response->response('dns'); + $privacy = false; + // If name doesn't exist, that means privacy is on, so we need to + // request contact details separately + if (!array_key_exists('name', $contact)) + { + $contact = $this->_getHandleInfo($contact['userid']); + $privacy = true; + } + + $c = new Registrar_Domain_Contact(); + $c->setName($contact['name']) + ->setEmail($contact['email']) + ->setCompany($contact['company']) + ->setTel($contact['phone']) + ->setFax($contact['fax']) + ->setAddress1($contact['street1']) + ->setAddress2($contact['street2']) + ->setCity($contact['city']) + ->setCountry($contact['country']) + ->setZip($contact['postcode']); + + $domain->setContactRegistrar($c); + $domain->setRegistrationTime($response->response('created')); + $domain->setExpirationTime($response->response('expires')); + $domain->setPrivacyEnabled($privacy); + $domain->setEpp($this->_getEpp($domain)); + + return $domain; + } + + /** + * Creates contact handle and returns its id. + * @param Registrar_Domain $domain + * @return string + */ + private function _createHandle(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $query = new CNic_Toolkit( + 'create_handle', + 1, + $this->config['user'], + $this->config['password'] + ); + + $params = array( + 'name' => $c->getName(), + 'company' => $c->getCompany(), + 'street1' => $c->getAddress1(), + 'street2' => $c->getAddress2(), + 'street3' => $c->getAddress3(), + 'city' => $c->getCity(), + 'sp' => $c->getCountry(), + 'postcode' => $c->getZip(), + 'country' => $c->getCountry(), + 'phone' => $c->getTelCc() . $c->getTel(), + 'fax' => $c->getFaxCc() . $c->getFax(), + 'email' => $c->getEmail(), + ); + + $query->set('handle', $params); + $query->set('visible', 1); + + return $this->_request($query)->handle(); + } + + /** + * Gets and formats information of the handle. + * @param string $userid + * @return array $contact + */ + private function _getHandleInfo($userid) + { + $query = new CNic_Toolkit( + 'handle_info', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('visible', 0); + $query->set('handle', $userid); + + $response = $this->_request($query); + + $contact = array(); + foreach (array('name', 'company', 'address', 'street1', + 'street2', 'street3', 'city', 'sp', 'postcode', + 'country', 'tel', 'fax', 'email') as $key) + { + $contact[$key] = $response->response($key); + } + + return $contact; + } + + /** + * Gets userid (handle) of a certain domain's contact. + * @param Registrar_Domain $domain + * @return string + */ + private function _getHandleId(Registrar_Domain $domain) + { + $query = new CNic_Toolkit('whois', $domain->getName()); + + $contact = $this->_request($query)->response('chandle'); + + return $contact['userid']; + } + + /** + * Gets transfer (authcode) of the domain. + * @param Registrar_Domain $domain + * @return string + */ + private function _getEpp(Registrar_Domain $domain) + { + $query = new CNic_Toolkit( + 'auth_info', + 1, + $this->config['user'], + $this->config['password'] + ); + + $query->set('domain', $domain->getName()); + + return $this->_request($query)->response('authcode'); + } + + /** + * Performs the request. + * @param CNic_Toolkit $query + * @return string + * @throws Registrar_Exception + */ + private function _request($query) + { + if ($this->isTestEnv()) + $query->set('test', 1); + + $response = $query->execute(); + + if ($response->is_success()) + return $response; + throw new Registrar_Exception($response->response('message')); + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Domainbox.php b/bb-library/Registrar/Adapter/Domainbox.php new file mode 100644 index 0000000..02b2494 --- /dev/null +++ b/bb-library/Registrar/Adapter/Domainbox.php @@ -0,0 +1,421 @@ + null, + 'user' => null, + 'password' => null + ); + + public function __construct($options) + { + if(!extension_loaded('soap')) { + throw new Registrar_Exception('Soap extension required for DomainBox registrar'); + } + + if(isset($options['reseller']) && !empty($options['reseller'])) { + $this->config['reseller'] = $options['reseller']; + unset($options['reseller']); + } else { + throw new Registrar_Exception('Domain registrar "Domainbox" is not configured properly. Please update configuration parameter "Domainbox Reseller" at "Configuration -> Domain registration".'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "Domainbox" is not configured properly. Please update configuration parameter "Domainbox Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "Domainbox" is not configured properly. Please update configuration parameter "Domainbox Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Domainbox via API', + 'form' => array( + 'reseller' => array('text', array( + 'label' => 'Domainbox Reseller', + 'description'=>'Domainbox Reseller', + ), + ), + 'user' => array('text', array( + 'label' => 'Domainbox Username', + 'description'=>'Domainbox Username', + ), + ), + 'password' => array('password', array( + 'label' => 'Domainbox Password', + 'description'=>'Domainbox Password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + return array( + 'asia', 'biz', 'com', 'info', 'mobi', 'net', 'org', + 'tel', 'xxx', 'eu', 'me', 'tv', 'cc', 'im', 'us', + 'in', 'co', 'cx', 'gs', 'ht', 'ki', 'mu', 'nf', 'tl', + 'at', 'be', 'so', 'la', + 'br.com', 'gb.net', 'uk.com', 'uk.net', 'uy.com', + 'hu.com', 'no.com', 'ru.com', 'sa.com', 'se.com', + 'se.net', 'za.com', 'jpn.com', 'eu.com', 'gb.com', + 'us.com', 'qc.com', 'de.com', 'ae.org', 'kr.com', + 'ar.com', 'cn.com', 'gr.com', 'com.cc', + 'net.cc', 'org.cc', 'art.ht', 'org.ht', 'com.ht', + 'net.ht', 'pro.ht', 'firm.ht', 'info.ht', 'shop.ht', + 'adult.ht', 'pol.ht', 'rel.ht', 'asso.ht', 'perso.ht', + 'biz.ki', 'com.ki', 'net.ki', 'org.ki', 'tel.ki', + 'info.ki', 'mobi.ki', 'phone.ki', 'ac.mu', 'co.mu', + 'net.mu', 'com.mu', 'org.mu', 'com.nf', 'net.nf', + 'per.nf', 'web.nf', 'arts.nf', 'firm.nf', 'info.nf', + 'store.nf', 'rec.nf', 'other.nf', 'com.sb', 'net.sb', + 'org.sb', 'tl', + ); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'LaunchPhase' => 'GA', + ); + + $result = $this->_request('CheckDomainAvailability', $params); + + return ($result->AvailabilityStatus == 0) + && ($result->AvailabilityStatusDescr == 'Available'); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + public function modifyNs(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + ); + + $params['Nameservers']['NS1'] = $domain->getNs1(); + $params['Nameservers']['NS2'] = $domain->getNs2(); + if($domain->getNs3()) { + $params['Nameservers']['NS3'] = $domain->getNs3(); + } + if($domain->getNs4()) { + $params['Nameservers']['NS4'] = $domain->getNs4(); + } + + $result = $this->_request('ModifyDomainNameservers', $params); + return true; + } + + public function modifyContact(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $contact = array( + 'Name' => $c->getName(), + 'Street1' => $c->getAddress1(), + 'Street2' => $c->getAddress2(), + 'Street3' => $c->getAddress3(), + 'City' => $c->getCity(), + 'State' => $c->getState(), + 'Postcode' => $c->getZip(), + 'CountryCode' => $c->getCountry(), + 'Telephone' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'Email' => $c->getEmail(), + // .us additional parameters + 'Nexus' => array( + 'AppPurpose' => 'P3', + 'Category' => 'C11', + ), + ); + + // Change the Name of every contact to register successfully + $admin = $tech = $bill = $contact; + $admin['Name'] .= 'a'; + $tech['Name'] .= 't'; + $bill['Name'] .= 'b'; + + $params = array( + 'DomainName' => $domain->getName(), + 'Contacts' => array( + 'Registrant' => $contact, + 'Admin' => $admin, + 'Tech' => $tech, + 'Billing' => $bill, + ), + ); + $result = $this->_request('ModifyDomainContacts', $params); + + return true; + } + + public function transferDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $contact = array( + 'Name' => $c->getName(), + 'Street1' => $c->getAddress1(), + 'Street2' => $c->getAddress2(), + 'Street3' => $c->getAddress3(), + 'City' => $c->getCity(), + 'State' => $c->getState(), + 'Postcode' => $c->getZip(), + 'CountryCode' => $c->getCountry(), + 'Telephone' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'Email' => $c->getEmail(), + // .us additional parameters + 'Nexus' => array( + 'AppPurpose' => 'P3', + 'Category' => 'C11', + ), + ); + + $admin = $tech = $bill = $contact; + $admin['Name'] .= 'a'; + $tech['Name'] .= 't'; + $bill['Name'] .= 'b'; + + $params = array( + 'DomainName' => $domain->getName(), + 'AutoRenew' => false, + 'AutoRenewDays' => 1, + 'AcceptTerms' => true, + 'KeepExistingNameservers' => true, + 'Contacts' => array( + 'Registrant' => $contact, + 'Admin' => $admin, + 'Tech' => $tech, + 'Billing' => $bill, + ), + ); + $this->_request('RequestTransfer', $params); + + return true; + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + ); + $result = $this->_request('QueryDomain', $params); + + $contact = $result->Contacts->Registrant; + + $tel = explode(".", $contact->Telephone); + $tel[0] = str_replace('+', '', $tel[0]); + + $c = new Registrar_Domain_Contact(); + $c->setName($contact->Name) + ->setEmail($contact->Email) + ->setTel($tel[1]) + ->setTelCc($tel[0]) + ->setAddress1($contact->Street1) + ->setAddress2($contact->Street2) + ->setCity($contact->City) + ->setCountry($contact->CountryCode) + ->setZip($contact->Postcode); + + $params = array( + 'DomainName' => $domain->getName(), + ); + $epp = $this->_request('QueryDomainAuthcode', $params); + + $domain->setNameservers($ns_list); + $domain->setExpirationTime(strtotime($result->ExpiryDate)); + $domain->setRegistrationTime(strtotime($result->CreatedDate)); + $domain->setEpp($epp->AuthCode); + $domain->setPrivacyEnabled($result->ApplyPrivacy); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $ns_list['NS1'] = $domain->getNs1(); + $ns_list['NS2'] = $domain->getNs2(); + if($domain->getNs3()) { + $ns_list['NS3'] = $domain->getNs3(); + } + if($domain->getNs4()) { + $ns_list['NS4'] = $domain->getNs4(); + } + + $contact = array( + 'Name' => $c->getName(), + 'Street1' => $c->getAddress1(), + 'Street2' => $c->getAddress2(), + 'Street3' => $c->getAddress3(), + 'City' => $c->getCity(), + 'State' => $c->getState(), + 'Postcode' => $c->getZip(), + 'CountryCode' => $c->getCountry(), + 'Telephone' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'Email' => $c->getEmail(), + // .us additional parameters + 'Nexus' => array( + 'AppPurpose' => 'P3', + 'Category' => 'C11', + ), + ); + + // Change the Name of every contact to register successfully + $admin = $tech = $bill = $contact; + $admin['Name'] .= 'a'; + $tech['Name'] .= 't'; + $bill['Name'] .= 'b'; + + $params = array( + 'DomainName' => $domain->getName(), + 'LaunchPhase' => 'GA', + 'ApplyLock' => false, + 'AutoRenew' => false, + 'AutoRenewDays' => 1, + 'ApplyPrivacy' => false, + 'AcceptTerms' => true, + 'Period' => $domain->getRegistrationPeriod(), + 'Nameservers' => $ns_list, + 'Contacts' => array( + 'Registrant' => $contact, + 'Admin' => $admin, + 'Tech' => $tech, + 'Billing' => $bill, + ), + ); + + if (($domain->getTld() == 'eu') || ($domain->getTld() == 'be')) { + unset($params['Contacts']['Admin']); + unset($params['Contacts']['Billing']); + } + $this->_request('RegisterDomain', $params); + + return true; + } + + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'Period' => $domain->getRegistrationPeriod(), + 'CurrentExpiry' => date('Y-m-d', $domain->getExpirationTime()), + ); + $this->_request('RenewDomain', $params); + + return true; + } + + public function togglePrivacyProtection(Registrar_Domain $domain) + { + $params = array( + 'DomainName' => $domain->getName(), + 'ApplyPrivacy' => !$domain->getPrivacyEnabled(), + ); + $result = $this->_request('ModifyDomainPrivacy', $params); + + return true; + } + + /** + * Runs an api command and returns parsed data. + * @param string $cmd + * @param array $params + * @return array + */ + private function _request($cmd, $params) + { + $params = array( + 'CommandParameters' => $params, + 'AuthenticationParameters' => array( + 'Reseller' => $this->config['reseller'], + 'Username' => $this->config['user'], + 'Password' => $this->config['password'], + ), + ); + + if ($this->_testMode) { + $wsdl = 'https://sandbox.domainbox.net/?wsdl'; + } else { + $wsdl = 'https://live.domainbox.net/?wsdl'; + } + + $client = new SoapClient($wsdl, + array('soap_version' => SOAP_1_2) + ); + + $result = $client->$cmd($params); + + $this->getLog()->debug(print_r($params, true)); + $this->getLog()->debug(print_r($result, true)); + + if ($result->{$cmd . 'Result'}->ResultCode != 100) { + throw new Registrar_Exception($result->{$cmd . 'Result'}->ResultMsg); + } + + return $result->{$cmd . 'Result'}; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Dotid.php b/bb-library/Registrar/Adapter/Dotid.php new file mode 100644 index 0000000..899f8c2 --- /dev/null +++ b/bb-library/Registrar/Adapter/Dotid.php @@ -0,0 +1,162 @@ + null, + 'token' => null, + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['username']) && !empty($options['username'])) { + $this->config['username'] = $options['username']; + unset($options['username']); + } else { + throw new Registrar_Exception('Domain registrar "DotId" is not configured properly. Please update configuration parameter "DotId username" at "Configuration -> Domain registration".'); + } + + if(isset($options['token']) && !empty($options['token'])) { + $this->config['token'] = $options['token']; + unset($options['token']); + } else { + throw new Registrar_Exception('Domain registrar "DotId" is not configured properly. Please update configuration parameter "DotId token" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on DotId via API', + 'form' => array( + 'username' => array('text', array( + 'label' => 'DotId username', + 'description'=>'DotId username', + ), + ), + 'token' => array('password', array( + 'label' => 'DotId token', + 'description'=>'DotId token', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + throw new Registrar_Exception('Cannot register domain using DotId Api.'); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $curl_opts = array( + CURLOPT_URL => 'whois.paneldotid.com', + CURLOPT_PORT => 43, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_CUSTOMREQUEST => $domain->getName() . "\r\n", + ); + + $ch = curl_init(); + curl_setopt_array($ch, $curl_opts); + $result = curl_exec($ch); + + return (strpos($result, 'NOT FOUND') !== false); + } + + public function modifyNs(Registrar_Domain $domain) + { + $dom = file_get_contents($this->_getApiUrl() . "getdomain.php?uid={$this->config['username']}&token={$this->config['token']}&domain={$domain->getName()}"); + $parse = explode("Error:", $dom); + if (count($parse) > 1) + { + throw new Registrar_Exception($parse[1]); + } + else + { + $ns_list = ''; $i = 1; + foreach ($domain->getNameservers() as $ns) + $ns_list .= '&ns' . $i++ . '=' . $ns->getHost(); + $getapi = file_get_contents($this->_getApiUrl() . "savens.php?session=12345&domain={$domain->getName()}" . $ns_list); + if (strpos($getapi,"Anda Belum Login")) + echo ""; + $parse = explode("Error:", $getapi); + if (count($parse) > 1) + throw new Registrar_Exception($parse[1]); + } + return true; + } + + public function modifyContact(Registrar_Domain $domain) + { + throw new Registrar_Exception('Cannot modify contact details using DotId Api.'); + } + + public function transferDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Cannot transfer domain using DotId Api.'); + } + + public function getDomainDetails(Registrar_Domain $domain) + { + throw new Registrar_Exception('Cannot get domain details using DotId Api.'); + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Cannot register domain using DotId Api.'); + } + + public function renewDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Cannot renew domain using DotId Api.'); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + return 'http://paneldotid.com/api/'; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Dottk.php b/bb-library/Registrar/Adapter/Dottk.php new file mode 100644 index 0000000..0ade0e6 --- /dev/null +++ b/bb-library/Registrar/Adapter/Dottk.php @@ -0,0 +1,208 @@ + null, + 'password' => null + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['email']) && !empty($options['email'])) { + $this->config['email'] = $options['email']; + unset($options['email']); + } else { + throw new Registrar_Exception('Domain registrar "dotTK" is not configured properly. Please update configuration parameter "dotTK email" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "dotTK" is not configured properly. Please update configuration parameter "dotTK password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on dotTK via API', + 'form' => array( + 'email' => array('text', array( + 'label' => 'dotTK email', + 'description'=>'dotTK email', + ), + ), + 'password' => array('password', array( + 'label' => 'dotTK password', + 'description'=>'dotTK password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + return array( + '.tk', + ); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = 'domainname=' . $domain->getName(); + + $result = $this->_request('availability_check', $params); + + return ($result->partner_availability_check->status == 'DOMAIN AVAILABLE'); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain transfer checking is not implemented'); + } + + public function modifyNs(Registrar_Domain $domain) + { + $params = 'domainname=' . $domain->getName(); + foreach ($domain->getNameservers() as $ns) + $params .= '&nameserver=' . $ns->getHost(); + + $result = $this->_request('modify', $params); + + return ($result->partner_modify->status == 'DOMAIN MODIFIED'); + } + + public function modifyContact(Registrar_Domain $domain) + { + throw new Registrar_Exception("Can't modify contacts using dotTK API."); + } + + public function transferDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception("Can't transfer domains using dotTK API."); + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $params = 'domainname=' . $domain->getName(); + $result = $this->_request('availability_check', $params); + + $nsList = array(); + foreach ($result->partner_availability_check->nameservers as $ns) + $nsList[] = (string) $ns->hostname; + + $date = $result->partner_availability_check->expiration_date; + $date_str = substr($date, 0, 4) . ' ' . substr($date, 4, 2) . ' '. substr($date, 6, 2); + + $domain->setExpirationTime(strtotime($date_str)); + $domain->setNameservers($nsList); + //$domain->setPrivacyEnabled($privacy); + //$domain->setEpp($result['transferauthinfo']); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $params = 'domainname=' . $domain->getName(); + $params .= '&enduseremail=' . $domain->getContactRegistrar()->getEmail(); + $params .= '&monthsofregistration=' . $domain->getRegistrationPeriod() * 12; + foreach ($domain->getNameservers() as $ns) + $params .= '&nameserver=' . $ns->getHost(); + + $result = $this->_request('register', $params); + + return ($result->partner_registration->status == 'DOMAIN REGISTERED'); + } + + public function renewDomain(Registrar_Domain $domain) + { + $params = 'domainname=' . $domain->getName(); + $params .= '&monthsofregistration=12'; + + $result = $this->_request('renew', $params); + + return ($result->partner_renew->status == 'DOMAIN RENEWED'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception("dotTK does not support Privacy protection"); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception("dotTK does not support Privacy protection"); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception('Epp code retrieval is not implemented'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain locking is not implemented'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain unlocking is not implemented'); + } + + /** + * Runs an api command and returns data. + * @param string $command + * @param array $params + * @return array + */ + private function _request($command, $params) + { + // Set authentication params + $params .= '&email=' . $this->config['email']; + $params .= '&password=' . $this->config['password']; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->_getApiUrl() . $command . '?' . $params); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $result = curl_exec($ch); + + if ($result === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + curl_close($ch); + + $xml = new SimpleXMLElement($result); + if ($xml->status == 'NOT OK') + { + throw new Registrar_Exception($xml->reason); + } + + return $xml; + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + return 'https://api.domainshare.tk/'; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Gandi.php b/bb-library/Registrar/Adapter/Gandi.php new file mode 100644 index 0000000..9137368 --- /dev/null +++ b/bb-library/Registrar/Adapter/Gandi.php @@ -0,0 +1,398 @@ + null, + 'password' => null + ); + + private $_s = null; + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "Gandi" is not configured properly. Please update configuration parameter "Gandi Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "Gandi" is not configured properly. Please update configuration parameter "Gandi Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Gandi via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'Gandi Username', + 'description'=>'Gandi Username', + ), + ), + 'password' => array('password', array( + 'label' => 'Gandi Password', + 'description'=>'Gandi Password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + return $this->_request('tld_list', array($this->_getSession())); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + if (($domain->getTld() == 'pl') || ($domain->getTld() == 'in')) { + throw new Registrar_Exception('Cannot check availablity of this TLD using Gandi api'); + } + + $params = array( + $this->_getSession(), + array( + $domain->getName(), + ), + ); + $result = $this->_request('domain_available', $params); + + return ($result[$domain->getName()] == 1); + } + + public function modifyNs(Registrar_Domain $domain) + { + $ns_list = array(); + foreach ($domain->getNameservers() as $ns) + $ns_list[] = $ns->getHost(); + + $params = array( + $this->_getSession(), + $domain->getName(), + $ns_list, + ); + $this->_request('domain_ns_set', $params); + + return true; + } + + public function modifyContact(Registrar_Domain $domain) + { + $params = array( + $this->_getSession(), + $domain->getName(), + ); + $result = $this->_request('domain_info', $params); + + $c = $domain->getContactRegistrar(); + + $params = array( + $this->_getSession(), + $result['owner_handle'], + new Zend_XmlRpc_Value_Struct( + array( + 'address' => $c->getAddress1(), + 'zipcode' => $c->getZip(), + 'city' => $c->getCity(), + 'country' => $c->getCountry(), + 'phone' => '+' . $c->getTelcc() . '.' . $c->getTel(), + 'email' => $c->getEmail(), + ) + ), + ); + $this->_request('contact_update', $params); + + return true; + } + + public function transferDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $handle_id = $this->_createHandle($domain, true); + + $params = array( + $this->_getSession(), + $domain->getName(), + ); + $result = $this->_request('domain_info', $params); + + $ns_list = array(); + foreach ($domain->getNameservers() as $ns) + $ns_list[] = (string) $ns->getHost(); + + $params = array( + $this->_getSession(), + $domain->getName(), + $handle_id, + $handle_id, + $handle_id, + $handle_id, + $ns_list, + $result['authorization_code'], + ); + + $this->_request('domain_transfer_in', $params); + + return true; + } + + public function getDomainDetails(Registrar_Domain $domain) + { + // Get Domain info + $params = array( + $this->_getSession(), + $domain->getName(), + ); + $result = $this->_request('domain_info', $params); + + // Get contact info + $params = array( + $this->_getSession(), + $result['owner_handle'], + ); + $contact = $this->_request('contact_info', $params); + + // Get nameservers + $params = array( + $this->_getSession(), + $domain->getName(), + ); + $nss = $this->_request('domain_ns_list', $params); + + $tel = explode(".", $contact['phone']); + $tel[0] = str_replace('+', '', $tel[0]); + + $c = new Registrar_Domain_Contact(); + $c->setFirstName($contact['firstname']) + ->setLastName($contact['lastname']) + ->setEmail($contact['email']) + ->setTel($tel[1]) + ->setTelCc($tel[0]) + ->setAddress1($contact['address']) + ->setCity($contact['city']) + ->setCountry($contact['country']) + ->setZip($contact['zipcode']); + + // Add nameservers + $ns_list = array(); + foreach ($nss as $ns) + { + $n = new Registrar_Domain_Nameserver(); + $n->setHost($ns); + $ns_list[] = $n; + } + + $domain->setNameservers($ns_list); + $domain->setExpirationTime(strtotime($result['registry_expiration_date'])); + $domain->setRegistrationTime(strtotime($result['registry_creation_date'])); + $domain->setEpp($result['authorization_code']); + $domain->setPrivacyEnabled($contact['whois_obfuscated']); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $handle_id = $this->_createHandle($domain, true); + + $ns_list = array(); + foreach ($domain->getNameservers() as $ns) + $ns_list[] = $ns->getHost(); + + $params = array( + $this->_getSession(), + $domain->getName(), + $domain->getRegistrationPeriod(), + $handle_id, + $handle_id, + $handle_id, + $handle_id, + $ns_list, + ); + $this->_request('domain_create', $params); + + return true; + } + + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + $this->_getSession(), + $domain->getName(), + 1 + ); + $this->_request('domain_renew', $params); + + return true; + } + + public function togglePrivacyProtection(Registrar_Domain $domain) + { + // Get Domain info + $params = array( + $this->_getSession(), + $domain->getName(), + ); + $result = $this->_request('domain_info', $params); + + // Get contact info + $params = array( + $this->_getSession(), + $result['owner_handle'], + ); + $contact = $this->_request('contact_info', $params); + + $handle_id = $this->_createHandle($domain, !$contact['whois_obfuscated']); + + $params = array( + $this->_getSession(), + $domain->getName(), + $handle_id, + $handle_id, + $handle_id, + $handle_id, + ); + $this->_request('domain_change_owner', $params); + + return true; + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Runs an api command and returns parsed data. + * @param string $cmd + * @param array $params + * @return array + */ + private function _request($cmd, $params) + { + $client = new Zend_XmlRpc_Client($this->_getApiUrl()); + try { + $result = $client->call( + $cmd, + $params + ); + } catch (Zend_XmlRpc_Client_HttpException $e) { + throw new Registrar_Exception($e->getMessage()); + } + + $this->getLog()->debug($cmd); + $this->getLog()->debug(print_r($params, true)); + $this->getLog()->debug(print_r($result, true)); + + return $result; + } + + /** + * Logins and gets session string. + * @return string + */ + private function _getSession() + { + if ($this->_s) { + return $this->_s; + } + + $params = array( + $this->config['user'], + $this->config['password'], + new Zend_XmlRpc_Value_Boolean(false) + ); + + return $this->_s = $this->_request('login', $params); + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) { + return 'https://api.ote.gandi.net/xmlrpc/'; + } + return 'https://rpc.gandi.net/xmlrpc/2.0/'; + } + + /** + * Creates new contact handle. + * @param Registrar_Domain $domain + * @param bool $privacy + * @return int + */ + private function _createHandle(Registrar_Domain $domain, $privacy) + { + $c = $domain->getContactRegistrar(); + + // Create contact + $params = array( + $this->_getSession(), + 'individual', + $c->getFirstName(), + $c->getLastName(), + $c->getAddress1(), + $c->getZip(), + $c->getCity(), + $c->getCountry(), + '+' . $c->getTelCc() . '.' . $c->getTel(), + $c->getEmail(), + new Zend_XmlRpc_Value_Struct(array('whois_obfuscated' => new Zend_XmlRpc_Value_Boolean((bool) $privacy))), + ); + + return $this->_request('contact_create', $params); + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Namecheap.php b/bb-library/Registrar/Adapter/Namecheap.php new file mode 100644 index 0000000..3bf803a --- /dev/null +++ b/bb-library/Registrar/Adapter/Namecheap.php @@ -0,0 +1,743 @@ + null, + 'apiKey' => null + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "Namecheap API Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['apiKey']) && !empty($options['apiKey'])) { + $this->config['apiKey'] = $options['apiKey']; + unset($options['apiKey']); + } else { + throw new Registrar_Exception('Domain registrar "Namecheap" is not configured properly. Please update configuration parameter "Namecheap API key" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Namecheap via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'Namecheap API Username', + 'description'=>'Namecheap API Username' + ), + ), + 'apiKey' => array('password', array( + 'label' => 'Namecheap API key', + 'description'=>'Namecheap API key', + 'renderPassword' => true, + ), + ), + ), + ); + } + + /** + * @return array + */ + public function getTlds() { + $params = array ( + 'command' => 'namecheap.domains.gettldlist' + ); + + $response = $this->_makeRequest($params, new Registrar_Domain()); + + $tlds = array(); + foreach($response->CommandResponse->Tlds->Tld as $tld) { + $tlds[] = '.' . (string)$tld->attributes()->Name; + } + + return $tlds; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function isDomainAvailable(Registrar_Domain $domain) { + $params = array( + 'command' => 'namecheap.domains.check', + 'DomainList'=> $domain->getName() + ); + + $response = $this->_makeRequest($params, $domain); + + foreach ($response->CommandResponse->DomainCheckResult as $result) { + if ($result->attributes()->Domain == $domain->getName() + && $result->attributes()->Available == 'true') { + return true; + } + } + + return false; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyNs(Registrar_Domain $domain) { + $oldNs = $this->_getNameservers($domain); + + $del_domain = $domain; + $del_domain->setNameservers($oldNs); + + $this->_deleteNameservers($del_domain); + + if (!$this->_setNameservers($domain)) { + return false; + } + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyContact(Registrar_Domain $domain) { + $params = array( + 'command' => 'namecheap.domains.setContacts', + 'DomainName' => $domain->getName(), + 'UserName' => $this->_getUsername($domain) + ); + + $c = $domain->getContactRegistrar(); + $types = array('Registrant', 'Tech', 'Admin', 'AuxBilling'); + foreach($types as $type) { + $params[$type . 'FirstName'] = $c->getFirstName(); + $params[$type . 'LastName'] = $c->getLastName(); + $params[$type . 'Address1'] = $c->getAddress1(); + $params[$type . 'City'] = $c->getCity(); + $params[$type . 'StateProvince'] = $c->getState(); + $params[$type . 'PostalCode'] = $c->getZip(); + $params[$type . 'Country'] = $c->getCountry(); + $params[$type . 'Phone'] = $c->getTel() ? '+'.$c->getTelCc().'.'.$c->getTel() : ''; + $params[$type . 'EmailAddress'] = $c->getEmail(); + + + $optional_params[$type . 'OrganizationName'] = $c->getCompany(); + $optional_params[$type . 'JobTitle'] = $c->getJobTitle(); + $optional_params[$type . 'Address2'] = $c->getAddress2(); + $optional_params[$type . 'Fax'] = $c->getFax() ? '+'.$c->getFaxCc().'.'.$c->getFax() : ''; + } + + $params = array_merge($params, $optional_params); + + $result = $this->_makeRequest($params, $domain); + $attr = $result->CommandResponse->DomainSetContactResult->attributes(); + if ($attr->Domain == $domain->getName() && $attr->IsSuccess == 'true') { + return true; + } else { + return false; + } + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function transferDomain(Registrar_Domain $domain) { + throw new Registrar_Exception('Can\'t transfer domain using Namecheap API'); + } + + /** + * 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) { + $domain->setContactRegistrar($this->_getContactDetails($domain)); + $domain->setNameservers($this->_getNameservers($domain)); + $domain = $this->_getDomainDates($domain); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function registerDomain(Registrar_Domain $domain) { + if (!$this->_checkUserExists($domain)) { + $this->_createUser($domain); + } + + $params = array( + 'command' => 'namecheap.domains.create', + 'DomainName' => $domain->getName(), + 'Years' => 1, + 'UserName' => $this->_getUsername($domain) + ); + + $optional_params = array( + 'PromotionCode' => '', + ); + + $c = $domain->getContactRegistrar(); + $types = array('Registrant', 'Tech', 'Admin', 'AuxBilling'); + foreach($types as $type) { + $params[$type . 'FirstName'] = $c->getFirstName(); + $params[$type . 'LastName'] = $c->getLastName(); + $params[$type . 'Address1'] = $c->getAddress1(); + $params[$type . 'City'] = $c->getCity(); + $params[$type . 'StateProvince'] = $c->getState(); + $params[$type . 'PostalCode'] = $c->getZip(); + $params[$type . 'Country'] = $c->getCountry(); + $params[$type . 'Phone'] = $c->getTel() ? '+'.$c->getTelCc().'.'.$c->getTel() : ''; + $params[$type . 'EmailAddress'] = $c->getEmail(); + + + $optional_params[$type . 'OrganizationName'] = $c->getCompany(); + $optional_params[$type . 'JobTitle'] = $c->getJobTitle(); + $optional_params[$type . 'Address2'] = $c->getAddress2(); + $optional_params[$type . 'Fax'] = $c->getFax() ? '+'.$c->getFaxCc().'.'.$c->getFax() : ''; + } + + $params['Nameservers'] = ''; + foreach($domain->getNameservers() as $nse) { + $params['Nameservers'] .= ($params['Nameservers']) ? ',' . $nse->getHost() : $nse->getHost(); + } + + $params = array_merge($params, $optional_params); + + $result = $this->_makeRequest($params, $domain); + + if ($result->CommandResponse->DomainCreateResult->attributes()->Domain == $domain->getName() + && $result->CommandResponse->DomainCreateResult->attributes()->Registered == 'true') { + return true; + } else { + return false; + } + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function renewDomain(Registrar_Domain $domain) { + $params = array( + 'command' => 'namecheap.domains.renew', + 'DomainName' => $domain->getName(), + 'Years' => 1, + 'UserName' => $this->_getUsername($domain) + ); + + $response = $this->_makeRequest($params, $domain); + if ($response->CommandResponse->DomainRenewResult->attributes()->DomainName == $domain->getName() + && $response->CommandResponse->DomainRenewResult->attributes()->Renew == 'true') { + return true; + } else { + return false; + } + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Makes API call + * @param array $params + * @param string $type + * @return bool + * @throws Registrar_Exception + */ + private function _makeRequest($params = array(), Registrar_Domain $domain, $type = 'xml') { + $params = array_merge(array( + 'ApiUser' => $this->config['user'], + 'ApiKey' => $this->config['apiKey'], + 'UserName' => isset($params['UserName']) ? $params['UserName'] : $this->config['user'], + ), $params); + + $c = $domain->getContactRegistrar(); + $clientIp = isset($params['UserName']) ? $this->_getIp($c, false) : $this->_getIp($c); + + $opts = array( + CURLOPT_CONNECTTIMEOUT => 10, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 60, + CURLOPT_USERAGENT => 'http://fordnox.com', + CURLOPT_URL => $this->_getApiUrl().'?ClientIp='.$clientIp, + //workaround to prevent errors related to SSL + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0, + + ); + + foreach ($params as $key => $param) + { + if (is_array($param)) $param = implode(',',$param); + $opts[CURLOPT_URL] .= '&'.$key.'='.urlencode((string)$param); + } + $this->getLog()->debug($opts[CURLOPT_URL]); + + $ch = curl_init(); + curl_setopt_array($ch, $opts); + $result = curl_exec($ch); + if ($result === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + curl_close($ch); + + return $this->_parseResponse($result, $type); + } + + /** + * + * get server or client ip + * @param Registrar_Domain_Contact $c + * @param boolean $server + * @throws Registrar_Exception + * @return string + */ + private function _getIp(Registrar_Domain_Contact $c, $server = true) { + if ($this->_isTestEnv()) return '87.247.113.219'; + + if($server) return $_SERVER['REMOTE_ADDR']; + + $table = Doctrine_Core::getTable('Model_ActivityClientHistory'); + $row = $table->findOneByClientId($c->id); + + if ($row instanceof Model_ActivityClientHistory) return $row->ip; + else throw new Registrar_Exception('NamecheapApiError: can\'t find client\'s ip'); + } + + + private function _isTestEnv() + { + return $this->_testMode; + } + + /** + * 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'; + } + + /** + * Parses response + * @param string $result + * @param string $type + * @return object + */ + private function _parseResponse($result, $type = 'xml') + { + try + { + $xml = simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA); + } catch (Exception $e) { + throw new Registrar_Exception('simpleXmlException: '.$e->getMessage()); + } + + if (isset($xml->Errors) && count($xml->Errors->Error) > 0) { + throw new Registrar_Exception(sprintf('NamecheapApiError: "%s"', $xml->Errors->Error[0]), 100); + } + + return $xml; + } + + private function _createUser(Registrar_Domain $d) { + $c = $d->getContactRegistrar(); + $params = array( + 'command' => 'namecheap.users.create', + 'NewUserName' => $this->_getUsername($d), + 'NewUserPassword' => $this->_getPassword($d), + 'EmailAddress' => $c->getEmail(), + 'Firstname' => $c->getFirstName(), + 'LastName' => $c->getLastName(), + 'AcceptTerms' => 1, + 'AcceptNews' => 0, + 'JobTitle' => $c->getJobTitle(), + 'Organization' => $c->getCompany(), + 'Address1' => $c->getAddress1(), + 'Address2' => $c->getAddress2(), + 'City' => $c->getCity(), + 'StateProvince' => $c->getState(), + 'Zip' => $c->getZip(), + 'Country' => $c->getCountry(), + 'Phone' => $c->getTel() ? '+'.$c->getTelCc().'.'.$c->getTel() : '', + 'Fax' => $c->getFax() ? '+'.$c->getFaxCc().'.'.$c->getFax() : '' + ); + + $response = $this->_makeRequest($params, $d); + + if ($response->CommandResponse->UserCreateResult->attributes()->Success == 'true') { + return true; + } else { + return false; + } + } + + /** + * + * Checks if client has account in namecheap + * @param Registrar_Domain $d + */ + private function _checkUserExists(Registrar_Domain $d) { + $c = $d->getContactRegistrar(); + $params = array( + 'command' => 'namecheap.users.login', + 'Password' => $this->_getPassword($d), + 'UserName' => $this->_getUsername($d) + ); + + try { + $response = $this->_makeRequest($params, $d); + } catch (Registrar_Exception $e) { + return false; + } + + if ($response->CommandResponse->UserLoginResult->attributes()->LoginSuccess == 'true') { + return true; + } else { + return false; + } + } + + /** + * + * Generates password for namecheap user + * @param unknown_type $d + */ + private function _getPassword(Registrar_Domain $d) { + $c = $d->getContactRegistrar(); + + return substr(MD5($this->config['apiKey'] . $c->getEmail()), 0, 20); + } + + /** + * + * Generates username for namecheap + * @param unknown_type $d + */ + private function _getUsername(Registrar_Domain $d) { + $email = $d->getContactRegistrar() + ->getEmail(); + + $email = strtolower($email); + $email = preg_replace('/[^a-z0-9]/', '', $email); + + $email_length = strlen($email); + if($email_length < 6) { + for ($i=$email_length; $i<6; $i++) { + $email .= '0'; + } + } elseif ($email_length > 20) { + $email = substr($email, 0, 20); + } + + return $email; + } + + /** + * + * Gets registrar lock status for domain + * @param Registrar_Domain $domain + * @return boolean + */ + private function _getRegistrarLock(Registrar_Domain $domain) { + $params = array ( + 'command' => 'namecheap.domains.getRegistrarLock', + 'UserName' => $this->_getUsername($domain), + 'DomainName' => $domain->getName() + ); + + $response = $this->_makeRequest($params, $domain); + if ($response->CommandResponse->DomainGetRegistrarLockResult->attributes()->Domain == $domain->getName() + && $response->CommandResponse->DomainGetRegistrarLockResult->attributes()->RegistrarLockStatus == 'true') { + return true; + } else { + return false; + } + } + + /** + * + * Switches registrar lock + * ($lock = true to lock; $lock = false to unlock); + * + * @param Registrar_Domain $domain + * @param boolean $lock + */ + private function _registrarLock(Registrar_Domain $domain, $lock = true) { + $currentLock = $this->_getRegistrarLock($domain); + if ($currentLock && $lock) { + return true; + } elseif ($currentLock && !$lock) { + $lockAction = 'UNLOCK'; + } elseif (!$currentLock && $lock) { + $lockAction = 'LOCK'; + } else { + return true; + } + + $params = array( + 'command' => 'namecheap.domains.setRegistrarLock', + 'DomainName' => $domain->getName(), + 'LockAction' => $lockAction, + 'UserName' => $this->_getUsername($domain) + ); + + $response = $this->_makeRequest($params, $domain); + if ($response->CommandResponse->DomainSetRegistrarLockResult->attributes()->Domain == $domain->getName() + && $response->CommandResponse->DomainSetRegistrarLockResult->attributes()->IsSuccess == 'true') { + return true; + } else { + return false; + } + } + + /** + * + * Get domain contacts info + * @param Registrar_Domain $domain + * @return Registrar_Domain_Contact + */ + private function _getContactDetails(Registrar_Domain $domain) { + $params = array( + 'command' => 'namecheap.domains.getContacts', + 'DomainName' => $domain->getName(), + 'UserName' => $this->_getUsername($domain) + ); + + $response = $this->_makeRequest($params, $domain); + $result = $response->CommandResponse->DomainContactsResult->Registrant; + + $tel = $this->_separateTelephone($result->Phone); + $fax = $this->_separateTelephone($result->Fax); + + $c = new Registrar_Domain_Contact(); + $c->setCompany((string)$result->OrganizationName) + ->setFirstName((string)$result->FirstName) + ->setLastName((string)$result->LastName) + ->setAddress1((string)$result->Address1) + ->setAddress2((string)$result->Address2) + ->setCity((string)$result->City) + ->setState((string)$result->StateProvince) + ->setZip((string)$result->PostalCode) + ->setCountry((string)$result->Country) + ->setTelCc($tel['code']) + ->setTel($tel['tel']) + ->setFaxCc($fax['code']) + ->setFax($fax['tel']) + ->setEmail((string)$result->EmailAddress); + + return $c; + } + + /** + * + * Separates telephone from international calling code + * @param string $tel + * @return array|string + */ + private function _separateTelephone($tel) { + $return = array( + 'code' => '', + 'tel' => '' + ); + + $tel = str_replace(array('+', '(', ')', ' '), '', $tel); + + if (strlen($tel) < 2) { + return $return; + } + + $tel = explode('.', $tel); + + if (isset($tel[0]) && !empty($tel[0]) && isset($tel[1]) && !empty($tel[1])) { + $return['code'] = $tel[0]; + $return['tel'] = $tel[1]; + } + + return $return; + } + + /** + * + * Get nameservers list for domain + * @param Registrar_Domain $domain + * @return array of Registrar_Domain_Nameserver + */ + private function _getNameservers(Registrar_Domain $domain) { + $params = array( + 'command' => 'namecheap.domains.dns.getList', + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld(), + 'UserName' => $this->_getUsername($domain) + ); + + $response = $this->_makeRequest($params, $domain); + $result = $response->CommandResponse->DomainDNSGetListResult->Nameserver; + + $ns = array(); + foreach ($result as $nameserver) { + $n = new Registrar_Domain_Nameserver(); + $n->setHost((string)$nameserver); + + $ns[] = $n; + } + + return $ns; + } + + /** + * + * Gets domain registration and expiration dates + * @param Registrar_Domain $domain + * @return Registrar_Domain + */ + private function _getDomainDates(Registrar_Domain $domain) { + $params = array ( + 'command' => 'namecheap.domains.getList', + 'ListType' => 'ALL', + 'SearchTerm' => $domain->getName(), + 'UserName' => $this->_getUsername($domain) + ); + + $response = $this->_makeRequest($params, $domain); + + $result = $response->CommandResponse->DomainGetListResult->Domain->attributes(); + $domain->setExpirationTime(strtotime((string)$result->Expires)); + $domain->setRegistrationTime(strtotime((string)$result->Created)); + $domain->setEpp('NAMECHEAP'); + + return $domain; + } + + /** + * + * Deletes nameservers + * + * @param Registrar_Domain $domain + * @throws Registrar_Exception + * @return boolean + */ + private function _deleteNameservers(Registrar_Domain $domain) { + $ns = $domain->getNameservers(); + + foreach($ns as $n) { + if (!$n instanceof Registrar_Domain_Nameserver) { + throw new Registrar_Exception('Nameservers should be objects of Registrar_Domain_Nameserver'); + } + + if (!$n->getHost()) { + throw new Registrar_Exception('Host of nameserver can\'t be empty'); + } + + $params = array( + 'command' => 'namecheap.domains.ns.delete', + 'UserName' => $this->_getUsername($domain), + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld(), + 'Nameserver' => $n->getHost() + ); + + $response = $this->_makeRequest($params, $domain); + if ($response->CommandResponse->DomainNSDeleteResult->attributes()->Nameserver != $n->getHost() + || $response->CommandResponse->DomainNsDeleteResult->attributes()->IsSuccess != 'true') { + throw new Registrar_Exception('Domain or nameserver mismatch'); + } + } + + return true; + } + + /** + * + * Set nameservers + * @param Registrar_Domain $domain + * @throws Registrar_Exception + * @return boolean + */ + private function _setNameservers(Registrar_Domain $domain) { + $ns = $domain->getNameservers(); + + foreach($ns as $n) { + if (!$n instanceof Registrar_Domain_Nameserver) { + throw new Registrar_Exception('Nameservers should be objects of Registrar_Domain_Nameserver'); + } + + if (!$n->getHost()) { + throw new Registrar_Exception('Host of nameserver can\'t be empty'); + } + + if (!$n->getIp()) { + throw new Registrar_Exception('IP of nameserver can\'t be empty'); + } + + $params = array( + 'command' => 'namecheap.domains.ns.create', + 'UserName' => $this->_getUsername($domain), + 'SLD' => $domain->getSld(), + 'TLD' => $domain->getTld(), + 'Nameserver' => $n->getHost(), + 'IP' => $n->getIP() + ); + + $response = $this->_makeRequest($params, $domain); + if ($response->DommandResponse->DomainNSCreateResult->attributes()->IsSuccess == "true") { + return true; + } else { + return false; + } + } + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Netregistry.php b/bb-library/Registrar/Adapter/Netregistry.php new file mode 100644 index 0000000..c41b1a0 --- /dev/null +++ b/bb-library/Registrar/Adapter/Netregistry.php @@ -0,0 +1,453 @@ + null, + 'password' => null, + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "Netregistry" is not configured properly. Please update configuration parameter "Netregistry Login" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "Netregistry" is not configured properly. Please update configuration parameter "Netregistry Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on Netregistry via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'Netregistry Login', + 'description'=>'Netregistry Login' + ), + ), + 'password' => array('password', array( + 'label' => 'Netregistry password', + 'description'=>'Netregistry password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + /** + * Return array of TLDs current Registar is capable to register + * If function returns empty array, this registrar can register any TLD + * @return array + */ + public function getTlds() + { + return array( + '.com.au', '.com', '.net.au', '.net', + '.org.au', '.org', '.co.nz', '.co.uk', + '.info', '.biz', '.au.com', '.id.au', + '.asn.au', '.asia', '.net.nz', '.org.nz', + '.geek.nz', '.org.uk', '.eu', '.tv', '.mobi','.us', + ); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getName(), + ); + + $result = $this->_request('domainLookup', $params); + + return true; + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain transfer checking is not implemented'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyNs(Registrar_Domain $domain) + { + $nsList = array(); + foreach ($domain->getNameservers() as $ns) + $nsList[] = $ns->getHost(); + + $params = array( + 'domain' => $domain->getName(), + 'nameServers' => $nsList, + ); + + $result = $this->_request('updateDomainNS', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyContact(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getName(), + ); + + $result = $this->_request('domainInfo', $params); + $contact_id = $result->entries[4]->value; + + $c = $domain->getContactRegistrar(); + $params = array( + 'domain' => $domain->getName(), + 'nicHandle' => $contact_id, + 'contactDetails' => array( + 'firstName' => $c->getFirstName(), + 'lastName' => $c->getLastName(), + 'organisation' => $c->getCompany(), + 'state' => $c->getState(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'suburb' => $c->getState(), + 'postcode' => $c->getZip(), + 'country' => $c->getCountry(), + 'phone' => $c->getTelCc() . $c->getTel(), + 'email' => $c->getEmail(), + ), + ); + + $result = $this->_request('contactUpdate', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function transferDomain(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getName(), + ); + + $result = $this->_request('domainInfo', $params); + $contact_id = $result->entries[4]->value; + + $c = $domain->getContactRegistrar(); + $params = array( + 'domain' => $domain->getName(), + 'nicHandle' => $contact_id, + 'period' => '1', + 'authcode' => $this->_getEPP($domain), + 'contactDetails' => array( + 'firstName' => $c->getFirstName(), + 'lastName' => $c->getLastName(), + 'organisation' => $c->getCompany(), + 'state' => $c->getState(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'suburb' => $c->getState(), + 'postcode' => $c->getZip(), + 'country' => $c->getCountry(), + 'phone' => $c->getTelCc() . $c->getTel(), + 'email' => $c->getEmail(), + ), + ); + + $result = $this->_request('transferDomain', $params); + + return true; + } + + /** + * 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( + 'domain' => $domain->getName(), + ); + + $result = $this->_request('domainInfo', $params); + $contact_id = $result->entries[4]->value; + + $params = array( + 'domain' => $domain->getName(), + 'nicHandle' => $contact_id, + ); + + $result1 = $this->_request('contactInfo', $params); + + $c = new Registrar_Domain_Contact(); + $c->setFirstName($result1->entries[0]->value) + ->setLastName($result1->entries[8]->value) + ->setEmail($result1->entries[6]->value) + ->setCompany($result1->entries[3]->value) + ->setTel($result1->entries[1]->value) + ->setAddress1($result1->entries[10]->value) + ->setAddress2($result1->entries[9]->value) + ->setCity($result1->entries[2]->value) + ->setCountry($result1->entries[12]->value) + ->setZip($result1->entries[7]->value); + + // Add nameservers + $nsList = array(); + foreach ($result->entries as $entry) + if (strpos($entry->key, 'ns.name') !== false) + { + $n = new Registrar_Domain_Nameserver(); + $n->setHost($entry->value); + $nsList[] = $n; + } + + $domain->setNameservers($nsList); + $domain->setExpirationTime(strtotime($result->entries[7]->value)); + $domain->setRegistrationTime(strtotime($result->entries[3]->value)); + //$domain->setPrivacyEnabled($privacy); + $domain->setEpp($this->_getEPP($domain)); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $nsList = array(); + foreach ($domain->getNameservers() as $ns) + { + $nsList[] = $ns->getHost(); + } + + $params = array( + 'domain' => $domain->getName(), + 'contactDetails' => array( + 'firstName' => $c->getFirstName(), + 'lastName' => $c->getLastName(), + 'organisation' => $c->getCompany(), + 'state' => $c->getState(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'suburb' => $c->getState(), + 'postcode' => $c->getZip(), + 'country' => $c->getCountry(), + 'phone' => $c->getTelCc() . $c->getTel(), + 'email' => $c->getEmail(), + ), + 'period' => $domain->getRegistrationPeriod(), + 'nameServers' => $nsList, + ); + + if ($domain->getTld() == 'au') + { + $params['eligibility'] = array( + array( + 'key' => 'au.registrant.name', + 'value' => $c->getName(), + ), + array( + 'key' => 'au.registrantid.type', + 'value' => 'ABN', + ), + array( + 'key' => 'au.registrant.number', + 'value' => 123456789, + ), + array( + 'key' => 'au.org.type', + 'value' => 'Company', + ), + ); + } + + if ($domain->getTld() == 'asia') + { + $params['eligibility'] = array( + array( + 'key' => 'asia.country', + 'value' => $c->getCountry(), + ), + array( + 'key' => 'asia.legal.entity.type', + 'value' => 'Natural Person', + ), + array( + 'key' => 'asia.id.form', + 'value' => 'Passport', + ), + array( + 'key' => 'asia.id.number', + 'value' => $c->getDocumentNr(), + ), + ); + } + + if ($domain->getTld() == 'ca') + { + $params['eligibility'] = array( + array( + 'key' => 'ca.legal.entity.type', + 'value' => 'CCO', + ), + array( + 'key' => 'ca.registrant.language', + 'value' => 'English', + ), + ); + } + + if ($domain->getTld() == 'es') + { + $params['eligibility'] = array( + array( + 'key' => 'es.id.type', + 'value' => 'Other', + ), + array( + 'key' => 'es.id.number', + 'value' => '123', + ), + ); + } + $result = $this->_request('registerDomain', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getName(), + 'period' => '1', + ); + + $result = $this->_request('renewDomain', $params); + + return true; + } + + /** + * @throws Registrar_Exception + */ + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception("Netregistry does not support Privacy protection"); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception("Netregistry does not support Privacy protection"); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception('Epp code retrieval is not implemented'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain locking is not implemented'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain unlocking is not implemented'); + } + + /** + * Runs an api command and returns data. + * @param string $command + * @param array $params + * @return array + */ + private function _request($cmd, $params) + { + $client = new SoapClient( + $this->_getApiUrl() . '?wsdl', array( + 'login' => $this->config['user'], + 'password' => $this->config['password'], + ) + ); + $client->__setLocation($this->_getApiUrl()); + + $result = $client->$cmd($params); + + $this->getLog()->debug(print_r($result, true)); + $this->getLog()->debug(print_r($params, true)); + + if ($result->return->success == 'FALSE') + { + if (is_array($result->return->errors)) + { + $error_msg = ''; + foreach ($result->return->errors as $error) + $error_msg .= $error->errorMsg . ' '; + } + else + $error_msg = $result->return->errors->errorMsg; + throw new Registrar_Exception($error_msg); + } + + return $result->return->fields; + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + return 'https://theconsole.netregistry.com.au/external/services/ResellerAPIService/'; + } + + /** + * Gets transfer (authcode) of the domain. + * @param Registrar_Domain $domain + * @return string + */ + private function _getEPP(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getName(), + ); + + return $this->_request('domainAuthCode', $params)->entries[0]->value; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Opensrs.php b/bb-library/Registrar/Adapter/Opensrs.php new file mode 100644 index 0000000..0c7c0b3 --- /dev/null +++ b/bb-library/Registrar/Adapter/Opensrs.php @@ -0,0 +1,538 @@ + null, + 'key' => null, + 'client_user' => null, + 'client_pass' => null + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "OpenSRS" is not configured properly. Please update configuration parameter "OpenSRS Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['key']) && !empty($options['key'])) { + $this->config['key'] = $options['key']; + unset($options['key']); + } else { + throw new Registrar_Exception('Domain registrar "OpenSRS" is not configured properly. Please update configuration parameter "OpenSRS key" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_user']) && !empty($options['client_user'])) { + $this->config['client_user'] = $options['client_user']; + unset($options['client_user']); + } else { + throw new Registrar_Exception('Domain registrar "OpenSRS" is not configured properly. Please update configuration parameter "OpenSRS client username" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_pass']) && !empty($options['client_pass'])) { + $this->config['client_pass'] = $options['client_pass']; + unset($options['client_pass']); + } else { + throw new Registrar_Exception('Domain registrar "OpenSRS" is not configured properly. Please update configuration parameter "OpenSRS client password" at "Configuration -> Domain registration".'); + } + + //@todo +// require_once 'Registrar/opensrs/openSRS_loader.php'; +// require_once 'Registrar/opensrs/spyc.php'; + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on OpenSRS via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'OpenSRS Username', + 'description'=>'OpenSRS Username' + ), + ), + 'key' => array('password', array( + 'label' => 'OpenSRS key', + 'description'=>'OpenSRS key', + 'renderPassword' => true, + ), + ), + 'client_user' => array('text', array( + 'label' => 'OpenSRS client username', + 'description'=>'The username of the registrant. For more information please visit www.opensrs.com' + ), + ), + 'client_pass' => array('password', array( + 'label' => 'OpenSRS client password', + 'description'=>'The registrants password. For more information please visit www.opensrs.com', + 'renderPassword' => true, + ), + ), + ), + ); + } + + /** + * Tells what TLDs can be registered via this adapter + * @return array + */ + public function getTlds() + { + return array( + '.com', '.net', '.org', '.info', '.tel', + '.biz', '.name', '.mobi', '.asia', + '.co', '.me', '.tv', '.ws', '.xxx', + '.at', '.au', '.be', '.bz', '.ca', '.cc', + '.ch', '.de', '.dk', '.es', '.eu', '.fr', '.in', + '.it', '.li', '.mx', '.nl', '.uk', '.us' + ); + } + + + public function isDomainAvailable(Registrar_Domain $domain) + { + $data = array( + 'func' => 'lookupDomain', + 'data' => array( + 'domain' => $domain->getName(), + 'selected' => $domain->getTld() + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + $result = $this->_process($data); + + if ($result) + return ($result[0]['status'] == 'available'); + return false; + } + + public function modifyNs(Registrar_Domain $domain) + { + $cookie = $this->_getCookie($domain); + + $ns = array(); + foreach ($domain->getNameservers() as $nse) + { + $ns[] = $nse->getHost(); + } + $nameservers = implode(',', $ns); + + $data = array( + 'func' => 'nsAdvancedUpdt', + 'data' => array( + 'domain' => $domain->getName(), + 'bypass' => '', + 'cookie' => $cookie, + 'op_type' => 'assign', + 'assign_ns' => $nameservers + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + return ((bool) $this->_process($data)); + } + + public function modifyContact(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + $cookie = $this->_getCookie($domain); + + $data = array( + 'func' => 'provUpdateContacts', + 'data' => array( + 'domain' => $domain->getName(), + 'types' => 'owner,admin,billing,tech', + 'cookie' => $cookie + ), + 'personal' => array( + 'first_name' => $c->getFirstName(), + 'last_name' => $c->getLastName(), + 'phone' => $c->getTelCc() . '.' . $c->getTel(), + 'fax' => $c->getFaxCc() . '.' . $c->getFax(), + 'email' => $c->getEmail(), + 'org_name' => $c->getCompany(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'address3' => $c->getAddress3(), + 'postal_code' => $c->getZip(), + 'city' => $c->getCountry(), + 'url' => '', + 'state' => $c->getState(), + 'country' => $c->getCountry(), + 'lang_pref' => 'EN' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + return ((bool) $this->_process($data)); + } + + public function transferDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $data = array( + 'func' => 'provSWregister', + 'data' => array( + 'auto_renew' => '0', + 'link_domains' => '0', + 'f_parkp' => 'Y', + 'custom_tech_contact' => '0', + 'domain' => $domain->getName(), + 'period' => '1', + 'reg_type' => 'transfer', + 'reg_username' => $this->config['client_user'], + 'reg_password' => $this->config['client_pass'], + 'custom_transfer_nameservers' => '0', + 'custom_nameservers' => '0' + ), + 'personal' => array( + 'first_name' => $c->getFirstName(), + 'last_name' => $c->getLastName(), + 'phone' => $c->getTelCc() . '.' . $c->getTel(), + 'fax' => $c->getFaxCc() . '.' . $c->getFax(), + 'email' => $c->getEmail(), + 'org_name' => $c->getCompany(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'address3' => $c->getAddress3(), + 'postal_code' => $c->getZip(), + 'city' => $c->getCountry(), + 'url' => '', + 'state' => 'n/a', + 'country' => $c->getCountry(), + 'lang_pref' => 'EN' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + return ((bool) $this->_process($data)); + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $cookie = $this->_getCookie($domain); + + $data = array( + 'func' => 'lookupGetDomain', + 'data' => array( + 'cookie' => $cookie, + 'bypass' => '', + 'type' => 'all_info', + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + $result = $this->_process($data); + + if ($result) + return $this->_createDomainObj($result['attributes'], $domain); + return false; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $data = array( + 'func' => 'provSWregister', + 'data' => array( + 'domain' => $domain->getName(), + 'custom_tech_contact' => '0', + 'custom_nameservers' => '1', + 'reg_username' => $this->config['client_user'], + 'reg_password' => $this->config['client_pass'], + 'reg_type' => 'new', + 'period' => $domain->getRegistrationPeriod(), + 'handle' => 'process' + ), + 'personal' => array( + 'first_name' => $c->getFirstName(), + 'last_name' => $c->getLastName(), + 'phone' => $c->getTelCc() . '.' . $c->getTel(), + 'fax' => $c->getFaxCc() . '.' . $c->getFax(), + 'email' => $c->getEmail(), + 'org_name' => $c->getCompany(), + 'address1' => $c->getAddress1(), + 'address2' => $c->getAddress2(), + 'address3' => $c->getAddress3(), + 'postal_code' => $c->getZip(), + 'city' => $c->getCountry(), + 'url' => '', + 'state' => 'n/a', + 'country' => $c->getCountry(), + 'lang_pref' => 'EN' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + // add nameservers to the data array + $i = 0; + foreach ($domain->getNameservers() as $nameserver) + { + $data['data']['name' . $i] = $nameserver->getHost(); + $data['data']['sortorder' . $i] = $i; + $i++; + } + + return ((bool) $this->_process($data)); + } + + public function renewDomain(Registrar_Domain $domain) + { + $data = array( + 'func' => 'provRenew', + 'data' => array( + 'auto_renew' => '0', + 'currentexpirationyear' => date('Y', $domain->getExpirationTime()), + 'domain' => $domain->getName(), + 'handle' => 'process', + 'period' => '1' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + return ((bool) $this->_process($data)); + } + + public function togglePrivacyProtection(Registrar_Domain $domain) + { + $cookie = $this->_getCookie($domain); + + if ($this->_isPrivacyEnabled($domain)) $state = 'disable'; + else $state = 'enable'; + + $data = array( + 'func' => 'provModify', + 'data' => array( + 'data' => 'whois_privacy_state', + 'state' => $state, + 'cookie' => $cookie, + 'affect_domains' => '0' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + return ((bool) $this->_process($data)); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Gets session. + * @param Registrar_Domain $domain + * @return string + * @throws Registrar_Exception + */ + private function _getCookie(Registrar_Domain $domain) + { + $data = array( + 'func' => 'cookieSet', + 'data' => array ( + 'reg_username' => $this->config['client_user'], + 'reg_password' => $this->config['client_pass'], + 'domain' => $domain->getName() + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + $result = $this->_process($data); + + if ($result) + return $result['attributes']['cookie']; + throw new Registrar_Exception($result['response_text']); + } + + /** + * Creates domain object from received data array. + * @param array $result + * @param Registrar_Domain $domain + * @return Registrar_Domain + */ + private function _createDomainObj($result, $domain) + { + $contact = $result['contact_set']['admin']; + $name = implode(' ', array($contact['first_name'], $contact['last_name'])); + + $telCc = explode('.', $contact['phone']); + $telCc = $telCc[0]; + + $c = new Registrar_Domain_Contact(); + $c->setName($name) + ->setEmail($contact['email']) + ->setCompany($contact['org_name']) + ->setTel($contact['phone']) + ->setTelCc($telCc) + ->setAddress1($contact['address1']) + ->setAddress2($contact['address2']) + ->setCity($contact['city']) + ->setCountry($contact['country']) + ->setState($contact['state']) + ->setZip($contact['postal_code']); + + $nsList = array(); + foreach ($result['nameserver_list'] as $ns) + { + $n = new Registrar_Domain_Nameserver(); + $n->setHost($ns['name']); + $nsList[] = $n; + } + + $domain->setNameservers($nsList); + $domain->setExpirationTime(strtotime($result['expiredate'])); + $domain->setRegistrationTime(strtotime($result['registry_createdate'])); + $domain->setContactRegistrar($c); + $domain->setEpp($this->_getEPPcode($domain)); + return $domain; + } + + /** + * Checks whether privacy is enabled + * @param Registrar_Domain $domain + * @return bool + */ + private function _isPrivacyEnabled(Registrar_Domain $domain) + { + $cookie = $this->_getCookie($domain); + + $data = array( + 'func' => 'lookupGetDomain', + 'data' => array ( + 'type' => 'whois_privacy_state', + 'cookie' => $cookie, + 'bypass' => '' + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + $result = $this->_process($data); + + return ($result && ($result['attributes']['state'] == 'enabled')); + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * Api URL + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) + return 'horizon.opensrs.net'; + return 'rr-n1-tor.opensrs.net'; + } + + /** + * Gets domain's EPP code. + * @param Registrar_Domain $domain + * @return string or bool + */ + private function _getEPPcode(Registrar_Domain $domain) + { + $cookie = $this->_getCookie($domain); + + $data = array( + 'func' => 'lookupGetDomain', + 'data' => array( + 'cookie' => $cookie, + 'bypass' => '', + 'type' => 'domain_auth_info', + ), + 'user' => $this->config['user'], + 'key' => $this->config['key'], + 'host' => $this->_getApiUrl() + ); + + $result = $this->_process($data); + + if ($result) + return $result['attributes']['domain_auth_info']; + return false; + } + + /** + * Process request. + * @param array + * @return array + * @throws Registrar_Exception + */ + private function _process($data) + { + try + { + $result = processOpensrs('array', $data)->resultFullRaw; + } + catch (Exception $e) + { + throw new Registrar_Exception($e->getMessage(), $e->getCode(), $e); + } + + if (($result['response_code'] == 200) && ($result['is_success'] == 1)) + return $result; + throw new Registrar_Exception($result['response_text']); + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Planetdomain.php b/bb-library/Registrar/Adapter/Planetdomain.php new file mode 100644 index 0000000..409cda0 --- /dev/null +++ b/bb-library/Registrar/Adapter/Planetdomain.php @@ -0,0 +1,407 @@ + null, + 'user' => null, + 'password' => null, + + 'client_user' => null, + 'client_pass' => null, + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['resellerid']) && !empty($options['resellerid'])) { + $this->config['resellerid'] = $options['resellerid']; + unset($options['resellerid']); + } else { + throw new Registrar_Exception('Domain registrar "PlanetDomain" is not configured properly. Please update configuration parameter "PlanetDomain Reseller ID" at "Configuration -> Domain registration".'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "PlanetDomain" is not configured properly. Please update configuration parameter "PlanetDomain Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "PlanetDomain" is not configured properly. Please update configuration parameter "PlanetDomain Password" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_user']) && !empty($options['client_user'])) { + $this->config['client_user'] = $options['client_user']; + unset($options['client_user']); + } else { + throw new Registrar_Exception('Domain registrar "PlanetDomain" is not configured properly. Please update configuration parameter "PlanetDomain Client Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_pass']) && !empty($options['client_pass'])) { + $this->config['client_pass'] = $options['client_pass']; + unset($options['client_pass']); + } else { + throw new Registrar_Exception('Domain registrar "PlanetDomain" is not configured properly. Please update configuration parameter "PlanetDomain Client Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on PlanetDomain via API', + 'form' => array( + 'resellerid' => array('text', array( + 'label' => 'PlanetDomain Reseller ID', + 'description'=>'PlanetDomain Reseller ID', + ), + ), + 'user' => array('text', array( + 'label' => 'PlanetDomain Username', + 'description'=>'PlanetDomain Username', + ), + ), + 'password' => array('password', array( + 'label' => 'PlanetDomain Password', + 'description'=>'PlanetDomain Password', + 'renderPassword' => true, + ), + ), + + 'client_user' => array('text', array( + 'label' => 'PlanetDomain Client Username', + 'description'=>'PlanetDomain Client Username', + ), + ), + 'client_pass' => array('password', array( + 'label' => 'PlanetDomain Client Password', + 'description'=>'PlanetDomain Client Password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + return array( + '.com', '.com.au', '.me.uk', '.co.nz', + '.net', '.net.au', '.us.com', '.net.nz', + '.org', '.org.au', '.uk.com', '.info', + '.mobi', '.asn.au', '.org.uk', '.us', + '.asia', '.id.au', '.tv', '.es', '.biz', + '.co.uk', '.eu', + ); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + ); + $result = $this->_request('domain.lookup', $params); + + return $result['domain.status'] == 'AVAILABLE'; + } + + public function modifyNs(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + ); + + $i = 0; + foreach ($domain->getNameservers() as $ns) + { + $params['ns.name.' . $i] = $ns->getHost(); + $params['ns.ip.' . $i++] = gethostbyname($ns->getHost()); + } + $this->_request('domain.update.ns', $params); + + return true; + } + + public function modifyContact(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $params = array( + 'domain.name' => $domain->getName(), + ); + $result = $this->_request('domain.info', $params); + + $params = array( + 'domain.name' => $domain->getName(), + 'user.id' => $result['domain.ownerid'], + + 'user.firstname' => $c->getFirstName(), + 'user.lastname' => $c->getLastName(), + 'user.company' => $c->getCompany(), + 'user.address1' => $c->getAddress1(), + 'user.address2' => $c->getAddress2(), + 'user.suburb' => $c->getCity(), + 'user.postcode' => $c->getZip(), + 'user.state' => $c->getState(), + 'user.country' => $c->getCountry(), + 'user.phone' => $c->getTelCc() . '.' . $c->getTel(), + 'user.email' => $c->getEmail(), + ); + $result = $this->_request('user.update', $params); + + return true; + } + + public function transferDomain(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + ); + $result = $this->_request('domain.info', $params); + + $params = array( + 'domain.name' => $domain->getName(), + 'user.id' => $result['domain.ownerid'], + ); + $result = $this->_request('domain.transfer', $params); + + return true; + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + ); + $result = $this->_request('domain.info', $params); + + $params = array( + 'user.id' => $result['domain.ownerid'], + ); + $user = $this->_request('user.info', $params); + + $tel = explode(".", $user['user.phone']); + + // Update domain + $c = new Registrar_Domain_Contact(); + $c->setFirstName($user['user.firstname']) + ->setLastName($user['user.lastname']) + ->setEmail($user['user.email']) + ->setCompany($user['user.company']) + ->setTel($tel[1]) + ->setTelCc($tel[0]) + ->setAddress1($user['user.address1']) + ->setAddress2($user['user.address2']) + ->setCity($user['user.suburb']) + ->setCountry($user['user.country']) + ->setZip($user['user.postcode']); + + // Add nameservers + $ns_list = array(); + for ($i = 0; $i < 5; $i++) { + if (!isset($result['ns.name.' . $i])) { + $n = new Registrar_Domain_Nameserver(); + $n->setHost($result['ns.name.' . $i]); + $ns_list[] = $n; + } + } + + $domain->setNameservers($ns_list); + $domain->setExpirationTime(strtotime($result['domain.expirydate'])); + $domain->setRegistrationTime(strtotime($result['domain.createddate'])); +// $domain->setPrivacyEnabled($privacy); + $domain->setEpp($this->_getEPP($domain)); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + // Register new user and get id + $params = array( + 'user.firstname' => $c->getFirstName(), + 'user.lastname' => $c->getLastName(), + 'user.address1' => $c->getAddress1(), + 'user.address2' => $c->getAddress2(), + 'user.suburb' => $c->getCity(), + 'user.postcode' => $c->getZip(), + 'user.state' => $c->getState(), + 'user.country' => $c->getCountry(), + 'user.phone' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'user.email' => $c->getEmail(), + 'user.username' => $this->config['client_user'], + 'user.password' => $this->config['client_pass'], + ); + $result = $this->_request('user.add', $params); + + $params = array( + 'domain.name' => $domain->getName(), + 'owner.id' => $result['user.id'], + 'tech.id' => $result['user.id'], + 'admin.id' => $result['user.id'], + 'billing.id' => $result['user.id'], + 'register.period' => $domain->getRegistrationPeriod(), + ); + + $i = 0; + foreach ($domain->getNameservers() as $ns) + { + $params['ns.name.' . $i] = $ns->getHost(); + $params['ns.ip.' . $i++] = gethostbyname($ns->getIp()); + } + + if ($domain->getTld() == 'us') + { + $params['us.intended_use'] = P3; + $params['us.nexus_category'] = C11; + } + + if ($domain->getTld() == 'com.au') + { + $params['au.org.type'] = 'NONPROFIT'; + $params['au.registrant.name'] = $domain->getContactRegistrar()->getName(); + } + + $this->_request('domain.register', $params); + + return true; + } + + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + 'register.period' => $domain->getRegistrationPeriod(), + ); + $this->_request('domain.renew', $params); + + return true; + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Runs an api command and returns parsed data. + * @param string $cmd + * @param array $params + * @return array + */ + private function _request($cmd, $params) + { + // Set authentication params + $params['operation'] = $cmd; + $params['admin.username'] = $this->config['user']; + $params['admin.password'] = $this->config['password']; + $params['reseller.id'] = $this->config['resellerid']; + + $curl_opts = array( + CURLOPT_URL => $this->_getApiUrl(), + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_FOLLOWLOCATION => 1, + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => http_build_query($params), + ); + + $ch = curl_init(); + curl_setopt_array($ch, $curl_opts); + $result = curl_exec($ch); + + if ($result === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + + curl_close($ch); + + $return = array(); + $splitResult = explode("\n", $result); + foreach ($splitResult as $str) { + if (strlen($str)) { + $splitStr = explode("=", trim($str)); + $return[$splitStr[0]] = $splitStr[1]; + } + } + + $this->getLog()->debug(print_r($params, true)); + $this->getLog()->debug(print_r($return, true)); + + if ($return['success'] == 'FALSE') { + throw new Registrar_Exception($return['error.desc.0']); + } + + return $return; + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) + return 'https://test-www.planetdomain.com/servlet/TLDServlet'; + return 'https://api.planetdomain.com/servlet/TLDServlet'; + } + + private function _getEPP(Registrar_Domain $domain) + { + $params = array( + 'domain.name' => $domain->getName(), + 'user.id' => $this->config['client_user'], + ); + $result = $this->_request('domain.authcode', $params); + + return $result['domain.password']; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Realtimeregister.php b/bb-library/Registrar/Adapter/Realtimeregister.php new file mode 100644 index 0000000..5bc48a2 --- /dev/null +++ b/bb-library/Registrar/Adapter/Realtimeregister.php @@ -0,0 +1,368 @@ + null, + 'password' => null, + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "RealtimeRegister" is not configured properly. Please update configuration parameter "RealtimeRegister Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "RealtimeRegister" is not configured properly. Please update configuration parameter "RealtimeRegister Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on RealtimeRegister via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'RealtimeRegister Username', + 'description'=>'RealtimeRegister Username', + ), + ), + 'password' => array('password', array( + 'label' => 'RealtimeRegister Password', + 'description'=>'RealtimeRegister Password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + public function getTlds() + { + return array( + '.nl', '.com', '.net', '.org', '.info', '.eu', + '.co.uk', '.me', '.be', '.biz','.de', '.dk', + '.ch', '.es', '.com.es', '.org.es', '.nom.es', + '.eu', '.li', '.me', '.nl', '.se', '.me.uk', + '.co.uk', '.org.uk', '.ltd.uk', '.plc.uk', '.net.uk', '.ae', + '.am', '.cc', '.fm', '.in', '.co.in', '.firm.in', '.gen.in', + '.ind.in', '.net.in', '.org.in', '.mobi', '.name', '.nu', '.tel', + '.to', '.tv', + ); + } + + public function isDomainAvailable(Registrar_Domain $domain) + { + $result = $this->_request('domains/' . $domain->getName() . '/check'); + + return $result->{$domain->getName()}->avail == 1; + } + + public function modifyNs(Registrar_Domain $domain) + { + // Send empty array to remove previous nameservers + $ns_list = array(); + $params = array( + 'ns' => $ns_list, + ); + $this->_request('domains/' . $domain->getName() . '/update', $params); + + foreach ($domain->getNameservers() as $ns) { + $ns_list[] = array( + 'host' => $ns->getHost(), + ); + } + + $params = array( + 'ns' => $ns_list, + ); + $this->_request('domains/' . $domain->getName() . '/update', $params); + + return true; + } + + public function modifyContact(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $result = $this->_request('domains/' . $domain->getName() . '/info'); + + $params = array( + 'email' => $c->getEmail(), + 'name' => $c->getName(), + 'street' => array( + $c->getAddress1(), + $c->getAddress2(), + $c->getAddress3(), + ), + 'city' => $c->getCity(), + 'sp' => $c->getState(), + 'pc' => $c->getZip(), + 'cc' => $c->getCountry(), + 'voice' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'fax' => ($c->getFax() ? '+' . $c->getFaxCc() . '.' . $c->getFax() : ''), + ); + $this->_request('contacts/' . $result->registrant . '/update', $params); + + return true; + } + + public function transferDomain(Registrar_Domain $domain) + { + $result = $this->_request('domains/' . $domain->getName() . '/info'); + + $params = array( + 'auth' => $domain->getEpp(), + 'request_type' => 'transfer', + 'registrant' => $result->registrant, + 'admin' => $result->admin, + 'tech' => $result->tech, + 'billing' => $result->billing, + ); + $this->_request('domains/' . $domain->getname() . '/transfer', $params); + + return true; + } + + public function getDomainDetails(Registrar_Domain $domain) + { + $result = $this->_request('domains/' . $domain->getName() . '/info'); + $contact = $this->_request('contacts/' . $result->registrant . '/info'); + + $tel = explode('.', $contact->voice); + + $c = new Registrar_Domain_Contact(); + $c->setName($contact->name) + ->setEmail($contact->email) + ->setTel($tel[1]) + ->setTelCc($tel[0]) + ->setCity($contact->city) + ->setCountry($contact->cc) + ->setZip($contact->pc); + + for ($i = 0; $i < 2; $i++) { + if (isset($contact->street[$i])) { + $c->{'setAddress' . ($i + 1)}($contact->street[$i]); + } + } + + // Add nameservers + $ns_list = array(); + foreach ($result->ns as $ns) + { + $n = new Registrar_Domain_Nameserver(); + $n->setHost($ns->host); + $ns_list[] = $n; + } + + $domain->setNameservers($ns_list); + $domain->setExpirationTime($result->exDate); + $domain->setRegistrationTime($result->crDate); + $domain->setEpp((isset($result->pw) ? $result->pw : '')); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + public function registerDomain(Registrar_Domain $domain) + { + $ns_list = array(); + foreach ($domain->getNameservers() as $ns) { + $ns_list[] = array( + 'host' => $ns->getHost(), + ); + } + + $c = $domain->getContactRegistrar(); + + $params = array( + 'ns' => $ns_list, + 'contact_data' => array( + 'registrant' => array( + 'email' => $c->getEmail(), + 'name' => $c->getName(), + 'street' => array( + $c->getAddress1(), + $c->getAddress2(), + $c->getAddress3(), + ), + 'city' => $c->getCity(), + 'sp' => $c->getState(), + 'pc' => $c->getZip(), + 'cc' => $c->getCountry(), + 'voice' => '+' . $c->getTelCc() . '.' . $c->getTel(), + ), + 'tech' => array( + 'email' => $c->getEmail(), + 'name' => $c->getName(), + 'street' => array( + $c->getAddress1(), + $c->getAddress2(), + $c->getAddress3(), + ), + 'city' => $c->getCountry(), + 'sp' => $c->getState(), + 'pc' => $c->getZip(), + 'cc' => $c->getCountry(), + 'voice' => '+' . $c->getTelCc() . '.' . $c->getTel(), + 'fax' => ($c->getFax() ? '+' . $c->getFaxCc() . '.' . $c->getFax() : ''), + ), + 'admin' => array( + 'email' => $c->getEmail(), + 'name' => $c->getName(), + 'street' => array( + $c->getAddress1(), + $c->getAddress2(), + $c->getAddress3(), + ), + 'city' => $c->getCountry(), + 'sp' => $c->getState(), + 'pc' => $c->getZip(), + 'cc' => $c->getCountry(), + 'voice' => '+' . $c->getTelCc() . '.' . $c->getTel(), + ), + 'billing' => array( + 'email' => $c->getEmail(), + 'name' => $c->getName(), + 'street' => array( + $c->getAddress1(), + $c->getAddress2(), + $c->getAddress3(), + ), + 'city' => $c->getCity(), + 'sp' => $c->getState(), + 'pc' => $c->getZip(), + 'cc' => $c->getCountry(), + 'voice' => '+' . $c->getTelCc() . '.' . $c->getTel(), + ), + ), + ); + $this->_request('domains/' . $domain->getName() . '/create', $params); + + return true; + } + + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'curExpDate' => $domain->getExpirationTime(), + ); + $this->_request('domains/' . $domain->getName() . '/renew', $params); + + return true; + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Exception('Checking if domain can be transfered is disabled for this registrar'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain locking'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support domain unlocking'); + } + + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection enable'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support privacy protection disable'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Exception('Registrar does not support EPP code retrieval'); + } + + /** + * Runs an api command and returns parsed data. + * @param string $cmd + * @param array $params + * @return array + */ + private function _request($cmd, $params = array()) + { + $params['login_handle'] = $this->config['user']; + $params['login_pass'] = $this->config['password']; + + $curl_opts = array( + CURLOPT_URL => $this->_getApiUrl() . $cmd, + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_FOLLOWLOCATION => 1, + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Accept: application/json', + ), + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => json_encode($params), + ); + + $ch = curl_init(); + curl_setopt_array($ch, $curl_opts); + + $result = curl_exec($ch); + + if ($result === false) { + $e = new Registrar_Exception(sprintf('CurlException: "%s"', curl_error($ch))); + $this->getLog()->err($e); + curl_close($ch); + throw $e; + } + + $result = json_decode($result); + + $this->getLog()->debug($this->_getApiUrl() . $cmd); + $this->getLog()->debug(print_r($params, true)); + $this->getLog()->debug(print_r($result, true)); + + curl_close($ch); + + if (strpos($result->code, '100') === false) { + throw new Registrar_Exception($result->msg . "\n" . implode("\n", $result->error)); + } + + return $result->response; + } + + public function isTestEnv() + { + return $this->_testMode; + } + + /** + * Api URL. + * @return string + */ + private function _getApiUrl() + { + if ($this->isTestEnv()) { + return 'https://httpapi.realtimeregister-ote.com/v1/'; + } + return 'https://httpapi.yoursrs.com/v1/'; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/Resellone.php b/bb-library/Registrar/Adapter/Resellone.php new file mode 100644 index 0000000..09b8af9 --- /dev/null +++ b/bb-library/Registrar/Adapter/Resellone.php @@ -0,0 +1,77 @@ +config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "ResellOne" is not configured properly. Please update configuration parameter "ReselleOne Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['key']) && !empty($options['key'])) { + $this->config['key'] = $options['key']; + unset($options['key']); + } else { + throw new Registrar_Exception('Domain registrar "ResellOne" is not configured properly. Please update configuration parameter "ReselleOne key" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_user']) && !empty($options['client_user'])) { + $this->config['client_user'] = $options['client_user']; + unset($options['client_user']); + } else { + throw new Registrar_Exception('Domain registrar "ResellOne" is not configured properly. Please update configuration parameter "ResellOne client username" at "Configuration -> Domain registration".'); + } + + if(isset($options['client_pass']) && !empty($options['client_pass'])) { + $this->config['client_pass'] = $options['client_pass']; + unset($options['client_pass']); + } else { + throw new Registrar_Exception('Domain registrar "ResellOne" is not configured properly. Please update configuration parameter "ResellOne client password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on ReselleOne via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'ResellOne Username', + 'description'=>'ResellOne Username' + ), + ), + 'key' => array('password', array( + 'label' => 'ResellOne key', + 'description'=>'ResellOne key', + 'renderPassword' => true, + ), + ), + 'client_user' => array('text', array( + 'label' => 'ResellOne client username', + 'description'=>'The username of the registrant. For more information please visit www.resellone.net' + ), + ), + 'client_pass' => array('password', array( + 'label' => 'ResellOne client password', + 'description'=>'The registrants password. For more information please visit www.resellone.net', + 'renderPassword' => true, + ), + ), + ), + ); + } + + protected function _getApiUrl() + { + if ($this->isTestEnv()) + return 'horizon.opensrs.net'; + return 'resellers.resellone.net'; + } +} \ No newline at end of file diff --git a/bb-library/Registrar/Adapter/TPPInternet.php b/bb-library/Registrar/Adapter/TPPInternet.php new file mode 100644 index 0000000..895203e --- /dev/null +++ b/bb-library/Registrar/Adapter/TPPInternet.php @@ -0,0 +1,347 @@ + null, + 'password' => null, + ); + + public function __construct($options) + { + if (!extension_loaded('curl')) { + throw new Registrar_Exception('CURL extension is not enabled'); + } + + if(isset($options['user']) && !empty($options['user'])) { + $this->config['user'] = $options['user']; + unset($options['user']); + } else { + throw new Registrar_Exception('Domain registrar "TPP Internet" is not configured properly. Please update configuration parameter "TPP Internet Username" at "Configuration -> Domain registration".'); + } + + if(isset($options['password']) && !empty($options['password'])) { + $this->config['password'] = $options['password']; + unset($options['password']); + } else { + throw new Registrar_Exception('Domain registrar "TPP Internet" is not configured properly. Please update configuration parameter "TPP Internet Password" at "Configuration -> Domain registration".'); + } + } + + public static function getConfig() + { + return array( + 'label' => 'Manages domains on TPP Internet via API', + 'form' => array( + 'user' => array('text', array( + 'label' => 'TPP Internet Username', + 'description'=>'TPP Internet Username' + ), + ), + 'password' => array('password', array( + 'label' => 'TPP Internet password', + 'description'=>'TPP Internet password', + 'renderPassword' => true, + ), + ), + ), + ); + } + + /** + * Return array of TLDs current Registar is capable to register + * If function returns empty array, this registrar can register any TLD + * @return array + */ + public function getTlds() + { + return array( + 'com', 'net', 'org', 'biz', 'info', + 'eu', 'asia', 'co', 'jobs', 'mobi', + 'tel', 'travel', 'com.au', 'net.au', + 'org.au', 'asn.au', 'id.au', + 'co.uk', 'org.uk', 'me.uk', + ); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function isDomainAvailable(Registrar_Domain $domain) + { + $params = array( + 'domain' => $domain->getSld(), + 'suffixes' => $domain->getTld(), + ); + $result = $this->_request('availability/check', $params); + + return isset($result['available']) + && ($result['available'] == $domain->getName()); + } + + public function isDomainCanBeTransfered(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain transfer checking is not implemented'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyNs(Registrar_Domain $domain) + { + $params = array( + 'TransactionType' => 'DELEGATION', + 'DomainName' => $domain->getName(), + ); + + $i = 1; + foreach ($domain->getNameservers() as $ns) { + $params['NameServer' . $i] = $ns->getHost(); + $params['NameServer' . $i++ . 'IP'] = gethostbyname($ns->getHost()); + } + $result = $this->_request('updates/domainupdate', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function modifyContact(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $params = array( + 'TransactionType' => 'CONTACT_UPDATE', + 'DomainName' => $domain->getName(), + + 'RegistrantFirstName' => $c->getFirstname(), + 'RegistrantLastName' => $c->getLastname(), + 'RegistrantCompanyName' => $c->getCompany(), + 'RegistrantEmail' => $c->getEmail(), + 'RegistrantPhone' => '+' . $c->getTelcc() . '.' . $c->getTel(), + 'RegistrantAddressLine1' => $c->getAddress1(), + 'RegistrantAddressLine2' => $c->getAddress2(), + 'RegistrantSuburb' => $c->getCity(), + 'RegistrantPostcode' => $c->getZip(), + 'RegistrantState' => $c->getState(), + 'RegistrantCountry' => $c->getCountry(), + ); + $result = $this->_request('updates/domainupdate', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function transferDomain(Registrar_Domain $domain) + { + $params = array( + 'RequestType' => 'T', + 'DomainName' => $domain->getName(), + ); + $result = $this->_request('orderrequest', $params); + + return true; + } + + /** + * 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(), + ); + $result = $this->_request('info/DomainInfo', $params); + + $tel = explode(".", $result['RegistrantPhone']); + + $c = new Registrar_Domain_Contact(); + $c->setName($result['RegistrantFirstName'] . ' ' . $result['RegistrantLastName']) + ->setEmail($result['RegistrantEmail']) + ->setTel($tel[1]) + ->setTelCc($tel[0]) + ->setAddress1($result['RegistrantAddress1']) + ->setAddress2($result['RegistrantAddress2']) + ->setCity($result['RegistrantSuburb']) + ->setCountry($result['RegistrantCountry']) + ->setState($result['RegistrantState']) + ->setZip($result['RegistrantPostcode']); + + // Add nameservers + $ns_list = array(); + for ($i = 0; $i < 10; $i++) { + $n = new Registrar_Domain_Nameserver(); + if ($i == 0) { + $n->setHost($result['PrimaryNameServer']); + } else { + $n->setHost($result['SecondaryNameServer' . $i]); + } + $ns_list[] = $n; + + if (!isset($result['SecondaryNameServer' . $i + 1])) { + break; + } + } + + $domain->setNameservers($ns_list); + $domain->setExpirationTime(strtotime($result['ExpiryDate'])); + $domain->setContactRegistrar($c); + + return $domain; + } + + public function deleteDomain(Registrar_Domain $domain) + { + throw new Registrar_Exception('Registrar does not support domain removal.'); + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function registerDomain(Registrar_Domain $domain) + { + $c = $domain->getContactRegistrar(); + + $params = array( + 'DomainName' => $domain->getName(), + 'RequestType' => 'R', + 'Period' => $domain->getRegistrationPeriod(), + 'RegistrantFirstName' => $c->getFirstname(), + 'RegistrantLastName' => $c->getLastname(), + 'RegistrantCompanyName' => $c->getCompany(), + 'RegistrantEmail' => $c->getEmail(), + 'RegistrantPhone' => '+' . $c->getTelcc() . '.' . $c->getTel(), + 'RegistrantAddressLine1' => $c->getAddress1(), + 'RegistrantAddressLine2' => $c->getAddress2(), + 'RegistrantSuburb' => $c->getCity(), + 'RegistrantPostcode' => $c->getZip(), + 'RegistrantState' => $c->getState(), + 'RegistrantCountry' => $c->getCountry(), + ); + + $i = 0; + foreach ($domain->getNameservers() as $ns) { + if ($i == 0) { + $params['PrimaryNS'] = $ns->getHost(); + $params['PrimaryNSIP'] = gethostbyname($ns->getHost()); + } else { + $params['SecondaryNS' . $i] = $ns->getHost(); + $params['SecondaryNS' . $i . 'IP'] = gethostbyname($ns->getHost()); + } + $i++; + } + + $this->_request('orderrequest', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function renewDomain(Registrar_Domain $domain) + { + $params = array( + 'TransactionType' => 'RENEWAL', + 'DomainName' => $domain->getName(), + 'Period' => 1, + ); + $result = $this->_request('updates/domainupdate', $params); + + return true; + } + + /** + * @return bool + * @throws Registrar_Exception + */ + public function enablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception('TPPInternet Registrar does not support Privacy protection.'); + } + + public function disablePrivacyProtection(Registrar_Domain $domain) + { + throw new Registrar_Exception('TPPInternet Registrar does not support Privacy protection.'); + } + + public function getEpp(Registrar_Domain $domain) + { + throw new Registrar_Exception('Epp code retrieval is not implemented'); + } + + public function lock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain locking is not implemented'); + } + + public function unlock(Registrar_Domain $domain) + { + throw new Registrar_Exception('Domain unlocking is not implemented'); + } + + private function _request($cmd, $params) + { + $params['ClientID'] = $this->config['user']; + $params['ClientPassword'] = $this->config['password']; + + $url = $this->_getApiUrl() . $cmd . '.php' . '?' . http_build_query($params); + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + $result = curl_exec($ch); + + $this->getLog()->debug($url); + $this->getLog()->debug(print_r($result, true)); + + $matches = array(); + if (preg_match('/1170#
#Description:#
#(.*?)#/i', $result, $matches)) { + throw new Registrar_Exception($matches[1]); + } + + return $this->_parseResponse($result); + } + + private function _parseResponse($result) { + $return = array(); + $result = str_replace(' ', '', $result); + $result = explode("
", $result); + + foreach ($result as $r) { + $matches = array(); + if (preg_match('/([\w\d]+):([^<#\n]+)/', $r, $matches)) { + $return[$matches[1]] = $matches[2]; + } + } + + return $return; + } + + private function _getApiUrl() + { + if ($this->isTestEnv()) { + return 'https://ssl.twoplums.com.au/tppautomation/test/'; + } + return 'https://ssl.twoplums.com.au/tppautomation/production/'; + } + + public function isTestEnv() + { + return $this->_testMode; + } +} \ No newline at end of file