From 6ed716ea25c4ee57caaa2072ee284aa20cd80c79 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 17 Jan 2022 14:22:21 +0100 Subject: [PATCH] dns/dyndns - flag for removal and move shared function get_dyndns_ip() into package to isolate it further. Our new ddclient plugin replaces the old dyndns one, make sure people know it's going away so they can contribute other vendors if needed or switch to the ones that are already supported. (also related to https://github.com/opnsense/core/issues/5434) --- .../src/etc/inc/plugins.inc.d/dyndns.inc | 39 +++++++++++++++++++ .../inc/plugins.inc.d/dyndns/phpDynDNS.inc | 2 +- dns/dyndns/src/www/services_dyndns.php | 9 ++++- .../widgets/widgets/dyn_dns_status.widget.php | 13 ++++++- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc index 762549e53..54f1db403 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc @@ -249,3 +249,42 @@ function dyndns_failover_interface($interface, $family = 'all') /* fall through to get real interface the hard way */ return get_real_interface($interface, $family); } + + +function get_dyndns_ip_address($int, $ipver = 4) +{ + $ip_address = $ipver == 6 ? get_interface_ipv6($int) : get_interface_ip($int); + if (empty($ip_address)) { + log_error("Aborted IPv{$ipver} detection: no address for {$int}"); + return 'down'; + } + + if ($ipver != 6 && is_private_ip($ip_address)) { + /* Chinese alternative is http://ip.3322.net/ */ + $hosttocheck = 'http://checkip.dyndns.org'; + $ip_ch = curl_init($hosttocheck); + curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address); + curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($ip_ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + $ip_result = curl_exec($ip_ch); + if ($ip_result !== false) { + preg_match('=Current IP Address: (.*)=siU', $ip_result, $matches); + $ip_address = trim($matches[1]); + } else { + log_error('Aborted IPv4 detection: ' . curl_error($ip_ch)); + $ip_address = ''; + } + curl_close($ip_ch); + } elseif ($ipver == 6 && is_linklocal($ip_address)) { + log_error('Aborted IPv6 detection: cannot bind to link-local address'); + $ip_address = ''; + } + + if (($ipver == 6 && !is_ipaddrv6($ip_address)) || ($ipver != 6 && !is_ipaddrv4($ip_address))) { + return 'down'; + } + + return $ip_address; +} diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc index 44ceb9755..0bf690816 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc @@ -2022,7 +2022,7 @@ class updatedns function _checkIP() { - $ip_address = get_dyndns_ip($this->_if, $this->_useIPv6 ? 6 : 4); + $ip_address = get_dyndns_ip_address($this->_if, $this->_useIPv6 ? 6 : 4); if (!is_ipaddr($ip_address)) { if ($this->_dnsVerboseLog) { log_error("Dynamic DNS ({$this->_dnsHost}): IP address could not be extracted"); diff --git a/dns/dyndns/src/www/services_dyndns.php b/dns/dyndns/src/www/services_dyndns.php index 30f5d259c..a209477ba 100644 --- a/dns/dyndns/src/www/services_dyndns.php +++ b/dns/dyndns/src/www/services_dyndns.php @@ -110,6 +110,11 @@ legacy_html_escape_form_data($a_dyndns);
+
@@ -146,14 +151,14 @@ legacy_html_escape_form_data($a_dyndns); $filename = dyndns_cache_file($dyndns, 4); $fdata = ''; if (file_exists($filename) && !empty($dyndns['enable'])) { - $ipaddr = get_dyndns_ip(dyndns_failover_interface($dyndns['interface'], 'all'), 4); + $ipaddr = get_dyndns_ip_address(dyndns_failover_interface($dyndns['interface'], 'all'), 4); $fdata = @file_get_contents($filename); } $filename_v6 = dyndns_cache_file($dyndns, 6); $fdata6 = ''; if (file_exists($filename_v6) && !empty($dyndns['enable'])) { - $ipv6addr = get_dyndns_ip(dyndns_failover_interface($dyndns['interface'], 'inet6'), 6); + $ipv6addr = get_dyndns_ip_address(dyndns_failover_interface($dyndns['interface'], 'inet6'), 6); $fdata6 = @file_get_contents($filename_v6); } diff --git a/dns/dyndns/src/www/widgets/widgets/dyn_dns_status.widget.php b/dns/dyndns/src/www/widgets/widgets/dyn_dns_status.widget.php index 7728dec22..55a59d611 100644 --- a/dns/dyndns/src/www/widgets/widgets/dyn_dns_status.widget.php +++ b/dns/dyndns/src/www/widgets/widgets/dyn_dns_status.widget.php @@ -48,14 +48,14 @@ if (!empty($_REQUEST['getdyndnsstatus'])) { $filename = dyndns_cache_file($dyndns, 4); $fdata = ''; if (!empty($dyndns['enable']) && file_exists($filename)) { - $ipaddr = get_dyndns_ip(dyndns_failover_interface($dyndns['interface'], 'all'), 4); + $ipaddr = get_dyndns_ip_address(dyndns_failover_interface($dyndns['interface'], 'all'), 4); $fdata = @file_get_contents($filename); } $filename_v6 = dyndns_cache_file($dyndns, 6); $fdata6 = ''; if (!empty($dyndns['enable']) && file_exists($filename_v6)) { - $ipv6addr = get_dyndns_ip(dyndns_failover_interface($dyndns['interface'], 'inet6'), 6); + $ipv6addr = get_dyndns_ip_address(dyndns_failover_interface($dyndns['interface'], 'inet6'), 6); $fdata6 = @file_get_contents($filename_v6); } @@ -86,6 +86,15 @@ if (!empty($_REQUEST['getdyndnsstatus'])) { + + +
+ +