array (
'friendlyName' => 'Username',
'validators' => array(
'required' => 'required',
)
),
'password' =>array (
'friendlyName' => 'Password',
'type'=> 'password',
'validators' => array(
'required' => 'required',
)
),
'default_ip' =>array (
'friendlyName' => 'Default IP',
'validators' => array(
'pattern' => Patterns::IP4_OR_IP6,
)
),
);
public $availableTypes = array('A', 'AAAA', 'NS', 'MX', 'CNAME', 'PTR', 'TXT');
private function get($request) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_USERPWD, $this->config['username'] . ":" . $this->config['password']);
curl_setopt ($ch, CURLOPT_URL, "https://secure.api-eurodns.com:20015/v2/");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode (urlencode ($request)));
$response = curl_exec ($ch);
if (curl_errno($ch)) {
throw new exceptions\DNSSubmoduleException("cURL Error: " . curl_errno($ch) . " - " . curl_error($ch), dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM);
}
if (empty($response) || $response === false) {
throw new exceptions\DNSSubmoduleException("Unexpected error(0)", dns\SubmoduleExceptionCodes::INVALID_RESPONSE);
}
curl_close($ch);
@$ret = simplexml_load_string($response, null, LIBXML_NOCDATA);
if($ret === false) {
throw new exceptions\DNSSubmoduleException("Unexpected error(1)", dns\SubmoduleExceptionCodes::INVALID_RESPONSE);
}
$code = (int)current($ret->result->attributes()->code);
if($code !== 1000) {
throw new exceptions\DNSSubmoduleException((string)$response->result->msg?:"Unknown Error", dns\SubmoduleExceptionCodes::INVALID_RESPONSE);
}
return $ret;
}
public function testConnection(){
$request = '
';
$this->get($request);
}
public function zoneExists() {
try {
$request = '
'.$this->domain.'
';
$response = $this->get($request);
$main = $response->resData->children('http://www.eurodns.com/zone');
return current($main->name) == $this->domain;
} catch (exceptions\DNSSubmoduleException $e) {
if($e->getCode() == dns\SubmoduleExceptionCodes::COMMAND_ERROR) {
return false;
}
throw $e;
}
}
public function activateZone() {
$request = '
'.$this->domain.'
';
$this->get($request);
}
public function terminateZone() {
//nie ma
}
public function getRecords($recordType = false) {
$request = '
'.$this->domain.'
';
$response = $this->get($request);
$main = $response->resData->children('http://www.eurodns.com/zone');
$out = array();
foreach($main->records->record as $r) {
$record = $r->children('http://www.eurodns.com/record');
if(in_array((string)$record->type, $recordType!==false ? array(strtoupper($recordType)) : $this->getAvailableRecordTypes())) {
$line = (string)$r->attributes()->id[0];
$new_record = new dns\record\Record();
$new_record->line = $line;
$new_record->name = (string)$record->host;
$new_record->type = (string)$record->type;
$new_record->ttl = (string)$record->ttl;
$new_record->createRDATAObject();
switch((string)$record->type) {
case 'MX':
$new_record->rdata->preference = (string)$record->priority;
$new_record->rdata->exchange = (string)$record->data;
break;
default:
$new_record->rdata->fromString((string)$record->data);
break;
}
$out[] = $new_record;
}
}
return $out;
}
private function recordToXML(dns\record\Record $record) {
$out = ''.$record->type.'
'.$record->name.'
'.$record->ttl.'';
switch($record->type) {
case 'MX':
$out .= '' . $record->rdata->exchange . '
'.$record->rdata->preference.'';
break;
default:
$out .= '' . $record->rdata->exchange . '';
break;
}
return $out;
}
public function addRecord(dns\record\Record $record) {
$request = '
'.$this->domain.'
'.$this->recordToXML($record).'
';
$this->get($request);
}
public function editRecord(dns\record\Record $record) {
$request = '
'.$this->domain.'
'.$this->recordToXML($record).'
';
$this->get($request);
}
public function deleteRecord(dns\record\Record $record) {
$request = '
'.$this->domain.'
';
$this->get($request);
}
public function getZones() {
$request = '
#TLD#
';
$response = $this->get($request);
$out = array();
$main = $response->resData->children('http://www.eurodns.com/zone');
foreach($main->list as $zone) {
$out[(string)$zone->name] = '';
}
return $out;
}
}