#!/usr/bin/perl ################################################################## # By BumbleBeeWare.com 2007 # Very Simple search program to search a specified web directory # easysearrch.cgi ################################################################## # configure # the directory with files you want to search $searchdir = "./"; # the file types you want to allow to be searched @filetypes = ('*.html','*.htm','*.txt'); # end configuration ###################### # print search form if($ENV{"REQUEST_METHOD"} ne "POST") { &print_form; exit;} # parse incoming form data read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); @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 files to search chdir($searchdir); # find all the files that match your file types only foreach $file (@filetypes){ $listedfiles = `ls $file`; @listedfiles = split(/\s+/,$listedfiles); # build an array of correct file types foreach $okfile (@listedfiles){ push(@OKFILES,$okfile); } } # read each file that matches your file type array foreach $file (@OKFILES){&search;} # print files with matching text $count = 0; print "Content-type: text/html\n\n"; print "
Search Results
"; foreach $file (keys %FILEOK) { # modify this html for your actual display output print "$TITLE{$file} ($file) - $FILEOK{$file}
\n"; $count++; } # show how many matches were found print "$count Matches Found
"; exit; ###################### # subroutines ###################### # search directory for matches sub search { $summary = ""; $filetext = ""; open (FILE, "$searchdir/$file"); @filetext=