Web Hosting Talk







View Full Version : CGI Problem


sjau
02-21-2004, 02:11 PM
Hiya,

I have a problem running a cgi on a server. The cgi-bin seems to work fine since the "hello.cgi" containing the following code prints out "Hello world" just fine:


#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "Hello, world!\n";



However when I try to run the init.cgi script from JMBSoft's AutoGallery SQL I just get a 500 error.

Apache logs following error message:

[Sat Feb 21 13:12:57 2004] [error] 11736: ModPerl::Registry: Undefined subroutine &ModPerl::ROOT::ModPerl::Registry::var_www_perl_hgw_init_2ecgi::Error called at /var/www/perl/hgw/init.cgi line 26.!

Here's part of that init script:

#!/usr/bin/perl
##############################
## AutoGallery SQL v3.0.x ##
#######################################################
## init.cgi - Initialize the software installation ##
#######################################################


my $passed = 1;
my $dbh = undef;
my $cwd = `pwd`;

chomp($cwd);

eval
{
require 'common.pl';
require 'ags.pl';
Header("Content-type: text/html\n\n");
Main();
};


if( $@ )
{
Error("$@", 'init.cgi');
}



sub Main
{
ParseRequest();

if( -e "$ADIR/.htpasswd" )
{
ParseTemplate('init_done.tpl');
}
else
{
if( $F{'Username'} && $F{'Database'} )
{
eval("use DBI;");

## Attempt a connection to the MySQL server
$dbh = DBI->connect("DBI:mysql:$F{'Database'}:$F{'Hostname'}", $F{'Username'}, $F{'Password'}, {'PrintError$

## Connection failed
if( !$dbh )
{
HashToTemplate(\%F);

$T{'Error'} = DBI->errstr();

ParseTemplate('init_main.tpl');
}

## Connection established
if( !$dbh )
{
HashToTemplate(\%F);

$T{'Error'} = DBI->errstr();

ParseTemplate('init_main.tpl');
}

## Connection established
else
{
## Create database tables
CreateTables();

## Record settings in the variables file
RecordSettings();

## Setup the scanner.cgi and cron.cgi files
SetupScripts();

## Setup .htaccess password protection
SetupLogin();

$dbh->disconnect();

ParseTemplate('init_login.tpl');
}
}
else
{
## Run the tests
$T{'DBI'} = ModuleTest('DBI');
$T{'DBD'} = ModuleTest('DBD::mysql');
$T{'Templates'} = TemplatesTest();
$T{'Language'} = FileTest("$DDIR/language");
$T{'Scanner'} = FileTest("scanner.cgi");
$T{'Cron'} = FileTest("cron.cgi");
$T{'Admin'} = DirectoryTest($ADIR);
$T{'Data'} = DirectoryTest($DDIR);


## All tests passed
if( $passed )
{
$T{'Hostname'} = 'localhost';
ParseTemplate('init_main.tpl');
}

## One or more tests failed
else
{
ParseTemplate('init_test.tpl');
}
}

}
}


Anyone knows what's causing that error?

perlninja
02-22-2004, 08:59 AM
On line 26 it's trying to call the subroutine "Error" but it doesn't exist.

Line 26: Error("$@", 'init.cgi');


Did you upload common.pl and ags.pl? those are being included on lines 17 and 18.

oletom
02-22-2004, 09:51 AM
opps I didn't read the post right so I removed my comment

They need a Delete button:blush:

sjau
02-22-2004, 10:03 AM
Thx for the reply but meanwhile I figured it out.

The support told me it's due to mod_perl. The script must not be run under mod_perl but directly as CGI (me not being a CGI pro don't know where the difference is).

Anway, I have now two perl/cgi bins:


Alias /perl /var/www/perl
<Directory /var/www/perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>

Alias /cgi-bin /var/www/cgi-bin
<Directory /var/www/cgi-bin>
Options +ExecCGI
</Directory>


And when I now run it in the cgi-bin it works.

Thx for the help anyway :)