#!/usr/bin/perl -w

##################################
##
## move_vtscan_infected.pl
##
## Moves infected files found with vt_scan2.pl, and puts them in safe directory
## 
##
##################################

$db_host = '172.20.1.3';
$db_name = 'vt_scan';
$db_user = 'vt_scan';
$db_pass = 'vt_scan';


#################  DO NOT CHANGE ANYTHING BELOW THIS LINE!!!

use Data::Dumper;
use DBI;
use File::Find;
use File::Basename;
use Cwd;
use Digest::SHA;
use Digest::MD5;
use LWP;

$| = 1;



#### create database connection....
($dbh = DBI->connect("DBI:mysql:$db_name;host=$db_host", "$db_user","$db_pass"))
    or die "Error connecting to database\n";
$select_prpst = $dbh->prepare("SELECT * from infected where SysID = ? && Infected >= ?");


##### need to fix this.  Won't scan if you give it a directory.
#####  only works to scan current directory and subdirectories.

if(!(@ARGV))
	{
	print "Usage: move_vtscan_infected.pl <SysID> <DestinationFolder> <infection count>";
	die "Infection count is inclusive.  Using a value of 5 will move all files with detection rate of 5 or above.";
}

$sysid = $ARGV[0];
$destination = $ARGV[1];
$infection_count = $ARGV[2];


$select_prpst->execute($sysid, $infection_count);
while (@row = $select_prpst->fetchrow_array())
	{
	$file_to_move = $row[4];
	print "Moving... ".$file_to_move."\n";
	$file_to_move =~ s/\(/\\\(/g;
	$file_to_move =~ s/\)/\\\)/g;
	$file_to_move =~ s/ /\\\ /g;
	system("mv -i $file_to_move $destination");
}







