#!/usr/local/bin/perl #################################################################### # URL Search Engine # Copyright 1996 Techno Trade http://www.technotrade.com # Written By : Sammy Afifi sammy@technotrade.com # Date Last Modified : Jan 14, 1997 #################################################################### # # This script is free of charge. # Please link back to http://technotrade.com, thank you :-) ####### # # Jan 14, stops people from entering html tags, converts < to < # #################################################################### # $linktitle, $linkdescrip, $linkwords, $linkemail, $linkurl # define some global variables $fields = 5; # Number of fields in each record $filename = "urls.txt"; # The database text file $results = 1000; # maximum number of results to display &parse_form; $searchstring = $FORM{'searchstring'}; &addrecord if ($searchstring eq "**ADD RECORD**"); &open_file("FILE1","",$filename); print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "Search Results\n"; print "

\n"; print "Search Results
\n"; print "

\n"; if ($counter == 0) { print "
Sorry, No Matches were found.\n"; } print "
\n"; print "
\n"; print "URL Search Brought to you by : Techno Trade's CGI Archive
\n"; print "\n"; print "\n"; ######################################### # # Print the matched record # ######################################### sub print_record { print "
\n"; print "
  • " . $linktitle . " : $linkdescrip
    \n"; } ########################################## # # Check to see if record matches search criteria # ########################################## sub check_record { # get the data from the record read from the file. $tabledata $linktitle = $tabledata[0]; $linkdescrip = $tabledata[1]; $linkwords = $tabledata[2]; $linemail = $tabledata[3]; $linkurl = $tabledata[4]; chop($linkurl); #build the search line with all fields we want to search in $searchline = $linktitle . " " . $linkdescrip . " " . $linkwords; #search by keywords # only perform the keyword search if the length of the search string is greater than 2 # don't think we want people to search for and or or etc. $sfound = 0; $found = 0; $notfound = 1; $stlen = length($searchstring); if ($stlen > 1) { @words = split(/ +/,$searchstring); foreach $aword (@words) { if ($searchline =~ /\b$aword/i) { $sfound = 1; } else { $notfound = 0; } } } if ($sfound == 1 && $notfound == 1) { $found = 1; } # if search string is too small .. set found to 1 if ($stlen <= 1) { $found = 1; } #if page doesn't have a title then return not found $tlen = length($linktitle); if ($tlen < 1) { $found = 0; } } ############################################ # # Add Record # ############################################ sub addrecord { $linktitle = $FORM{'linktitle'}; $linkdescrip = $FORM{'linkdescrip'}; $linkwords = $FORM{'linkwords'}; $linkemail = $FORM{'linkemail'}; $linkurl = $FORM{'linkurl'}; # Convert < tags to < $linktitle =~ s/>",$filename); &write_file("FILE1",$linktitle . "|". $linkdescrip. "|" .$linkwords ."|" .$linkemail ."|" .$linkurl ."\n"); close(FILE1); print "Content-type: text/html\n\n"; print "Thank You\n"; print "

    Thank You For Adding to this database

    \n"; print "\n"; exit; } sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @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; } } sub open_file { local ($filevar, $filemode, $filename) = @_; open ($filevar,$filemode . $filename) || die ("Can't open $filename"); } sub read_file { local ($filevar) = @_; <$filevar>; } sub write_file { local ($filevar, $line) = @_; print $filevar ($line); }