Added JSON checks for widgets to prevent parsing errors.

This commit is contained in:
Stephen Jones 2017-10-17 15:00:08 -05:00
parent 08a5e9a651
commit 63f686bde3
2 changed files with 21 additions and 13 deletions

View File

@ -28,7 +28,7 @@
$nocsrf = true;
require_once("auth_check.inc");
require_once("guiconfig.inc");
require_once("functions.inc");
require_once("ipsec.inc");
@ -253,9 +253,7 @@ if (isset($config['ipsec']['phase2'])): ?>
<p style="padding-left:10px;"><?=gettext('IPsec can be configured <a href="vpn_ipsec.php">here</a>.')?></p>
</div>
<?php endif;
// This function was in index.php It seems that the ipsec widget is the only place it is used
// so now it lives here. It wouldn't hurt to update this function and the tab display, but it
// looks OK for now. The display_widget_tabs() function in guiconfig.inc would need to be updated to match
?>
<script type="text/javascript">
//<![CDATA[
@ -310,11 +308,15 @@ events.push(function(){
// Callback function called by refresh system when data is retrieved
function ipsec_callback(s) {
var obj = JSON.parse(s);
try{
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);
$('tbody', '#<?=$widgetkey_nodash?>-Overview').html(obj.overview);
$('tbody', '#<?=$widgetkey_nodash?>-tunnel').html(obj.tunnel);
$('tbody', '#<?=$widgetkey_nodash?>-mobile').html(obj.mobile);
}catch(e){
}
}
// POST data to send via AJAX

View File

@ -137,12 +137,18 @@ print("</div>");
success: function(data){
if (data.length > 0) {
var obj = JSON.parse(data);
try{
var obj = JSON.parse(data);
$('#summary').removeClass("alert");
$('#summary').removeClass("alert-warning");
$('#summary').html(obj.summary);
$('#htmltxt').html(obj.htmltext);
}catch(e){
}
$('#summary').removeClass("alert");
$('#summary').removeClass("alert-warning");
$('#summary').html(obj.summary);
$('#htmltxt').html(obj.htmltext);
}
},