#!/usr/local/bin/perl5 # Name: backyard/previous.cgi Author: Joe Smith 16-Dec-98 # Purpose: Creates a chronological list of images in HTML form. # Usage: last two hours. # This is run by the Apache server (UNIX) and the Sambar server (Win95/WinNT) # The command-line argument is expected to be "hour", "day", or "old". open(IN,"current-hour/capture.txt"); # cwd = $HOME/backyard $_ = ; ($file,$bytes,$date,$time,$TZ,$res) = split; $_ = ; close IN; $file = $bytes = $date = $time = $res if $^W; # Keep 'perl -w' happy $light = /light=(\S+)/ ? $1 : "05:30"; # 20 minutes before sunrise in July $dark = /dark=(\S+)/ ? $1 : "20:30"; # 20 minutes after sunset in July $ENV{TZ} = $TZ if -f "/usr/share/zoneinfo/$TZ"; # PST8PDT for FreeBSD-2.2.8 @t = localtime; $hh_mm = sprintf "%02d:%02d", $t[2], $t[1]; if ($ARGV[0] eq "video1") { $dir = ".video/1"; $what = "Camera 1"; $href = <main picture | camera 1 | camera 2 | camera 3 | EOM $refresh = ''; $message = ""; } elsif ($ARGV[0] eq "video2") { $dir = ".video/2"; $what = "Camera 2"; $href = <main picture | camera 1 | camera 2 | camera 3 | EOM $refresh = ''; $message = ""; } elsif ($ARGV[0] eq "video3") { $dir = ".video/3"; $what = "Camera 3"; $href = <main picture | camera 1 | camera 2 | camera 3 | EOM $refresh = ''; $message = ""; } elsif ($ARGV[0] eq "day") { $dir = "current-today"; $what = "last 24 hours"; $href = <current picture | last 2 hours | last 24 hours | previous 24 hours | EOM $refresh = $message = ""; } elsif ($ARGV[0] eq "old") { $dir = "current-yester"; $what = "24 to 48 hours"; $href = <current picture | last 2 hours | last 24 hours | previous 24 hours | EOM $refresh = $message = ""; } else { # Assume anything else is "hour" $dir = "current-hour"; $what = "last hour"; $href = <current picture | last 2 hours | last 24 hours | previous 24 hours | EOM $message = "

Please check back during daylight hours, $light to $dark $TZ

\n"; $message = "" if $hh_mm gt $light && $hh_mm lt $dark; $refresh = qq|\n| unless $message; } $href .= ' gallery'; $img_stuff = 'WIDTH=80 HEIGHT=60 ALIGN=MIDDLE VSPACE=5'; $img_left = 'WIDTH=80 HEIGHT=60 ALIGN=LEFT'; $bgcolor = 'BGCOLOR="#CCCCCC"'; # Light gray background @w = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); print "Content-type: text/html\n\n"; $| = 1; close(STDERR); open(STDERR,">&1"); # Send errors to browser $title = sprintf("Pictures as of %s %02d/%02d/%04d at %02d:%02d:%02d", $w[$t[6]], $t[4]+1, $t[3], $t[5]+1900, $t[2], $t[1], $t[0]); $_ = ''; print <$what: $title $refresh EOM chdir($dir) || die "Unable to access directory '$dir': $!\n"; opendir(DIR,"."); @imgs = grep(/\.jpg$/,readdir(DIR)); closedir(DIR); @files = (); foreach $_ (@imgs) { next if -l $_; # Ignore symlinks push(@files,(stat _)[9] . " $_"); # Get modification time } @files = sort @files; # Chronological order foreach $n (0 .. $#files) { $_ = $files[-1-$n]; # Newest next if /capture_t.jpg/; ($jtime,$jpg) = split; ($gif = $jpg) =~ s/jpg$/gif/; last if -s $gif; # Find newest image with thumb } $_ = localtime($jtime); print <   $href
$_
EOM $oldday = ""; foreach $_ (@files) { # Oldest first ($jtime,$jpg) = split; next if $jpg eq "capture_t.jpg"; # This is not full-sized ($gif = $jpg) =~ s/jpg$/gif/; @t = localtime($jtime); ($mm,$hh,$wday) = ($t[1],$t[2],$t[6]); $hhmm = sprintf("%02d:%02d",$hh,$mm); $day = $w[$wday]; print "

$day

\n" if $day ne $oldday; # First picture of the day $oldday = $day; $img_src = -f $gif ? "$dir/$gif" : "capture.gif"; print qq| $hhmm\n|; } print "\n$message

$title $TZ

\n$href\n\n"; exit;