Perl帮助:无法在未定义的值上调用方法“display”

时间:2012-11-19 18:08:38

标签: linux perl cgi

让我们从基本的背景开始。我们最近带来了我们的网站托管。 很少有旧网站仍然使用Perl。我没有使用Perl的经验。 让我们开始。我们在主域上有一个子网站。

公开链接:http://www.gatewayrehab.org/eap/

当您转到网站时,我们收到以下错误消息

 "Software error:

Can't call method "display" on an undefined value at /var/www/www.gatewayrehab.org/app/webroot/eap/index.cgi line 47."

查看EAP网站/目录,所有文件都有适当的权限,我再次没有使用Perl / Cgi的经验。下面是index.cgi文件:

#!/usr/bin/perl -w

### the main control file used in the system
BEGIN { unshift @INC, qw(./cgi-bin/include/); }

### send all fatal errors to the browser
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use Error_Handler;
use File_Handler;
use Cookie_Handler;

require "./cgi-bin/setup.cgi";
do "./cgi-bin/include/common.cgi";

### initialize the file handling module
my $File = new File_Handler;
### initialize the cookie handling module
my $Cookie = new Cookie_Handler;

###parse 
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST"){
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
    $buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);

#&error_check;

foreach $pair (@pairs){
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ tr/+/ /;
    $name =~ s/\breq\_//ig;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ tr/A-Z/a-z/;
    $name = trim($name);
    $FORM{$name} = trim($value);
}

my %cookiedata = $Cookie -> get_cookies();

### read the summary database
my $summary_ref = $File -> read($login_summary)|| $Error -> display("$!". __LINE__);
my (@summary) = @$summary_ref;

### read the companies database
my $companies_ref = $File -> read($companies_db)|| $Error -> display("$!". __LINE__);
my (@companies) = @$companies_ref;

my %COMP = ();
foreach (@companies) {
    $_ =~ s/\n|\r//g;
    my ($c_num, $c_name) = split(/\t/, $_);
    $COMP{$c_num} = $c_name;
}

if ( $cookiedata{'LOGIN'} != 1 ) {
    my $found = 0;
    my $company_number = $ENV{'REMOTE_USER'};
    $company_number =~ s/s|e|w//g;

    foreach (@summary) {
        $_ =~ s/\n|\r//g;
        my @field = split(/\t/, $_);
        $field[0] = &trim($field[0]);
        $field[2] = &trim($field[2]);       
        $field[3] = &trim($field[3]);
        $field[4] = &trim($field[4]);
        $field[5] = &trim($field[5]);
        $field[6] = &trim($field[6]);

        if ( $field[0] eq "$company_number" ) {
            $found = 1;

            my $firstletters = substr($ENV{'REMOTE_USER'}, 0, 2);
            $firstletters = trim($firstletters);
            if ( $firstletters ne "sw" && $firstletters ne "lf" ) {
                $firstletters = substr($firstletters, 0, 1);
            }
            if ( lc($firstletters) eq "e" ) {
                $field[3] = ($field[3] + 1);                
            } elsif ( lc($firstletters) eq "s" ) {
                $field[2] = ($field[2] + 1);
            } elsif ( lc($firstletters) eq "w" ) {
                $field[4] = ($field[4] + 1);
            } elsif ( lc($firstletters) eq "sw" ) {
                $field[5] = ($field[2] + 1);
            } elsif ( lc($firstletters) eq "lf" ) {
                $field[6] = ($field[6] + 1);
            } else {
                $field[3] = ($field[3] + 1);
            }           

            $_ = join("\t", @field);
        } 
    }

    if ( $found == 1 ) {
        # write data back to file
        # append to summary file
        open(LOG, ">$login_summary") || $Error -> display("$!". __LINE__);
        flock(LOG,2);
        foreach (@summary) {
            print LOG $_ ."\n";
        }
        flock(LOG,8);
        close(LOG);         
        #$File -> file($login_summary);
        #$File -> data(\@summary);
        #$File -> write() || $Error -> display("$!". __LINE__); 
    } else {
        $e = 0;
        $s = 0;
        $w = 0;
        $sw = 0;
        $lf = 0;

        my $firstletters = substr($ENV{'REMOTE_USER'}, 0, 2);
        $firstletters = trim($firstletters);
        if ( $firstletters ne "sw" && $firstletters ne "lf" ) {
            $firstletters = substr($firstletters, 0, 1);
        }
        if ( lc($firstletters) eq "e" ) {
            $e = 1;         
        } elsif ( lc($firstletters) eq "s" ) {
            $s = 1;
        } elsif ( lc($firstletters) eq "w" ) {
            $w = 1;
        } elsif ( lc($firstletters) eq "sw" ) {
            #$sw = 1;
            $s = 1;
        } elsif ( lc($firstletters) eq "lf" ) {
            $lf = 1;
        } else {
            $e = 1;
        }

        # append to summary file
        open(LOG, ">>$login_summary") || $Error -> display("$!". __LINE__);
        flock(LOG,2);
        print LOG $company_number ."\t". $COMP{$company_number} ."\t". $s ."\t". $e ."\t". $w . "\t". $sw ."\t". $lf ."\n";
        flock(LOG,8);
        close(LOG); 
    }

    my (@login_logs) = ();
    my $logline = "";
    $login_logs[0] = $ENV{'REMOTE_USER'};
    $login_logs[1] = $ENV{'REMOTE_ADDR'};
    $login_logs[2] = time();

    open(LOG, ">>$login_logs") || $Error -> display("$!". __LINE__);
    flock(LOG,2);
    print LOG $ENV{'REMOTE_USER'} ."\t". $ENV{'REMOTE_ADDR'} ."\t". time() ."\n";
    flock(LOG,8);
    close(LOG);

    print "Set-Cookie: LOGIN=1";
    print "; path=$cookiepath; domain=$cookiedomain;\n";    
}

