array ( 'friendlyName' => 'Email', 'type' => 'email', 'validators' => array( 'required' => 'required', ) ), 'password' => array ( 'friendlyName' => 'Password', 'type' => 'password', 'validators' => array( 'required' => 'required', ) ), 'api_url' => array ( 'friendlyName' => 'Host', 'validators' => array( 'required' => 'required', ) ), ); public $availableTypes = array('A', 'AAAA', 'CNAME', 'LOC', 'MX', 'NAPTR', 'RP', 'TXT'); public function testConnection() { try { $this->get('dnsrecord/list.xml', array()); } catch(exceptions\DNSSubmoduleException $e) { if($e->getCode() == dns\SubmoduleExceptionCodes::COMMAND_ERROR) { return true; } throw $e; } } public function zoneExists() { try { $xml = $this->get('dnsrecord/list.xml', array( 'domainname' => $this->domain )); return isset($xml->dnsrecord) || $xml->result == 'NO ENTRIES'; } catch(exceptions\DNSSubmoduleException $e) { if($e->getCode() == dns\SubmoduleExceptionCodes::COMMAND_ERROR) { return false; } throw $e; } } public function activateZone() { $this->post('domain/enable_fn_dns.xml', array( 'domainname' => $this->domain )); } public function terminateZone() { $this->post('domain/disable_fn_dns.xml', array( 'domainname' => $this->domain )); } public function getRecords($recordType = false) { $xml = $this->get('dnsrecord/list.xml', array( 'domainname' => $this->domain )); $out = array(); $i = 0; foreach($xml->dnsrecord as $r) { if(in_array((string)$r->rrtype, $recordType!==false ? array(strtoupper($recordType)) : $this->getAvailableRecordTypes())) { $record = new dns\record\Record(); $record->line = $i; $record->name = (string)$r->name; $record->type = (string)$r->rrtype; $record->ttl = (string)$r->ttl; $record->createRDATAObject(); switch((string)$r->rrtype) { case 'MX': $record->rdata->preference = (string)$r->priority; $record->rdata->exchange = (string)$r->value; break; case 'RP': $record->rdata->mbox = (string)$r->priority; $record->rdata->txtdname = (string)$r->value; break; default: $record->rdata->setFirstProperty((string)$r->value); break; } $i++; $out[] = $record; } } return $out; } private function recordToParamsArray(dns\record\Record $record) { $params = array( 'rrtype' => $record->type, 'ttl' => $record->ttl, 'name' => $record->nameToAbsolute($domain, false), ); switch((string)$r->rrtype) { case 'MX': $params['value'] = $record->rdata->exchange; $params['priority'] = $record->rdata->preference; break; case 'RP': $params['value'] = $record->rdata->txtdname; $params['priority'] = $record->rdata->mbox; break; default: $params['value'] = $record->rdata->toString(); break; } return $params; } public function addRecord(dns\record\Record $record) { $params = $this->recordToParamsArray($record); $params['domainname'] = $this->domain; $this->post('dnsrecord/register.xml', $params); } public function editRecord(dns\record\Record $record) { $records = $this->getRecords(); foreach($records as $r) { if($r->line == $record->line) { $this->addRecord($record); $this->deleteRecord($r); break ; } } } public function deleteRecord(dns\record\Record $record) { $params = $this->recordToParamsArray($record); $params['domainname'] = $this->domain; $this->post('dnsrecord/delete.xml', $params); } private function get($function, $params = array()) { $url = trim($this->config['api_url'], '/').'/'.$function; if(is_array($params)) { $params['email'] = $this->config['email']; $params['password'] = $this->config['password']; $url .= '?'; foreach($params as $key=>$value) { $value = urlencode($value); $key = urlencode($key); $url .= "{$key}={$value}&"; } } $ch = curl_init(); $chOptions = array ( CURLOPT_URL => trim($url, '&'), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_TIMEOUT => 30 ); curl_setopt_array($ch, $chOptions); return $this->execCurl($ch); } private function post($function, $params = array()) { $url = trim($this->config['api_url'], '/').'/'.$function; $post_data = ''; if(is_array($params)) { $params['email'] = $this->config['email']; $params['password'] = $this->config['password']; foreach($params as $key=>$value) { $value = urlencode($value); $key = urlencode($key); $post_data .= "{$key}={$value}&"; } } $ch = curl_init(); $chOptions = array ( CURLOPT_URL => trim($url, '&'), CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $post_data, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_TIMEOUT => 30 ); curl_setopt_array($ch, $chOptions); return $this->execCurl($ch); } private function execCurl($ch) { $retval = curl_exec($ch); if (curl_errno($ch)) { throw new exceptions\DNSSubmoduleException("cURL Error: " . curl_errno($ch) . " - " . curl_error($ch), dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM); } curl_close($ch); @$result = simplexml_load_string($retval); if($result === false) { throw new exceptions\DNSSubmoduleException('The requested URL was not found on this server.', dns\SubmoduleExceptionCodes::INVALID_RESPONSE); } if((string)$result->status != 'OK') { throw new exceptions\DNSSubmoduleException((string)$result->error?:'Unknown Error', dns\SubmoduleExceptionCodes::COMMAND_ERROR); } return $result; } public function getZones() { $xml = $this->get('dnsrecord/list.xml', array('results_per_page' => 9999)); $out = array(); foreach($xml->domain as $domain) { $out[(string)$domain->domainname] = ''; } return $out; } }