CGI脚本不在浏览器中显示结果

时间:2012-11-05 16:23:52

标签: forms perl cgi

我试图从infoblox设备显示一些信息。当我使用html帖子在浏览器中运行此代码时,显示MAC地址条目的表不会显示api中的值。当我在unix命令行中运行此代码时,变量会正确显示。任何建议?

#!/usr/bin/perl

use strict;
use Infoblox;
use CGI;
my $cgi = new CGI;

print

$cgi->header() .

$cgi->start_html( -title => 'Form Results') .

$cgi->h1('Form Results') . "\n";

my @params = $cgi->param();
my $username = $cgi->param('username');
print '<table border="1" cellspacing="0" cellpadding="0">' . "\n";
foreach my $parameter (sort @params) {
print "<tr><th>$parameter</th><td>" . $cgi->param($parameter) . "</td></tr>\n";
}
print "</table>\n";
print "<p>$username</p>";

print $cgi->end_html . "\n";



#Create a session to the Infoblox appliance
my $session = Infoblox::Session->new(
    master   => "server",          #appliance host ip
    username => "username",          #appliance user login
    password => "password"           #appliance password
);

unless ($session) {
    die("Construct session failed: ",
    Infoblox::status_code() . ":" . Infoblox::status_detail());
}

print "Session created successfully\n<br>";

my @list = $session->get(
    object => "Infoblox::DHCP::MAC",
    filter => "macfilter",
);

my $nextobject = $list[0];

print <<EOF;
<br>
<table>
<tr>
<th>MAC</th>
<th>Description</th>
<th>UserID</th>
<th>Expiration</th>
</tr>
EOF

foreach my $test ( @list ) {

   print "<tr>";
   print "<td> $test->mac()</td>";
   print "<td>" . scalar($test->comment()) . "</td>\n";
   print "<td>" . scalar($test->username()) . "</td>\n";
   print "<td>" . scalar(localtime(scalar($test->expiration_time()))) . "</td>\n";
   print "</tr>";

}

exit (0);

1 个答案:

答案 0 :(得分:0)

我的权限不正确。该脚本以用户nobody身份运行,不会在网页上正确显示项目。