#!/usr/bin/perl require 5; use strict; =item header Fluid Dynamics Search Engine, Version 2.x Copyright 1997-2000 by Zoltan Milosevic. Please adhere to the copyright notice and conditions of use, described in the attached help file and hosted at the URL below. For the latest version and help files, visit: http://www.xav.com/scripts/search/ This search engine is managed from the web, and it comes with a password to keep it secure. You can set the password when you first visit this script using the special "Mode=Admin" query string - for example: http://my.host.com/search.pl?Mode=Admin =cut my $all_code = <<'END_OF_FILE'; use vars qw( $VERSION $realms %const %FORM %Rules @MonthNames @SearchTerms ); $VERSION = '2.0.0.0009'; # Give location relative to this script: my $DataFilesDir = 'searchdata'; %const = ( 'help_file' => 'http://www.xav.com/scripts/search/admin_help.html', 'script_start_time' => time, 'script_name' => $ENV{'SCRIPT_NAME'}, 'admin_url' => $ENV{'SCRIPT_NAME'} . '?Mode=Admin', 'form_password' => '', 'request_method' => 'POST', 'log_file' => 'search.log.txt', 'temp_file' => 'search.temp.txt', 'back_file' => 'search.back.txt', 'pending_file' => 'search.pending.txt', 'realm_file' => 'search.realms.txt', 'file_mask' => 0766, ); @MonthNames = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); my $No_Documents_Found = <<"EOM";
Results: No documents were found.EOM my ($is_error, $error_message, $Header, $Footer); MainBlock: { ($is_error, $error_message, $Header, $Footer) = load_files($DataFilesDir); if ($is_error) { print "Content-Type: text/html\015\012\015\012"; print "
$error_message
"; last MainBlock; } %FORM = ReadInput(); if ($FORM{'NextLink'}) { # security re-director from admin screen (prevents query-string-based # password from showing up in referer logs of remote systems: print "Content-Type: text/html\015\012\015\012"; print <<"EOM"; $FORM{'NextLink'} EOM } elsif ($FORM{'Mode'} eq 'AnonAdd') { print "Content-Type: text/html\015\012\015\012"; print $Header; if (defined($FORM{'Realm'}) and defined($FORM{'URL'})) { &AddURL(0, 1, $FORM{'Realm'}, $FORM{'URL'}); } &PrintAddRemoteSiteForm('Add Your Own Website', '', $FORM{'Realm'}, 1); &PrintFooter($Footer, $Rules{'allowanonadd'}); } elsif (($FORM{'Mode'} ne 'Admin') and (not $FORM{'Terms'})) { print "Content-Type: text/html\015\012\015\012"; print $Header; &SearchForm; my ($ErrorMsg, $FileText) = ReadFile("templates/tips.htm"); if ($ErrorMsg) { print "$ErrorMsg
"; } else { print $FileText; } &PrintFooter($Footer, $Rules{'allowanonadd'}); } elsif ($FORM{'Mode'} ne 'Admin') { print "Content-Type: text/html\015\012\015\012"; # Anonymous search engine code: # Idea: add all non-forbidden terms as a string and add that as a phrase # with highest priority. Multiply hit relevance by length of string to # give longer search terms and phrases more weight. # This controls the display, so these extra terms aren't shown to the user: my $Rank = $FORM{'Rank'} ? $FORM{'Rank'} : 1; my ($bTermsExist, $Ignored_Terms, $Important_Terms, $DocSearch, $RealmSearch, @search_terms) = &parse_search_terms($FORM{'Terms'}, $FORM{'Match'}); @SearchTerms = @search_terms; my $Realm = $FORM{'Realm'} ? $FORM{'Realm'} : 'All'; my $NumPagesSearched = 0; my @HITS = (); if ($bTermsExist) { # Search terms have been formatted. Now search the database(s): # each sub populates @HITS as needed. # If Realm is specific, search it - otherwise search all: if ($Realm ne 'All') { my ($type, $file) = $realms->lookup($Realm, 'type', 'file'); if ($type == 1) { ($NumPagesSearched, @HITS) = SearchRunTime($Realm, $DocSearch); } else { ($NumPagesSearched, @HITS) = SearchIndexFile($file, $RealmSearch); } } else { my $RH; my ($pages_searched, @hits) = (0); foreach $RH ($realms->list('has_file')) { ($pages_searched, @hits) = SearchIndexFile($$RH{'file'}, $RealmSearch); push(@HITS, @hits); $NumPagesSearched += $pages_searched; } foreach $RH ($realms->list('is_runtime')) { ($pages_searched, @hits) = SearchRunTime($$RH{'name'}, $DocSearch); push(@HITS, @hits); $NumPagesSearched += $pages_searched; } } } else { print ""; } my ($HitCount, $PerPage, $Next, $summary) = (scalar @HITS, $Rules{'hits per page'}); if (($FORM{'maxhits'} =~ m!^(\d+)$!) and ($FORM{'maxhits'} > 0)) { $PerPage = $1; } my $Remaining = $HitCount - $Rank - $PerPage + 1; my $RangeUpper = $Rank + $PerPage - 1; if ($Remaining >= $PerPage) { $Next = $PerPage; } elsif ($Remaining > 0) { $Next = $Remaining; } else { $RangeUpper = $HitCount; } if ($Ignored_Terms) { $summary = "\n"; my $i = $Rank; foreach ((reverse sort @HITS)[($Rank-1)..($RangeUpper-1)]) { next unless (m!^(\d+)\.(\d+) u= (.+) t= (.*?) d= (.*?) $!); my ($relevance, $URL, $Title, $Description) = ($1, $3, $4, $5); my ($DD, $MM, $YYYY, $FBYTES) = (unpack('A2A2A2A4A*', $2))[1..4]; print StandardVersion($i, $URL, $Title, $Description, $FBYTES, $DD, $MonthNames[$MM], $YYYY); $i++; } print "Documents $Rank-$RangeUpper of $HitCount displayed.\n"; last PrintHits if ($Remaining < 1); my ($url_realm, $url_terms) = (url_encode($FORM{'Realm'}), url_encode($FORM{'Terms'})); print "
\n"; print "
Next "; ($Next == 1) ? print 'Match' : print "$Next Matches"; print '
Data Folder Required
This script requires a writable folder named "$DataFilesDir".
A folder exists with that name, but it isn't readable and writable.
Give this folder RWX permissions for Everyone. Your ISP can usually assist with this.
Need help? Visit $const{'help_file'}.