www.pudn.com > rsSearch.zip > rssearch.pl, change:1998-12-16,size:9203b


#!/usr/local/bin/perl 
my($version) = "1.22"; 
my($incSub); 
############################################################################# 
# jasearch.pl - Simple search script - Version 1.1a - Released 18/02/97 
# 
# requires 4 paramaters from form 
# 
# 'sv'    = search value 
# 'type'  = all terms or any terms 
# 'base'  = base directory to search 
# 'rbase' = returned base 
# 
# optionals 
# 
# 'background' = gif to display as background 
# 'text'       = text colour 
# 'link'       = colour of links 
# 'alink'      = colour of active link 
# 'vlink'      = colour of visited links 
# 'bgcolor'    = colour of background 
# 'log'        = log file 
# 
# base = /home/jason & rbase = http://www.aquapal.co.uk 
# 
# /home/jason/jason.html would be http://www.aquapal.co.uk/jason.html 
# 
# This script is Copyright 1997 Jason Anthony, janthony@aquapal.co.uk 
############################################################################# 
# 為了對原作者表示尊重,本程式前段表頭保留不動,以下為傅鴻銘修改之版本: 
# 本 1.22 版修改者: 
#   姓名:傅鴻銘 
#   信箱:redsnow@pemail.net 
#   網頁:http://tacocity.com.tw/redsnow/ 
# 程式名稱:網頁搜尋程式 
# 最初修改日期:12/22/1997 
# 最後修改日期:11/07/1998 
 
 
&readForm; 
 
$incSub = 1; 
if (lc($FORM{'subdir'}) eq "no") { $incSub = 0; } 
 
 
&printHtmlTop; 
&checkFiles($FORM{'base'}); 
&printHtmlBottom; 
 
exit; 
 
############################## 
 
