#!/usr/bin/perl -w use HTML::Parser; #The following code deals with the form data if ($ENV{'REQUEST_METHOD'} eq 'POST') { 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; } } #######instead of the above code use the CGI module. #HTML::Parser stuff. Stolen from the HTML::Parser package's htext #example my $keyword; my $hit; my $title; my %inside; sub htmltag { my($tag, $num) = @_; $inside{$tag} += $num; } sub htmltext { return if $inside{script} || $inside{style}; $title = $_[0] if ($inside{title}); $hit = 1 if ($_[0] =~ /$keyword/); } my $parser = HTML::Parser->new( 'api_version' => 3, 'handlers' => [start => [\&htmltag, "tagname, '+1'"], end => [\&htmltag, "tagname, '-1'"], text => [\&htmltext, "dtext"], ], 'marked_sections' => 1); $keyword=$FORM{keyword}; print "Content-type: text/html\n\n"; print "

Here are the files we found

\n\n"; chdir("/usr/local/etc/httpd"); opendir(DIR, "."); while($file = readdir(DIR)) { next if ($file !~ /.htm/); $hit = 0; $title = ""; %inside = (); open(FILE, $file) || die "couldnt open $!"; $parser->parse(\*FILE)->eof; close(FILE); if($hit) { $title = $file unless ($title); print "$title
"; $listed=1; } }