summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Beaver <sbeaver@netgate.com>2017-08-15 08:02:36 -0400
committerSteve Beaver <sbeaver@netgate.com>2017-08-15 08:02:36 -0400
commitcabbaf7a49b76d87349929bee7f1d1d7df8fedba (patch)
tree4e8cd0e7b9ab5ed9bb28782db71e722fd2c11170
parent0e78c2f544ad577234a0a2f87ce2e8caefdfdb77 (diff)
downloadpfsense-cabbaf7a49b76d87349929bee7f1d1d7df8fedba.zip
pfsense-cabbaf7a49b76d87349929bee7f1d1d7df8fedba.tar.gz
ipsec widget converted to JSON formatted refresh
-rw-r--r--src/usr/local/www/widgets/widgets/ipsec.widget.php93
1 files changed, 50 insertions, 43 deletions
diff --git a/src/usr/local/www/widgets/widgets/ipsec.widget.php b/src/usr/local/www/widgets/widgets/ipsec.widget.php
index 4ffeb3d..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";
- case "mobile" :
- if (!is_array($mobile['pool'])) {
- break;
+
+ $jsondata .= "\"mobile\":\"";
+
+ 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;
}
@@ -296,13 +300,16 @@ events.push(function(){
// Callback function called by refresh system when data is retrieved
function ipsec_callback(s) {
- $('tbody', '#<?=$widgetkey_nodash?>-' + curtab).html(s);
+ var obj = JSON.parse(s);
+
+ $('tbody', '#<?=$widgetkey_nodash?>-Overview').html(obj.overview);
+ $('tbody', '#<?=$widgetkey_nodash?>-tunnel').html(obj.tunnel);
+ $('tbody', '#<?=$widgetkey_nodash?>-mobile').html(obj.mobile);
}
// POST data to send via AJAX
var postdata = {
- ajax: "ajax",
- tab : curtab
+ ajax: "ajax"
};
// Create an object defining the widget refresh AJAX call
OpenPOWER on IntegriCloud