From f2769fe0992cfb48e320e5fe6c80bddd93ce0b30 Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Tue, 18 Jun 2019 17:46:05 +0200 Subject: [PATCH] Sort interface groups in GUI to match firewall rule order (#3537) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This now makes it easy and predictable to add interfaces to multiple groups. Before this change, the interfaces_groups GUI was sorted by the order that interface groups were added. However, this was not the order that the actual pf rules would then be generated making it unpredictable when adding interfaces to multiple groups. The filter_rules_sort function already took care of the actual pf rule order. I also took care of only marking the filter subsystem dirty when needed. I tested this patch quite a bit on 19.1.8. When updating, users only need to make one change to the interface groups to have them sorted in the GUI. I hope I did not miss anything because this patch is against master. In it’s current state, the patch can be directly applied to 19.1.x or master. --- src/www/interfaces_groups.php | 14 +++++++++++++- src/www/interfaces_groups_edit.php | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/www/interfaces_groups.php b/src/www/interfaces_groups.php index c005a8feb..89ee5cf3d 100644 --- a/src/www/interfaces_groups.php +++ b/src/www/interfaces_groups.php @@ -30,6 +30,8 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); +require_once("filter.inc"); +require_once("system.inc"); $a_ifgroups = &config_read_array('ifgroups', 'ifgroupentry'); @@ -38,7 +40,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = $_POST['id']; } - if (!empty($_POST['action']) && $_POST['action'] == "del" && isset($id)) { + if (isset($_POST['apply'])) { + system_cron_configure(); + filter_configure(); + clear_subsystem_dirty('filter'); + $savemsg = gettext('The settings have been applied and the rules are now reloading in the background.'); + } elseif (!empty($_POST['action']) && $_POST['action'] == "del" && isset($id)) { $members = explode(" ", $a_ifgroups[$id]['members']); foreach ($members as $ifs) { mwexecf('/sbin/ifconfig %s -group %s', array(get_real_interface($ifs), $a_ifgroups[$id]['ifname'])); @@ -92,6 +99,11 @@ $main_buttons = array(
+ + +

+ You must apply the changes in order for them to take effect."));?> +

diff --git a/src/www/interfaces_groups_edit.php b/src/www/interfaces_groups_edit.php index be00c9e22..a0009c34c 100644 --- a/src/www/interfaces_groups_edit.php +++ b/src/www/interfaces_groups_edit.php @@ -30,6 +30,7 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); +require_once("filter.inc"); $a_ifgroups = &config_read_array('ifgroups', 'ifgroupentry'); @@ -112,6 +113,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } } + mark_subsystem_dirty('filter'); } $old_ifname = isset($id) ? $a_ifgroups[$id]['ifname'] : $pconfig['ifname']; // remove group members @@ -123,9 +125,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { // update item $a_ifgroups[$id] = $ifgroupentry; } else { + mark_subsystem_dirty('filter'); // add new item $a_ifgroups[] = $ifgroupentry; } + usort($a_ifgroups, function($a, $b) { + return strnatcmp($a['ifname'], $b['ifname']); + }); + filter_rules_sort(); write_config(); interface_group_setup($ifgroupentry); header(url_safe('Location: /interfaces_groups.php'));