my $firstletters = substr($ENV{'REMOTE_USER'}, 0, 2);
$firstletters = trim($firstletters);
if ( $firstletters ne "sw" && $firstletters ne "lf") {
    $firstletters = substr($firstletters, 0, 1);
}

if ( lc($firstletters) eq "e" ) {
    print "Location: http://www.gatewayrehab.org/eap/new/employee/member.htm\n\n";          
} elsif ( lc($firstletters) eq "s" ) {
    print "Location: http://www.gatewayrehab.org/eap/supervisor/\n\n";
} elsif ( lc($firstletters) eq "w" ) {
    print "Location: http://www.gatewayrehab.org/eap/new/worklife/member.htm\n\n";
} elsif ( lc($firstletters) eq "sw" ) {
    print "Location: http://www.gatewayrehab.org/eap/supervisor-wl/\n\n";
    exit;
} elsif ( lc($firstletters) eq "lf" ) {
    print "Location: http://www.gatewayrehab.org/eap/legalandfinancial/\n\n";
    exit;
} else {
    print "Location: http://www.gatewayrehab.org/eap/new/employee/member.htm\n\n";
}

#output html
print "Content-type: text/html\n\n";
print "<h1>hello world!</h1>";

$e = `perl -ver`;
$r = `whereis perl5`;
$z = `whereis sendmail`;#
$w = `top`;#
$d = `w`;

print "<pre>perl version:<br>$e<hr>perl path:<br>$r<hr>sendmail path:<br>$z<hr>top:<br>$w<hr>w:<br>$d<hr>environment vars:<br>";##

while (($key, $val) = each %ENV) {
    print "$key = $val\n";
}


$x= 'lowercase';
print "<hr>path tranlsated(NT)<br>$ENV{'PATH_TRANSLATED'}</pre>";
#$x = uc($x);
print "<br>$x";
exit;

请让我知道我错过了什么。如果你需要查看更多“包含”的文件,请告诉我。

此处还有我们的cgi配置链接。 http://www.gatewayrehab.org/eap/cgi-bin/cgi.cgi

谢谢。

2 个答案:

答案 0 :(得分:1)

错误来自这一行:my $summary_ref = $File -> read($login_summary)|| $Error -> display("$!". __LINE__);。这意味着$Error不存在或其值为undef。事实上,我没有看到这样的变量被声明或初始化。也许它假设由Error_Handler ???

导出

尝试报告其他错误时会发生此错误。您可以尝试使用$Error -> display("$!". __LINE__);替换(如果仅暂时)die($!)并检查服务器的错误日志以获取错误消息。也就是说,它肯定是“没有这样的文件或目录”或“权限被拒绝”,所以也许不值得花时间找出确切的消息。 (更新:实际上,我认为该消息将被“重定向”到您的浏览器,这样可以使事情变得更容易。)

我猜这里,但看起来它正试图读取$login_summary命名的文件。我不知道它在哪里设置(如果有的话),所以你可能想要找出它的值,也许它在哪里设置。

答案 1 :(得分:0)

我通过快速解决方案解决了这个问题。我不知道它为什么会起作用但它对我有用。 在这里我做了...在线阅读后,我发现在所有。(点)cgi文件的标题上添加“-w”使其工作。 我希望有一种更好的方法可以在一个地方添加“-w”,然后将其添加到所有.cgi文件中。

简而言之,将#!/usr/bin/perl改为#!/usr/bin/perl -w

谢谢大家。