#!/usr/bin/perl -w
##########################################################################
# $Id: applydate,v 1.5 2000/09/22 14:47:02 kirk Exp $
##########################################################################
# $Log: applydate,v $
# Revision 1.5  2000/09/22 14:47:02  kirk
# *** empty log message ***
#
# Revision 1.4  1998/02/24 01:38:37  kirk
# Calls /bin/date explicitly, and not just 'date'...
#
# Revision 1.3  1998/02/23 01:16:53  kirk
# Getting ready for a first distribution
#
# Revision 1.2  1998/02/22 20:56:31  kirk
# Actually applies the date properly now...
#
# Revision 1.1  1998/02/22 20:05:46  kirk
# Special filters for xferlog format
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# 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" +"%b %d"`;
   $SearchYear = `/bin/date -d "1 day ago" +"%Y"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "today") {
   $SearchDate = `/bin/date +"%b %d"`;
   $SearchYear = `/bin/date +"%Y"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "all") {
   $SearchDate = "... ..";
   $SearchYear = "....";
}

# The date might be "Dec 09", but it needs to be "Dec  9"...
$SearchDate =~ s/ 0/  /;
chomp($SearchDate);

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

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