#!/usr/local/perl use Time::Local; $today = timelocal(localtime); $now = &unix_to_date($today - 3600); sub unix_to_date { my ($date) = $_[0]; # reads in variable passed to subroutine reates array of month names my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!; #c @time = (localtime($date))[3,4,5,0,0]; #creates array of date from unix time $time[2] += 1900; # converts year to proper format return "$months[$time[1]]/$time[0]/$time[2] "; } $datafile = "report.data"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $FORM{$name} = $value; } $searchstr = $FORM{'name'}; open(INF,$datafile); @mydata = ; close(INF); print "Content-type:text/html\n\n"; print "Check Report\n"; print "

Check Report

\n"; @results = grep(/$searchstr/i,@mydata); if ($#results >= 0) { foreach $i (@results) { chomp($i); ($sn , $Location, $starttime, $endtime, $item, $family, $status) = split(/|/,$i); print "

$FORM{'name'} This serial is in Report List

\n"; open(OUTF,">>found_it.txt") or dienice("Couldn't open found_it.txt for writing: $!"); # This locks the file so no other CGI can write to it at the # same time... flock(OUTF,2); # Reset the file pointer to the end of the file, in case # someone wrote to it while we waited for the lock... seek(OUTF,0,2); print OUTF "$FORM{'name'}\|$item\|\|$now\n"; } } else { print "

$FORM{'name'} . Alert! This serial number is not in Report list, Please check.

\n"; open(OUTF,">>found_it.txt") or dienice("Couldn't open found_it.txt for writing: $!"); # This locks the file so no other CGI can write to it at the # same time... flock(OUTF,2); # Reset the file pointer to the end of the file, in case # someone wrote to it while we waited for the lock... seek(OUTF,0,2); print OUTF "$FORM{'name'}\|$item\|NA\|$now"; } print "\n";