Gossamer Forum
Home : Products : Links 2.0 : Customization :

the latest version of altavista.cgi is not working

Quote Reply
the latest version of altavista.cgi is not working
i have moved to anew server (linux) guess what it's not working.
i know it's working on some server, there is something wrong with the coding
when i run from telnet i get:
Undefined subroutine &main::cgierr called at /home/httpd/html/search/altavista.c
gi line 129
could the person who wrote the script check to see if he can fix line 129?
thanks

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
Why do you run it from telnet??

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
if it's not working then you run it from telnet to see what's wrong.
that's why i found it there is something wrong with line129
how do you troubleshoot your scripts?

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
Code:

perl -c scriptname.extension


Regards,

Eliot Lee

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
What do you have at line 129?

Regs
JackofNone

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
i think this is line129
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {

i do not think you can figure it out until you look at the whole code:

#!/usr/bin/perl

use LWP::Simple;

%in = &parse_form;

&altavista;
&print_template;

sub print_template {
# --------------------------------------------------------
#
#
if (!$in{'query'}) {$error="Please enter one or more keywords:";}
if ($error) {$results = $error;}
# Bold Search Terms
@search_terms = split (/\s/, $in{'query'});
foreach $term (@search_terms) {
$results =~ s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "<STRONG>$2</STRONG>",gie; # Bold Search Terms
}
# Get the template
open (READIT, "results.html");
read (READIT, $template, 20000,0);
close (READIT);
$template =~ s#<%results%>#$results#igs;
$template =~ s#<%query%>#$query#igs;
$template =~ s#<%next%>#$next#igs;
$template =~ s#<%hits%>#$hits#igs;
# Print the results
print "Content-type: text/html\n\n";
print $template;
exit;
}

sub altavista {
# --------------------------------------------------------
# Search Altavista
#
$query = $in{'query'};
$query_q = &urlencode($query);
$font = "<font face=verdana size=2>";
$font2 = "<font color=#808080 face=verdana size=1>";
$page = ($in{'page'} * 10) || 0;
$pageXX = $page - 10;
$url = "http://www.altavista.com/cgi-bin/query?q=$query_q&text=yes&stq=$pageXX";
$av_results = get ($url);
$av_results or $error = "No Results Available!" and &print_template;
# If we see this, then we couldn't get a match.
$none = quotemeta ("AltaVista found no document matching your query.");
if ($av_results =~ m/$none/) {$error = "No matching sites for: <b>$query</b>" and &print_template;}
# Get the results.
else {
if ($av_results =~ /([^>\s]+) pages found./) { $hits = $1; }
else {$error = "Can't Parse Results!" and &print_template;}
while ($av_results =~ m#<b>#sog) {
$av_results =~ s/<b>//gie;
$av_results =~ s/<\/b>//gie;
}
while ($av_results =~ m#<EM>#sog) {
$av_results =~ s/<EM>//gie;
$av_results =~ s/<\/EM>//gie;
}
while ($av_results =~ m#(\d+)\.\s*\n<a href="([^"]+)">\n([^<]+)</a></dt>\n<dd>([^<]+)</dd>\n
<font color="\#808080">URL:([^\n]+)\n#sog) {
($count, $url, $title, $description, $url2) = ($1, $2, $3, $4, $5);
$url2 =~ s/\s//gie;
$url2 = "http://" . $url2;
$results .= qq~<p>$font$count. <a href="$url">$title</a>
\n$description</font>
\n$font2 $url2</font>\n~;
}
# If less than 10 don't build search bar
while ($hits =~ m#,#sog) {$hits =~ s/,//;}
$next = &next_hits($page, $hits, 10);
if ($hits <= 10) {$next="";}
}
&print_template;
}

sub next_hits {
# --------------------------------------------------------
# Creates a next hits toolbar.
#
my ($page, $numhits, $maxhits) = @_;
my ($left, $right, $upper, $lower, $next_hit, $prev_hit, $i);
my $nh = int ($page / $maxhits) || 1;
my $output = '';
$numhits =~ s/,//g;
$numhits = int ($numhits);

$next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&page=\d+//;
$next_hit = $nh + 1;
$prev_hit = $nh - 1;

# First, set how many pages we have on the left and the right.
$left = $nh;
$right = int($numhits/$maxhits) - $nh;
# Then work out what page number we can go above and below.
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);
# Finally, adjust those page numbers if we are near an endpoint.
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));

# Then let's go through the pages and build the HTML.
($nh > 1) and ($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$prev_hit">[<<]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
if ($i < $lower) { $output .= " ... "; $i = ($lower-1); next; }
if ($i > $upper) { $output .= " ... "; last; }
($i == $nh) ?
($output .= qq~$i ~) :
($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$i">$i</a> ~);
(($i * $maxhits) >= $numhits) and print "Exiting3" and last; # Special case if we hit exact.
}
$output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$next_hit">[>>]</a> ~ unless ($nh == $i);
return $output;
}

sub parse_form {
# --------------------------------------------------------
# Parses the form input and returns a hash with all the name
# value pairs. Removes any field with "---" as a value
# (as this denotes an empty SELECT field.
#
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr('You cant run this script from telnet/shell.');
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}

sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%x",ord($1))/eg;
$toencode =~ s/\//\//g;
return $toencode;
}

1;

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
You're missing sub cgierr. Try adding the following codes before 1;

Code:
sub cgierr {
print "ContentType: text/html\n\n";
print "Eror: $_[0]\n
exit;
}
(this is just a guess based on sub error in jump.cgi)

--Drew
Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
it did not work, i got 500 server error
any other ideas

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
Okay...here's sub cgierr from db_utils.pl
Code:
sub cgierr {
# --------------------------------------------------------
# Displays any errors and prints out FORM and ENVIRONMENT
# information. Useful for debugging.
#
if (!$html_headers_printed) {
print "Content-type: text/html\n\n";
$html_headers_printed = 1;
}
print "<PRE>\n\nCGI ERROR\n==========================================\n";
$_[0] and print "Error Message : $_[0]\n";
$0 and print "Script Location : $0\n";
$] and print "Perl Version : $]\n";

print "\nForm Variables\n-------------------------------------------\n";
foreach $key (sort keys %in) {
my $space = " " x (20 - length($key));
print "$key$space: $in{$key}\n";
}
print "\nEnvironment Variables\n-------------------------------------------\n";
foreach $env (sort keys %ENV) {
my $space = " " x (20 - length($env));
print "$env$space: $ENV{$env}\n";
}
print "\n</PRE>";
exit -1;
}
--Drew
Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
it did not work. no server error but no results. same original problem

Quote Reply
Re: the latest version of altavista.cgi is not working In reply to
the question was posted during the holiday. maybe someone has a solution to this problem