| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules;
- use \MGModule\DNSManager2\mgLibs\custom\dns;
- use \MGModule\DNSManager2\mgLibs\custom\dns\exceptions;
- use \MGModule\DNSManager2\mgLibs\custom\dns\interfaces;
- use \MGModule\DNSManager2\mgLibs\custom\dns\utils\Patterns;
- class EuroDNS extends dns\SubmoduleAbstract implements interfaces\SubmoduleTTLInterface, interfaces\SubmoduleImportInterface {
-
- public $configFields = array(
- 'username' =>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 = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:agent="http://www.eurodns.com/agent">
- <agent:balance />
- </request> ';
- $this->get($request);
- }
- public function zoneExists() {
- try {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone">
- <zone:info>
- <zone:name>'.$this->domain.'</zone:name>
- </zone:info>
- </request>';
- $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 = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone" xmlns:record="http://www.eurodns.com/record">
- <zone:create>
- <zone:name>'.$this->domain.'</zone:name>
- </zone:create>
- </request>';
-
- $this->get($request);
- }
- public function terminateZone() {
- //nie ma
- }
- public function getRecords($recordType = false) {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone">
- <zone:info>
- <zone:name>'.$this->domain.'</zone:name>
- </zone:info>
- </request>';
- $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->type.'</record:type>
- <record:host>'.$record->name.'</record:host>
- <record:ttl>'.$record->ttl.'</record:ttl>';
-
- switch($record->type) {
- case 'MX':
- $out .= '<record:data>' . $record->rdata->exchange . '</record:data>
- <record:mx_priority>'.$record->rdata->preference.'</record:mx_priority>';
- break;
- default:
- $out .= '<record:data>' . $record->rdata->exchange . '</record:data>';
- break;
- }
-
- return $out;
- }
-
- public function addRecord(dns\record\Record $record) {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone" xmlns:record="http://www.eurodns.com/record">
- <zone:update>
- <zone:name>'.$this->domain.'</zone:name>
- <zone:records>
- <zone:add>
- <zone:record>'.$this->recordToXML($record).'</zone:record>
- </zone:add>
- </zone:records>
- </zone:update>
- </request> ';
- $this->get($request);
- }
- public function editRecord(dns\record\Record $record) {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone" xmlns:record="http://www.eurodns.com/record">
- <zone:update>
- <zone:name>'.$this->domain.'</zone:name>
- <zone:records>
- <zone:change>
- <zone:record id="'.$record->line.'">'.$this->recordToXML($record).'</zone:record>
- </zone:change>
- </zone:records>
- </zone:update>
- </request>';
- $this->get($request);
- }
- public function deleteRecord(dns\record\Record $record) {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone" xmlns:record="http://www.eurodns.com/record">
- <zone:update>
- <zone:name>'.$this->domain.'</zone:name>
- <zone:records>
- <zone:remove>
- <zone:record id="'.$record->line.'"></zone:record>
- </zone:remove>
- </zone:records>
- </zone:update>
- </request> ';
-
- $this->get($request);
- }
- public function getZones() {
- $request = '<?xml version="1.0" encoding="UTF-8"?>
- <request xmlns:zone="http://www.eurodns.com/zone">
- <zone:list>
- <zone:tld>#TLD#</zone:tld>
- </zone:list>
- </request>';
- $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;
- }
- }
|