From e07347f7014043d2d88a70da23f6432a7d6be74a Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 25 Apr 2019 15:04:23 +0200 Subject: [PATCH] system: services.inc removal splatter --- src/etc/inc/services.inc | 53 ---------------------------------------- src/etc/inc/util.inc | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 1f5bf49a8..a6cefc0ef 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -1695,59 +1695,6 @@ function services_dhcrelay6_configure($verbose = false) } } -function get_dyndns_ip($int, $ipver = 4) -{ - global $config; - - $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'; - } - - $gateways_status = return_gateways_status(); - - /* - * 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 (!empty($gateways_status[$config['interfaces'][$int]['gateway']]['status']) && - stristr($gateways_status[$config['interfaces'][$int]['gateway']]['status'], 'down')) { - log_error("Aborted IPv{$ipver} detection: gateway down 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; -} - function is_radvd_enabled() { global $config; diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index a6192754d..dd68537b4 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -1325,3 +1325,56 @@ function dhcp6c_duid_clear() /* clear the backup so that it will not be restored: */ @unlink('/conf/dhcp6c_duid'); } + +function get_dyndns_ip($int, $ipver = 4) +{ + global $config; + + $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'; + } + + $gateways_status = return_gateways_status(); + + /* + * 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 (!empty($gateways_status[$config['interfaces'][$int]['gateway']]['status']) && + stristr($gateways_status[$config['interfaces'][$int]['gateway']]['status'], 'down')) { + log_error("Aborted IPv{$ipver} detection: gateway down 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; +}