#!/usr/bin/perl
print "Content-Type: text/html\r\n\r\n";
# We obtain the last file from each folder
# add more lines for week, month, etc, here and in the
# substitution code
$Last = &LastFile("in/","");
$LastHour = &LastFile("out/hour/","hour");
$Last6Hours = &LastFile("out/qday/","qday");
$Last12Hours = &LastFile("out/hday/","hday");
$Last24Hours = &LastFile("out/day/","day");
# Open the skeleton HTML file
open (HTML, "< index_base.htm");
# Substitute the strings in the skeleton HTML by the images we've found
# Then print the altered varsion of this HTML
while () {
s/\#\#\#\#24HR\#\#\#\#/out\/day\/$Last24Hours/;
s/\#\#\#\#12HR\#\#\#\#/out\/hday\/$Last12Hours/;
s/\#\#\#\#6HR\#\#\#\#/out\/qday\/$Last6Hours/;
s/\#\#\#\#1HR\#\#\#\#/out\/hour\/$LastHour/;
s/\#\#\#\#LAST\#\#\#\#/in\/$Last/;
print;
}
close (HTML);
# Routine to find the last picture in a directory
# 1st parameter: path to pictures
# 2nd parameter: starting label of file names
sub LastFile() {
local ($Path, $FileStart, $Command, $LastFiles, $Biggest, $Fline);
local (@LastFiles);
($Path, $FileStart) = @_;
$Command = "ls $Path/$FileStart\*.jpg";
$LastFiles = `$Command`;
@LastFiles = split(/\n/,$LastFiles);
$Biggest = 0;
foreach $Fline (@LastFiles) {
if ($Fline =~ /$FileStart([-\d]+)\.jpg/) {
if ($1 gt $Biggest) {
$Biggest = $1;
}
}
}
$LastFiles = $FileStart . $Biggest . ".jpg";
return ($LastFiles);
}