#!/home/product/code/webui-perl/bin/perl -T -I /home/product/code/firmware/current/lib/perl5
#SUDOER_USERS: nobody
#SUDOER_RUNAS_USERS: root, mta
#SUDOER_TAGS: NOPASSWD, EXEC
use strict;
use warnings;
use Barracuda::Sudo::Lib;
use Barracuda::Environment;
use IPC::Run qw(run);

###############################################################################

=pod

=head1 NAME

count_queues

=head1 DESCRIPTION

Call /home/product/code/firmware/current/bin/count_queues.

The scripts accepts one string argument. The argument is a list of paths seperated by colon.

Any of the following paths will be accepted:

	/mail/email /mail/email_outbound /mail/email_notify

=cut

###############################################################################

my %known_queues = ('/mail/email'=>1, '/mail/email_outbound'=>1, '/mail/email_notify'=>1);
my $outfile = sudo_out();
(my $locations) = get_argv(sub {my @locs = split(':', shift); for my $loc (@locs) {return 0 unless exists $known_queues{$loc};} return 1;});
my @argv = split(':', $locations);
my $cmd = "${Barracuda::Environment::path_firmware}/bin/count_queues";

my $status = run([$cmd, @argv], \undef, $outfile, $outfile);

exit !$status;