sub printHtmlTop { 
# prints top part of html file, upto the list of files..... 
    if ($FORM{'log'} ne "") { doLog(); } 
 
    print "Content-type: text/html\n\n"; 
    print "<HTML><HEAD><TITLE>Search Results</TITLE></HEAD>\n"; 
 
    print "<STYLE type=\"text/css\">\n"; 
    print "<!--\n"; 
    print "SMALL {font-size: 9pt}\n"; 
    print "-->\n"; 
    print "</STYLE>\n"; 
 
    print "<BODY"; 
    $body = ""; 
 
    if ($FORM{'bgcolor'} ne "") { $body = "$body BGCOLOR=\"$FORM{'bgcolor'}\" "; } 
    if ($FORM{'text'} ne "") { $body = "$body TEXT=\"$FORM{'text'}\" "; } 
    if ($FORM{'link'} ne "") { $body = "$body LINK=\"$FORM{'link'}\" "; } 
    if ($FORM{'alink'} ne "") { $body = "$body ALINK=\"$FORM{'alink'}\" "; } 
    if ($FORM{'vlink'} ne "") { $body = "$body VLINK=\"$FORM{'vlink'}\" "; } 
    if ($body eq "") { $body = " BGCOLOR=\"#FFFFFF\""; } 
    print "$body>\n"; 
 
    $bg = ""; 
    if ($FORM{'background'} ne "") { $bg = "$bg BACKGROUND=\"$FORM{'background'}\""; } 
    print "<table width=\"100%\"><tr><td$bg>\n"; 
 
    print "<br><CENTER><FONT COLOR=\"#FF0000\" SIZE=\"6\" FACE=\"標楷體\"><STRONG>搜尋結果</STRONG></FONT></CENTER><HR><P>\n"; 
    print "<FORM METHOD=\"post\" ACTION=\"$ENV{'SCRIPT_NAME'}\">\n"; 
    print "<INPUT TYPE=\"hidden\" NAME=\"base\" VALUE=\"$FORM{'base'}\">\n"; 
    print "<INPUT TYPE=\"hidden\" NAME=\"rbase\" VALUE=\"$FORM{'rbase'}\">\n"; 
    if ($FORM{'background'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$FORM{'background'}\">\n"; } 
    if ($FORM{'bgcolor'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$FORM{'bgcolor'}\">\n"; } 
    if ($FORM{'text'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"text\" VALUE=\"$FORM{'text'}\">\n"; } 
    if ($FORM{'link'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"link\" VALUE=\"$FORM{'link'}\">\n"; } 
    if ($FORM{'alink'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"alink\" VALUE=\"$FORM{'alink'}\">\n"; } 
    if ($FORM{'vlink'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"vlink\" VALUE=\"$FORM{'vlink'}\">\n"; } 
    if ($FORM{'log'} ne "") { print "<INPUT TYPE=\"hidden\" NAME=\"log\" VALUE=\"$FORM{'log'}\">\n"; } 
    print " 以 "; 
    print "<SELECT NAME=\"type\">\n"; 
    print "<OPTION VALUE=\"AND\""; 
    if ($FORM{'type'} eq "AND") { print " SELECTED"; } 
    print ">AND\n"; 
    print "<OPTION VALUE=\"OR\""; 
    if ($FORM{'type'} eq "OR") { print " SELECTED"; } 
    print ">OR\n"; 
    print "</SELECT>\n"; 
    print " 的邏輯條件搜尋 "; 
    print "<INPUT TYPE=\"text\" NAME=\"sv\" VALUE=\"$FORM{'sv'}\">"; 
    print " 字句  \n"; 
    print "<INPUT TYPE=\"submit\" VALUE=\"開始搜尋\">\n"; 
    print "<INPUT TYPE=\"reset\" VALUE=\"重新設定\"></FORM>\n"; 
    print "</td></tr></table>\n"; 
    print "<UL>\n"; 
} 
 
sub printHtmlBottom { 
# prints last part of html file after list of files.... 
    print "</UL>\n"; 
 
    print "<font color=\"#FF0000\">"; 
    if ($numberreturned == 0) { 
        print " <H2>抱歉!未找到符合搜尋條件的資料。</H2>"; 
    } else { 
	print "<P>"; 
	print " "; 
	if (!($numberreturned == 1)) { 
		print "共"; 
	} else { 
		print "僅"; 
	} 
        print "找到 <font color=\"#0000FF\">$numberreturned</font> 筆符合的資料"; 
    } 
    print "</font>\n"; 
 
    $bg = ""; 
    if ($FORM{'background'} ne "") { $bg = "$bg BACKGROUND=\"$FORM{'background'}\""; } 
    print "<table width=\"100%\"><tr><td$bg>\n"; 
 
    print "<br><CENTER>rssearch.pl V$version<BR>"; 
    print "本網頁搜尋程式由 <A HREF=\"http://tacocity.com.tw/redsnow/index.htm\">紅雪網頁</A> 改自 <A HREF=\"http://www.aquapal.co.uk/jason.html\">Jason Anthony</A> 所設計 1.1e 版的 jasearch.pl</CENTER><br>\n"; 
    print "</td></tr></table>\n"; 
    print "</BODY>\n</HTML>\n"; 
} 
 
 
sub readForm { 
# reads data pairs from form 
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); 
    if ($buffer eq "") { $buffer = $ENV{'QUERY_STRING'}; } 
 
    @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{lc($name)} = $value; 
    } 
 
    @search = split( / /, $FORM{'sv'}); 
    my($numberreturned) = 0; 
 
    $multiext = 0; 
    if ($FORM{'ext'} ne "") {  
	@fileext = split(/;/,$FORM{'ext'}); 
        $multiext = 1; 
    } 
}    
 
sub checkFiles { 
# read files in directory, passed as first paramater 
    my($path) = shift; 
    my($fullFilename); 
    my(@files); 
    my(@lines); 
    my($line); 
    my($title); 
 
    opendir(ROOT,$path); 
    @files = readdir(ROOT); 
    closedir(ROOT); 
 
    foreach (@files) { 
	 next if /^\.|\.\.$/; 
 
	 $fullFilename = "$path/$_"; 
	 $index = -1; 
	 $kword = ""; 
 
	 if (-d $fullFilename) { 
	    if ($incSub > 0) { checkFiles($fullFilename); } 
	    next; 
	 } 
 
	 $gocheck = 0; 
	 if ($multiext > 0) { 
            foreach $ext (@fileext) { 
	       if ($fullFilename =~ m/\.$ext/) { 
	          $gocheck = 1; 
	          last; 
	       } 
	    } 
	 } else { 
	    if ($fullFilename =~ m/\.htm/) { 
	       $gocheck = 1; 
	    } 
         } 
 
	 if ($gocheck > 0) { 
	    open(FILE, $fullFilename); 
	    @lines = <FILE>; 
	    close(FILE); 
 
	    $line = join(' ',@lines); 
	    $line =~ s/\n//g; 
	    $title = "No Title"; 
 
	    if ($line =~ m!<title>(.+?)</title>!i) { $title = $1; } 
 
	    if ($line =~ m!NOSEARCH!i) { 
	       $found = 0; 
	    } else { 
	       if ($line =~ m!<body(.+)</body>!i) { $line = $1; } 
 
	       $line =~ s/(<!--.*?-->)//g; 
	       $line =~ s/<([^>]|\n)*>//g; 
 
	       if ($FORM{'type'} =~ m/AND/i ) { 
	          $found = 1; 
	          foreach $se (@search) { 
		       if ($kword eq "") { $kword = $se; } 
		       $ss = quotemeta $se; 
		       if ($line !~ m/$ss/i) { 
			    $found = 0; 
			    last; 
		       } 
		    } 
	       } else { 
		    $found = 0; 
		    foreach $se (@search) { 
			 $ss = quotemeta $se; 
			 if ($line =~ m/$ss/i) { 
			    if ($kword eq "") { $kword = $se; } 
			    $found = 1; 
			    last; 
			 } 
		    } 
	       } 
	    } 
 
	    if ($found == 1 ) { 
	       $tmp = $fullFilename; 
	       $tmp =~ s/$FORM{'base'}//; 
	       $tmp = "$FORM{'rbase'}$tmp"; 
 
	       $size = -s "$fullFilename"; 
	       if ($size >= 1024) {$size = int($size/1024) . " KB";} 
	       else {$size = "$size Bytes";} 
	       print "<LI><a href=\"$tmp\">$title</a> ($size)<br>\n"; 
 
	       $line2 = $line; 
	       $line2 =~ tr/A-Z/a-z/; 
	       $kword =~ tr/A-Z/a-z/; 
	       $index = index($line2, $kword); 
	       $aa = substr($line,$index,300); 
	       print "$aa\n"; 
	       $mtime = (stat($fullFilename))[9]; 
	       $update = &Get_Date; 
	       print "<BR><SMALL><FONT COLOR=\"#009900\">最後更新時間: $update</FONT></SMALL><P>\n"; 
	       $numberreturned++; 
	    } 
	 } 
    } 
} 
 
sub doLog { 
#write details of use to log file 
   my($site); 
 
   $site = $ENV{'REMOTE_HOST'}; 
   if ($site eq "") { 
      $site = $ENV{'REMOTE_ADDR'}; 
   } 
   if (!(-e "$FORM{'log'}" )) { 
      open( OUTFILE,">$FORM{'log'}") or return; 
      print OUTFILE "\"searh value\",\"search type\",\"time\",\"remote site\"\n"; 
      close(OUTFILE); 
   } 
   open( OUTFILE,">>$FORM{'log'}") or return; 
   print OUTFILE "\"$FORM{'sv'}\",\"$FORM{'type'}\",\"" . localtime() . "\",\"$site\"\n"; 
   close( OUTFILE ); 
} 
 
sub Get_Date { 
   $mtime = time unless ($mtime); 
   ($min,$hour,$mday,$mon,$year,$wday) = (localtime($mtime))[1,2,3,4,5,6]; 
 
   $year += 1900;  
   $mon++; 
   $week = ('日','一','二','三','四','五','六')[$wday];  
   $date = sprintf("$year年%02d月%02d日, 星期$week, %02d:%02d時", $mon, $mday, $hour, $min); 
   $shortdate = "$mon/$mday/$year $hour:$min:$sec $isdst"; 
 
   return $date; 
}