Files
webmin/nftables/active.cgi
Ilia Ross 12eff54277 Add nftables apply-needed header action
* Note: Track saved nftables configuration changes with Apache-style config/apply timestamp flags, expose the standard restart.cgi header action for themes, and use it as the single apply endpoint. The button expands to “Apply Changes” when saved rules need applying, while the existing Apply Configuration action now routes through restart.cgi and clears the pending state after a successful apply.
2026-05-03 13:59:58 +02:00

65 lines
2.0 KiB
Perl
Executable File

#!/usr/bin/perl
# active.cgi
# Show active nftables tables for viewing and import
require './nftables-lib.pl'; ## no critic
use strict;
use warnings;
our (%text);
ui_print_header(undef, $text{'active_title'}, "", "intro", 1, 1,
undef, restart_button());
my ($tables, $err) = get_active_nftables_save();
if ($err) {
print text('active_failed', $err);
}
elsif (!@$tables) {
print "<b>$text{'active_none'}</b><p>\n";
}
else {
my @saved_tables = get_nftables_save();
print ui_columns_start(
[ $text{'active_table'}, $text{'active_flags'},
$text{'active_chains'}, $text{'active_sets'},
$text{'active_rules'}, $text{'active_status'},
$text{'index_actions'} ], 100);
foreach my $t (@$tables) {
my $chains = $t->{'chains'} && ref($t->{'chains'}) eq 'HASH' ?
scalar(keys %{$t->{'chains'}}) : 0;
my $sets = $t->{'sets'} && ref($t->{'sets'}) eq 'HASH' ?
scalar(keys %{$t->{'sets'}}) : 0;
my $rules = $t->{'rules'} && ref($t->{'rules'}) eq 'ARRAY' ?
scalar(@{$t->{'rules'}}) : 0;
my $flags = $t->{'flags'} || "-";
my $status_key = active_table_status($t, \@saved_tables);
my $status = $text{'active_'.$status_key};
my $is_saved = table_is_webmin_managed($t, \@saved_tables);
my $table_url = "active_table.cgi?family=".urlize($t->{'family'}).
"&name=".urlize($t->{'name'});
my @actions;
push(@actions, ui_link(
"import_table.cgi?family=".urlize($t->{'family'}).
"&name=".urlize($t->{'name'}),
$text{'active_import'})) if (!$is_saved);
push(@actions, ui_link(
"clear_table.cgi?family=".urlize($t->{'family'}).
"&name=".urlize($t->{'name'}),
$text{'active_clear'}))
if (!table_is_externally_managed($t));
my $actions = @actions ? join(" ", @actions) : "-";
print ui_columns_row([
ui_link($table_url, html_escape(nft_table_spec($t))),
html_escape($flags),
$chains,
$sets,
$rules,
$status,
$actions,
]);
}
print ui_columns_end();
}
ui_print_footer("index.cgi", $text{'index_return'});