#!/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, NOEXEC
use strict;
use warnings;
use Barracuda::Sudo::Lib;
use Barracuda::Environment;

=pod

=head1 NAME

rmfile_in_dir

=head1 DESCRIPTION

removes a file or glob of files from a whitelisted directory

=cut

my @whitelist = (
    dir_prefix($Barracuda::Environment::path_config . '/valid_recipients/'),
    dir_prefix('/var/run/jobs/pid/'),
    dir_prefix('/var/run/jobs/in/'),
    dir_prefix('/tmp/test_rmfile_in_dir/')
);

my ($path) = get_argv(is_whitelisted(@whitelist));

my @files;
for my $file (glob $path) {
    $file =~ /(.*)/;
    push @files, $1;
}
for my $file (@files) {
    unlink $file or die ("Can't delete file $file: $!\n");
}
