#!/usr/local/bin/perl
###
# pushin.cgi - by David Efflandt - efflandt@xnet.com 9/4/95 [updated 1/2/96]
# For NCSA or Apache server may need to rename 'nph-push.cgi'
# for unbuffered output if pausing between images.
#
# Pushes gif files listed in a file in QUERY_STRING following scriptname
#
# Usage:
# CGI filname may include URL/path.
#
# img_list format per line: $file [$pause]
#
# img_list and $file: should be in $path defined below.
# $pause: optional seconds.
#
# img_list example: foo.gif 1
# shows foo.gif then pauses 1 second
###
# path/ or /full_path_from_root/ for img_list and images
$path = 'img/';
# Image list file from URL
$filein = $ENV{'QUERY_STRING'};
$filein =~ /(\w[^\s\;]*)/; # minimize hacking
$filein = $path.$1;
# Uncomment the following line for 'nph-':
# print "$ENV{'SERVER_PROTOCOL'} 200 OK\n";
# Use last image if not Netscape 1.1 or later (Mosaic 2.0 tested)
$agent = $ENV{'HTTP_USER_AGENT'};
undef($agent) if ($agent =~ /compatible/i); # fake Mozilla
($agent =~ /Mozilla\/(\S*)/) && ($agent = $1);
unless ($agent > 1) {
open(IN, $filein) || die "Can't open script $filein: $!\n";
while() {
/(.*[^\n\r])/;
$item = $1;
($file, $pause) = split (/ /, $item);
$file = $path.$file;
}
open (IMG, "<$file") || die "Can't open $file: $!\n";
print "Content-type: image/gif\n";
$len = -s $file;
print "Content-length: $len\n\n";
print
;
close IMG;
exit;
}
# Send images
open(IN, "<$filein") || die "Can't open script $filein: $!\n";
print "Content-type: multipart/x-mixed-replace;boundary=ThisRandomString\n";
$| = 1; # unbuffered
while() {
/(.*[^\n\r])/;
$item = $1;
print "\n--ThisRandomString\n";
sleep $pause if ($pause); # from previous image
($file, $pause) = split (/ /, $item);
$file = $path.$file;
open (IMG, "<$file") || die "Can't open $file: $!\n";
print "Content-type: image/gif\n\n";
print
;
close IMG;
}
print "\n--ThisRandomString--\n";