#/usr/bin/perl -Tw # # $Id: ssi_rand_image.pl,v 1.12 2002/07/23 21:00:17 nickjc Exp $ # use strict; use POSIX qw(locale_h strftime); use CGI qw(header img a); use Fcntl qw(:DEFAULT :flock); use vars qw($DEBUGGING $done_headers); use lib 'C:\Inetpub\vhosts\beyondmasculinity.com\httpdocs\beyondmasculinity.com\cgi-bin'; # Configuration # # $DEBUGGING must be set in a BEGIN block in order to have it be set before # the program is fully compiled. # This should almost certainly be set to 0 when the program is 'live' # BEGIN { $DEBUGGING = 1; } my @images = ({ file => 'http://www.beyondmasculinity.com/images/spotlight/ahmed.jpg', url => 'http://www.beyondmasculinity.com/articles/ahmed.php', alt => 'Spotlight on Hammad Ahmed' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/autrey.jpg', url => 'http://www.beyondmasculinity.com/articles/autrey.php', alt => 'Spotlight on William Autrey' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/blumenfeld.jpg', url => 'http://www.beyondmasculinity.com/articles/blumenfeld.php', alt => 'Spotlight on Warren Blumenfeld' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/calderwood.jpg', url => 'http://www.beyondmasculinity.com/articles/calderwood.php', alt => 'Spotlight on Brent Calderwood' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/cole.jpg', url => 'http://www.beyondmasculinity.com/articles/cole.php', alt => 'Spotlight on Joshua Bastian Cole' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/daywalker.jpg', url => 'http://www.beyondmasculinity.com/articles/daywalker.php', alt => 'Spotlight on Rob Day-Walker' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/dilts.jpg', url => 'http://www.beyondmasculinity.com/articles/dilts.php', alt => 'Spotlight on Jason Dilts' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/driskill.jpg', url => 'http://www.beyondmasculinity.com/articles/driskill.php', alt => 'Spotlight on Qwo-li Driskill' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/faris.jpg', url => 'http://www.beyondmasculinity.com/articles/faris.php', alt => 'Spotlight on Michael Faris' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/gyshen.jpg', url => 'http://www.beyondmasculinity.com/articles/gyshen.php', alt => 'Spotlight on Sean Gyshen Fennell' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/harris.jpg', url => 'http://www.beyondmasculinity.com/articles/harris.php', alt => 'Spotlight on Keith M. Harris' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/hoppe.jpg', url => 'http://www.beyondmasculinity.com/articles/hoppe.php', alt => 'Spotlight on Trevor Hoppe' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/jost.jpg', url => 'http://www.beyondmasculinity.com/articles/jost.php', alt => 'Spotlight on Eric Jost' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/julius.jpg', url => 'http://www.beyondmasculinity.com/articles/julius.php', alt => 'Spotlight on Patrick Julius' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/lobel.jpg', url => 'http://www.beyondmasculinity.com/articles/lobel.php', alt => 'Spotlight on Brian Lobel' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/long.jpg', url => 'http://www.beyondmasculinity.com/articles/long.php', alt => 'Spotlight on Elliot Long' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/macey.jpg', url => 'http://www.beyondmasculinity.com/articles/macey.php', alt => 'Spotlight on J. Macey' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/martinez.jpg', url => 'http://www.beyondmasculinity.com/articles/martinez.php', alt => 'Spotlight on Daniel E. Solis y Martinez' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/purcell.jpg', url => 'http://www.beyondmasculinity.com/articles/purcell.php', alt => 'Spotlight on Paul Purcell' }, { file => 'http://www.beyondmasculinity.com/images/spotlight/snyder.jpg', url => 'http://www.beyondmasculinity.com/articles/snyder.php', alt => 'Spotlight on Mark Snyder' }); my $uselog = 0; my $logfile = '/path/to/log/file'; my $date_fmt = '%c'; my $link_image = 1; my $align = 'right'; my $border = 0; my $locale = ''; # End configuration # We need finer control over what gets to the browser and the CGI::Carp # set_message() is not available everywhere :( # This is basically the same as what CGI::Carp does inside but simplified # for our purposes here. BEGIN { sub fatalsToBrowser { my ( $message ) = @_; if ( $DEBUGGING ) { $message =~ s//>/g; } else { $message = ''; } my ( $pack, $file, $line, $sub ) = caller(0); my ($id ) = $file =~ m%([^/]+)$%; return undef if $file =~ /^\(eval/; print "Content-Type: text/html\n\n" unless $done_headers; print < Error

Application Error

An error has occurred in the program

$message

EOERR die @_; }; $SIG{__DIE__} = \&fatalsToBrowser; } my $img = $images[rand(@images)]; # Print Out Header With Random Filename and Base Directory print header; $done_headers++; my $output = img({-src => $img->{file}, -alt => $img->{alt}, -border => $border, -align => $align}); if ($link_image && $img->{url}) { $output = a({-href => $img->{url}}, $output); } print $output; # If You want a log, we add to it here. if ($uselog) { eval { setlocale(LC_TIME, $locale) if $locale ; }; my $date = strftime $date_fmt, localtime; sysopen(LOG, $logfile, O_APPEND|O_CREAT|O_RDWR) or die "Can't open log file: $!\n"; flock LOG, LOCK_EX or die "Can't lock log file: $!\n"; print LOG "$img->{file} - $date - $ENV{REMOTE_HOST}\n"; close(LOG); }