Make your own free website on Tripod.com
# Parse Form Search Information &parse_form; # Get Files To Search Through &get_files; # Search the files &search; # Print Results of Search &return_html; 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 { 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"; } } } sub return_html { print "Content-type: text/html\n\n"; print "<html>\n <head>\n <title>Results of Search\n \n"; print "\n
\n

Results of Search in $title

\n
\n"; print "Below are the results of your Search in no particular order:


\n"; print "

\n"; print "
\n"; print "Search Information:

\n"; print "



\n"; print "

\n"; print "
\n"; print "Search Script written by Matt Wright and can be found at Matt's Script Archive\n"; print "\n\n"; }