#!/usr/bin/perl -- require 5; use strict; =head1 copyright Fluid Dynamics Search Engine Copyright 1997-2001 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 If you edit the source code, you'll find it useful to restore the function comments and #&Assert checks: cd "search/searchmods/powerusr/" hacksubs.pl build_map hacksubs.pl restore_comments hacksubs.pl assert_on
Powered by the
Fluid Dynamics
Search Engine
v$VERSION
© 2001
' . $address_offer . '
'; } my $Rank = $FORM{'Rank'} || 1; my ($bTermsExist, $Ignored_Terms, $Important_Terms, $DocSearch, $RealmSearch, $where_clause, @SearchTerms) = &parse_search_terms($terms, $FORM{'Match'}); #changed 0042 - persist maxhits my $linkhits = $const{'search_url'} . '?Realm=' . &url_encode($FORM{'Realm'}) . "&Match=$FORM{'Match'}&Terms=" . &url_encode($terms); unless ($realms->realm_count('is_runtime')) { $linkhits .= '&nocpp=1'; } if ($FORM{'sort-method'}) { $linkhits .= '&sort-method=' . &url_encode($FORM{'sort-method'}); } my ($pages_searched, @HITS, $p_realm_data, $DD, $MM, $YYYY, $FBYTES) = (0); Search: { next Search unless ($bTermsExist); #changed 0042 -- added support for include-by-name, fixed runtime under sql # include runtime realms: if ($Realm eq 'include-by-name') { unless ($FORM{'nocpp'}) { foreach $p_realm_data ($realms->listrealms('is_runtime')) { next unless ($FORM{"Realm:$$p_realm_data{'name'}"}); $linkhits .= "&Realm:$$p_realm_data{'url_name'}=1"; $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchRunTime($p_realm_data, $DocSearch, \$pages_searched, \@HITS); } } } elsif ($Realm eq 'All') { unless ($FORM{'nocpp'}) { foreach $p_realm_data ($realms->listrealms('is_runtime')) { $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchRunTime($p_realm_data, $DocSearch, \$pages_searched, \@HITS); } } } else { ($err, $p_realm_data) = $realms->hashref($Realm); next Err if ($err); if (($$p_realm_data{'is_runtime'}) and (not $FORM{'nocpp'})) { $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchRunTime($p_realm_data, $DocSearch, \$pages_searched, \@HITS); last Search; } } # include indexed realms: if ($Rules{'sql: enable'}) { if ($Realm eq 'include-by-name') { my @id_ok = (); foreach $p_realm_data ($realms->listrealms('all')) { next unless ($FORM{"Realm:$$p_realm_data{'name'}"}); $linkhits .= "&Realm:$$p_realm_data{'url_name'}=1"; push(@id_ok, "(realm_id = $$p_realm_data{'realm_id'})"); $pages_searched += $$p_realm_data{'pagecount'}; } last Search unless (@id_ok); $where_clause .= ' AND (' . join(' OR ', @id_ok) . ')'; } elsif ($Realm ne 'All') { ($err, $p_realm_data) = $realms->hashref($Realm); next Err if ($err); $where_clause .= " AND realm_id = $$p_realm_data{'realm_id'}"; $pages_searched = $$p_realm_data{'pagecount'}; } else { foreach $p_realm_data ($realms->listrealms('all')) { $pages_searched += $$p_realm_data{'pagecount'}; } } $const{'record_realm'} = ''; &SearchDatabase($where_clause, $DocSearch, \@HITS); } else { if ($Realm eq 'include-by-name') { foreach $p_realm_data ($realms->listrealms('has_file')) { next unless ($FORM{"Realm:$$p_realm_data{'name'}"}); $linkhits .= "&Realm:$$p_realm_data{'url_name'}=1"; $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchIndexFile($$p_realm_data{'file'}, $RealmSearch, \$pages_searched, \@HITS); } } elsif ($Realm ne 'All') { ($err, $p_realm_data) = $realms->hashref($Realm); next Err if ($err); $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchIndexFile($$p_realm_data{'file'}, $RealmSearch, \$pages_searched, \@HITS); } else { foreach $p_realm_data ($realms->listrealms('has_file')) { $const{'record_realm'} = $$p_realm_data{'url_name'}; &SearchIndexFile($$p_realm_data{'file'}, $RealmSearch, \$pages_searched, \@HITS); } } } } my ($HitCount, $PerPage, $Next) = (scalar @HITS, $Rules{'hits per page'}, 0); if (($FORM{'maxhits'} =~ m!^(\d+)$!) and ($FORM{'maxhits'} > 0)) { $PerPage = $1; $linkhits .= '&maxhits=' . $PerPage; } my $Remaining = $HitCount - $Rank - $PerPage + 1; my $RangeUpper = $Rank + $PerPage - 1; if ($Remaining >= $PerPage) { $Next = $PerPage; } elsif ($Remaining > 0) { $Next = $Remaining; } else { $RangeUpper = $HitCount; } my @Ads = &SelectAdEx(\@SearchTerms); print $Ads[0]; print '' . $str[10] . '$str[19]
\n"; last PrintHits; } # print: Results $Rank-$RangeUpper of $HitCount &ppstr(14, $Rank, $RangeUpper, $HitCount ); my ($jump_sum, $jumptext) = &str_jumptext( $Rank, $PerPage, $HitCount, "$linkhits&Rank=", 1 ); # $jump_sum = "Documents 1-10 of 15 displayed." # $jumptext = "<- Previous 1 2 3 4 5 Next ->
" my $i = $Rank; foreach ((sort @HITS)[($Rank-1)..($RangeUpper-1)]) { next unless (m!^\d+\.(\d+)\.(\d+)\s*\d*\s*\d* u= (.+) t= (.*?) d= (.*?) c= (.*?) r= (.*?)$!); ($DD, $MM, $YYYY, $FBYTES) = (unpack('A2A2A2A4A*',$2))[1..4]; my $relevance = 10E6 - $1; print &StandardVersion( \@SearchTerms, 'relevance' => $relevance, 'redirector' => $Rules{'redirector'}, 'rank' => $i, 'url' => $3, 'title' => $4, 'description' => $5, 'size' => $FBYTES, 'dd' => $DD, 'mm' => $MM, 'yyyy' => $YYYY, 'context' => $6, 'record_realm' => &html_encode(&url_decode($7)), ); $i++; } print $jump_sum; print $jumptext; } print $Ads[2]; print &str_search_form($const{'search_url'}); print $Ads[3]; &log_search( $Realm, $terms, $Rank, $HitCount, $pages_searched ); } if (($Rules{'allowanonadd'}) and ($realms->realm_count('has_no_base_url')) and ($const{'mode'} != 3)) { # print: Search Tips - Add New URL - Main Page &PrintTemplate(0, 'linkline2.txt', $Rules{'language'}, \%const); } else { # print: Search Tips - Main Page &PrintTemplate(0, 'linkline1.txt', $Rules{'language'}, \%const); } &PrintTemplate(0, 'footer.htm', $Rules{'language'}, \%const); last Err; } continue { print "Content-Type: text/html\015\012\015\012"; print "Error: $err.
\n"; } sub query_env { my ($name,$default) = @_; if (($ENV{$name}) and ($ENV{$name} =~ m!^(.*)$!s)) { return $1; } elsif (defined($default)) { return $default; } else { return ''; } } sub untaintme { my ($p_val) = @_; $$p_val = $1 if ($$p_val =~ m!^(.*)$!s); } sub load_files { my ($data_files_dir) = @_; my $err = ''; Err: { # This manually sets the current working directory to the directory that # contains this script. This is necessary in case people have used a # relative path to the $data_files_dir: if (($0 =~ m!^(.*)(\\|/)!) and ($0 !~ m!safeperl\d*$!)) { #changed 0045 - added error check unless (chdir($1)) { $err = "unable to chdir to script folder '$1' - $!"; next Err; } push(@INC, "$1/searchmods"); } push(@INC, './searchmods', '../searchmods'); unless (-e 'searchmods') { $err = "directory 'searchmods' does not exist"; next Err; } #require my $lib = 'common.pl'; delete $INC{$lib}; require $lib; if (&version_c() ne $VERSION) { $err = "the library '$lib' is not version $VERSION"; next Err; } #/require &ReadInput(); #require unless ($FORM{'nocpp'}) { $lib = 'common_parse_page.pl'; delete $INC{$lib}; require $lib; if (&version_cpp() ne $VERSION) { $err = "the library '$lib' is not version $VERSION"; next Err; } } #/require if ($FORM{'ApproveRealm'}) { $FORM{'Realm'} = $FORM{'ApproveRealm'}; $FORM{'Mode'} = 'Admin'; $FORM{'Action'} = 'FilterRules'; $FORM{'subaction'} = 'ShowPending'; } unless ($FORM{'Mode'}) { #reverse compat - pre-0010 if ($FORM{'AddSite'}) { $FORM{'Mode'} = 'AnonAdd'; $FORM{'URL'} = $FORM{'AddSite'}; delete $FORM{'AddSite'}; } #/reverse compat #changed 0043 - be nice to precious users; ?mode=admin, ?MODE=ADMIN will work if ('mode=admin' eq lc(&query_env('QUERY_STRING'))) { $FORM{'Mode'} = 'Admin'; } } #reverse compat 0030 if ($FORM{'Action'} eq 'ReCrawlRealm') { $FORM{'Action'} = 'rebuild'; } #/reverse compat my $is_admin_rq = (($FORM{'Mode'}) and (($FORM{'Mode'} eq 'Admin') or ($FORM{'Mode'} eq 'AnonAdd'))) ? 1 : 0; $is_admin_rq = 1 if (&query_env('FDSE_NO_EXEC')); #require if ($is_admin_rq) { $lib = 'common_admin.pl'; delete $INC{$lib}; require $lib; if (&version_ca() ne $VERSION) { $err = "the library '$lib' is not version $VERSION"; next Err; } $lib = 'common_parse_page.pl'; require $lib; if (&version_cpp() ne $VERSION) { $err = "the library '$lib' is not version $VERSION"; next Err; } } #/require unless (chdir($data_files_dir)) { $err = "unable to chdir to data files directory '$data_files_dir' - $!"; next Err; } $const{'bypass_file_locking'} = (-e 'bypass_file_locking.txt') ? 1 : 0; # Can we load the rules? $err = &LoadRules(); next Err if ($err); my $str_file = 'templates/' . $Rules{'language'} . '/strings.txt'; my $str_text; ($err, $str_text) = &ReadFileL($str_file); next Err if ($err); @str = (0); my $i = 1; foreach (split(m!\n!s,$str_text)) { s!(\r|\n|\015|\012)!!g; push(@str,$_); unless ($is_admin_rq) { last if ($i > 87);#strdepth } $i++; } unless (&Trim($str[1]) eq "VERSION $VERSION") { $err = "strings file is not version $VERSION ($str[1])"; next Err; } $const{'language_str'} = $str[2]; $realms = &fdse_realms_new(); $realms->use_database($Rules{'sql: enable'}); $realms->load(); $const{'is_demo'} = 1 if (-e 'is_demo'); $const{'mode'} = $Rules{'mode'}; if (($const{'mode'} == 2) and (not $Rules{'regkey'})) { $const{'mode'} = 1; } $const{'mode'} = 0 if (-e 'is_demo'); last Err; } return $err; } END_OF_FILE undef($@); eval $all_code; if ($@) { my $errstr = $@; print "Content-Type: text/html\015\012\015\012"; print "Perl Execution Error in $0:
";#$@