#!/usr/bin/perl -w
#
# $Id: TWChk,v 1.1 2001/12/20 14:24:12 cvs Exp $
#
# TWChk: Checks FileSystem Integrity using TriWire
#
# Miguel Armas <kuko@ulpgc.es>
#

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

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

#--------------------------------------------[ Configuration Section ]----- 
my $priority = "Warning";
my $alarm = "TWChk";
# Directory where we will write te TripWire reports
my $twreportdir = "/var/lib/tripwire/report";
# Tripwire check command
my $twchk = '/usr/sbin/tripwire -m c -n -s';
# Tripwire Report print command
my $twprint = '/usr/sbin/twprint -m r -s -t 1';

#--------------------------------------------[ 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="$twreportdir/$hostname-$tstamp.twr";

if ($verbose) {
   print "Running Tripwire. Report: $report \n";
}
my $ret=system("$twchk -r $report 2>/dev/null");

## Run TripWire in Check mode
if ($ret) {
   my @out=`$twprint -r $report`;
   print "WARNING: Changes in the Filesystem: \n";
   foreach my $line (@out) {
      print "   $line";
   }
}
else {
   print "DONE. NO CHANGES \n" if ($verbose);
};

