diff options
author | Jason McCormick <jason@mfamily.org> | 2016-12-03 08:00:52 -0500 |
---|---|---|
committer | Jason McCormick <jason@mfamily.org> | 2016-12-03 08:00:52 -0500 |
commit | a5676b5dd9f4b1083ec2e061b79dd878a2d4a133 (patch) | |
tree | 1e70bb89cbe7884c1776f03cf5e233aea5aabfad /src/etc/inc/dyndns.class | |
parent | 16b163661b1d1a5bcc9a24ce023f7a06c5fb420e (diff) | |
parent | 7d4d9ec5866ad034e5432af6decd7e442cfd2bd1 (diff) | |
download | pfsense-a5676b5dd9f4b1083ec2e061b79dd878a2d4a133.zip pfsense-a5676b5dd9f4b1083ec2e061b79dd878a2d4a133.tar.gz |
Merge remote-tracking branch 'upstream/master' into 6751_route53
Diffstat (limited to 'src/etc/inc/dyndns.class')
-rw-r--r-- | src/etc/inc/dyndns.class | 128 |
1 files changed, 89 insertions, 39 deletions
diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index a9f6813..8b488dc 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -3,7 +3,7 @@ * dyndns.class * * part of pfSense (https://www.pfsense.org) - * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC + * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate) * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,6 +57,9 @@ * - DNS Made Easy (www.dnsmadeeasy.com) * - SPDYN (spdyn.de) * - SPDYN IPv6 (spdyn.de) + * - All-Inkl (all-inkl.com) + * - DuiaDNS (www.duiadns.net) + * - DuiaDNS IPv6 (www.duiadns.net) * +----------------------------------------------------+ * Requirements: * - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library @@ -107,6 +110,9 @@ * DNS Made Easy - Last Tested: 27 April 2015 * SPDYN - Last Tested: 02 July 2016 * SPDYN IPv6 - Last Tested: 02 July 2016 + * All-Inkl - Last Tested: 12 November 2016 + * DuiaDNS - Last Tested: 25 November 2016 + * DuiaDNS IPv6 - Last Tested: 25 November 2016 * +====================================================+ * * @author E.Kristensen @@ -169,9 +175,8 @@ $dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '', $dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) { - global $config, $g; - - if ($dnsService == "namecheap") { + global $config, $g, $dyndns_split_domain_types; + if (in_array($dnsService, $dyndns_split_domain_types)) { $this->_FQDN = $dnsHost . "." . $dnsDomain; } else { $this->_FQDN = $dnsHost; @@ -196,7 +201,15 @@ case 'freedns-v6': if (!$dnsHost) $this->_error(5); break; - case 'namecheap': + case "namecheap": + if (!$dnsPass) $this->_error(4); + if (!$dnsHost) $this->_error(5); + if (!$dnsDomain) $this->_error(5); + break; + case "cloudflare-v6": + case "cloudflare": + case "gratisdns": + if (!$dnsUser) $this->_error(3); if (!$dnsPass) $this->_error(4); if (!$dnsHost) $this->_error(5); if (!$dnsDomain) $this->_error(5); @@ -218,6 +231,7 @@ case 'he-net-v6': case 'custom-v6': case 'spdyn-v6': + case 'duiadns-v6': case 'freedns-v6': case 'cloudflare-v6': $this->_useIPv6 = true; @@ -227,7 +241,7 @@ } $this->_dnsService = strtolower($dnsService); $this->_dnsUser = $dnsUser; - $this->_dnsPass = $dnsPass; + $this->_dnsPass = base64_decode($dnsPass); $this->_dnsHost = $dnsHost; $this->_dnsDomain = $dnsDomain; $this->_dnsServer = $dnsServer; @@ -286,6 +300,8 @@ case 'namecheap': case 'he-net': case 'he-net-v6': + case 'duiadns': + case 'duiadns-v6': case 'selfhost': case 'he-net-tunnelbroker': case 'route53': @@ -300,6 +316,7 @@ case 'dnsmadeeasy': case 'spdyn': case 'spdyn-v6': + case 'all-inkl': $this->_update(); if ($this->_dnsDummyUpdateDone == true) { // If a dummy update was needed, then sleep a while and do the update again to put the proper address back. @@ -343,7 +360,7 @@ } if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') { - curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); @@ -590,6 +607,15 @@ $server = "https://dynamicdns.park-your-domain.com/update?host={$this->_dnsHost}&domain={$this->_dnsDomain}&password={$dnspass}&ip={$this->_dnsIP}"; curl_setopt($ch, CURLOPT_URL, $server); break; + case 'duiadns': + case 'duiadns-v6': + $needsIP = FALSE; + $server = "https://ipv4.duiadns.net/dyndns.duia?"; + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass); + curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP); + break; case 'he-net': case 'he-net-v6': $needsIP = FALSE; @@ -665,8 +691,6 @@ $needsIP = TRUE; $dnsServer ='api.cloudflare.com'; $dnsHost = str_replace(' ', '', $this->_dnsHost); - $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( @@ -676,12 +700,12 @@ )); // Get zone ID - $getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$bottom_host_name}"; + $getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$this->_dnsDomain}"; 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}&type={$recordType}"; + $getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_FQDN}&type={$recordType}"; curl_setopt($ch, CURLOPT_URL, $getHostId); $output = json_decode(curl_exec($ch)); $host = $output->result[0]->id; @@ -712,15 +736,7 @@ case 'gratisdns': $needsIP = TRUE; $server = "https://ssl.gratisdns.dk/ddns.phtml"; - $host = trim($this->_dnsHost); - $hostnames = explode(".", $host); - $hostnames_count = count($hostnames); - if ($hostnames_count > 2) { - $domain = $hostnames[$hostnames_count-2] . "." . $hostnames[$hostnames_count-1]; - } else { - $domain = $host; - } - curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $host . '&d=' . $domain . '&i=' . $this->_dnsIP); + curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $this->_dnsHost . '&d=' . $this->_dnsDomain . '&i=' . $this->_dnsIP); break; case 'ovh-dynhost': $needsIP = FALSE; @@ -795,12 +811,21 @@ } curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP); break; + case 'all-inkl': + $needsIP = FALSE; + $server = 'https://dyndns.kasserver.com/'; + curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); + curl_setopt($ch, CURLOPT_URL, $server . 'myip=' . $this->_dnsIP); + break; default: break; } if ($this->_dnsService != 'ods') { - $data = curl_exec($ch); - $this->_checkStatus($ch, $data); + $response = curl_exec($ch); + $header_size = curl_getinfo($ch, CURLINFO_ ER_SIZE); + $header = substr($response, 0, $header_size); + $data = substr($response, $header_size); + $this->_checkStatus($ch, $data, $header); @curl_close($ch); } } @@ -1167,7 +1192,26 @@ $this->_debug($data); } break; - + case 'duiadns': + case 'duiadns-v6': + if (preg_match("/error/i", $data)) { + $status = $status_intro . $error_str . gettext("Server side error."); + } else if (preg_match('/nohost/i', $data)) { + $status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided."); + } else if (preg_match('/badauth/i', $data)) { + $status = $status_intro . $error_str . gettext("Invalid username or password."); + } else if (preg_match('/good/i', $data)) { + $status = $status_intro . $success_str . gettext("IP Address Updated Successfully!"); + $successful_update = true; + } else if (preg_match('/nochg/i', $data)) { + $status = $status_intro . $success_str . gettext("No Change In IP Address."); + $successful_update = true; + } else { + $status = $status_intro . "(" . gettext("Unknown Response") . ")"; + log_error($status_intro . gettext("PAYLOAD:") . " " . $data); + $this->_debug($data); + } + break; case 'he-net': case 'he-net-v6': if (preg_match("/badip/i", $data)) { @@ -1318,14 +1362,12 @@ /* Responds with HTTP 200 on success. Responds with HTTP 4xx on error. Returns JSON data as body */ - $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $header = substr($data, 0, $header_size); - $body = substr($data, $header_size); - if (preg_match("/Status: 200\s/i", $header)) { +; + if (preg_match("/\s200\sOK/i", $header)) { $status = $status_intro . $success_str . gettext("IP Address Updated Successfully!"); $successful_update = true; - } else if (preg_match("/Status: 4\d\d\s/i", $header)) { - $arrbody = json_decode($body, true); + } else if (preg_match("/\s4\d\d\s/i", $header)) { + $arrbody = json_decode($data, true); $message = $arrbody['message'] . "."; if (isset($arrbody['errors']['content'])) { foreach ($arrbody['errors']['content'] as $key => $content) { @@ -1335,8 +1377,8 @@ $status = $status_intro . $error_str . $message; } else { $status = $status_intro . "(" . gettext("Unknown Response") . ")"; - log_error($status_intro . gettext("PAYLOAD:") . " " . $body); - $this->_debug($body); + log_error($status_intro . gettext("PAYLOAD:") . " " . $data); + $this->_debug($data); } break; case 'googledomains': @@ -1422,12 +1464,27 @@ $this->_debug($data); } break; + case 'all-inkl': + if (preg_match('/good\s'.$this->_dnsIP.'/i', $data)) { + $status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")"; + $successful_update = true; + } else if (preg_match('/good/i', $data)) { + $status = $status_intro . $error_str . gettext("Result did not match."); + } else if (preg_match("/\s401\sUnauthorized/i", $header)) { + $status = $status_intro . $error_str . gettext("Invalid username or password"); + } + else { + $status = $status_intro . "(" . gettext("Unknown Response") . ")"; + log_error($status_intro . gettext("PAYLOAD:") . " " . $header.$data); + $this->_debug($data); + $this->_debug($header); + } + break; } if ($successful_update == true) { /* Write WAN IP to cache file */ $wan_ip = $this->_checkIP(); - conf_mount_rw(); if ($this->_useIPv6 == false && $wan_ip > 0) { $currentTime = time(); notify_all_remote(sprintf(gettext('DynDNS updated IP Address on %1$s (%2$s) to %3$s'), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip)); @@ -1444,7 +1501,6 @@ } else { @unlink($this->_cacheFile_v6); } - conf_mount_ro(); } $this->status = $status; log_error($status); @@ -1527,10 +1583,8 @@ $initial = false; $log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP); } else { - conf_mount_rw(); $cacheIP = '::'; @file_put_contents($this->_cacheFile, "::|{$currentTime}"); - conf_mount_ro(); $cacheTime = $currentTime; $initial = true; $log_error .= gettext("No Cached IPv6 found."); @@ -1543,10 +1597,8 @@ $initial = false; $log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP); } else { - conf_mount_rw(); $cacheIP = '0.0.0.0'; @file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}"); - conf_mount_ro(); $cacheTime = $currentTime; $initial = true; $log_error .= gettext("No Cached IP found."); @@ -1603,11 +1655,9 @@ return; } $string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n"; - conf_mount_rw(); $file = fopen($this->_debugFile, 'a'); fwrite($file, $string); fclose($file); - conf_mount_ro(); } function _checkIP() { global $debug; |