mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
DynDNS status widget async update
The Dynamic DNS status widget performs remote operations to the www to check the cached dynamic DNS IP against the actual current public-facing IP. When an external link is slow, or particularly when the cable is plugged in (it seems up) but actually the internet is down, it takes a long time for a response from http://checkip.dyndns.com/ to time out. The dashboard page hangs in a half-drawn state (up to drawing the DynDNS status table) for up to 30 seconds. This change puts the code that does these external operations into some ajax/Java script that runs after the dashboard has drawn up. Code concept unashamedly stolen from the system information widget.
This commit is contained in:
parent
ccc5f959ad
commit
c1dcb7abe7
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
/*
|
||||
Original status page code from: services_dyndns.php
|
||||
Copyright (C) 2008 Ermal Lu\xe7i
|
||||
Edits to convert it to a widget: dyn_dns_status.php
|
||||
Copyright (C) 2008 Ermal Luci
|
||||
Edits to convert it to a widget: dyn_dns_status.widget.php
|
||||
Copyright (C) 2013 Stanley P. Miller \ stan-qaz
|
||||
All rights reserved.
|
||||
|
||||
@ -44,6 +44,33 @@ if (!is_array($config['dyndnses']['dyndns']))
|
||||
|
||||
$a_dyndns = &$config['dyndnses']['dyndns'];
|
||||
|
||||
if($_REQUEST['getdyndnsstatus']) {
|
||||
$first_entry = true;
|
||||
foreach ($a_dyndns as $dyndns) {
|
||||
if ($first_entry)
|
||||
$first_entry = false;
|
||||
else
|
||||
// Put a vertical bar delimiter between the echoed HTML for each entry processed.
|
||||
echo "|";
|
||||
|
||||
$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}.cache";
|
||||
if (file_exists($filename)) {
|
||||
$ipaddr = dyndnsCheckIP($dyndns['interface']);
|
||||
$cached_ip_s = split(":", file_get_contents($filename));
|
||||
$cached_ip = $cached_ip_s[0];
|
||||
if ($ipaddr <> $cached_ip)
|
||||
echo "<font color='red'>";
|
||||
else
|
||||
echo "<font color='green'>";
|
||||
echo htmlspecialchars($cached_ip);
|
||||
echo "</font>";
|
||||
} else {
|
||||
echo "N/A";
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
||||
@ -101,23 +128,34 @@ $a_dyndns = &$config['dyndnses']['dyndns'];
|
||||
?>
|
||||
</td>
|
||||
<td class="listlr">
|
||||
<?php
|
||||
$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}.cache";
|
||||
if (file_exists($filename)) {
|
||||
$ipaddr = dyndnsCheckIP($dyndns['interface']);
|
||||
$cached_ip_s = split(":", file_get_contents($filename));
|
||||
$cached_ip = $cached_ip_s[0];
|
||||
if ($ipaddr <> $cached_ip)
|
||||
echo "<font color='red'>";
|
||||
else
|
||||
echo "<font color='green'>";
|
||||
echo htmlspecialchars($cached_ip);
|
||||
echo "</font>";
|
||||
} else {
|
||||
echo "N/A";
|
||||
}
|
||||
?>
|
||||
<div id='dyndnsstatus<?php echo $i; ?>'><?php echo gettext("Checking ..."); ?></div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function dyndns_getstatus() {
|
||||
scroll(0,0);
|
||||
var url = "/widgets/widgets/dyn_dns_status.widget.php";
|
||||
var pars = 'getdyndnsstatus=yes';
|
||||
jQuery.ajax(
|
||||
url,
|
||||
{
|
||||
type: 'get',
|
||||
data: pars,
|
||||
complete: dyndnscallback
|
||||
});
|
||||
}
|
||||
function dyndnscallback(transport) {
|
||||
// The server returns a string of statuses separated by vertical bars
|
||||
var responseStrings = transport.responseText.split("|");
|
||||
for (var count=0; count<responseStrings.length; count++)
|
||||
{
|
||||
var divlabel = '#dyndnsstatus' + count;
|
||||
jQuery(divlabel).prop('innerHTML',responseStrings[count]);
|
||||
}
|
||||
}
|
||||
setTimeout('dyndns_getstatus()', 2000);
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user