1

我仍然是 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

4

1 回答 1

2

Javascript 是一种客户端脚本语言,不会在服务器上运行。

Node.js 应该更有帮助: http ://en.wikipedia.org/wiki/Node.js

于 2012-11-11T15:18:25.037 回答