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)
This commit is contained in:
Ad Schellevis
2022-01-17 14:22:21 +01:00
parent 6bf0c63865
commit 6ed716ea25
4 changed files with 58 additions and 5 deletions
@@ -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('=<body>Current IP Address: (.*)</body>=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;
}
@@ -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");
+7 -2
View File
@@ -110,6 +110,11 @@ legacy_html_escape_form_data($a_dyndns);
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<div class="alert alert-warning" role="alert">
<strong>
<?=gettext("Please make sure to upgrade to os-ddclient before 21.7 is released as this plugin will be removed from our repository");?>
</strong>
</div>
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
@@ -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);
}
@@ -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'])) {
<table class="table table-striped table-condensed">
<thead>
<tr>
<th colspan="4">
<div class="alert alert-warning" role="alert">
<strong>
<?=gettext("Please make sure to upgrade to os-ddclient before 21.7 is released as this plugin will be removed from our repository");?>
</strong>
</div>
</th>
</tr>
<tr>
<th style="word-break:break-word;"><?=gettext("Interface");?></th>
<th style="word-break:break-word;"><?=gettext("Service");?></th>