#!/usr/bin/perl ########################################################## # AGo Version 1 # Copyright 2002 by Brian Benison www.bigandloud.com # TO CALL THIS PROGRAM: # /cgi-bin/AGo.cgi?1234567 # # the beginning of the URL (part BEFORE the bit sent to this CGI) $mystart = 'http://www.amazon.com/exec/obidos/ASIN/'; # the end of the URL (part AFTER the bit sent to this CGI) $myfinish = '/brianbenisonm-20'; # Where this script goes if a) the parameter sent is invalid and # b) printstat is turned off $defaultdest = 'http://www.amazon.com/exec/obidos/redirect-home/brianbenisonm-20'; $printstat = '0'; # (good) $mystart = 'http://www.'; # (good) $myfinish = '.com'; $string = $ENV{'QUERY_STRING'}; $countstat = '1'; $counterfile = "/www/b/benison/htdocs/AGoCounter.txt"; ######################### # First, add this execution of the CGI to the counter, # if countstat is turned on if ($countstat) { open (COUNTER, "$counterfile"); $count = ; chop ($count) if $count =~ /\n$/; close (COUNTER); # Increase Count $count += 1; open (COUNTER, ">$counterfile"); print COUNTER ("$count"); close (COUNTER); } ######################### # Just to be on the safe side, we'll only accept alphanumeric # characters, so there'll be no tricky business. If $printstat = '1', # user will also see a page saying their query string was not accepted. # If no string, then same deal. (Mostly you'll want to set $printstat # for testing) ######################### if ($string eq '') {&error('is_blank')} if ($string =~ /[^a-zA-Z0-9]/) {&error('is_bad')} ######################### # Now, back to business: ######################### $mydestination = "$mystart$string$myfinish"; print "Location: $mydestination\n\n"; # sub error { # Localize variable. local($error) = @_; if ($printstat) { print "Content-type: text/html\n\n"; print "\n \n"; if ($error eq 'is_bad') { print "You sent me a bad thing:\n"; } if ($error eq 'is_blank') { print "You forgot to send a query expression!\n"; } print "$string\n\n"; print "\n"; } else {print "Location: $defaultdest\n\n"; } } exit;