#!/usr/bin/perl

                         ### *** IMPORTANT *** ###

       ### *** Make sure the path to PERL above is correct *** ###

       ########################################################### 
       # RLAJ.COM Search The Web                                 #
       # Script name - web-search.cgi                            #
       # Written by Ranson Johnson - Email  ranson@rlaj.com      #
       # Version 1.0                                             #
       ###########################################################

                      ### *** IMPORTANT *** ###

### *** If FTP'ing this file, be sure to send in ASCII format *** ###


# This is a very simple to set-up program for searching the web. There is one
# cgi script that does all the work. No configuration of the script is 
# necessary. Just place the script anywhere on your site that you can run
# cgi's and chmod the web-search.cgi to 775 to make it executable by the 
# server.

# In the main-search.htm change the FORM tag to point to your 
# web-search.cgi. 

# EXAMPLE: &lt;FORM METHOD="POST" ACTION="/cgi-bin/web-search.cgi"&gt;



            ### *** DO NOT CHANGE ANYTHING BELOW *** ###

&parse;

$FORM{'query'} =~ s/\s/\%20/g;

if ($FORM{'site'} eq 'altavista') {

print "Location: http://www.altavista.digital.com/cgi-bin/query\?pg=q\&what=web\&kl=XX\&q=$FORM{'query'}\n\n";

}

if ($FORM{'site'} eq 'excite') {

print "Location: http://www.excite.com/search.gw?trace=a&search=$FORM{'query'}\n\n";

}

if ($FORM{'site'} eq 'infoseek') {

print "Location: http://www2.infoseek.com/Titles?qt=$FORM{'query'}&col=WW&sv=IS&lk=noframes&nh=10\n\n";

}

if ($FORM{'site'} eq 'lycos') {

print "Location: http://www.lycos.com/cgi-bin/pursuit?query=$FORM{'query'}&matchmode=and&cat=lycos\n\n";

}

if ($FORM{'site'} eq 'yahoo') {

print "Location: http://search.yahoo.com/bin/search?p=$FORM{'query'}\n\n";

}

if ($FORM{'site'} eq 'webcrawler') {

print "Location: http://webcrawler.com/cgi-bin/WebQuery?mode=compact&maxHits=25&searchText=$FORM{'query'}\n\n";



}

exit;

sub parse {

  local (*FORM) = @_ if @_;
  local ($i, $key, $val);

  # Read in text
  if (&LocalMethGet) 
  {
    $FORM = $ENV{'QUERY_STRING'};
  } 
  elsif (&LocalMethPost) 
  {
    read(STDIN,$FORM,$ENV{'CONTENT_LENGTH'});
  }

  @FORM = split(/[&;]/,$FORM); 

  foreach $i (0 .. $#FORM) 
  {
    # Convert plusses to spaces
    $FORM[$i] =~ s/\+/ /g;

    # Split into key and value
    # splits on the first =
    ($key, $val) = split(/=/,$FORM[$i],2); 

    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;

    # Associate key and value 
    # \0 is the multiple separator
    $FORM{$key} .= "\0" if (defined($FORM{$key})); 
    $FORM{$key} .= $val;
  }
  return scalar(@FORM);
 
} # End sub parse


sub LocalMethGet 
# from Steven Brenner's cgi-lib.pl v1.14
# true if this cgi call was using the GET request, false otherwise
{
  return ($ENV{'REQUEST_METHOD'} eq "GET");
}

sub LocalMethPost 
# from Steven Brenner's cgi-lib.pl v1.14
# true if this cgi call was using the POST request, false otherwise
{
  return ($ENV{'REQUEST_METHOD'} eq "POST");
}




