#!/usr/bin/perl -wT # # Author : C Matthew Curtin # Created On : <1998/10/22 00:14:30 cmcurtin> # Last Modified By: $Author: cmcurtin $ # Last Modified On: $Date: 2003/07/23 15:31:57 $ # Update Count : # Status : # # HISTORY # $Log: rotbanner.txt,v $ # Revision 1.2 2003/07/23 15:31:57 cmcurtin # committing new content # # Revision 1.1 1998/10/29 12:43:48 cmcurtin # Initial revision # # # dependencies use CGI; use CGI::Carp; use strict; my $cgi = new CGI; # file dependencies my $bannerdir = "/var/www/sam/images/poweredby"; my $relbannerdir = "http://" . $cgi->virtual_host() . "/images/poweredby"; # $bannerdir/.last has to exist and be writable by the http daemon uid # LOG (see bottom) needs to be defined. If the file exists, it must be # writable, if not, the directory must be writable so LOG file can be created. opendir(BANNERS, "$bannerdir") or croak "Cannot open $bannerdir: $!"; my @banners = grep(!/^\./, readdir(BANNERS)); # all non dot-files, i.e., .foo closedir BANNERS; my $last; undef $/; open(LAST, "< $bannerdir/.last") or croak "Cannot open $bannerdir/.last: $!"; $last = ; chomp $last; close LAST; $last++; $last = 0 if ($last >= scalar @banners); # give redirect to the banner we want #print "Location: " . $relbannerdir . "/" . $banners[$last] . "\n\n"; # or... actually spew the thing directly, which is probably a better idea. my @stat = stat("$bannerdir/$banners[$last]"); my $type = "$banners[$last]"; $type =~ s/^.*\.([a-zA-Z]+)$/$1/; if (lc($type) eq "jpg") { $type = "jpeg"; } elsif (lc($type) eq "jpeg") { $type = "jpeg"; } elsif (lc($type) eq "gif") { $type = "gif"; } else { croak "Don't know how to generate header for file type $type"; } $/="\n"; open(BANNER, "< $bannerdir/$banners[$last]") or croak "Cannot open $bannerdir/$banners[$last]: $!"; print "Pragma: No-cache\n"; print "Expires: Thu, 01 Dec 1994 16:00:00 GMT\n"; print "Content-type: image/$type\n"; print "Content-length: $stat[7]\n\n"; while() { print; } close BANNER; open(LAST, "> $bannerdir/.last") or croak "Cannot write to $bannerdir/.last: $!"; print LAST $last; close LAST; open(LOG, ">> $bannerdir/.log") or croak ("Cannot open $bannerdir/.log: $!"); print LOG $banners[$last] . ":" . $cgi->referer() . ":" . scalar localtime() . "\n"; close LOG;