#!/usr/bin/perl -- #use warnings 'all';#if-debug #use strict;#if-debug =head1 copyright Fluid Dynamics Search Engine Copyright 1997-2005 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 . '
© 2005
' . &pstr(23, &he($address, $address) ) . '
'; if ($::Rules{'handling url search terms'} == 3) { &header_print( "Location: $address" ); print $address_offer; last Err; } } } if (exists($::FORM{'NextLink'})) { #changed 0034 - fixes bug where NextLink contains & if (&query_env('QUERY_STRING') =~ m!^NextLink=(.*)$!s) { $::FORM{'NextLink'} = $1; } my $html_link = &he($::FORM{'NextLink'}); # security re-director from admin screen (prevents query-string-based # password from showing up in referer logs of remote systems: &header_print(); print qq!$html_link!; last Err; } # changed 0067 my $Realm = 'All'; block: { last unless exists $::FORM{'Realm'}; if ($::FORM{'Realm'} eq '') { $Realm = 'All'; } elsif (($::FORM{'Realm'} eq 'All') or ($::FORM{'Realm'} eq 'include-by-name')) { # reserved names; ok $Realm = $::FORM{'Realm'}; } else { # explode if invalid $Realm param is passed, but special-case for All include-by-name and empty my $p_realm; ($err, $p_realm) = $::realms->hashref( $::FORM{'Realm'} ); next Err if ($err); $Realm = $::FORM{'Realm'}; } } $::const{'realm'} = &he($Realm); if ($::FORM{'Mode'} eq 'Admin') { $err = &admin_main(); next Err if ($err); last Err; } if (($b_is_shell_include) and (not $ARGV[0])) { $err = "the 'is_shell_include' parameter can only be set when this script is being called from the command line"; next Err; } if ($b_is_shell_include) { $::private{'needs_header'} = 0; } $::const{'copyright'} =~ s!' . $::str[10] . '
';
print '
';
if ($Ignored_Terms) {
&ppstr(11, &he($Ignored_Terms));
}
if ($HitCount) {
&ppstr(12, &he($Important_Terms), $pages_searched);
}
else {
&ppstr(13, &he($Important_Terms), $pages_searched);
}
print '
';
print $Ads[1];
PrintHits: {
if ($HitCount < 1) {
# print: No documents found
print qq!
$::str[19]
\n!; last PrintHits; } # print: Results $Rank-$RangeUpper of $HitCount &ppstr(14, $Rank, $RangeUpper, $HitCount ); print ''; 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= (.*?)$!s); ($DD, $MM, $YYYY, $FBYTES) = (unpack('A2A2A2A4A*',$2))[1..4]; my $relevance = 10E6 - $1; print &StandardVersion( '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' => &he(&ud($7)), ); $i++; } print $jump_sum; # kams print $jumptext; } print $Ads[2]; print &str_search_form($::const{'search_url'}) if ($::Rules{'ui: search form display'} > 1); print $Ads[3]; $err = &log_search( $Realm, $terms, $Rank, $HitCount, $pages_searched ); next Err if ($err); #printf("Error: $err.
\n"; # still print meaningful errors when $::str[] fails to load } } print $::private{'html_footer'}; 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 header_add { my ($header) = @_; $::private{'http_headers'} .= $header . "\015\012"; } sub header_print { return unless $::private{'needs_header'}; return if $::const{'is_cmd'}; foreach (@_) { &header_add( $_ ); } # fine-tune the header response: if ($::private{'PRINT_HTTP_STATUS_HEADER'}) { my $status = '200 OK'; if ($::private{'http_headers'} =~ m!(^|\012)Location:!is) { $status = '302 Moved'; &header_add( 'Status: ' . $status ); # duplicate } $::private{'http_headers'} = "HTTP/1.0 $status\015\012" . $::private{'http_headers'}; } if ($::private{'http_headers'} !~ m!(^|\012)Content-Type:!is) { &header_add( "Content-Type: text/html" ); } # prepare and print: $::private{'http_headers'} .= "\015\012"; print $::private{'http_headers'}; delete $::private{'http_headers'}; #save mem $::private{'needs_header'} = 0; } sub load_files_ex { ($::private{'support_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!^(.+)(\\|/)!s) and ($0 !~ m!safeperl\d*$!is)) { #changed 0045 - added error check unless (chdir($1)) { $err = "unable to chdir to folder '$1' - $! ($^E)"; next Err; } } # force forward slashes: $::private{'support_dir'} =~ s!\\!/!sg; $::private{'support_dir'} .= "/searchdata"; $::private{'support_dir'} =~ s!/+searchdata$!/searchdata!s; unless (chdir($::private{'support_dir'})) { $err = "unable to chdir to folder '$::private{'support_dir'}' - $! ($^E)"; next Err; } @INC = ( '../searchmods', @INC ); #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(); if (exists($::FORM{'ApproveRealm'})) { $::FORM{'Realm'} = $::FORM{'ApproveRealm'}; $::FORM{'Mode'} = 'Admin'; $::FORM{'Action'} = 'FilterRules'; $::FORM{'subaction'} = 'ShowPending'; } unless ($::FORM{'Mode'}) { #revcompat - pre-0010 if (exists($::FORM{'AddSite'})) { $::FORM{'Mode'} = 'AnonAdd'; $::FORM{'URL'} = $::FORM{'AddSite'}; delete $::FORM{'AddSite'}; } #/revcompat if ('mode=admin' eq lc(&query_env('QUERY_STRING'))) { $::FORM{'Mode'} = 'Admin'; delete $::FORM{'mode'}; } } #revcompat 0030 if ((exists($::FORM{'Action'})) and ($::FORM{'Action'} eq 'ReCrawlRealm')) { $::FORM{'Action'} = 'rebuild'; } #/revcompat my $is_admin_rq = (($::FORM{'Mode'}) and (($::FORM{'Mode'} eq 'Admin') or ($::FORM{'Mode'} eq 'AnonAdd'))) or (&query_env('FDSE_NO_EXEC')); $::private{'bypass_file_locking'} = (-e 'bypass_file_locking.txt') ? 1 : 0; # Can we load the rules? my $DEFAULT_LANGUAGE = 'english'; $err = &LoadRules($DEFAULT_LANGUAGE); next Err if ($err); #0056 - user lang selection algorithm by Ian Dobson ($err, $::const{'lang_options'}, $::Rules{'language'}) = &choose_interface_lang($is_admin_rq, &query_env('HTTP_ACCEPT_LANGUAGE')); next Err if ($err); #to hard-code a lang, uncomment this line: # $::Rules{'language'} = 'english'; $::const{'language'} = $::FORM{'set:lang'} = $::Rules{'language'}; # init err strings $::str[44] = 'unable to read from file "$s1" - $s2'; my $str_file = 'templates/' . $::Rules{'language'} . '/strings.txt'; my $str_text; ($err, $str_text) = &ReadFileL($str_file); next Err if ($err); my $MAX_PUB_STR = 88; @::str = (0); my $i = 1; foreach (split(m!\n!s,$str_text)) { s!(\r|\n|\015|\012)!!sg; push(@::str,$_); unless ($is_admin_rq) { last if ($i > $MAX_PUB_STR); } $i++; } unless (&Trim($::str[1]) eq "VERSION $::VERSION") { $err = "strings file '$str_file' is not version $::VERSION ($::str[1]).Loaded $i strings from file; sample:
Error: $s1.
'; # force default value $err = qq!strings file "$str_file" is corrupted. Extra line breaks have been added or removed. We know this because line $_ does not have expected value "$_-anchor".To fix, re-upload the original strings.txt file in ASCII mode!;
next Err;
}
last if ((not $is_admin_rq) and ($_ >= $MAX_PUB_STR));
}
$::const{'dir'} = $::str[4];
$::const{'content_type'} = $::str[3];
$::const{'language_str'} = $::str[2];
$::realms = &fdse_realms_new();
$::realms->load();
# set mode: demo/trial/registered/freeware == 0/1/2/3
$::private{'mode'} = $::Rules{'mode'};
if (-e 'is_demo') {
$::private{'mode'} = 0;
}
elsif (($::private{'mode'} == 2) and (not $::Rules{'regkey'})) {
$::private{'mode'} = 1;
}
$::private{'is_demo'} = ($::private{'mode'} == 0);
$::private{'is_freeware'} = ($::private{'mode'} == 3);
#require
if (($is_admin_rq) or ($::realms->listrealms('is_runtime'))) {
$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;
}
}
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;
}
}
#/require
last Err;
}
return $err;
}
package FDSC::HEH;
sub TIEHASH { bless {}, $_[0] }
sub STORE { $_[0]->{$_[1]} = $_[2] }
sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
sub NEXTKEY { each %{$_[0]} }
sub EXISTS { exists $_[0]->{$_[1]} }
sub DELETE { delete $_[0]->{$_[1]} }
sub CLEAR { %{$_[0]} = () }
sub FETCH {
my ($self, $key) = @_;
if (exists ($self->{$key})) {
return $self->{$key};
}
else {
my ($package, $file, $line) = caller();
my $err = "blind fetch of non-existent hash element '$key' file $file line $line
\n";
foreach (sort keys %$self) {
$err .= "$_: $self->{$_}
\n";
}
die $err;
}
};
END_OF_FILE
sub he {
my @out = @_;
local $_;
foreach (@out) {
$_ = '' if (not defined($_));
s!\&!\&!sg;
s!\>!\>!sg;
s!\ 0)) {
return @out;
}
else {
return $out[0];
}
}
undef($@);
eval $all_code;
if ($@) {
my $errstr = &he($@);
print "Content-Type: text/html\015\012\015\012";
print "
Perl Execution Error in $0:
"; print <<"EOM";$errstr