#!/usr/bin/perl -w
#
# $Id: AVChk,v 1.1 2002/06/22 18:33:31 cvs Exp $
#
# AVChk: Checks filesystem for viruses
#
# Miguel Armas <kuko@maarmas.com>
#

#--------------------------------------------[ Initialization Section ]----

use strict;
use Getopt::Std;
#use pifia;

#--------------------------------------------[ Configuration Section ]----- 
my $priority = "Warning";
my $alarm = "AVChk";
# Directory where we have the antivirus software
my $avdir = '<#$avdir#>';
# Directory where we will write the Antivirus reports
my $avreportdir = '<#$avdir#>/report';
# Antivirus check command
my $avchk = 'cd <#$avdir#>; kavscanner -I0';
# Antivirus report print command
my $avprint = 'cat';
# Filesystems to check
my $avfilesystems = '<#$avfilesystems#>';

#--------------------------------------------[ Code Section ]----

# Set a safe PATH
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin:/root/bin";

# Option declaration
use vars qw($opt_v $opt_n);
getopts('vn');

# Verbosity level. If not verbose, we shouldn't write any output unless 
# there is a problem
my $verbose = 1 if ($opt_v);

# Create a TimeStamp
my @tmp=localtime();
my $year=$tmp[5]+1900;
my $mon=$tmp[4]+1;
my $mday=$tmp[3];
my $tstamp=sprintf("%04d%02d%02d",$year,$mon,$mday);

# Hotname
my $hostname=`uname -n`;
chomp $hostname;

# Report File
my $report="$avreportdir/$hostname-$tstamp.avrep";

if ($verbose) {
   print "Running Antivirus. Report: $report \n";
}
my $ret=system("$avchk -WT=$report $avfilesystems >/dev/null 2>&1");

## Run Antivirus in Check mode
if ($ret) {
   my @out=`$avprint $report | grep "infected:"`;
   print "WARNING: Infected files: \n";
   foreach my $line (@out) {
      print "   $line";
   }
}
else {
   print "DONE. NO VIRUSES FOUND \n" if ($verbose);
};

