From c8b57d0bfecd1e654507007b2c39c4a4c1eacacb Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 6 Aug 2019 13:09:11 +0200 Subject: [PATCH] firewall/rules, toggle enabled/disabled, log on/off via ajax call, as discussed https://github.com/opnsense/core/pull/3605 --- src/www/firewall_rules.php | 115 +++++++++++++++---------------------- 1 file changed, 45 insertions(+), 70 deletions(-) diff --git a/src/www/firewall_rules.php b/src/www/firewall_rules.php index f868e313f..edefc8736 100644 --- a/src/www/firewall_rules.php +++ b/src/www/firewall_rules.php @@ -290,7 +290,10 @@ 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 @@ -301,16 +304,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } write_config(); mark_subsystem_dirty('filter'); - header(url_safe('Location: /firewall_rules.php?if=%s', array($current_if))); + //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; - } elseif (isset($pconfig['act']) && in_array($pconfig['act'], array('log_enable', 'log_disable')) && isset($pconfig['rule']) && count($pconfig['rule']) > 0) { - foreach ($pconfig['rule'] as $rulei) { - $a_filter[$rulei]['log'] = $pconfig['act'] == 'log_enable'; - } - write_config(); - mark_subsystem_dirty('filter'); - header(url_safe('Location: /firewall_rules.php?if=%s', array($current_if))); - exit; } } @@ -423,48 +422,6 @@ $( document ).ready(function() { }); }); - // enable/disable logging on selected - $(".act_log_enable").click(function(event){ - event.preventDefault(); - BootstrapDialog.show({ - type:BootstrapDialog.TYPE_DANGER, - title: "", - message: "", - buttons: [{ - label: "", - action: function(dialogRef) { - dialogRef.close(); - }}, { - label: "", - action: function(dialogRef) { - $("#id").val(""); - $("#action").val("log_enable"); - $("#iform").submit() - } - }] - }); - }); - $(".act_log_disable").click(function(event){ - event.preventDefault(); - BootstrapDialog.show({ - type:BootstrapDialog.TYPE_DANGER, - title: "", - message: "", - buttons: [{ - label: "", - action: function(dialogRef) { - dialogRef.close(); - }}, { - label: "", - action: function(dialogRef) { - $("#id").val(""); - $("#action").val("log_disable"); - $("#iform").submit() - } - }] - }); - }); - // link move buttons $(".act_move").click(function(event){ event.preventDefault(); @@ -476,20 +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(); - var id = $(this).attr("id").split('_').pop(-1); - $("#id").val(id); - $("#action").val("log"); - $("#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': '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 @@ -952,12 +933,6 @@ $( document ).ready(function() { - - @@ -978,7 +953,7 @@ $( document ).ready(function() { - + @@ -995,7 +970,7 @@ $( document ).ready(function() {   - +