#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # # csSearchPro - 061402 $basepath = './'; # 3.9 Multiple search terms with 'AND' fixed # 3.8 Duplicate search results fixed # 3.75 Changes # misc minor fixes # 3.6 Changes # -- Added ability to manually increase keywords with # # 3.5 Changes # -- Searches for multiple SSI methods when option is selected # 3.3 Changes # -- ability to use # -- partial searces or full word searches.. # -- ability for server side includes in the templates. # 3.0 Changes # -- Ability to log search terms # -- Improved Indexing ##################################################################### # # # Copyright © 1999-2001 CGISCRIPT.NET - All Rights Reserved # # # ##################################################################### # # # THIS COPYRIGHT INFORMATION MUST REMAIN INTACT # # AND MAY NOT BE MODIFIED IN ANY WAY # # # ##################################################################### # # When you downloaded this script you agreed to accept the terms # of this Agreement. This Agreement is a legal contract, which # specifies the terms of the license and warranty limitation between # you and CGISCRIPT.NET. You should carefully read the following # terms and conditions before installing or using this software. # Unless you have a different license agreement obtained from # CGISCRIPT.NET, installation or use of this software indicates # your acceptance of the license and warranty limitation terms # contained in this Agreement. If you do not agree to the terms of this # Agreement, promptly delete and destroy all copies of the Software. # # Versions of the Software # Only one copy of the registered version of CGISCRIPT.NET # may used on one web site. # # License to Redistribute # Distributing the software and/or documentation with other products # (commercial or otherwise) or by other than electronic means without # CGISCRIPT.NET's prior written permission is forbidden. # All rights to the CGISCRIPT.NET software and documentation not expressly # granted under this Agreement are reserved to CGISCRIPT.NET. # # Disclaimer of Warranty # THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND # WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER # WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE # AND SOFTWARE ENVIRONMENTS INTO WHICH CGISCRIPT.NET MAY BE USED, NO WARRANTY # OF FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE # ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF CGISCRIPT.NET WILL BE # LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. # IN NO CASE SHALL CGISCRIPT.NET BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR # CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS # OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE # BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT, # NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF # CGISCRIPT.NET IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL # CGISCRIPT.NET' LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID # BY LICENSEE TO CGISCRIPT.NET. # # Credits: # Andy Angrick - Programmer - angrick@cgiscript.net # Mike Barone - Design - mbarone@cgiscript.net # # For information about this script or other scripts see # http://www.cgiscript.net # # Thank you for trying out our script. # If you have any suggestions or ideas for a new innovative script # please direct them to suggest@cgiscript.net. Thanks. # ######################################################################## # Config Variables # ######################################################################## ##################################################################### # # # Configuration variables # # # ##################################################################### (! -e "$basepath/setup.cgi")?($nosetup=1):(require("$basepath/setup.cgi")); (!$htmlpath)&&($htmlpath=$cgipath); (!$htmlurl)&&($htmlurl=$cgiurl); $in{'htmlurl'} = $htmlurl; $in{'cgiurl'} = $cgiurl."/csSearchPro.cgi"; $flock=1; $in{'cinfo'} = qq|
Powered
by csSearchPro - © 2000,2001 CGIScript.net
|;
#####################################################################
# #
# End Configuration Variables. #
# #
#####################################################################
require("$basepath/libs.cgi");
$| = 1;
&main;
exit;
sub main{
print "Content-type: text/html\n\n";
($ARGV[0] eq 'index')&&($ARGV[1] eq $username)&&(&CreateIndexStart);
&getdata();
$in{'terms'} =~ s/([\\\|\(\)\[\]\{\}\^\$\*\+\?\.])/\\$1/g;
($in{'command'} eq '')&&($nosetup)&&(&Setup);
($in{'command'} eq '')&&(!$nosetup)&&(&ShowSearchForm);
($in{'command'} eq 'login')&&(&Login);
($in{'command'} eq 'query')&&(&Query);
($in{'command'} eq 'info')&&(&Info);
($in{'command'} eq 'savesetup')&&(($nosetup)?(&SaveSetup):(&PError("Error. Permission denied.")));
#all require password below
&GetLogin;
($in{'command'} eq 'manage')&&(&Manage);
($in{'command'} eq 'aae')&&(&AddExtExcludes);
($in{'command'} eq 'ade')&&(&AddDirectoryExcludes);
($in{'command'} eq 'ae')&&(&AddIgnore);
($in{'command'} eq 'as')&&(&AddSkip);
($in{'command'} eq 'gu')&&(&GoUp);
($in{'action'} eq '-=Skip/UnSkip All Selected=-')&&(&SkipSelected);
($in{'action'} eq '-=Ignore/UnIgnore All Selected=-')&&(&IgnoreSelected);
($in{'command'} eq "showadv")&&(&ShowAdv);
($in{'command'} eq "setstyles")&&(&SetStyles);
($in{'command'} eq "showcolor")&&(&ShowColor);
($in{'command'} eq "setcolor")&&(&SetColor);
($in{'command'} eq "index")&&(&CreateIndexStart);
($in{'command'} eq "clearlog")&&(&ClearLog);
($in{'command'} eq "viewlogs")&&(&ViewQueryLog);
exit;
}
sub ShowAdv{
&GetAdvSettings;
$in{'S'.$in{'style'}}='checked';
(!$in{'extinc'})?($in{'EXTY'}='checked'):($in{'EXT'.$in{'extinc'}}='checked');
$in{'directlinks'} = qq|
|;
$in{'directlinksnojs'} = qq|
|;
&PageOut("$htmlpath/t_search_advanced_settings.htm");
exit;
}
sub GetAdvSettings{
(-e "$htmlpath/styles.pl")&&(require "$htmlpath/styles.pl");
}
sub ShowColor{
$in{'c'.$in{'cc'}} = checked;
&PageOut("$htmlpath/color_selector.htm");
exit;
}
sub SetColor{
open(ADV,"<$htmlpath/styles.pl");
open(TMP,">$htmlpath/styles.pl.tmp");
while(
No se han encontrado resultados para su consulta.');
$in{$in{'mcase'}} = 'selected';
$in{$in{'mbool'}} = 'selected';
($count)&&(&GetNlinks);
$in{'count'} = $count;
$in{'count'} = "Su busqueda retornó $in{'count'} resultados.";
$in{'terms'} =~ s/\\//g;
($in{'template'})?(&InsertPage($in{'template'},"$htmlpath/t_searchresults.htm")):(&PageOut("$htmlpath/t_searchresults.htm"));
exit;
}
sub Query{
&GetAdvSettings;
&LogQuery;
($in{'useindex'})&&(&QueryI);
if($in{'parsessi'}){
require("$cgipath/ssi.cgi");
}
(!$in{'page'})&&($in{'page'} = 1);
$start = ($in{'page'}*$in{'entriesperpage'})-$in{'entriesperpage'};
$end = $start + $in{'entriesperpage'};
(!$in{'terms'})&&(&PError("Error. Please enter something to search for."));
&LoadVars;
&GetGlobalIgnore;
chdir($rootpath);
&GetFiles(".");
##start actual search
foreach $i (sort keys %ftsearch){
&SearchFile($i);
}
(!$in{'count'})&&($in{'count'} = '0');
(!$in{'searchresults'})&&($in{'searchresults'} = '
No se han obtenido resultados de su búsqueda');
$in{$in{'mcase'}} = 'selected';
$in{$in{'mbool'}} = 'selected';
($count)&&(&GetNlinks);
$in{'count'} = $count;
$in{'count'} = "Su busqueda retornó $in{'count'} resultados.";
($in{'template'})?(&InsertPage($in{'template'},"$htmlpath/t_searchresults.htm")):(&PageOut("$htmlpath/t_searchresults.htm"));
exit;
}
sub CreateIndexStart{
&GetAdvSettings;
&GetGlobalIgnore;
$cid=0;
$pid=0;
&LoadVars;
if($in{'parsessi'}){
require("$cgipath/ssi.cgi");
}
print "Indexando archivos.. por favor paciencia\n";
chdir($rootpath);
undef $/;
&GetFiles(".");
foreach $i (keys %ftsearch){
&CreateIndex($i);
}
#uninit
open(IDX,">$htmlpath/site.idx");
foreach my $i (keys %site){
print IDX "$i:$site{$i}\n";
}
close IDX;
open(IDX,">$htmlpath/page.idx");
foreach my $i (keys %page){
print IDX "$page{$i}:$i\n";
}
close IDX;
dbmclose %site;
dbmclose %page;
close DB;
print <<"EOF";
EOF
exit;
}
sub CreateIndex{
local($file) = @_;
$cg=0;
undef @words;
print "Indexing file $file =->";
open(FILE,"<$rootpath/$file")||print "$!:$rootpath/$file
";
$data =
";
while(
";
$data =
";
}
}
else{
if($data =~ /$b$in{'terms'}$b/){
&DisplayFound;
#print "Found: $in{'terms'}
";
}
}
}
else{
@aq = split(/\s+/,$in{'terms'});
foreach $k (@aq){
if($in{'mcase'} eq 'Insensitive'){
if($data =~ /$b$k$b/i){
&DisplayFound;
#print "Found: $in{'terms'}
";
}
}
else{
if($data =~ /$b$k$b/){
&DisplayFound;
#print "Found: $in{'terms'}
";
}
}
}
}
}
sub DisplayFound{
$data = $tdata;
$count++;
if(($count > $start) & ($count <= $end)){
&OutputPage
}# end next page
}
sub GetNlinks{
((!$in{'page'})||($in{'lpage'} < 0))&&($in{'lpage'} = 1);
$nstart = ($in{'lpage'}+10)-10;
$nend = $nstart + 10;
$sstring = "command=$in{'command'}&terms=$in{'terms'}&mbool=$in{'mbool'}&mcase=$in{'mcase'}";
$sstring =~ s/([^\w&=])/'%'.sprintf("%.2x",ord($1))/ge;
$npages = int($count/$in{'entriesperpage'});
(($count/$in{'entriesperpage'}) > $npages)&&($npages++);
for $i (1..$npages){
if(($i > $nstart) & ($i <= $nend)){
($i eq $in{'page'})?($link .= " $i "):($link .= " $i ");
}
}
$nend;
$pend = $nend - 20;
($npages > $nend)&&($link .= " [Next] ");
($nend > 11)&&($link = " [Prev] " . $link);
(!$link)&&($link='0');
$link = "Páginas con resultados: " . $link;
$in{'link'} = $link;
}
sub DeHTML{
#########################################################
# remove anything between
#########################################################
$data =~ s/.*//gsi;
#########################################################
# next we'll remove all the
EOF
exit;
}
sub ConvertForChars{
%fc = ('À','À',
'Ç','Ç',
'Á','Á',
'ç','ç',
'Â','Â',
'Ã','Ã',
'È','È',
'Ä','Ä',
'É','É',
'Å','Å',
'Ê','Ê',
'à','à',
'Ë','Ë',
'á','á',
'è','è',
'â','â',
'é','é',
'ã','ã',
'ê','ê',
'ä','ä',
'ë','ë',
'å','å',
'æ','æ',
'ß','ß',
'ª','ª',
'Ì','Ì',
'Ù','Ù',
'Í','Í',
'Ú','Ú',
'Î','Î',
'Û','Û',
'Ï','Ï',
'Ü','Ü',
'ì','ì',
'ù','ù',
'í','í',
'ú','ú',
'î','î',
'û','û',
'ï','ï',
'ü','ü',
'Ñ','Ñ',
'Ò','Ò',
'ñ','ñ',
'Ó','Ó',
'Ô','Ô',
'¡','¡',
'Õ','Õ',
'¿','¿',
'Ö','Ö',
'Ø','Ø',
'«','«',
'ò','ò',
'»','»',
'ó','ó',
'ô','ô',
'','ô',
'õ','õ',
'©','©',
'ö','ö',
'®','®',
'º','º',
' ','');
foreach $x (keys %fc){
$nc = $fc{$x};
$data =~ s/$x[;\s]/$nc/g;
}
}
sub InsertPage{
#format
local($out,$file) = @_;
open(OUT,"<$file");
while(
";
while(