mirror of
https://github.com/webmin/webmin.git
synced 2026-05-06 23:30:29 +01:00
Rework the nftables module so Webmin manages its saved nftables configuration as the source of truth instead of directly editing the live ruleset. Add an active ruleset view for inspecting live tables and importing copies into Webmin-managed config if needed, track managed and imported tables with metadata, and prevent externally managed tables from being overwritten during apply. Co-authored-by: Copilot <copilot@github.com>
58 lines
1.7 KiB
Perl
Executable File
58 lines
1.7 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);
|
|
|
|
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 = $is_saved ? "-" :
|
|
ui_link(
|
|
"import_table.cgi?family=".urlize($t->{'family'}).
|
|
"&name=".urlize($t->{'name'}),
|
|
$text{'active_import'});
|
|
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'});
|