#! /usr/local2/mosaic/bin/perl # libsearch.pl # written by Huijie Chen for searching library's home pages. # this is the location of library pages $homedir = "/usr/local2/WebUsers/library/v2/"; $pcnt = 0; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs=split(/&/, $buffer); # this is the name-value apir splitter... put into $form array 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; } if (($FORM{$key1} lt "") && ($FORM{$key2} lt "")) { #invalid search } else { if (($FORM{$key1} lt "") || ($FORM{$key2} lt "")) { if ($FORM{$key1} lt "") { $FORM{$key1} = $FORM{$key2}; } $qtype = 3; } else { $qtype = $FORM{$case}; } # search all the .html file in the current dir foreach $file (<$homedir*.htm*>) { $found = 0; #read the entire file into a variable open(HTML, $file); undef $/; $body=; $/="\n"; close(HTML); #check to seee if it contains the key(s) if (($qtype==3) && ($body=~/$FORM{key1}/i)) { $found=1; } else { if (($qtype==1) && (($body=~/$FORM{key1}/i) || ($body=~/$FORM{key2}/i))) { $found=1; } else { if (($qtype==2) && ($body=~/$FORM{key1}/i) && ($body=~/$FORM{key2}/i)) { $found=1; } } # push the data array if found if ($found == 1) { $file =~ s($homedir)(); push(@doclist,$file); $pcnt += 1; if ($body =~//i) { @tbuffer = split(/<\/title>/i, $body); $body = @tbuffer[0]; @tbuffer = split(/<title>/i, $body); $body = @tbuffer[1]; if ($body gt "") { push(@tilist, $body); } else { push(@tilist, "(no title information available)"); } } else { push(@tilist, "(no title information available)"); } } } # Print the results in HTML form to the browser ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $day=(Sunday,Monday,Tuesday,Wednesday,Thursday,Frieday,Saturday)[$wday]; $month=(January,Febuary,March,April,May,June,July,August,September,October,November,December)[$mon]; print "Content-type: text/html\n\n"; print "<HTML>\n<TITLE>Search Results\n"; print "\n"; print "\n"; print "\"Penn\n"; print "

Search Reresult<\/H2>

\n"; print "
Report Time: $day $month $mday, 19$year $hour: $min:$sec

\n"; print "


There is/are $pcnt document(s) containing the word/phrase$FORM{key}, sorted by file name.\n

\n"; print "\n"; $pcnt = 0; foreach $name (@doclist) { print " "; print " \n"; $pcnt += 1; } print "
$name......@tilist[$pcnt]
\n"; print "


* * * end of the report * * *
\n"; print "
\n\n"; } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $day=(Sunday,Monday,Tuesday,Wednesday,Thursday,Frieday,Saturday)[$wday]; $month=(January,Febuary,March,April,May,June,July,August,September,October,November,December)[$mon]; print "Content-type: text/html\n\n"; print "\nSearch Results\n"; print "\n"; print "\n"; print "\"Penn\n"; print "

Search Reresult<\/H2>

\n"; print "
Report Time: $day $month $mday, 19$year $hour: $min:$sec

\n"; print "


You didn't input any search term. Please go back and try again.\n"; print "
* * * end of the report * * *
\n"; print "
\n\n"; } }