Fix to factor out command check

This commit is contained in:
Ilia Ross
2026-05-02 00:34:15 +02:00
parent a6db30bb49
commit 1d67452a00
3 changed files with 14 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ if (!$partial) {
}
# Check for nft command
my $cmd = $config{'nft_cmd'} || has_command("nft");
my $cmd = get_nft_command();
if (!$cmd) {
print text('index_ecommand', "<tt>nft</tt>");
if (!$partial) {

View File

@@ -8,12 +8,21 @@ use warnings;
our (%config, $module_config_directory);
init_config();
# get_nft_command()
# Returns the configured nft command path, or finds it in PATH
sub get_nft_command
{
my $cmd = $config{'nft_cmd'} || "nft";
return has_command($cmd);
}
# get_nftables_save([file])
# Returns a list of tables and their chains/rules
sub get_nftables_save
{
my ($file) = @_;
my $cmd = $config{'nft_cmd'} || has_command("nft");
my $cmd = get_nft_command();
if (!$file) {
if ($config{'direct'}) {
$file = "$cmd list ruleset |";
@@ -1017,7 +1026,8 @@ sub apply_restore
{
my ($file) = @_;
$file ||= $config{'save_file'} || "$module_config_directory/nftables.conf";
my $cmd = $config{'nft_cmd'} || has_command("nft");
my $cmd = get_nft_command();
return text('index_ecommand', "<tt>nft</tt>") if (!$cmd);
my $out = backquote_logged("$cmd -f $file 2>&1");
if ($?) {
return "<pre>$out</pre>";

View File

@@ -161,7 +161,7 @@ if ($in{'delete'}) {
}
if ($in{'edit_direct'}) {
my $cmd = $config{'nft_cmd'} || has_command("nft");
my $cmd = get_nft_command();
if ($cmd) {
my $tmp = tempname();
open_tempfile(my $fh, ">$tmp");