#! /usr/bin/perl
use DBI;
use File::Find;
use Archive::Zip;
use YAML;
#require "/etc/squarantine/squarantine.conf";
$conf = YAML::LoadFile("/etc/squarantine/squarantine.conf");
# print $conf->{WEBROOT};

sub autodelete {
  $dir = $_[0];
# my $dir = '.';
  ##### /autorun.inf delete ########
  opendir(H_DIR,$dir) || die "no $dir: $!";
  while ($file = readdir(H_DIR)) {
    $filename = $file;
    $filename =~ s#.*/##;
    $filename =~ s/([a-zA-Z])/\L$1\E/g;
    if ( "autorun.inf" eq $filename ){
    print "$file<br>\n";
       // unlink $dir."/".$file;
       system("mv $dir."/".$file $conf->{SAVE_DIST}."/".$file ) ;
    }
  }
  closedir(H_DIR);
  ##### other delete ########
  find( \&wantedmove, ($dir) );
}
sub wantedmove {
  my $file = $File::Find::name;
  if ( $file =~ /\.(exe|com|cmd|bat|scr|pif|vbs|vbe|js|jse|wsf|wsh|lnk)$/i ){
  ##### execute file ########
    print "execute: $file<br>¥n";
     system("mv $file $conf->{SAVE_DIST}."/".$file ) ;
  }
  if ( $file =~ /\.(zip)$/i ){
  ##### zip file ########
#    print "zip: $file¥n";
    if ( my $zip = Archive::Zip->new( $file )) { ;
      foreach $archived ($zip->memberNames) {
#        print "zipped: $archived<br>\n";
         if ( $archived =~ /\.(exe|com|cmd|bat|scr|pif|vbs|vbe|js|jse|wsf|wsh|lnk)$/i ){
           print "zipexecute: $file:$archived<br>¥n";
            system("mv $file $conf->{SAVE_DIST}."/".$file ) ;
         }
      }
    }
  }
}

 if (@ARGV < 1) {
    die "must mount point\n";
}

$mountpoint = shift @ARGV;

autodelete($mountpoint);


