Jump to content

Cgi Perl Modules


LF help

Recommended Posts

Looking for help with CGI files. I try to include one on my website but it gives an error and sometimes it doesnt show anything. I'am on the Johnny host what i got to do.

 

<!--#include virtual="/cgi-bin/poll.cgi?poll=1" --> actually that is my include for the poll

 

The script contains the following

 

#!usr/bin/perl

print "content-type: text/html\n\n"

use strict;
use CGI qw(:all);
my $poll_id = int(param('poll'));
my $action;
open FH, "poll_${poll_id}_ip.txt";
my $ip = <FH>;
close FH;
chomp $ip;
$ip = defined($ip) ? $ip : '';
if ($ip eq '') { $ip = ':' }
my $pat = join('\.', split(/\./, $ENV{'REMOTE_ADDR'}));
my $mode = $ip =~ /\:$pat\:/ ? 0 : 1;
if (($mode == 0) || defined(param('see'))) {
print "Content-Type: text/html\n\n";
print "<center>Poll results</center>\n";
open FH, "poll_${poll_id}_text.txt";
my @lines = <FH>;
close FH;
print join("<br>", @lines);
open FH, "poll_${poll_id}_lines.txt";
my @lines = <FH>;
close FH;
open FH, "poll_${poll_id}_results.txt";
my @votes = <FH>;
close FH;
my $sum = 0;
foreach (@votes) {
$sum += int($_);
}
print "<center><table border=0 cellspacing=0 cellpadding=4>";
for (my $i = 0; $i <= $#lines; $i++) {
my $width = 200;
my $a = int($votes[$i] * $width / $sum);
my $b = $width - $a;
print "<tr><td align=right>$lines[$i] (".int($votes[$i]).")</td><td><table width=$width height=10><tr><td width=$a bgcolor=black></td><td width=$b bgcoloe=blue></td></tr></table></td></tr>";
}
print "</table></center>";
} else {
if (defined(param('dovote'))) {
my $vote = int(param('vote'));
open FH, "poll_${poll_id}_lines.txt";
my @lines = <FH>;
close FH;
if ($vote > $#lines) {
print "Content-Type: text/html\n\nError";
exit 0;
}
open FH, "poll_${poll_id}_results.txt";
my @lines = <FH>;
close FH;
foreach (@lines) {
chomp $_;
}
$lines[$vote] = int($lines[$vote]) + 1;
open FH, ">poll_${poll_id}_results.txt";
print FH join("\n", @lines);
close FH;
open FH, ">poll_${poll_id}_ip.txt";
print FH "$ip$ENV{'REMOTE_ADDR'}:";
close FH;
print redirect(-uri => $ENV{'HTTP_REFERER'});
} else {
print "Content-Type: text/html\n\n";
print "<form action=/cgi-bin/poll.cgi method=post>";
print "<input type=hidden name=poll value=$poll_id>";
open FH, "poll_${poll_id}_text.txt";
my @lines = <FH>;
close FH;
print join("<br>", @lines);
print "<center><table border=0 cellspacing=0 cellpadding=4>";
open FH, "poll_${poll_id}_lines.txt";
my @lines = <FH>;
close FH;
for (my $i = 0; $i <= $#lines; $i++) {
print "<tr><td align=center><input type=radio name=vote value=$i></td><td>$lines[$i]</td></tr>";
}
print "<tr><td align=center colspan=2><input type=submit name=dovote value=Vote> <input type=submit name=see value=\"See results\"></td></tr>";
print "</table></center>";
print "</form>";
}
}

 

my error log says

[Tue Feb 28 11:03:07 2012] [error] [client 92.66.136.41] unable to include "cgi-bin/poll.cgi?poll=1" in parsed file /home/jeroenn/public_html/Home.shtml

please help me

 

on the page it is showing

[an error occurred while processing this directive]

Link to comment
Share on other sites

  • 3 years later...

I have precisely this problem today and no solution so am disappointed to see no replies alas. I cna however help you by observing the content of the script is irrelevant as it isn't even loaded. It is found, but not loaded. I know it's found because if I change the name of the script I get another error in the log saying it's not found. So I firts suspect permissions, and ensured it had 755 and still no luck. So I'm presently bamboozled as SSH is not available to log on and do manual execution diagnositics or poke around. So am relying on some tips here as to what might be at play. My situation is:

 

/public_html/bernd/index.shtml

Perms 0644

Complete content:

&--#60;META http-equiv="expires" content="0"&--#62;

&--#60;!--#include virtual="cgi-bin/build_home.pl"--&--#62;

 

/public_html/bernd/cgi-bin/build_home.pl

Perms 0755

Head:

#!/usr/bin/perl

#####################################################################################

## Builds a home page and prints it

 

I would appreciate some insights here. A slight mystery. This is a port form anotehr host where it worked fine, but something is awry here and the include is failing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...