checkip: retain old default without relying on new model

This commit is contained in:
Franco Fichtner 2018-03-04 10:39:05 +00:00
parent 06bc82ee3f
commit 719ecf1d9e
2 changed files with 27 additions and 32 deletions

View File

@ -1570,21 +1570,6 @@ function services_dhcrelay6_configure($verbose = false)
}
}
/* Factory default check IP service. */
function factory_default_checkipservice()
{
return array(
"enable" => true,
"name" => 'Default',
"url" => 'http://checkip.dyndns.org',
# "url" => 'http://ip.3322.net/', /* Chinese alternative */
# "username" => '',
# "password" => '',
# "verifysslpeer" => true,
"descr" => 'Factory Default Check IP Service'
);
}
function get_dyndns_ip($int, $ipver = 4)
{
global $config;
@ -1607,26 +1592,24 @@ function get_dyndns_ip($int, $ipver = 4)
}
if ($ipver == 4 && is_private_ip($ip_address)) {
/* Append the factory default check IP service to the list (if not disabled). */
if (!isset($config['checkipservices']['disable_factory_default'])) {
$config['checkipservices']['service'][] = factory_default_checkipservice();
}
$hosttocheck = 'http://checkip.dyndns.org';
$verifysslpeer = false;
$username = null;
$password = null;
/* Use the first enabled check IP service as the default. */
if (is_array($config['checkipservices']['service'])) {
if (isset($config['checkipservices']['service'])) {
foreach ($config['checkipservices']['service'] as $i => $checkipservice) {
if (isset($checkipservice['enable'])) {
$url = $checkipservice['url'];
$verifysslpeer = isset($checkipservice['verifysslpeer']);
$username = $checkipservice['username'];
$password = $checkipservice['password'];
$verifysslpeer = isset($checkipservice['verifysslpeer']);
$hosttocheck = $checkipservice['url'];
break;
}
}
}
$hosttocheck = $url;
$ip_ch = curl_init($hosttocheck);
curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, $verifysslpeer);
@ -1634,8 +1617,11 @@ function get_dyndns_ip($int, $ipver = 4)
curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ip_ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ip_ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ip_ch, CURLOPT_USERPWD, "{$username}:{$password}");
if (!empty($username) && !empty($password)) {
curl_setopt($ip_ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ip_ch, CURLOPT_USERPWD, "{$username}:{$password}");
}
$ip_result = curl_exec($ip_ch);
if ($ip_result !== false) {
preg_match('=<body>Current IP Address: (.*)</body>=siU', $ip_result, $matches);

View File

@ -33,7 +33,16 @@ require_once("services.inc");
$a_checkipservices = &config_read_array('checkipservices', 'service');
// Append the factory default check IP service to the list.
$a_checkipservices[] = factory_default_checkipservice();
$a_checkipservices[] = array(
"enable" => true,
"name" => 'Default',
"url" => 'http://checkip.dyndns.org',
#"url" => 'http://ip.3322.net/', /* Chinese alternative */
#"username" => '',
#"password" => '',
#"verifysslpeer" => true,
"descr" => 'Factory Default Check IP Service'
);
$factory_default = count($a_checkipservices) - 1;
// Is the factory default check IP service disabled?
@ -146,15 +155,15 @@ $main_buttons = array(
?>
<tr>
<td class="text-left" style="width:0px">
<a href="#" class="act_toggle" data-id="<?=$i;?>" data-toggle="tooltip" title="<?=(!empty($checkipservice['enable'])) ? gettext("disable") : gettext("enable");?>">
<i style="width:15px" class="glyphicon glyphicon-play <?=(!empty($checkipservice['enable'])) ? "text-success" : "text-muted";?>"></i>
<a href="#" class="act_toggle" data-id="<?=$i;?>" data-toggle="tooltip" title="<?=(!empty($checkipservice['enable'])) ? gettext("Disable") : gettext("Enable");?>">
<i style="width:15px" class="fa fa-play <?=(!empty($checkipservice['enable'])) ? "text-success" : "text-muted";?>"></i>
</a>
</td>
<td>
<?=htmlspecialchars($checkipservice['name'])?>
</td>
<td>
<a target="Check_IP" rel="noopener noreferrer" href="<?=$checkipservice['url']?>"><?=htmlspecialchars($checkipservice['url'])?></a>
<a target="Check_IP" rel="noopener noreferrer" href="<?= html_safe($checkipservice['url']) ?>"><?=htmlspecialchars($checkipservice['url'])?></a>
</td>
<td class="text-center">
<i<?=(isset($checkipservice['verifysslpeer'])) ? ' class="fa fa-check"' : '';?>></i>
@ -164,10 +173,10 @@ $main_buttons = array(
</td>
<td>
<a href="services_checkip_edit.php?id=<?=$i;?>" class="btn btn-default btn-xs <?=$visibility?>">
<i class="glyphicon glyphicon-pencil"></i>
<i class="fa fa-pencil"></i>
</a>
<a href="#" data-id="<?=$i;?>" class="act_delete_service btn btn-default btn-xs <?=$visibility?>">
<i class="glyphicon glyphicon-trash"></i>
<i class="fa fa-trash"></i>
</a>
</td>
</tr>