diff options
author | Daniel Becker <razzfazz@gmail.com> | 2013-07-07 12:39:13 -0700 |
---|---|---|
committer | Daniel Becker <razzfazz@gmail.com> | 2013-07-07 12:39:13 -0700 |
commit | b4025ccd10e0dd07a22c58c4ff35bd8199518853 (patch) | |
tree | d7653e7a68264f3ce1dbc98d9735225f02910a22 | |
parent | ba581f076acc3068c37bd86c97656bf53b29781b (diff) | |
download | pfsense-b4025ccd10e0dd07a22c58c4ff35bd8199518853.zip pfsense-b4025ccd10e0dd07a22c58c4ff35bd8199518853.tar.gz |
Add backend support for HE.net AAAA record updates.
Defines a new DynDNS provider 'he-net-v6' for updating AAAA entries on
dns.he.net.
-rw-r--r-- | etc/inc/dyndns.class | 117 | ||||
-rw-r--r-- | etc/inc/services.inc | 4 |
2 files changed, 118 insertions, 3 deletions
diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index bb1bbc5..79cf168 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -38,8 +38,10 @@ * - _checkStatus() * - _error() * - _detectChange() + * - _detectChangev6() * - _debug() * - _checkIP() + * - _checkIPv6() * +----------------------------------------------------+ * DynDNS Dynamic - Last Tested: 12 July 2005 * DynDNS Static - Last Tested: NEVER @@ -78,6 +80,7 @@ class updatedns { var $_cacheFile; + var $_cacheFilev6; var $_debugFile; var $_UserAgent = 'User-Agent: phpDynDNS/0.7'; var $_errorVerbosity = 0; @@ -86,6 +89,7 @@ var $_dnsPass; var $_dnsHost; var $_dnsIP; + var $_dnsIPv6; var $_dnsWildcard; var $_dnsMX; var $_dnsBackMX; @@ -106,6 +110,7 @@ var $_dnsMaxCacheAgeDays; var $_dnsDummyUpdateDone; var $_forceUpdateNeeded; + var $_useIPv6; /* * Public Constructor Function (added 12 July 05) [beta] @@ -125,6 +130,7 @@ global $config, $g; $this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache"; + $this->_cacheFilev6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache"; $this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.debug"; $this->_curlIpresolveV4 = $curlIpresolveV4; @@ -157,6 +163,13 @@ if (!$dnsHost) $this->_error(5); } + switch ($dnsService) { + case 'he-net-v6': + $this->_useIPv6 = true; + break; + default: + $this->_useIPv6 = false; + } $this->_dnsService = strtolower($dnsService); $this->_dnsUser = $dnsUser; $this->_dnsPass = $dnsPass; @@ -169,6 +182,8 @@ $this->_dnsTTL = $dnsTTL; $this->_if = get_failover_interface($dnsIf); $this->_checkIP(); + if($this->_useIPv6 == true) + $this->_checkIPv6(); $this->_dnsUpdateURL = $dnsUpdateURL; $this->_dnsResultMatch = $dnsResultMatch; $this->_dnsRequestIf = get_failover_interface($dnsRequestIf); @@ -188,7 +203,7 @@ $this->_debugID = rand(1000000, 9999999); - if ($forceUpdate == false && $this->_detectChange() == false) { + if ($forceUpdate == false && $this->_detectChange() == false && ($this->_useIPv6 == false || $this->_detectChangev6() == false)) { $this->_error(10); } else { switch ($this->_dnsService) { @@ -212,6 +227,7 @@ case 'opendns': case 'namecheap': case 'he-net': + case 'he-net-v6': case 'selfhost': case 'he-net-tunnelbroker': case 'route53': @@ -490,6 +506,15 @@ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP); break; + case 'he-net-v6': + $needsIP = FALSE; + if ($this->_dnsVerboseLog) + log_error("HE.net IPv6 ({$this->_dnsHost}): DNS update() starting."); + $server = "https://dyn.dns.he.net/nic/update?"; + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); + curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIPv6); + break; case 'he-net-tunnelbroker': $needsIP = FALSE; if ($this->_dnsVerboseLog) @@ -948,6 +973,7 @@ break; case 'he-net': + case 'he-net-v6': if (preg_match("/badip/i", $data)) { $status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid."; } else if (preg_match('/nohost/i', $data)) { @@ -1086,6 +1112,8 @@ if($successful_update == true) { /* Write WAN IP to cache file */ $wan_ip = $this->_checkIP(); + if ($this->_useIPv6 == true) + $wan_ipv6 = $this->_checkIPv6(); conf_mount_rw(); if ($wan_ip > 0) { $currentTime = time(); @@ -1094,6 +1122,13 @@ @file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}"); } else @unlink($this->_cacheFile); + if ($this->_useIPv6 == true && $wan_ipv6 > 0) { + $currentTime = time(); + notify_all_remote(sprintf(gettext("DynDNS updated IPv6 Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ipv6)); + log_error("phpDynDNS: updating cache file {$this->_cacheFilev6}: {$wan_ipv6}"); + @file_put_contents($this->_cacheFilev6, "{$wan_ipv6}@{$currentTime}"); + } else + @unlink($this->_cacheFilev6); conf_mount_ro(); } $this->status = $status; @@ -1216,6 +1251,71 @@ return false; } + function _detectChangev6() { + global $debug; + + if ($debug) + log_error("DynDns ({$this->_dnsHost}): _detectChangev6() starting."); + + $currentTime = time(); + + $wan_ipv6 = $this->_checkIPv6(); + if ($wan_ipv6 == 0) { + log_error("DynDns ({$this->_dnsHost}): Current WAN IPv6 could not be determined, skipping update process."); + return false; + } + $log_error = "DynDns ({$this->_dnsHost}): Current WAN IPv6: {$wan_ipv6} "; + + if (file_exists($this->_cacheFilev6)) { + $contents = file_get_contents($this->_cacheFilev6); + list($cacheIPv6,$cacheTime) = explode('@', $contents); + $this->_debug($cacheIPv6.'/'.$cacheTime); + $initial = false; + $log_error .= "Cached IPv6: {$cacheIPv6} "; + } else { + conf_mount_rw(); + $cacheIPv6 = '::'; + @file_put_contents($this->_cacheFilev6, "::@{$currentTime}"); + conf_mount_ro(); + $cacheTime = $currentTime; + $initial = true; + $log_error .= "No Cached IPv6 found."; + } + if ($this->_dnsVerboseLog) + log_error($log_error); + + // Convert seconds = days * hr/day * min/hr * sec/min + $maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60; + + $needs_updating = FALSE; + /* lets determine if the item needs updating */ + if ($cacheIPv6 != $wan_ipv6) { + $needs_updating = true; + $update_reason = "DynDns: cacheIPv6 != wan_ipv6. Updating. "; + $update_reason .= "Cached IPv6: {$cacheIPv6} WAN IPv6: {$wan_ipv6} "; + } + if (($currentTime - $cacheTime) > $maxCacheAgeSecs) { + $needs_updating = true; + $this->_forceUpdateNeeded = true; + $update_reason = "DynDns: More than " . $this->_dnsMaxCacheAgeDays . " days. Updating. "; + $update_reason .= "{$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} "; + } + if ($initial == true) { + $needs_updating = true; + $update_reason .= "Initial update. "; + } + + /* finally if we need updating then store the + * new cache value and return true + */ + if ($needs_updating == true) { + if ($this->_dnsVerboseLog) + log_error("DynDns ({$this->_dnsHost}): {$update_reason}"); + return true; + } + + return false; + } /* * Private Function (added 16 July 05) [beta] @@ -1283,6 +1383,21 @@ return $ip_address; } + function _checkIPv6() { + global $debug; + + if ($debug) + log_error("DynDns ({$this->_dnsHost}): _checkIPv6() starting."); + + $ipv6_address = find_interface_ipv6($this->_if); + if (!is_ipaddrv6($ipv6_address)) + return 0; + if ($this->_dnsVerboseLog) + log_error("DynDns ({$this->_dnsHost}): {$ipv6_address} extracted from local system."); + $this->_dnsIPv6 = $ipv6_address; + + return $ipv6_address; + } } diff --git a/etc/inc/services.inc b/etc/inc/services.inc index 6c2e045..aab8e93 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -38,8 +38,8 @@ pfSense_MODULE: utils */ -define('DYNDNS_PROVIDER_VALUES', 'dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip noip-free ods zoneedit loopia freedns dnsexit opendns namecheap he-net he-net-tunnelbroker selfhost route53 cloudflare custom eurodns'); -define('DYNDNS_PROVIDER_DESCRIPTIONS', 'DNS-O-Matic,DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,No-IP (free),ODS.org,ZoneEdit,Loopia,freeDNS,DNSexit,OpenDNS,Namecheap,HE.net,HE.net Tunnelbroker,SelfHost,Route 53,CloudFlare, Custom, Euro Dns'); +define('DYNDNS_PROVIDER_VALUES', 'dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip noip-free ods zoneedit loopia freedns dnsexit opendns namecheap he-net he-net-v6 he-net-tunnelbroker selfhost route53 cloudflare custom eurodns'); +define('DYNDNS_PROVIDER_DESCRIPTIONS', 'DNS-O-Matic,DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,No-IP (free),ODS.org,ZoneEdit,Loopia,freeDNS,DNSexit,OpenDNS,Namecheap,HE.net,HE.net (v6),HE.net Tunnelbroker,SelfHost,Route 53,CloudFlare, Custom, Euro Dns'); /* implement ipv6 route advertising deamon */ function services_radvd_configure() { |