diff options
author | Renato Botelho <renato@netgate.com> | 2015-09-21 16:02:27 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-09-21 16:02:27 -0300 |
commit | 62f3a0ea27e277ebc88ca4e84eaa67271d84d6b5 (patch) | |
tree | b6235ff9e6cffea18e736c2c54dbff31039d2074 | |
parent | adbf3f4652b8484267fde3f645521d52221d47f1 (diff) | |
parent | 9aa75e0d5e6b75c0e138408a80ce9615b4136391 (diff) | |
download | pfsense-62f3a0ea27e277ebc88ca4e84eaa67271d84d6b5.zip pfsense-62f3a0ea27e277ebc88ca4e84eaa67271d84d6b5.tar.gz |
Merge pull request #1916 from doktornotor/patch-15
-rw-r--r-- | etc/inc/dyndns.class | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index a28d332..5633ade 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -605,10 +605,43 @@ break; case 'cloudflare': $needsIP = TRUE; - $dnsServer ='www.cloudflare.com'; + $dnsServer ='api.cloudflare.com'; $dnsHost = str_replace(' ','', $this->_dnsHost); - $URL = "https://{$dnsServer}/api.html?a=DIUP&email={$this->_dnsUser}&tkn={$this->_dnsPass}&ip={$this->_dnsIP}&hosts={$dnsHost}"; - curl_setopt($ch, CURLOPT_URL, $URL); + $host_names = explode(".", $dnsHost); + $bottom_host_name = $host_names[count($host_names)-2] . "." . $host_names[count($host_names)-1]; + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'X-Auth-Email: '.$this->_dnsUser.'', + 'X-Auth-Key: '.$this->_dnsPass.'', + 'Content-Type: application/json' + )); + + // Get zone ID + $getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$bottom_host_name}"; + curl_setopt($ch, CURLOPT_URL, $getZoneId); + $output = json_decode(curl_exec($ch)); + $zone = $output->result[0]->id; + if ($zone){ // If zone ID was found get host ID + $getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_dnsHost}"; + curl_setopt($ch, CURLOPT_URL, $getHostId); + $output = json_decode(curl_exec($ch)); + $host = $output->result[0]->id; + if ($host){ // If host ID was found update host + $hostData = array( + "content" => "{$this->_dnsIP}", + "type" => "A", + "name" => "{$this->_dnsHost}", + "proxiable" => false, + "proxied" => false + ); + $data_json = json_encode($hostData); + $updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}"; + curl_setopt($ch, CURLOPT_URL, $updateHostId); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); + } + } break; case 'eurodns': $needsIP = TRUE; @@ -1101,35 +1134,20 @@ $status = "phpDynDNS: (Error) Result did not match."; break; case 'cloudflare': - // recieve multipe results - $data = explode("\n",$data); - $lines = count($data)-1; - - // loop over the lines - for ($pos=0; ($successful_update || $pos == 0) && $pos < $lines; $pos++){ - $resp = $data[$pos]; - if (preg_match('/UAUTH/i', $resp)) { - $status = "DynDNS: The username specified is not authorized to update this hostname and domain."; - } else if (preg_match('/NOHOST/i', $resp)) { - $status = "DynDNS: No valid FQDN (fully qualified domain name) was specified"; - } else if (preg_match('/INVLDHST/i', $resp)) { - $status = "DynDNS: An invalid hostname was specified. This may be due to the fact the hostname has not been created in the system. Creating new host names via clients is not supported."; - } else if (preg_match('/INVLDIP/i', $resp)) { - $status = "DynDNS: The IP address given is not valid."; - } else if (preg_match('/DUPHST/i', $resp)) { - $status = "DynDNS: Duplicate values exist for a record. Only single values for records are supported currently."; - } else if (preg_match('/NOUPDATE/i', $resp)) { - $status = "DynDNS: No changes made to the hostname (".strtok($resp,' ')."). Continual updates with no changes lead to blocked clients."; - $successful_update = true; //success if it is the same so that it saves - } else if (preg_match('/OK/i', $resp)) { - $status = "DynDNS: (Success) (".strtok($resp,' ').") IP Address for Changed Successfully!"; - $successful_update = true; - } else { - $status = "DynDNS: (Unknown Response)"; - log_error("DynDNS: PAYLOAD: {$resp}"); - $this->_debug($resp); - } - log_error($status); + $output = json_decode($data); + if ($output->result->content === $this->_dnsIP){ + $status = "DynDNS: (Success) {$this->_dnsHost} updated to {$this->_dnsIP}"; + $successful_update = true; + } + elseif ($output->errors[0]->code === 9103){ + $status = "DynDNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with CloudFlare."; + } + elseif (($output->success) && (!$output->result[0]->id)) { + $status = "DynDNS ({$this->_dnsHost}): ERROR - Zone or Host ID was not found, check your hostname."; + } + else { + $status = "DynDNS ({$this->_dnsHost}): UNKNOWN ERROR - {$output->errors[0]->message}"; + log_error("DynDNS ({$this->_dnsHost}): PAYLOAD: {$data}"); } break; case 'eurodns': |