diff --git a/src/usr/local/www/widgets/widgets/ipsec.widget.php b/src/usr/local/www/widgets/widgets/ipsec.widget.php index 4ffeb3d80b..b7e34befd0 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(" \n"); - print( "" . $activecounter . "\n"); - print( "" . $inactivecounter . "\n"); - print( "" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . "\n"); - print( "\n"); - break; + // Generate JSON formatted data for the widget to update from + $jsondata = "{"; - case "tunnel" : - foreach ($ipsec_detail_array as $ipsec) { - print(" \n"); - print( "" . htmlspecialchars($ipsec['src']) . "\n"); - print( "" . $ipsec['remote-subnet'] . "
(" . htmlspecialchars($ipsec['dest']) . ")\n"); - print( "" . htmlspecialchars($ipsec['descr']) . "\n"); + $jsondata .= "\"overview\":\""; + $jsondata .= ""; + $jsondata .= "" . $activecounter . ""; + $jsondata .= "" . $inactivecounter . ""; + $jsondata .= "" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . ""; + $jsondata .= ""; + $jsondata .= "\",\n"; - if ($ipsec['status'] == "true") { - print('' . "\n"); - } else { - print('' . "\n"); - } + $jsondata .= "\"tunnel\":\""; + foreach ($ipsec_detail_array as $ipsec) { + $jsondata .= ""; + $jsondata .= "" . htmlspecialchars($ipsec['src']) . ""; + $jsondata .= "" . $ipsec['remote-subnet'] . "
(" . htmlspecialchars($ipsec['dest']) . ")"; + $jsondata .= "" . htmlspecialchars($ipsec['descr']) . ""; - print( "\n"); - } - break; + if ($ipsec['status'] == "true") { + $jsondata .= ''; + } else { + $jsondata .= ''; + } - case "mobile" : - if (!is_array($mobile['pool'])) { - break; - } - foreach ($mobile['pool'] as $pool) { - if (!is_array($pool['lease'])) { - continue; - } - - foreach ($pool['lease'] as $muser) { - print(" \n"); - print( "" . htmlspecialchars($muser['id']) . "\n"); - print( "" . htmlspecialchars($muser['host']) . "\n"); - print( "" . htmlspecialchars($muser['status']) . "\n"); - print(" \n"); - } - } - break; + $jsondata .= ""; } + $jsondata .= "\",\n"; + + + $jsondata .= "\"mobile\":\""; + + if (is_array($mobile['pool'])) { + foreach ($mobile['pool'] as $pool) { + if (!is_array($pool['lease'])) { + continue; + } + + foreach ($pool['lease'] as $muser) { + $jsondata .= ""; + $jsondata .= "" . htmlspecialchars($muser['id']) . ""; + $jsondata .= "" . htmlspecialchars($muser['host']) . ""; + $jsondata .= "" . htmlspecialchars($muser['status']) . ""; + $jsondata .= ""; + } + } + } 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', '#-' + curtab).html(s); + var obj = JSON.parse(s); + + $('tbody', '#-Overview').html(obj.overview); + $('tbody', '#-tunnel').html(obj.tunnel); + $('tbody', '#-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