perl << 'EOF'
use strict;
use Cwd;
my $defmax = 20; # Default number of quarantines to list
my $showmax;
my @files;
my $user = "user_placeholder";
my $selection = "selection_placeholder";

if(!-f "/var/cpanel/users/".$user){
    print("User \"".$user."\" not found\n");
    exit(1);
}
my $dir = '/home/'.$user.'/.security';
if(!-d "$dir"){
    print("No quarantine spaces found\n");
    exit(1);
}
opendir(my $dh, "$dir") or die "Error opening ".$dir.": ".$!;
while(defined(my $file = readdir($dh))){
    next if(!($file =~ /^amc_archive\.\d+$/));
    my $path = Cwd::abs_path($dir).'/'.$file;
    next unless(-d $path);
    push(@files, [stat(_), $path]);
}
closedir($dh);
my @files = sort { $b->[9] <=> $a->[9] } @files;
if(!$selection||!($selection =~ /^\d+$/)){
    if(scalar(@files)>0){
        if($selection =~ /all/){
            $showmax=$#files+1;
        } else {
            $showmax=(($#files+1>$defmax) ? $defmax : ($#files+1));
        }
        print("\nFound ".scalar(@files)." quarantined areas. Showing ".$showmax." most recent:\n");
        for(my $i=0;$i<=$#files && $i<$showmax;$i++){
            printf("%3i) %-25s (%i)\n",($i+1),scalar(localtime($files[$i][9])),($files[$i][9]));
        }
    } else {
        print("Could not find quarantined files\n");
        exit(1);
    }
} else {
    if($selection<=scalar(@files)||$selection=~/^\d{10}$/){
        my $file;
        if($selection=~/^\d{10}$/&&-f $dir.'/amc_archive.'.$selection.'/amclog.'.$selection){
            $file = $dir.'/amc_archive.'.$selection.'/amclog.'.$selection;
        } else {
            $file = $dir.'/amc_archive.'.$files[($selection-1)][9].'/amclog.'.$files[($selection-1)][9];
        }
        if(-f "$file"){
            open(my $fh, "<", "$file") or die "Error opening ".$file.": ".$!;
            print("\nFiles quarantined at ".(($selection=~/^\d{10}$/)?localtime($selection):localtime($files[($selection-1)][9])).":\n");
            while(<$fh>){
                if(/^Filename: (\S+), /){
                    print("  ".$1."\n");
                }
            }
        } else {
            print("\'".$file."\" not found.\n");
            exit(1);
        }
    } else {
        print("Specified quanrantine area not found\n");
        exit(1);
    }
}
print("\n");
EOF
