diff --git a/src/www/firewall_rules.php b/src/www/firewall_rules.php index fb272230a..edefc8736 100644 --- a/src/www/firewall_rules.php +++ b/src/www/firewall_rules.php @@ -176,13 +176,6 @@ function firewall_rule_item_icons($filterent) ); } - if (isset($filterent['log'])) { - $result .= sprintf( - "", - !empty($filterent['disabled']) ? 'text-muted' : 'text-info' - ); - } - return $result; } @@ -202,6 +195,15 @@ function firewall_rule_item_action($filterent) return "fa fa-play fa-fw text-muted"; } } + +function firewall_rule_item_log($filterent) +{ + if ($filterent['log'] == true) { + return "fa fa-info-circle fa-fw text-info"; + } else { + return "fa fa-info-circle fa-fw text-muted"; + } +} /*********************************************************************************************************** * ***********************************************************************************************************/ @@ -288,7 +290,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } write_config(); mark_subsystem_dirty('filter'); - header(url_safe('Location: /firewall_rules.php?if=%s', array($current_if))); + $response = array("id" => $id); + $response["new_label"] = !isset($a_filter[$id]['disabled']) ? gettext("Disable Rule") : gettext("Enable Rule"); + $response["new_state"] = !isset($a_filter[$id]['disabled']) ; + echo json_encode($response); + exit; + } elseif (isset($pconfig['act']) && $pconfig['act'] == 'log' && isset($id)) { + // toggle logging + if(isset($a_filter[$id]['log'])) { + unset($a_filter[$id]['log']); + } else { + $a_filter[$id]['log'] = true; + } + write_config(); + mark_subsystem_dirty('filter'); + //header(url_safe('Location: /firewall_rules.php?if=%s', array($current_if))); + $response = array("id" => $id); + $response["new_label"] = isset($a_filter[$id]['log']) ? gettext("Disable Log") : gettext("Enable Log"); + $response["new_state"] = isset($a_filter[$id]['log']) ; + echo json_encode($response); exit; } } @@ -413,11 +433,44 @@ $( document ).ready(function() { // link toggle buttons $(".act_toggle").click(function(event){ - event.preventDefault(); - var id = $(this).attr("id").split('_').pop(-1); - $("#id").val(id); - $("#action").val("toggle"); - $("#iform").submit(); + event.preventDefault(); + let target = $(this); + let id = target.attr("id").split('_').pop(-1); + $.ajax("firewall_rules.php",{ + type: 'post', + cache: false, + dataType: "json", + data: {'act': 'toggle', 'id': id}, + success: function(response) { + target.prop('title', response['new_label']).tooltip('fixTitle').tooltip('hide'); + if (response['new_state']) { + target.find('span').removeClass('text-muted').addClass('text-success'); + } else { + target.find('span').removeClass('text-success').addClass('text-muted'); + } + } + }); + }); + + // link log buttons + $(".act_log").click(function(event){ + event.preventDefault(); + let target = $(this); + let id = target.attr("id").split('_').pop(-1); + $.ajax("firewall_rules.php",{ + type: 'post', + cache: false, + dataType: "json", + data: {'act': 'log', 'id': id}, + success: function(response) { + target.prop('title', response['new_label']).tooltip('fixTitle').tooltip('hide'); + if (response['new_state']) { + target.find('i').removeClass('text-muted').addClass('text-info'); + } else { + target.find('i').removeClass('text-info').addClass('text-muted'); + } + } + }); }); // watch scroll position and set to last known on page load @@ -657,6 +710,7 @@ $( document ).ready(function() { + @@ -709,10 +763,13 @@ $( document ).ready(function() { - "> + "> + "> + +