home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- ##############################################################################
- # Simple Search Version 1.0 #
- # Copyright 1996 Matt Wright mattw@worldwidemart.com #
- # Created 12/16/95 Last Modified 12/16/95 #
- # Scripts Archive at: http://www.worldwidemart.com/scripts/ #
- ##############################################################################
- # COPYRIGHT NOTICE #
- # Copyright 1996 Matthew M. Wright All Rights Reserved. #
- # #
- # Simple Search may be used and modified free of charge by anyone so long as #
- # this copyright notice and the comments above remain intact. By using this #
- # code you agree to indemnify Matthew M. Wright from any liability that #
- # might arise from it's use. #
- # #
- # Selling the code for this program without prior written consent is #
- # expressly forbidden. In other words, please ask first before you try and #
- # make money off of my program. #
- # #
- # Obtain permission before redistributing this software over the Internet or #
- # in any other medium. In all cases copyright and header must remain intact.#
- ##############################################################################
- # Define Variables #
-
- $basedir = '/www/doc/servery/';
- $baseurl = 'http://servery.cz/';
- #@files = ('*.shtml','demos/links/*.html','demos/guest/*.html');
- @files = ('*.html','faq/*.html','gesto/*.html','help/*.html','navod/*.html');
- $title = "SERVERY.CZ";
- $title_url = 'http://servery.cz/navod/';
- $search_url = 'http://servery.cz/navod/search.html';
-
- # Done #
- ##############################################################################
-
- # Parse Form Search Information
- &parse_form;
-
- # Get Files To Search Through
- &get_files;
-
- # Search the files
- &search;
-
- # Print Results of Search
- &return_html;
-
-
- sub parse_form {
-
- # Get the input
- read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
-
- # Split the name-value pairs
- @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;
- }
- }
-
- sub get_files {
-
- chdir($basedir);
- foreach $file (@files) {
- $ls = `ls $file`;
- @ls = split(/\s+/,$ls);
- foreach $temp_file (@ls) {
- if (-d $file) {
- $filename = "$file$temp_file";
- if (-T $filename) {
- push(@FILES,$filename);
- }
- }
- elsif (-T $temp_file) {
- push(@FILES,$temp_file);
- }
- }
- }
- }
-
- sub search {
-
- @terms = split(/\s+/, $FORM{'terms'});
-
- foreach $FILE (@FILES) {
-
- open(FILE,"$FILE");
- @LINES = <FILE>;
- close(FILE);
-
- $string = join(' ',@LINES);
- $string =~ s/\n//g;
- if ($FORM{'boolean'} eq 'AND') {
- foreach $term (@terms) {
- if ($FORM{'case'} eq 'Insensitive') {
- if (!($string =~ /$term/i)) {
- $include{$FILE} = 'no';
- last;
- }
- else {
- $include{$FILE} = 'yes';
- }
- }
- elsif ($FORM{'case'} eq 'Sensitive') {
- if (!($string =~ /$term/)) {
- $include{$FILE} = 'no';
- last;
- }
- else {
- $include{$FILE} = 'yes';
- }
- }
- }
- }
- elsif ($FORM{'boolean'} eq 'OR') {
- foreach $term (@terms) {
- if ($FORM{'case'} eq 'Insensitive') {
- if ($string =~ /$term/i) {
- $include{$FILE} = 'yes';
- last;
- }
- else {
- $include{$FILE} = 'no';
- }
- }
- elsif ($FORM{'case'} eq 'Sensitive') {
- if ($string =~ /$term/) {
- $include{$FILE} = 'yes';
- last;
- }
- else {
- $include{$FILE} = 'no';
- }
- }
- }
- }
- if ($string =~ /<title>(.*)<\/title>/i) {
- $titles{$FILE} = "$1";
- }
- else {
- $titles{$FILE} = "$FILE";
- }
- }
- }
-
- sub return_html {
- print "Content-type: text/html\n\n";
- print "<html>\n <head>\n <title>SERVERY.CZ - V²sledky hledßnφ</title>\n </head>\n";
- print "<BODY background=\"img/o5.gif\" bgcolor=\"#FFE7A2\" text=\"#271E9F\" link=\"#846300\" vlink=\"gray\" alink=\"red\">\n <center>\n <FONT FACE=\"Arial CE\"><br><blockquote><h1>V²sledky hledßnφ na $title</h1>\n </center></blockquote><FONT SIZE=\"-1\">\n";
- print "<br><hr width=75%>\n";
- print "<blockquote><ul>\n";
- foreach $key (keys %include) {
- if ($include{$key} eq 'yes') {
- print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
- }
- }
- print "</ul></blockquote>\n";
-
- ##########
- ##########
-
- print "<hr width=75%><blockquote>\n";
- print "Vyhledßno podle:<p>\n";
- print "<ul>\n";
- print "<li><b>V²raz:</b> ";
- $i = 0;
- foreach $term (@terms) {
- print "$term";
- $i++;
- if (!($i == @terms)) {
- print ", ";
- }
- }
- print "\n";
- print "<li><b>Logika:</b> $FORM{'boolean'}\n";
- print "<li><b>VELK┴/malß pφsmena:</b> $FORM{'case'}\n";
- print "</ul></blockquote>\n";
-
- #print "</ul><br><hr width=75%><P>\n";
- #print "<ul>\n<li><a href=\"$search_url\">Back to Search Page</a>\n";
- #print "<li><a href=\"$title_url\">$title</a>\n";
- #print "</ul></blockquote>\n";
- #print "<hr width=75%>\n";
- #print "Search Script written by Matt Wright and can be found at <a href=\"http://www.worldwidemart.com/scripts/\">Matt's Script Archive</a>\n";
-
- ##########
- ##########
-
-
- print "<HR width=75%><blockquote><FONT SIZE=\"-1\" FACE=\"Arial CE\">Tento vyhledßvacφ script je";
- print " souΦßstφ standardnφho scriptovΘho vybavenφ dodßvanΘho zßkaznφkum slu₧by SERVERY.CZ\n";
- print "</FONT></blockquote></center><CENTER><A HREF=\"http://www.globe.cz\" target=\"_blank\">";
- print "<IMG SRC=\"img/globelogo.gif\"border=0 ALT=\"Globe Internet, s.r.o.\"></A></CENTER>";
-
- print "</body>\n</html>\n";
- }
-
-