#!/usr/bin/perl # # Written by Hendra $doc = "/home/httpd/banners/default/banner01.jpg"; $log = "/tmp/bannerlog"; if (-e "/home/clients/cciflorida-2003/banner") { $bbin = "/home/clients/cciflorida-2003/banner"; } elsif (-e "/home/clients/cciflorida/banner") { $bbin = "/home/clients/cciflorida/banner"; } else { $h = `pwd`; chomp($h); $bbin = "$h/banner"; } $index = "bannerindex"; $report = "/tmp/imagereport.txt"; $default = "default"; $bannerindex = "$bbin/bindex"; ($server = $ENV{'SERVER_NAME'}) =~ tr/A-Z/a-z/; ($raccess = ($ENV{'REMOTE_HOST'} ||$ENV{'REMOTE_ADDR'})) =~ tr/A-Z/a-z/; ($rref = $ENV{'HTTP_REFERER'}) =~ tr/A-Z/a-z/; $expires = `date +'%a, %e %b %Y %X %Z'`; $rat = $rref; $rref =~ s%.+/(\w+)/%$1%; `echo "$rref - $rat" >$report`; $rref = 'list' if $rref =~ /listindex.cgi/; $rref =~ s/\?.+$//; $rref =~ s/(\d+)$//; if (-e "$bbin/$rref") { $banb = "$bbin/$rref"; } else { $banb = "$bbin"; } sub puinque { my ($f, $banb, $i, $done, $o) = @_; $i = 1; while (!$done) { $o++; $done = 1 if $o > 100; if ($banner{"$i"}) { if ($banner{"$i"} !~ /^missing$/) { $i++; } else { delete $banner{"$i"}; } } else { $banner{"$i"} = "$banb/$f"; $banner{"file:$f"} = $i; $done = 1; } } } sub verify { my ($f, $i, $x, $o) = @_; $i = $banner{$f}; if (-e "$banner{$i}") { $o = 1; } else { $x = $banner{$f}; $debug .= "banner $x - $i was $banner{$x}\n"; $banner{$x} = 'missing'; delete $banner{$f}; } } dbmopen (%banner, "$bannerindex-$rref", 0644); opendir BB, "$banb"; while ($file = readdir(BB)) { $debug .= "$file - found\n"; if (($file =~ /jpg$/) || ($file =~ /gif$/)) { &puinque("$file","$banb" ) unless $banner{"file:$file"}; } } $fnum = $banner{'active'} || 1; $fnext = $fnum + 1; foreach (sort {$a <=> $b} keys %banner) { &verify($_) if /^file/; } $done = 0; while (!$done) { $o++; $done = 1 if $o > 100; if ($banner{$fnext} =~ /^missing$/) { ++$fnext; } elsif (!$banner{$fnext}) { $fnext = 1; } else { $banner{'active'} = $fnext; $doc = $banner{$fnext}; $done = 1; } } $suffix = "jpeg"; $suffix = "gif" if $doc =~ /gif$/; print "Expires: $expiresCache-Control: no-cache\nPragma: no-cache\nContent-type: image/$suffix\n\n"; open (I, "$doc"); while () { print; } close I;