diff --git a/nftables/active.cgi b/nftables/active.cgi index 4f7843b90..e8472dc68 100755 --- a/nftables/active.cgi +++ b/nftables/active.cgi @@ -36,11 +36,17 @@ else { 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( + my @actions; + push(@actions, ui_link( "import_table.cgi?family=".urlize($t->{'family'}). "&name=".urlize($t->{'name'}), - $text{'active_import'}); + $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), diff --git a/nftables/clear_table.cgi b/nftables/clear_table.cgi new file mode 100755 index 000000000..a42879b5d --- /dev/null +++ b/nftables/clear_table.cgi @@ -0,0 +1,41 @@ +#!/usr/bin/perl +# clear_table.cgi +# Remove one table from the active nftables ruleset + +require './nftables-lib.pl'; ## no critic +use strict; +use warnings; +our (%in, %text); +ReadParse(); +error_setup($text{'clear_err'}); + +my ($tables, $err) = get_active_nftables_save(); +error(text('active_failed', $err)) if ($err); + +my $table; +foreach my $t (@$tables) { + if ($t->{'family'} eq $in{'family'} && $t->{'name'} eq $in{'name'}) { + $table = $t; + last; + } + } +$table || error($text{'active_table_notable'}); + +if ($in{'confirm'}) { + $err = delete_active_table($table); + error(text('clear_failed', $err)) if ($err); + webmin_log("clear", "table", $table->{'name'}, + { 'family' => $table->{'family'} }); + redirect("active.cgi"); + } + +ui_print_header(undef, $text{'clear_title'}, "", "intro", 1, 1); +print "
\n"; +print ui_form_end([ [ "confirm", $text{'active_clear'} ] ]); +print "