#!/usr/bin/perl ############################################################################# # Simple Search Script # # Written By Matt Wright http://www.worldwidemart.com/scripts/ # # Created on: 12/16/95 # # Version 2.0 # # Last Modified on: 02/18/97 # # Modified by Ranson scripts@rlaj.com # # Scripts found at: http://www.artsearch.net/artsearch/zip # ############################################################################# # Define Variables # What is the base url of your files? - If this script is in say, cgi-bin, # then you need to tell the script to go back to your HOME Dir. to start the # search - to do this use ../ that means go up (back) one directory. # Use ../../ if you need to go up (back) two directories # You may need to use an absolute path here, example: # /www/users/public_html/ranson/ (ask your server administrator) $basedir = '../'; # What is the url of your home directory? $baseurl = 'http://www.abisource.com.au; # The name of this program $search_url = '/usr/lib/cgi-bin/search.cgi'; # If you want the user to be able to search individual directories, then # put a '1' in the $seperate_dir = '1'; variable - or '0' for no. $seperate_dir = '1'; # If you want users to be able to search individual directories, list the # directories below in the OPTION VALUE tags. # NOTE: before each quote (") you MUST have a backslash (\"), you will get # an error if you forget. sub seperate { # DO NOT CHANGE THE NEXT TWO LINES print " Area to Search \n"; } # DO NOT CHANGE THIS LINE # Where are your files you want to search? The default below will search # down 2 levels or subdirectories (* = base_dir. */ = base/sub etc.) @files = ('*.htm','*/*.htm','*/*/*.htm','*.html','*/*.html','*/*/*.html'); # If you use the sample text option enter the maxium number of charactors # to be returned to the user ( 100 equals about 20 words ) $sample_text = '200'; # Set to '0' if you do not want to use the sample text option $show_sample_text = '1'; # You have an option here to show specific text with the search results, # or the search engine will pick up the first # of charactors specified # in the '$show_sample_text' option above. ## If you want to show specific sample text with the search results ## set the next variable to '1' $specific_text = '0'; ## In your HTML file use this code for the sample text: ## Put sample text here ## The tags can be anywhere in your file, I suggest in the HEAD. #>>>>>>>>>>>>>>>>>>> BLANK FORM PAGE VARIABLES <<<<<<<<<<<<<<<<<<<<<# # Name of your homepage, for the blank form. # Also appears on the bottom of the search results page with a link (below). $homepage = "Abiword"; # What is the title of your blank form page? $title = "Abiword Search Engine"; # Page header $header = "Abiword"; # Body and background color $b_body = ''; #>>>>>>>>>>>>>>>>> SEARCH RESULTS PAGE VARIABLES <<<<<<<<<<<<<<<<<<<# # The Title for the search results page $SEARCH_RESULTS_TITLE = 'Search Results for Abiword'; # The Header for the search results page $SEARCH_RESULTS_HEADER = 'Search Results for Abiword'; # Body and background color $BODY = ''; # Logo and link that appears at the top of the page, text or image. $LOGO_LINK ='http://www.abisource.com'; $LOGO = ''; # Your homepage url $home_url = 'http://www.abisource.com'; # Text for bottom of page $COPY_RITE = 'Copyrite 1996 byArtSearch
all rights reserved.'; # Done . . . You shouldnt need to change anything below. # ############################################################################# if ($ENV{'REQUEST_METHOD'} eq "POST"){ # We are doing a Search # Parse Form Search Information &parse_form; # Get Files To Search Through &get_files; # Search the files &search; # See if we found anything - if not send the user a nothing found page $amount_found = grep(/yes/i, values(%include)); if ($amount_found == 0) { &no_results; } &return_html; }else{ &return_blank_form; # We are sending a blank form to the user } sub parse_form { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @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 get_files { $DIR = "$FORM{'directory'}"; if ($seperate_dir eq '1') { if ($FORM{'directory'} eq 'all') { @files = @files } else { @files = $DIR; } }else{ @files = @files } chdir($basedir); foreach $file (@files) { $ls = `ls $file`; @ls = split(/\s+/,$ls); foreach $temp_file (@ls) { if (-d $file) { $filename = "$file$temp_file"; if (-T $filename) { push(@FILES,$filename); } } elsif (-T $temp_file) { push(@FILES,$temp_file); } } } } sub search { @terms = split(/\s+/, $FORM{'terms'}); foreach $FILE (@FILES) { open(FILE,"$FILE"); @LINES = ; close(FILE); $string = join(' ',@LINES); $string =~ s/\n//g; if ($FORM{'boolean'} eq 'AND') { foreach $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if (!($string =~ /$term/i)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } elsif ($FORM{'case'} eq 'Sensitive') { if (!($string =~ /$term/)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } } } elsif ($FORM{'boolean'} eq 'OR') { foreach $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if ($string =~ /$term/i) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } elsif ($FORM{'case'} eq 'Sensitive') { if ($string =~ /$term/) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } } } if ($string =~ /(.*)<\/title>/i) { $titles{$FILE} = "$1"; } else { $titles{$FILE} = "$FILE"; } ## This is used to show a specific sample text hidden in your HTML page. if ($specific_text eq '1'){ if ($string =~ /<\!\$>(.*)<\!\/\$>/i) { $sample{$FILE} = "$1"; } }else{ ## This will read the first # of charactors of text in your HTML page. $sample{$FILE} = "$string"; $sample{$FILE} =~ s/<head> (.*)<\/head>//gi; $sample{$FILE} =~ s/\t / /g; $sample{$FILE} =~ s/<([^>]|\n)*>//g; $sample{$FILE} = (substr($sample{$FILE},0,$sample_text)); } } } #####################.No Results Sub-routine.########################### sub no_results { print "Content-type: text/html\n\n"; print "<html><head><title>No Results\n"; print "$BODY\n"; print "
"; print "$LOGO\n"; print "

\n"; print "

\n"; print "

\n"; print "There are no matching files for: "; print "\n"; $i = 0; foreach $term (@terms) { print "$term"; $i++; if (!($i == @terms)) { print ", "; } } print" \n"; print <<'END_OF_HTML';

\n"; } print "

\n