#!/usr/local/bin/perl
##########################################################################
# z_search Version 1.0 #
# Created 08/1/00 Last Modified 09/02/00 #
# cyber-robotics.com http://cyber-robotics.com #
# Copyright 2000 cyber-robotics.com All Rights Reserved. #
# #
# Copyright notice and the comments above must remain intact. By using #
# this code you agree to indemnify cyber-robotics.com from any liability #
# that might arise from its use. #
# #
# Selling or distributing this program is forbidden. #
# #
##########################################################################
# Variables that require changing.
# The "#" is a remark symbol, for comments only, and
# those lines preceeded by it are not executed.
# Change the following to match your website and server.
#####################################################
# 1) The server's hard disk path name to the links directory.
# Include the trailing '/' or '\'.
# If this script is installed on a Windows server,
# un-remark the Windows line and remark out the Unix line
#
# $pathname = "c:\website\htdocs\links\"; # for windows server
$pathname = "/usr/local/etc/httpd/htdocs/cyberrob/directories/webresources/links/"; # for Unix server
# 2) The url web address to your website's link directory. Include the trailing '/'
$linkurl = "http://www.cyber-robotics.com/directories/webresources/links/";
# 3) The URL address of this search script
$This_CGI_script = "http://www.cyber-robotics.com/cgi-bin/z_search.cgi";
# 4) Background -
# The url web address to your website's background image
#$background = "http://www.crownjewels.com/images/backwhit.jpg";
#
# un-remark the following line to use the numerical background number
# embedded in the
tag code below:
$background = "#FFFFFF";
# 5) Only this domain will be able to use this script.
# You don't want others, calling your script, using your index.
# Enter your website's domain name.
#
$referer = ('www.cyber-robotics.com');
#########################################################################
# Variables that normally DO NOT require changing
#####################################################
# If 1, this puts a count of the listings found for the search at the top of the
# page returned to the user. This does slow the search down by about 40% or more.
# Change to 0 if your Link Directory becomes large or if you have a slow server.
#
$countresults = 1;
# Index text file
$index_text_file = "search.txt";
# File extensions in your directory
$ext = ".html";
# maximum number of listings to display
$amount_listings = 1000;
#########################################################################
# There is nothing below this to edit
#####################################################
&parse_form;
&check_refer;
$userquerystring = $FORM{'searchstring'};
$userquerystring =~ tr/A-Z/a-z/;
$userquerystring =~ s/\sand//g;
$userquerystring =~ s/\sor//g;
$userquerystring =~ s/\+//g;
$userquerystring =~ s/\-//g;
if ($FORM{'type'}) {
$typesearch = $FORM{'type'};
}
else {
$typesearch = "all";
}
$filename = $pathname . $index_text_file;
print "Content-type: text/html\n\n";
print "\n";
print "\n";
&print_search_box;
if ($countresults == 1) {
$counter = 0;
open ("INDEXFILE",$filename) || die "$!, Couldn't open file $filename";
while (($record = ) && ($counter < $amount_listings)) {
@recorddata = split(/\s*\|\s*/,$record ,7);
&check_index_record;
if ($printrecord == 1) {
$counter++;
}
}
}
close(INDEXFILE);
print "Search Results\n";
print "
\n";
print "" . $counter . " Listings found for: " . $userquerystring . "\n";
print "
\n";
$counter = 0;
open ("INDEXFILE",$filename) || die "$!, Couldn't open file $filename";
while (($record = ) && ($counter < $amount_listings)) {
@recorddata = split(/\s*\|\s*/,$record ,7);
&check_index_record;
if ($printrecord == 1) {
$counter++;
&print_listing;
}
}
close(INDEXFILE);
print "
\n";
if ($counter == 0) {
print "\n";
print "
Sorry, No Matches found for: " . $userquerystring . "\n";
print "";
}
print "
\n";
print "
\n";
print "\n";
&print_search_box;
print "\n";
print "\n";
print "These web site links are listed as a convenience to our visitors. If you use these links, we take no responsibility and give no guarantees, warranties or representations, implied or otherwise, for the content or accuracy of these third-party sites.\n";
print "\n";
print "\n";
print "\n";
sub check_index_record {
$url = $recorddata[0];
$title = $recorddata[1];
$description = $recorddata[2];
$linked = $recorddata[3];
$theme = $recorddata[4];
$comments = $recorddata[5];
$bannerurl = $recorddata[6];
$temptheme = $theme;
$temptheme =~ s/\s//g;
$temptheme =~ tr/A-Z/a-z/;
$searchindexline = $title . " " . $description . " " . $theme . " " . $comments;
$somewordswerefound = 0;
$allwerefound = 1;
$printrecord = 0;
$lengthuserquerystring = length($userquerystring);
if ($lengthuserquerystring > 1) {
@userquerywords = split(/ +/,$userquerystring);
foreach $userqueryword (@userquerywords) {
if ($searchindexline =~ /\b$userqueryword/i) {
$somewordswerefound = 1;
}
else {
$allwerefound = 0;
}
}
}
if ($typesearch eq "all" && $somewordswerefound == 1 && $allwerefound == 1) {
$printrecord = 1;
}
elsif ($typesearch eq "any" && $somewordswerefound == 1) {
$printrecord = 1;
}
if ($lengthuserquerystring <= 1) {
$printrecord = 0;
}
if ((length($title) < 1) || (length($description) < 1)) {
$printrecord = 0;
}
}
sub print_listing {
print "- \n";
if ($linked eq "T") {
print "
\n";
}
print " \n";
print "\n";
print "" . $title . "...\n";
print " \n";
print "- \n";
print $description . "...\n";
print "
\n";
print "\n";
print "" . $url . "\n";
print "\n";
print " | \n";
print "\n";
print "Similiar " . $theme . " ThemeSites\n";
print "\n";
print "
\n";
}
sub print_search_box {
print "
\n";
print " Search our Link Directory\n";
print " \n";
print " \n";
print "
\n";
}
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@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;
$value =~ s/\n/\s/g; # strip newlines
$value =~ s/\t/ /g; # strip tabs
$value =~ s/\0//g; # strip nulls
$value =~ s//g; # strip less than
$value =~ s/>//g; # strip greater than
$value =~ s/\'//g; # strip apostrophe
$value =~ s/\"//g; # strip quote
$value =~ s/\(//g; # strip open parenthesis
$value =~ s/\)//g; # strip close parenthesis
if ($name && $value) { $FORM{$name} = $value; }
}
}
sub check_refer {
local($ok) = 0;
if ($ENV{'HTTP_REFERER'}) {
if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) { $ok = 1; }
}
else {
$ok = 1;
}
if ($ok != 1 && ($ENV{'HTTP_REFERER'} =~ m|^https?://([\w\.]+)|i)) {
print <<"(BODY)";
Content-type: text/html
Access Denied
This form is denied.
This form is not allowed to use this cgi script.
(BODY)
exit;
}
}