#!/usr/bin/perl -w
##########################################################################
# $Id: applydate,v 1.2 1998/07/30 19:44:45 kirk Exp $
##########################################################################
# $Log: applydate,v $
# Revision 1.2  1998/07/30 19:44:45  kirk
# Prepping for Version 1.4.2
#
# Revision 1.1  1998/05/11 13:03:27  kirk
# Applied some wonderful patches sent in by
# Luuk de Boer <luuk_de_boer@pi.net>.
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Luuk de Boer <luuk@pi.net>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
#
########################################################

# I plan to add a *lot* more date flexibility at a later time...

if ( $ENV{'LOGWATCH_DATE_RANGE'} eq "yesterday") {
   $SearchDate = `/bin/date -d "1 day ago" +"%m/%d/%y"`;
   $SearchDate2 = `/bin/date -d "1 day ago" +"%Y/%m/%d"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "today") {
   $SearchDate = `/bin/date +"%m/%d/%y"`;
   $SearchDate2 = `/bin/date +"%Y/%m/%d"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "all") {
   $SearchDate = "../../..";
   $SearchDate2 = "..../../..";
}

# get rid of any carriage return
chomp($SearchDate);
chomp $SearchDate2;

if ( $ENV{'LOGWATCH_DEBUG'} > 5 ) {
   print STDERR "DEBUG: Inside ApplyDate (samba)...\n";
   print STDERR "DEBUG: Range: " . $ENV{'LOGWATCH_DATE_RANGE'} . "\n";
   print STDERR "DEBUG: Looking For: $SearchDate or $SearchDate2\n";
}

while (defined($ThisLine = <STDIN>)) {
    if ($ThisLine =~ m/^$SearchDate ..:..:.. /o) {
      print $ThisLine;
    }
    elsif ($ThisLine =~ m/^\[$SearchDate2 ..:..:../o) {
      print $ThisLine;
    }
}
