#!/usr/bin/perl -Tw # search-CGI.pl - by dual # # Performs queries using a # reverse keyword index ########################## use strict; use CGI qw(:standard); # Boot 'em if there's funny business sub error { print header(); print start_html(); print "I don't think so..."; print end_html(); exit; } # Prevent empty GETs error() unless defined( my $query = param("query") ); # Whitelist the query error() if $query =~ /[^ \w]/; # Prevent empty POSTs error() unless $ENV{'CONTENT_LENGTH'} > 6; # Limit overly long queries server-side # (Thanks, minddog!) my @word = split(//, $query); error() unless (scalar @word < 51); # Print opening HTML print header(); print < Results EOF # Print header print "

These results were found for the query $query.

\n"; # Perform the search open INDEX, "\n"; print "
    \n"; while () { if ($_ =~ /\b$query\b/i) { my ($temp, undef) = split(/=>/, $_); my ($dir, $title) = split(/\//, $temp); print "
  1. $title
  2. \n"; } } # Close HTML and INDEX print "
\n"; print ""; print end_html(); close INDEX;