我仍然是Perl的新手并且遇到了困难。
我这里有一个系统,需要为用户分配权限才能运行报告。
系统在计算机上托管的本地测试环境中完全正常运行,但一旦将其上载到Windows Server 2008 for dev,它似乎不再填充已分配的报告表单。
我们使用Javascript函数填充用户下拉列表,并填充可用的可用报告。当涉及分配的报告时,不再有任何填充。从存放处获取的完全相同的代码将在本地环境中运行,没有任何问题。
只有在我们将Perl脚本的目录更改为指向本地计算机环境而不是服务器上的Perl脚本时,才会填充已分配的报告。
这是指向服务器目录:
function ReadUserPermission( iUserID )
{
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
var szURL;
var iPermNumber = 0;
szURL = "/Scripts/Security/ReadPermissions.pl";
xmlhttp.Open("POST", szURL, false);
xmlhttp.Send( iUserID );
var bRetVal = PermissionTab.loadXML( xmlhttp.responseText );
var rt = xmlhttp.responseText;
RGCollection = PermissionTab.XMLDocument.selectNodes("//REPORTGROUP");
for (var i=0; i< RGCollection.length; i++)
{
RGXML = new ActiveXObject("Msxml2.DOMDocument")
RGXML.loadXML( RGCollection.item(i).xml );
ReportCollection = RGXML.selectNodes( "//REPORTGROUPNAME" );
szReportGroupName = ReportCollection.item(0).text;
ReportCollection = RGXML.selectNodes( "//REPORTGROUPID" );
iReportGroupID = ReportCollection.item(0).text;
ReportCollection = RGXML.selectNodes( "//REPORT" );
for( var j=0; j < ReportCollection.length; j++ )
{
IR = new ActiveXObject( "MSXML2.DOMDocument" );
IR.loadXML( ReportCollection.item(j).xml );
IRD = IR.selectNodes( "//REPORTNAME" ); szReportName = IRD.item(0).text;
IRD = IR.selectNodes( "//REPORTID" ); iReportID = IRD.item(0).text;
IRD = IR.selectNodes( "//PERMISSION" ); bPermission = IRD.item(0).text;
Users[iUserID].Permissions[iPermNumber] = new DataClass;
Users[iUserID].Permissions[iPermNumber].ReportGroupName = szReportGroupName;
Users[iUserID].Permissions[iPermNumber].ReportGroupID = iReportGroupID;
Users[iUserID].Permissions[iPermNumber].ReportName = szReportName;
Users[iUserID].Permissions[iPermNumber].ReportID = iReportID;
Users[iUserID].Permissions[iPermNumber].Permission = bPermission;
iPermNumber++;
}
}
}
但是当szURL =“//028-07743/Scripts/Security/ReadPermissions.pl”时,它运行没有任何问题。
任何人都可以提供任何帮助,因为这让我很困惑。
以下是我们认为未运行的ReadPermissions.pl脚本。
use CGI qw/:standard *table start_ul :cgi-lib/;
use Win32::ODBC;
require "ServerDetails.cfg";
#Reads Details for Connection from CFG file
sub ReadCfg
{
my $file = $_[0];
our $err;
{ # Put config data into a separate namespace
package CFG;
# Process the contents of the config file
my $rc = do($file);
# Check for errors
if ($@) {
$::err = "ERROR: Failure compiling '$file' - $@";
} elsif (! defined($rc)) {
$::err = "ERROR: Failure reading '$file' - $!";
} elsif (! $rc) {
$::err = "ERROR: Failure processing '$file'";
}
}
return ($err);
}
# Get our configuration information
if (my $err = ReadCfg('ServerDetails.cfg')) {
print(STDERR $err, "\n");
exit(1);
}
$szDataSource = "DSN=$CFG::CFG{'server'}{'DSN'};UID=$CFG::CFG{'server'}{'UID'};PWD=$CFG::CFG{'server'}{'PWD'}";
%PARM = Vars;
$iUser = $PARM{'keywords'};
open TMP, ">dhtml.txt";
$db = OpenConnection( $szDataSource );
$szSQLStatement = "EXEC spGetUserPermissionTabData '$iUser'";
$iNumRecordsRead = ReadData( -dbconnection=>$db, -sqlstatement=>$szSQLStatement, -datahash=>\%UserData );
$szXMLString = "<Permissions>\n";
$szCurrentReportGroupName = "";
foreach $KEY ( sort{ $a <=> $b } keys %UserData )
{
if( $szCurrentReportGroupName ne $UserData{$KEY}{AppGroupName} )
{
if( $szCurrentReportGroupName ne "" ) #Close any previous report groups
{
$szXMLString .= "\t</REPORTGROUP>\n";
}
$szXMLString .= "\t<REPORTGROUP>\n" .
"\t\t<REPORTGROUPNAME>$UserData{$KEY}{AppGroupName}</REPORTGROUPNAME>\n" .
"\t\t<REPORTGROUPID>$UserData{$KEY}{ApplicationGroupID}</REPORTGROUPID>\n";
$szCurrentReportGroupName = $UserData{$KEY}{AppGroupName};
}
$szXMLString .= "\t<REPORT>\n" .
"\t\t<REPORTNAME>$UserData{$KEY}{AppDisplayName}</REPORTNAME>\n" .
"\t\t<REPORTID>$UserData{$KEY}{ApplicationID}</REPORTID>\n" .
"\t\t<PERMISSION>$UserData{$KEY}{PermissionType}</PERMISSION>\n" .
"\t</REPORT>\n";
}
$szXMLString .= "\t</REPORTGROUP>\n" .
"</Permissions>";
print TMP "UserID = $szUser\n";
print TMP "XML = $szXMLString\n";
print TMP "Size of XML = " . length( $szXMLString ) . "\n";
close $TMP;
print "Content-Type: text/html\n\n";
print "$szXMLString";
sub OpenConnection()
{
my( $szDSN ) = @_;
my $db = new Win32::ODBC( $szDSN );
if( !defined $db )
{
my $szLocalTime = localtime();
$szHTMLString = header;
$szHTMLString .= "Error creating ODBC connection\n";
$szHTMLString .= "<BR>Time: $szLocalTime\n";
$szHTMLString .= end_html();
print $szHTMLString;
return NULL;
}
return $db;
}
sub ReadData()
{
my ( %fnArgs ) = @_;
my $szSQLStatement = $fnArgs{-sqlstatement};
my $cDBConnection = $fnArgs{-dbconnection};
local( *DataHash ) = $fnArgs{-datahash};
my $iRowID = 0;
if ($cDBConnection->Sql($szSQLStatement))
{
print "SQL failed. Error: " . $cDBConnection->Error() . "\n";
$cDBConnection->Close();
exit;
}
while($cDBConnection->FetchRow())
{
$DataHash{$iRowID++} = {$cDBConnection->DataHash()};
}
return $iRowID;
}
sub XMLizer
{
local ( *DataHash ) = @_;
my $szXMLString = "";
foreach $KEY ( keys %DataHash )
{
$szXMLString .= "\t<" . $KEY . ">" . $DataHash{$KEY} . "</" . $KEY . ">\n";
}
return $szXMLString;
}
现在看来,如果我们将Perl文件中的SQL语句更改为$szSQLStatement = "EXEC spGetUserPermissionTabData 464";
,它将使用该特定用户报告填充指定的窗口,即使该用户未选择(预期)。我们现在认为可能Perl文件没有收到Javascript发送给它的iUserID
答案 0 :(得分:2)
Javascript是一种客户端脚本语言,不会在服务器上运行。
Node.js应该更有帮助: http://en.wikipedia.org/wiki/Node.js