summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/widgets/widgets/ipsec.widget.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr/local/www/widgets/widgets/ipsec.widget.php')
-rw-r--r--src/usr/local/www/widgets/widgets/ipsec.widget.php129
1 files changed, 68 insertions, 61 deletions
diff --git a/src/usr/local/www/widgets/widgets/ipsec.widget.php b/src/usr/local/www/widgets/widgets/ipsec.widget.php
index ff577b7..b7e34be 100644
--- a/src/usr/local/www/widgets/widgets/ipsec.widget.php
+++ b/src/usr/local/www/widgets/widgets/ipsec.widget.php
@@ -121,53 +121,57 @@ if ($_REQUEST && $_REQUEST['ajax']) {
unset($ikenum);
}
- // Only generate the data for the tab that is currently being viewed
- switch ($_REQUEST['tab']) {
- case "Overview" :
- print(" <tr>\n");
- print( "<td>" . $activecounter . "</td>\n");
- print( "<td>" . $inactivecounter . "</td>\n");
- print( "<td>" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . "</td>\n");
- print( "</tr>\n");
- break;
-
- case "tunnel" :
- foreach ($ipsec_detail_array as $ipsec) {
- print(" <tr>\n");
- print( "<td>" . htmlspecialchars($ipsec['src']) . "</td>\n");
- print( "<td>" . $ipsec['remote-subnet'] . "<br />(" . htmlspecialchars($ipsec['dest']) . ")</td>\n");
- print( "<td>" . htmlspecialchars($ipsec['descr']) . "</td>\n");
-
- if ($ipsec['status'] == "true") {
- print('<td><i class="fa fa-arrow-up text-success"></i></td>' . "\n");
- } else {
- print('<td><i class="fa fa-arrow-down text-danger"></i></td>' . "\n");
- }
+ // Generate JSON formatted data for the widget to update from
+ $jsondata = "{";
+
+ $jsondata .= "\"overview\":\"";
+ $jsondata .= "<tr>";
+ $jsondata .= "<td>" . $activecounter . "</td>";
+ $jsondata .= "<td>" . $inactivecounter . "</td>";
+ $jsondata .= "<td>" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . "</td>";
+ $jsondata .= "</tr>";
+ $jsondata .= "\",\n";
+
+ $jsondata .= "\"tunnel\":\"";
+ foreach ($ipsec_detail_array as $ipsec) {
+ $jsondata .= "<tr>";
+ $jsondata .= "<td>" . htmlspecialchars($ipsec['src']) . "</td>";
+ $jsondata .= "<td>" . $ipsec['remote-subnet'] . "<br />(" . htmlspecialchars($ipsec['dest']) . ")</td>";
+ $jsondata .= "<td>" . htmlspecialchars($ipsec['descr']) . "</td>";
+
+ if ($ipsec['status'] == "true") {
+ $jsondata .= '<td><i class=\"fa fa-arrow-up text-success\"></i></td>';
+ } else {
+ $jsondata .= '<td><i class=\"fa fa-arrow-down text-danger\"></i></td>';
+ }
- print( "</tr>\n");
- }
- break;
+ $jsondata .= "</tr>";
+ }
+
+ $jsondata .= "\",\n";
+
+
+ $jsondata .= "\"mobile\":\"";
- case "mobile" :
- if (!is_array($mobile['pool'])) {
- break;
+ if (is_array($mobile['pool'])) {
+ foreach ($mobile['pool'] as $pool) {
+ if (!is_array($pool['lease'])) {
+ continue;
}
- foreach ($mobile['pool'] as $pool) {
- if (!is_array($pool['lease'])) {
- continue;
- }
- foreach ($pool['lease'] as $muser) {
- print(" <tr>\n");
- print( "<td>" . htmlspecialchars($muser['id']) . "</td>\n");
- print( "<td>" . htmlspecialchars($muser['host']) . "</td>\n");
- print( "<td>" . htmlspecialchars($muser['status']) . "</td>\n");
- print(" </tr>\n");
- }
+ foreach ($pool['lease'] as $muser) {
+ $jsondata .= "<tr>";
+ $jsondata .= "<td>" . htmlspecialchars($muser['id']) . "</td>";
+ $jsondata .= "<td>" . htmlspecialchars($muser['host']) . "</td>";
+ $jsondata .= "<td>" . htmlspecialchars($muser['status']) . "</td>";
+ $jsondata .= "</tr>";
}
- break;
+ }
+ } else {
+ $jsondata .= "\"}";
}
+ print($jsondata);
exit;
}
@@ -291,32 +295,35 @@ function changeTabDIV(selectedDiv) {
}
}
-function get_ipsec_stats_<?=$widgetkey_nodash?>() {
- var ajaxRequest;
+events.push(function(){
+ // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
- ajaxRequest = $.ajax({
- url: "/widgets/widgets/ipsec.widget.php",
- type: "post",
- data: {
- ajax: "ajax",
- tab: curtab
- }
- });
+ // Callback function called by refresh system when data is retrieved
+ function ipsec_callback(s) {
+ var obj = JSON.parse(s);
- // Deal with the results of the above ajax call
- ajaxRequest.done(function (response, textStatus, jqXHR) {
+ $('tbody', '#<?=$widgetkey_nodash?>-Overview').html(obj.overview);
+ $('tbody', '#<?=$widgetkey_nodash?>-tunnel').html(obj.tunnel);
+ $('tbody', '#<?=$widgetkey_nodash?>-mobile').html(obj.mobile);
+ }
- $('tbody', '#<?=$widgetkey_nodash?>-' + curtab).html(response);
+ // POST data to send via AJAX
+ var postdata = {
+ ajax: "ajax"
+ };
- // and do it again
- setTimeout(get_ipsec_stats_<?=$widgetkey_nodash?>, "<?=$widgetperiod?>");
- });
-}
+ // Create an object defining the widget refresh AJAX call
+ var ipsecObject = new Object();
+ ipsecObject.name = "IPsec";
+ ipsecObject.url = "/widgets/widgets/ipsec.widget.php";
+ ipsecObject.callback = ipsec_callback;
+ ipsecObject.parms = postdata;
+ ipsecObject.freq = 1;
-events.push(function(){
- // Start polling for updates some small random number of seconds from now (so that all the widgets don't
- // hit the server at exactly the same time)
- setTimeout(get_ipsec_stats_<?=$widgetkey_nodash?>, Math.floor((Math.random() * 10000) + 1000));
+ // Register the AJAX object
+ register_ajax(ipsecObject);
+
+ // ---------------------------------------------------------------------------------------------------
});
//]]>
</script>
OpenPOWER on IntegriCloud