Mystery

liunx

Guest
A few days ago, a banner rotating script that I wrote suddenly stopped working. It's a perl script called by SSI. There are two seperate copies of this script, one on the front page and one in a subdomain. These two are, of course, completely isolated from one another and thus have only three common dependencies: Apache, Perl, and Perl's Image::Magick module. We haven't touched these files in months, but still, I've checked all of the files in both directories against my originals. I've checked to ensure the originals still work. I uploaded the known working copies over what was on the server. I even checked the permissions for the scripts. Everything is now as it was when the scripts were working. None of the SSI calls have changed either. The funny thing is that both of the scripts mysteriously stopped working at the same time. That leads me to believe that something has changed server-side of which I am not aware. And, luckily, all of the admins are greedy with even jailed shells, so all I have to go on is Apache's extremely helpful, catch-all error message: "Premature end of script headers." So, anyway, I was just wondering if anything on the server has been upgraded or changed recently that may impact perl cgi scripts and whether or not anyone else has experienced a similar mysterious failure.<br /><br />Thanks in advance,<br /> -Mark<!--content-->
Hi Mark,<br /><br />This error is usually caused by a blank line at the end of the script, or because it was uploaded using binary from dos (rather than ascii).<br /><br />Have you got a link to the error?<!--content-->
Actually, from my experience, errors can occassionally occur because of a LACK of a blank line or two at the end. Anyway, if that were the problem, then I should have gotten that from the beginning, not a sudden, unprompted change like this. I developed this script on and uploaded it from my Slackware10 box here. No winblows involved. The script is located here: <a href="http://garden.shop-etc.com/cgi-bin/rotb/rotb.cgi" target="_blank">http://garden.shop-etc.com/cgi-bin/rotb/rotb.cgi</a>. Running it with no input (as it is in that link) should produce a snippet of html code. Instead, I get a 500 from Apache.<!--content-->
<!--QuoteBegin-shop-et+Mar 22 2005, 05:24 PM--><div class='quotetop'>QUOTE(shop-et @ Mar 22 2005, 05:24 PM)</div><div class='quotemain'><!--QuoteEBegin-->. The script is located here: <a href="http://garden.shop-etc.com/cgi-bin/rotb/rotb.cgi" target="_blank">http://garden.shop-etc.com/cgi-bin/rotb/rotb.cgi</a>. Running it with no input (as it is in that link) should produce a snippet of html code. Instead, I get a 500 from Apache.<br /><div align="right"><a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=120839"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Post up the code, maybe someone can figure it out.<!--content-->
As I said, this script is known to run flawlessly. It still runs fine on my box and it has been running fine on the server for months on end until the last few days, when it simply stopped working for no apparent reason. No one changed anything and I triple checked to confirm this. This isn't a problem with my code, unless some dependency on the server has changed to invalidate it. But, just in case there is something someone knows about that I don't, here's the code. The file 'db' is a small text database, one entry per line, laid out in the format: <image_filename> || <affiliate_link_for_this_image><br /><br />This script works in three stages. The first (when run with no input), returns an html snippet referring the browser back to the script for an image source. The second stage scales the image for a consistant height (51 pixels) and feeds the browser the image headers and then the image itself. The third handles the click-thru connection, acting as a make-shift ghosting script for the banners. I'm writing this here because the script is small enough and simple enough that I didn't bother throwing in any comments.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->#!/usr/bin/perl -w<br /><br />$| = 1;<br />use Image::Magick;<br />use strict;<br /><br />my $input;<br /><br />$input = $ENV{'QUERY_STRING'};<br />if (!$input) { $input = <STDIN>; }<br />if (!$input) { $input = $ARGV[0]; }<br />chomp $input unless !$input;<br /><br />if (!$input) {<br />    my (@info,$elnum,$el);<br /><br />    open (READ,"< db") or die ("Couldn't open db: $!\n");<br />    while (<READ>) { chomp $_; push (@info,$_); }<br />    close READ;<br /><br />    srand( time() ^ ($$ + ($$ << 15)) );<br />    $elnum = int (rand scalar (@info));<br /><br />    $el = $info[$elnum];<br />    $el =~ /([^\|]+) \|\| (.+)/;<br /><br />    print "Content-type: text/html\n\n";<br />    print "<a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"http://www.shop-etc.com/cgi-bin/rotb/rotb.cgi?ral=$1\" target=\"_blank\">";<br />    print "<img hspace=\"6\" vspace=\"6\" src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"http://www.shop-etc.com/cgi-bin/rotb/rotb.cgi?ilap=$1\" border=\"0\"></a>\n";<br />}<br />elsif ($input =~ /^ilap/) {<br />    $input =~ s/[^\=]+?=//;<br />    my $image  = Image::Magick->new();<br />    my $x    = $image->Read("$input");<br /><br />    my ($width, $height) = $image->Get('columns','rows');<br />    my $new_width = int (51 * ($width / $height));<br /><br />    $x        = $image->Scale(height=>'51', width=>"$new_width");<br />    $x        = $image->Contrast(sharpen=>'1');<br /><br />    $input =~ /.+\.(\w+)$/;<br />    print STDOUT "Content-type: image/$1\n\n";<br />    $x        = $image->Write('-');<br />}<br />elsif ($input =~ /^ral/) {<br />    $input =~ s/[^\=]+?=//;<br />    my (@info, $line, $el);<br />    open (READ,"< db") or die ("Couldn't open db: $!\n");<br />    while (<READ>) { chomp $_; push (@info,$_); }<br />    close READ;<br /><br />    foreach $line (@info) { if ($line =~ /^$input/) { $el = $line; } }<br />    $el =~ s/([^\|]+) \|\| //;<br /><br />    print "Content-type: text/html\n\n<html><head><title></title>\n<script language=\"Javascript\" type=\"text/javascript\">";<br />    print "window.location='$el';\n</script>\n</head><body></body></html>\n\n";<br />}<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
Mark, I think you may need to open a help desk ticket to get this resolved. Link at top of page.<!--content-->
 
Top