Commit 983134be authored by Franco Fichtner's avatar Franco Fichtner

rfc2136: rework dyndnsCheckIP() as get_dyndns_ip(); closes #1478

parent 0dd2c697
......@@ -129,6 +129,7 @@
/usr/local/etc/rc.reload_interfaces
/usr/local/etc/rc.resolv_conf_generate
/usr/local/etc/rc.restart_webgui
/usr/local/etc/rc.rfc2136.update
/usr/local/etc/rc.shutdown
/usr/local/etc/rc.sshd
/usr/local/etc/rc.syshook
......@@ -632,6 +633,7 @@
/usr/local/opnsense/service/conf/actions.d/actions_openssh.conf
/usr/local/opnsense/service/conf/actions.d/actions_openvpn.conf
/usr/local/opnsense/service/conf/actions.d/actions_proxy.conf
/usr/local/opnsense/service/conf/actions.d/actions_rfc2136.conf
/usr/local/opnsense/service/conf/actions.d/actions_routedns.conf
/usr/local/opnsense/service/conf/actions.d/actions_system.conf
/usr/local/opnsense/service/conf/actions.d/actions_systemhealth.conf
......
......@@ -65,7 +65,7 @@ function rfc2136_configure_do($verbose = false, $int = '', $updatehost = '', $fo
$if = get_real_interface($dnsupdate['interface']);
if (isset($dnsupdate['usepublicip'])) {
$wanip = dyndnsCheckIP($dnsupdate['interface']);
$wanip = get_dyndns_ip($dnsupdate['interface']);
} else {
$wanip = get_interface_ip($dnsupdate['interface']);
}
......
......@@ -1551,33 +1551,36 @@ function services_dhcrelay6_configure($verbose = false)
}
}
function dyndnsCheckIP($int)
function get_dyndns_ip($int, $ipver = 4)
{
global $config;
$ip_address = get_interface_ip($int);
$ip_address = $ipver == 6 ? get_interface_ipv6($int) : get_interface_ip($int);
if (is_private_ip($ip_address)) {
if ($ipver == 6 || is_private_ip($ip_address)) {
$gateways_status = return_gateways_status(true);
// If the gateway for this interface is down, then the external check cannot work.
// Avoid the long wait for the external check to timeout.
if (stristr($gateways_status[$config['interfaces'][$int]['gateway']]['status'],"down")) {
return "down";
return 'down';
}
$hosttocheck = "http://checkip.dyndns.org";
$hosttocheck = $ipver == 6 ? 'http://checkipv6.dyndns.org' : 'http://checkip.dyndns.org';
$ip_ch = curl_init($hosttocheck);
curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ip_ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ip_ch, CURLOPT_IPRESOLVE, $ipver == 6 ? CURL_IPRESOLVE_V6 : CURL_IPRESOLVE_V4);
$ip_result_page = curl_exec($ip_ch);
curl_close($ip_ch);
$ip_result_decoded = urldecode($ip_result_page);
preg_match('=Current IP Address: (.*)</body>=siU', $ip_result_decoded, $matches);
preg_match('=<body>Current IP Address: (.*)</body>=siU', $ip_result_decoded, $matches);
$ip_address = trim($matches[1]);
if (($ipver == 6 && !is_ipaddrv6($ip_address)) || ($ipver != 6 && !is_ipaddrv4($ip_address))) {
return 'down';
}
}
return $ip_address;
}
......
......@@ -143,14 +143,14 @@ $main_buttons = array(
$filename = "/conf/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}.cache";
$fdata = '';
if (file_exists($filename) && !empty($dyndns['enable'])) {
$ipaddr = dyndnsCheckIP($dyndns['interface']);
$ipaddr = get_dyndns_ip($dyndns['interface'], 4);
$fdata = @file_get_contents($filename);
}
$filename_v6 = "/conf/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}_v6.cache";
$fdata6 = '';
if (file_exists($filename_v6) && !empty($dyndns['enable'])) {
$ipv6addr = get_interface_ipv6($dyndns['interface']);
$ipv6addr = get_dyndns_ip($dyndns['interface'], 6);
$fdata6 = @file_get_contents($filename_v6);
}
......
......@@ -143,7 +143,7 @@ $main_buttons = array(
if (file_exists($filename) && !empty($rfc2136['enable']) && (empty($dnsupdate['recordtype']) || $dnsupdate['recordtype'] == 'A')) {
echo "IPv4: ";
if (isset($rfc2136['usepublicip'])) {
$ipaddr = dyndnsCheckIP($rfc2136['interface']);
$ipaddr = get_dyndns_ip($rfc2136['interface'], 4);
} else {
$ipaddr = get_interface_ip($rfc2136['interface']);
}
......@@ -162,7 +162,11 @@ $main_buttons = array(
echo "<br />";
if (file_exists("{$filename}.ipv6") && !empty($rfc2136['enable']) && (empty($dnsupdate['recordtype']) || $dnsupdate['recordtype'] == 'AAAA')) {
echo "IPv6: ";
if (isset($rfc2136['usepublicip'])) {
$ipaddr = get_dyndns_ip($rfc2136['interface'], 6);
} else {
$ipaddr = get_interface_ipv6($rfc2136['interface']);
}
$cached_ip_s = explode("|", file_get_contents("{$filename}.ipv6"));
$cached_ip = $cached_ip_s[0];
if ($ipaddr <> $cached_ip) {
......
......@@ -53,14 +53,14 @@ if (!empty($_REQUEST['getdyndnsstatus'])) {
$filename = "/conf/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}.cache";
$fdata = '';
if (!empty($dyndns['enable']) && file_exists($filename)) {
$ipaddr = dyndnsCheckIP($dyndns['interface']);
$ipaddr = get_dyndns_ip($dyndns['interface'], 4);
$fdata = @file_get_contents($filename);
}
$filename_v6 = "/conf/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}_v6.cache";
$fdata6 = '';
if (!empty($dyndns['enable']) && file_exists($filename_v6)) {
$ipv6addr = get_interface_ipv6($dyndns['interface']);
$ipv6addr = get_dyndns_ip($dyndns['interface'], 6);
$fdata6 = @file_get_contents($filename_v6);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment