#!/usr/bin/perl $sitetitle = 'CodeSpy.com'; $searchurl = 'http://www.codespy.com'; $searchemail = 'webmaster@codespy.com'; $mailprogram = '/usr/lib/sendmail'; $base = 'base.txt'; $headfile = 'head.txt'; $footfile = 'foot.txt'; $respondfile = 'respond.txt'; $smutfile = 'smut.txt'; $scripturl = 'http://www.codespy.com/cgi-bin/search.cgi'; $font = 'FACE=arial,helvetica COLOR=000000'; $minword = '1'; $maxtitle = '50'; $maxdescription = '150'; $maxkeywords = '150'; $numnew = '1000000000'; $uselock = '1'; $userespond = '1'; # Get the form variables if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # Break em up into a format the script can read @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } # Get the heading information unless (open (DATA,"$headfile")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @headinfo = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); foreach $headline (@headinfo){ $heading = $heading.$headline; } # Get the footer information unless (open (DATA,"$footfile")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @footinfo = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); foreach $footline (@footinfo){ $footer = $footer.$footline; } # Get the smut filter information unless (open (DATA,"$smutfile")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @smutinfo = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); foreach $smutline (@smutinfo){ $smutfilter = $smutfilter.$smutline; @smutwords = split (/::/,$smutfilter); } # Determine what part of the script we need if ($FORM{'action'} eq "showadd") { &showadd; } if ($FORM{'action'} eq "addurl") { &addurl; } if ($FORM{'action'} eq "newurls"){ &newurls; } if ($FORM{'action'} eq "randomurl"){ &randomurl; } # Assign shorter variable names # (Laziness on my part - but I find the longer # a script gets the more work typing long # variable names becomes.) $position = $FORM{'code'}; $addshow = 0; $noshow = 0; $match = 0; if ($FORM{'safe'} ne "on") { $safekey = "off"; } else { $safekey = "on"; } # Begin the search process and output the results unless (open (DATA,"$base")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @input = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); # Routine for 'words' search if ($FORM{'mode'} eq "words") { $searchstring=$FORM{'keywords'}; @words = split (/ /,$searchstring); foreach $word (@words) { $wordlength = length($word); if ($wordlength < $minword) { &stringshort; } } &heading; $entries = @input; if ($position == 0) { $currentline = $entries; } else { $currentline = $position; } $found="0"; print "
Search Results : '$FORM{'keywords'}'

"; print "
"; print ""; until ($found > 9 || $currentline == 0) { foreach $word (@words) { if ($input[$currentline] =~ /$word/i) { @data = split (/::/,$input[$currentline]); if ($data[4] ne "") { if ($safekey eq "on" && $match == 0) { foreach $smutword (@smutwords) { if ($input[$currentline] =~ /$smutword/i) { $smut = 1; } } unless ($smut == 1) { print "$data[1]
"; print "$data[4]
"; print "$data[0]

"; ++$found; ++$match; } $smut = 0; } if ($safekey eq "off" && $match == 0) { print "$data[1]
"; print "$data[4]
"; print "$data[0]

"; ++$found; ++$match; } } } } --$currentline; $match = 0; } } # Routine for 'phrases' search if ($FORM{'mode'} eq "phrases") { $searchstring=$FORM{'keywords'}; $wordlength = length($FORM{'keywords'}); if ($wordlength < $minword) { &phrase; } &heading; $entries = @input; if ($position == 0) { $currentline=$entries; } else { $currentline = $position; } print "

Search Results : '$FORM{'keywords'}'

"; print "
"; print ""; until ($found > 9 || $currentline == 0) { if ($input[$currentline] =~ /$FORM{'keywords'}/i) { @data = split (/::/,$input[$currentline]); if ($data[4] ne "") { if ($safekey eq "on") { foreach $smutword (@smutwords) { if ($input[$currentline] =~ /$smutword/i) { $smut = 1; } } unless ($smut == 1) { print "$data[1]
"; print "$data[4]
"; print "$data[0]

"; ++$found; } $smut = 0; } if ($safekey eq "off") { print "$data[1]
"; print "$data[4]
"; print "$data[0]

"; ++$found; } } } --$currentline; } } print ""; &footer; ################# SUBROUTINES ###################### sub heading { print "Content-type: text/html\n\n"; print "$heading"; } sub footer { $keyencode=$FORM{'keywords'}; $keyencode =~ tr/ /+/; if ($found > 9) { $position=$currentline; print "

More Results

"; } else { unless ($addshow == 1) { print "


\n"; } } unless ($noshow == 1) { unless ($addshow == 1) { print "

Search For :
WordsPhrase

\n"; } if ($FORM{'keywords'} ne "") { print "
Search for \"$FORM{'keywords'}\" in these search engines...
AltaVista DejaNews Excite GO Network HotBot Lycos WebCrawler Yahoo!

\n"; } } &generate; print "$footer"; exit; } sub error { $noshow = 1; &heading; print "

File Access Error

You have an error in your PATH configuration variables in the $ENV{'SCRIPT_NAME'} file.

Your server reports that your BASE path is : $ENV{'DOCUMENT_ROOT'}
Note that this is reported as your BASE path, not the FULL path to your files.

If you require help installing this script please consider purchasing the professional version of this script. Your purchase includes full tech support and installation.

Get it at : http://getperl.virtualave.net/easysearch/

\n"; &footer; } sub stringshort { $noshow = 1; print "Content-type: text/html\n\n"; &heading; print "

Word Too Short

Sorry...each word must be at least $minword characters long.

\n"; &footer; } sub phrase { $noshow = 1; print "Content-type: text/html\n\n"; &heading; print "

Phrase Too Short

Sorry...your phrase must be at least $minword characters long.

\n"; &footer; } sub generate { print ""; print ""; print ""; } sub showadd { &heading; $addshow = 1; print "

Add URL
\n"; print "Please fill out the following information and press the SUBMIT button.
\n"; print "Please note that all fields are required.

\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
E-mail :
Site Title :
Url :
Description :
Keywords :
(Commas, no spaces)

\n"; print "\n"; print "
\n"; &footer; } sub addurl { &heading; $noshow = 1; unless ($FORM{'url'} =~ /http:\/\//) { &submiterror; } if ($FORM{'url'} eq "" || $FORM{'title'} eq "" || $FORM{'email'} eq "" || $FORM{'description'} eq "" || $FORM{'keywords'} eq "") { ∅ } unless (open (DATA,"$base")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @input = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); $entries = @input; $urlsearch = "$FORM{'url'}"."::"; $urltemp = $FORM{'url'}; chomp($urltemp); chop($urltemp); $urlsearchtwo = "$urltemp"."::"; $urlsearchthree = "$FORM{'url'}"."/::"; $currentline = 0; until ($currentline == $entries) { if ($input[$currentline] =~ /$urlsearch/i) { &exists; } if ($input[$currentline] =~ /$urlsearchtwo/i) { &exists; } if ($input[$currentline] =~ /$urlsearchthree/i) { &exists; } ++$currentline; } $testline = $input[$currentline-1]; $testline2 = $input[$currentline-2]; $testline3 = $input[$currentline-3]; $testline4 = $input[$currentline-4]; $testline5 = $input[$currentline-5]; $testline6 = $input[$currentline-6]; $testline7 = $input[$currentline-7]; $testline8 = $input[$currentline-8]; $testline9 = $input[$currentline-9]; $testline10 = $input[$currentline-10]; if ($testline =~ /$FORM{'description'}/) { &samestuff; } if ($testline =~ /$FORM{'title'}/) { &samestuff; } if ($testline =~ /$FORM{'keywords'}/) { &samestuff; } if ($testline =~ /$FORM{'email'}/i || $testline2 =~ /$FORM{'email'}/i || $testline3 =~ /$FORM{'email'}/i || $testline4 =~ /$FORM{'email'}/i || $testline5 =~ /$FORM{'email'}/i || $testline6 =~ /$FORM{'email'}/i || $testline7 =~ /$FORM{'email'}/i || $testline8 =~ /$FORM{'email'}/i || $testline9 =~ /$FORM{'email'}/i || $testline10 =~ /$FORM{'email'}/i) { &justsubmitted; } $newemail = $FORM{'email'}; if ($FORM{'send'} ne "on") { $newemail = "X"."$newemail"."X"; } $newtitle = substr($FORM{'title'},0,$maxtitle); $newdesc = substr($FORM{'description'},0,$maxdescription); $newkeywords = substr($FORM{'keywords'},0,$maxkeywords); $line = join ("::","$FORM{'url'}","$newtitle","$newkeywords","$newemail","$newdesc"); unless (open (DATA,">>$base")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 2; } print DATA "$line\n"; if ($uselock eq '1') { flock DATA, 8; } close (DATA); print "

Submission Received

\n"; print "The following submission has been received by $sitetitle :
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
URL :$FORM{'url'}
Title : $FORM{'title'}
Keywords : $FORM{'keywords'}
Description : $FORM{'description'}
E-mail : $FORM{'email'}

\n"; if ($userespond eq '1') { unless (open (DATA,"$respondfile")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @respondinfo = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); foreach $respondline (@respondinfo){ $respondmessage = $respondmessage.$respondline; } open (MAIL, "|$mailprogram -t"); print MAIL "To: $FORM{'email'}\n"; print MAIL "From: $searchemail\n"; print MAIL "Subject: Got it!\n\n"; print MAIL "Welcome to the Webmaster's Search Engine!\n"; print MAIL "\n\n"; print MAIL "YOUR SUBMISSION:\n"; print MAIL "---------------------------------------------\n"; print MAIL "URL : $FORM{'url'}\n"; print MAIL "Title : $FORM{'title'}\n"; print MAIL "Description : $FORM{'description'}\n"; print MAIL "Keywords : $FORM{'keywords'}\n"; print MAIL "E-mail : $FORM{'email'}\n"; print MAIL "---------------------------------------------\n\n"; print MAIL "$respondmessage"; print MAIL "\n---------------------------------------------\n\n"; print MAIL "Thanks again\n"; print MAIL "---------------------------------------------\n"; print MAIL "$sitetitle\n"; print MAIL "$searchemail\n"; print MAIL "$searchurl\n"; print MAIL "---------------------------------------------\n"; close (MAIL); } &footer; } sub exists { $noshow = 1; print "

URL Already Exists


$FORM{'url'}
Sorry...Each URL is only allowed one entry.

\n"; &footer; } sub samestuff { $noshow = 1; print "

Recent URL Submission


You have recently submitted an URL with either the exact same title, description, or keywords. Since this is a different URL, please change your title, description and keywords to match this new page.

\n"; &footer; } sub justsubmitted { $noshow = 1; print "

Recent URL Submission


In order to avoid domain name overflow on the Newest URLs page,
we ask that you try your submission again later.

\n"; &footer; } sub empty { $noshow = 1; print "

Field Empty


Please make sure that you have filled in all fields on the form.

\n"; &footer; } sub submiterror { $noshow = 1; print "

Invalid URL


Please make sure that your URL contains http:// and is correct.

\n"; &footer; } sub newurls { &heading; unless (open (DATA,"$base")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @input = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); $entries = @input; print "

Newest URLs :
"; $currentline = $entries; print ""; $count = 0; until ($count == $numnew) { @data = split (/::/,$input[$currentline]); if ($data[4] ne "") { foreach $smutword (@smutwords) { if ($input[$currentline] =~ /$smutword/i) { $smut = 1; } } unless ($smut == 1) { print ("$data[1]
"); print ("$data[4]
"); print ("$data[0]

"); ++$count; } $smut = 0; } --$currentline; } print ""; &footer; } sub randomurl { &heading; unless (open (DATA,"$base")) {die (&error);} if ($uselock eq '1') { flock DATA, 2; seek DATA, 0, 0; } @input = ; if ($uselock eq '1') { flock DATA, 8; } close (DATA); $entries = @input; print "

Random URL :
"; $count=0; while ($count != 1) { srand (time + $$); $currentline = int( rand ($entries)); print ""; @data = split (/::/,$input[$currentline]); foreach $smutword (@smutwords) { if ($input[$currentline] =~ /$smutword/i) { $smut = 1; } } unless ($smut == 1) { if ($data[4] ne "") { print "$data[1]
"; print "$data[4]
"; print "$data[0]

"; $count=1; } } $smut = 0; } &footer; }