diff --git a/nftables/index.cgi b/nftables/index.cgi index 545eb585f..6ff6b585c 100755 --- a/nftables/index.cgi +++ b/nftables/index.cgi @@ -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', "nft"); if (!$partial) { diff --git a/nftables/nftables-lib.pl b/nftables/nftables-lib.pl index 7ac1ac977..693b36318 100644 --- a/nftables/nftables-lib.pl +++ b/nftables/nftables-lib.pl @@ -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', "nft") if (!$cmd); my $out = backquote_logged("$cmd -f $file 2>&1"); if ($?) { return "
$out
"; diff --git a/nftables/save_rule.cgi b/nftables/save_rule.cgi index 04d083233..2464e3dbc 100755 --- a/nftables/save_rule.cgi +++ b/nftables/save_rule.cgi @@ -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");