Merge pull request #1916 from doktornotor/patch-15

This commit is contained in:
Renato Botelho 2015-09-21 16:02:27 -03:00
commit 62f3a0ea27

View File

@ -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':