diff options
Diffstat (limited to 'etc/inc/dyndns.class')
-rw-r--r-- | etc/inc/dyndns.class | 117 |
1 files changed, 116 insertions, 1 deletions
diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index 5ac93d4..0a2789d 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -36,8 +36,10 @@ * - _checkStatus() * - _error() * - _detectChange() + * - _detectChangev6() * - _debug() * - _checkIP() + * - _checkIPv6() * +----------------------------------------------------+ * DynDNS Dynamic - Last Tested: 12 July 2005 * DynDNS Static - Last Tested: NEVER @@ -74,6 +76,7 @@ class updatedns { var $_cacheFile; + var $_cacheFilev6; var $_debugFile; var $_UserAgent = 'User-Agent: phpDynDNS/0.7'; var $_errorVerbosity = 0; @@ -82,6 +85,7 @@ var $_dnsPass; var $_dnsHost; var $_dnsIP; + var $_dnsIPv6; var $_dnsWildcard; var $_dnsMX; var $_dnsBackMX; @@ -100,6 +104,7 @@ var $_dnsMaxCacheAgeDays; var $_dnsDummyUpdateDone; var $_forceUpdateNeeded; + var $_useIPv6; /* * Public Constructor Function (added 12 July 05) [beta] @@ -119,6 +124,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->_dnsVerboseLog = $dnsVerboseLog; @@ -149,6 +155,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; @@ -161,6 +174,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); @@ -180,7 +195,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) { @@ -204,6 +219,7 @@ case 'opendns': case 'namecheap': case 'he-net': + case 'he-net-v6': case 'selfhost': case 'he-net-tunnelbroker': case 'route53': @@ -480,6 +496,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) @@ -912,6 +937,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)) { @@ -1001,6 +1027,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(); @@ -1009,6 +1037,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; @@ -1131,6 +1166,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] @@ -1198,6 +1298,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; + } } |