#!/usr/bin/perl
# Shortened for URL length with switch to GET method
# maxresults mr
# previews pr
# query q
# searchkind sk
#Keyword from html form for any kind of pet
$anykind = "any";
# My directory for the log file
$logdir = ".";
#Path to the index
$index = "petindex";
#Path to the configuration file
$config = "search.conf";
#- Main Program -------------------------------------------------------------#
#Parse the form data
&parse_form_data (*FORM);
#Construct a simple query
$query = $FORM{'q'};
$results = $FORM{'mr'};
$temp_previews = $FORM{'pr'};
$sk = $FORM{'sk'};
if ($temp_previews eq "ON")
{
$show_previews = 1;
}
else
{
$show_previews = 0;
}
if ($query || ($sk ne $anykind) )
{
&search_parse;
}
else
{
&search_error("Please enter at least one word in the \"Search for\" box.");
}
#- Subroutines ---------------------------------------------------------------#
#Subroutine for checking and parsing the incoming form data.
sub parse_form_data {
local (*FORM_DATA) = @_;
local ($request_method, $query_string, @key_value_pairs, $key_value, $key, $value);
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET") {
$query_string = $ENV{'QUERY_STRING'};
} elsif ($request_method eq "POST") {
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
} else {
&search_error ("Forms must use either GET or POST.");
}
@key_value_pairs = split (/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split (/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
if (defined ($FORM_DATA{$key})) {
$FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
} else {
$FORM_DATA{$key} = $value;
}
}
}
#Subroutine for constructing the search request and formating the results.
sub search_parse {
#Create your query command
if ($results < 1 || $results > 500) {$results = 10;};
$count=0;
if ($sk eq "Dogs") { $restriction = "kind=dog "; }
elsif ($sk eq "Alpacas") { $restriction = "kind=Alpaca "; }
elsif ($sk eq "Bats") { $restriction = "kind=bat "; }
elsif ($sk eq "Birds") { $restriction = "kind=bird "; }
elsif ($sk eq "Bisons") { $restriction = "kind=bison "; }
elsif ($sk eq "Burros") { $restriction = "kind=burro "; }
elsif ($sk eq "Camels") { $restriction = "kind=camel "; }
elsif ($sk eq "Cats") { $restriction = "kind=cat "; }
elsif ($sk eq "Cattle") { $restriction = "kind=cattle "; }
elsif ($sk eq "Chickens") { $restriction = "kind=chicken "; }
elsif ($sk eq "Chinchillas") { $restriction = "kind=chinchilla "; }
elsif ($sk eq "Cows") { $restriction = "kind=cow "; }
elsif ($sk eq "Deer") { $restriction = "kind=deer "; }
elsif ($sk eq "Degus") { $restriction = "kind=degu "; }
elsif ($sk eq "Dogs") { $restriction = "kind=dog "; }
elsif ($sk eq "Donkeys") { $restriction = "kind=donkey "; }
elsif ($sk eq "Ducks") { $restriction = "kind=duck "; }
elsif ($sk eq "Duprasis") { $restriction = "kind=duprasi "; }
elsif ($sk eq "Ferrets") { $restriction = "kind=ferret "; }
elsif ($sk eq "Fish") { $restriction = "kind=fish "; }
elsif ($sk eq "Frogs") { $restriction = "kind=frog "; }
elsif ($sk eq "Gerbils") { $restriction = "kind=gerbil "; }
elsif ($sk eq "Goats") { $restriction = "kind=goat "; }
elsif ($sk eq "Guinea Pigs") { $restriction = "kind=guinea pig "; }
elsif ($sk eq "Hamsters") { $restriction = "kind=hamster "; }
elsif ($sk eq "Hedgehogs") { $restriction = "kind=hedgehog "; }
elsif ($sk eq "Horses") { $restriction = "kind=horse "; }
elsif ($sk eq "Iguanas") { $restriction = "kind=iguana "; }
elsif ($sk eq "Lizards") { $restriction = "kind=lizard "; }
elsif ($sk eq "Llamas") { $restriction = "kind=llama "; }
elsif ($sk eq "Monkeys") { $restriction = "kind=monkey "; }
elsif ($sk eq "Mice") { $restriction = "kind=mice "; }
elsif ($sk eq "Mules") { $restriction = "kind=mule "; }
elsif ($sk eq "Opossum") { $restriction = "kind=opossum "; }
elsif ($sk eq "Parrots") { $restriction = "kind=parrot "; }
elsif ($sk eq "Pigs") { $restriction = "kind=pig "; }
elsif ($sk eq "Porcupines") { $restriction = "kind=porcupine "; }
elsif ($sk eq "Prairie Dogs") { $restriction = "kind=prairiedog "; }
elsif ($sk eq "Rabbits") { $restriction = "kind=rabbit "; }
elsif ($sk eq "Raccoons") { $restriction = "kind=raccoon "; }
elsif ($sk eq "Rats") { $restriction = "kind=rat "; }
elsif ($sk eq "Sheep") { $restriction = "kind=sheep "; }
elsif ($sk eq "Skunks") { $restriction = "kind=skunk "; }
elsif ($sk eq "Snakes") { $restriction = "kind=snake "; }
elsif ($sk eq "Spiders") { $restriction = "kind=spider "; }
elsif ($sk eq "Squirrels") { $restriction = "kind=squirrel "; }
elsif ($sk eq "Sugar Gliders") { $restriction = "kind=sugar glider "; }
elsif ($sk eq "Toads") { $restriction = "kind=toad "; }
elsif ($sk eq "Tortoises") { $restriction = "kind=tortoise "; }
elsif ($sk eq "Turtles") { $restriction = "kind=turtle "; }
elsif ($sk eq "Wallabys") { $restriction = "kind=wallaby "; }
elsif ($sk eq "Whales") { $restriction = "kind=whale "; }
else
{ $restriction = ""; }
$restricted_query = $restriction . $query;
#
#
# logging
open(SEARCHLOG_FH,">> searchlog");
chdir $logdir;
# print SEARCHLOG_FH (localtime(time))," ",$ENV{'REMOTE_ADDR'}," ",$restricted_query,"\n";
($mysec,$mymin,$myhour,$mymday,$mymon,$myyear,$mywday,$myyday,$myisdst) = localtime(time);
$mymon += 1;
print SEARCHLOG_FH $myhour, ":", $mymin,":",$mysec," ",$mymon,"/",$mymday," ",$ENV{'REMOTE_ADDR'}," ",$restricted_query,"\n";
close(SEARCHLOG_FH);
#
#
#
open(SEARCH_P, "./search -w $restricted_query -m $results -f $index|");
#Check for errors
$foundIt = 0;
while (
"; # Change size below too print " | "; print " | $PetName $PetKind $PetDate | \n";
$InLeftColumn = 0;
}
else
{
print ""; print " | "; print " | $PetName $PetKind $PetDate | ||
"; # print " | "; # print " | $title | "; print " | "; print " | \n"; } # print " |
|
HTML_Header
# if ($show_previews)
# {
# print " |