Sort interface groups in GUI to match firewall rule order (#3537)

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.
This commit is contained in:
Robin Schneider 2019-06-18 17:46:05 +02:00 committed by Ad Schellevis
parent 464495b58e
commit f2769fe099
2 changed files with 20 additions and 1 deletions

View File

@ -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(
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php print_service_banner('firewall'); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('filter')): ?><p>
<?php print_info_box_apply(gettext("The firewall rule configuration has been changed.<br />You must apply the changes in order for them to take effect."));?>
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">

View File

@ -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'));