#!/usr/bin/perl # ------------------------------------------------------------------- # Program: swish-cgi.pl # Author : John Millard (millarj@muohio.edu) # # -------- User defined configuration variables ----------- # Optional parameters to pass to the SWISH searcher $params = " "; # The Full name of your organization -- Printed with Search Results # $organization = "Fornits Workshop"; # The full name of your department -- Printed with search Results # $department = "Swish-e Hack Shop"; # Open our Configuration file, you can edit this by running setup dbmopen(%Conf,"admin/conf/Init",undef); # Absolute path to your peaars installation $BasePath =$Conf{'PEAARSRoot'}; # Path to your http root for proper URL translation $httpRoot = $Conf{'HTTPRoot'}; # Absolute path and command to execute the SWISH searcher $swish = $Conf{'SwisheRoot'}; # URL of where you put this cgi $swishcgi = $ENV{'SCRIPT_NAME'};# $title = $Conf{'title'}; $head = `cat inc/head1.txt`; $body = `cat inc/body.txt`; $foot = `cat inc/foot.txt`; $dbase = $Conf{'dbase'}; $table = $Conf{'table'}; $imgpath = $Conf{'imgpath'}; $recipient = "curiosity\@fornits.com"; # ------ End of Configuration Variables ------------ use CGI qw(:all); #sub read_form # Read in form data if it exists read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the Name value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; push(@search_tags, $value), next if ($name eq 'search_tags'); $FORM{$name} = $value } if ($fetch=param('fetch')){ ## Compatability For the Old Peaars $BasePath =~ /$httpRoot(.*)/i; $tmp1 = $1; $swishcgi =~ /(^.*?)\/.*\..*/i; my $base="http://".$ENV{'HTTP_HOST'}.$tmp1.$1; dbmopen(%Articles,"OldArticleList",0775) || die $!; print "location: $base/$Articles{$fetch}\n\n"; exit; } if ($FORM{'query'}){ $query = $FORM{'query'}; $results =$FORM{'results'}; $month_limit= $FORM{'months'}; }elsif (param('query')){ $query = param('query'); #$FORM{'query'}; $results=0 unless $results = param('results'); #$FORM{'results'}; $month_limit=0 unless $month_limit=param('months');# $FORM{'months'}; }elsif (param('keywords')){ $query = param('keywords'); #$FORM{'query'}; $results=0 unless $results = param('results'); #$FORM{'results'}; $month_limit=0 unless $month_limit=param('months');# $FORM{'months'}; }else{ &html_header($head1," "); &print_form; &html_trailer; } if (@search_tags) { $tags = join("",@search_tags); $search_tags = "\-t $tags"; } else { $search_tags = ""; } if ($query){ &html_header($head1,"Your Search Results"); &print_form; &search_parse; &html_trailer; }else{ &html_header($head1," "); &print_form; &html_trailer; } sub print_form { my $count=0; @dir=<$BasePath/articles/*>; $month_options = "\n"; foreach $dir (reverse(@dir)){ if (-d $dir){ ++$count; $month_options .= "\n"; } } # To change the form that get's generated on the fly, edit the HTML below. print <

Search Form

Enter word(s). You can connect terms with and or or

Maximum # of Items
Months to go back

and will find items that contain both terms
or will find items that contain either word, but not necessarily both

Search In the following Tags: Leave Blank to search everything
Title Tags Heading Tags Comment Tags Emphasized Text

or Browse the archive.


EOF } sub search_parse # Run SWISH and parse output { #Initialize counter variable for number of results $count = 0; $month_count = 0; @dir=<$BasePath/articles/*>; foreach $dir (reverse(@dir)) { if (-d $dir) { ++$month_count; $dir =~ /^.*\/(\d*)/i; $index ="$BasePath/articles/$1/swish-$1.idx"; open(SWISH, "$swish -w $query -m $results $search_tags -f $index|")|| die "Cant open swish
$!"; while () { # First, check to see if search produced an error chop; #if ($_ eq "err: no results") #{&search_error("There were no items that matched your search request");} if ($_ eq "err: could not open index file") {&search_error("Could not open SWISH Index File $index");} if ($_ eq "err: no search words specified") {&search_error("Please Enter at least one Search Word");} if ($_ eq "err: a word is too common") {&search_error("One of your search terms is too common, please try again");} # Next Line ignores lines that begin with a non-digit next if /^\D/; $count++; push(@results, $_); } } last if ($month_count == $month_limit && $month_limit !=0) ; last if ($count == $results && $results != 0); } print "

Your Search for $query, returned $count Items

\n"; print "
    \n"; foreach (@results) { select(STDOUT); ($stringone, $title, $filesize) = split(/\"/, $_); ($rank, $url) = split(/ /, $stringone); open(IN,$url); undef($content); $go=0;$line=0; while(){ if (/[source|Date]\:/gi){$go =1}; if ($go==1){ last if length($content)>250 or $line ==50; ++$line; s/\<.*?\>//sgi; $content .= $_; } } $content = substr($content,0,350) if length($content) >250; $url =~ s/$httpRoot//i; print "
  1. $title
    \n"; print "http://$ENV{'HTTP_HOST'}$url
    "; print "
    $content
    \n" unless $content=~ /[<|>]/sgi; print "
    Relevancy Score:     $rank Size of Document: $filesize Bytes

    \n"; } print "

    \n"; } sub search_error { &html_header(head1,"Your Search Results"); $error_message = $_[0]; print "$error_message\n"; &html_trailer; } sub html_header # This subroutine takes the document title as a command # line parameter and adds header information to the top # of the HTML document to be returned. { print header(-type => 'text/html'), start_html(-title=>$_[1], -author=>'WebMistress@Fornits.com', -meta=>{'keywords'=>'keywords', 'copyright'=>'copyright 1998 Fornits\' Workshop'}, -bgcolor=>$Conf{'bgcolor'}, -LINK=>$Conf{'link'}, -ALINK=>$Conf{'alink'}, -VLINK=>$Conf{'vlink'}, -TEXT=>$Conf{'text'}, -background=>"$imgpath/$Conf{'background'}"), $_[0]; print '

    '; } sub html_trailer # This subroutine prints a suitable HTML trailer { print "

    \n"; print "$organization
    \n"; print "$department

    \n"; print '

    '; print "$foot\n"; print "\n\n"; exit; }