对我的Active Directory + LDAP查询的JavaScript代码进行同行评审

时间:2015-03-03 14:14:04

标签: javascript active-directory ldap

不确定StackOverflow是否允许这样做...我希望有人可以/会审核我的JavaScript代码,看看这是否合适和/或是否有更好的方法可以做到这一点?代码有效,但这是我第一次尝试使用JS查询AD,并认为一些同行评审可能会很有成效。

var ADConnection = new ActiveXObject( "ADODB.connection" );
var ADCommand = new ActiveXObject( "ADODB.Command" );

ADConnection.ConnectionTimeout = 600;
ADConnection.Open( "Data Source=Active Directory Provider;Provider=ADsDSOObject" );
ADCommand.ActiveConnection = ADConnection;
ADCommand.Properties( "Page Size" ) = 10000;
ADCommand.Properties( "Searchscope" ) = 2;
ADCommand.Properties( "Timeout" ) = 600;
ADCommand.Properties( "Cache Results" ) = false;
ADCommand.Properties( "Chase Referrals" ) = 96;
ADCommand.CommandTimeout = 600;

var ou = "DC=company,DC=com";
var filter = "....";
var fields = "name";
var level = "sublevel";

var queryType = fields.match( /memberof/ig ) ? "LDAP" : "GC";

ADCommand.CommandText = "<" + queryType + "://" + ou + ">;" + filter + ";" + fields + ";" + level;

var recordSet = ADCommand.Execute;

fields = fields.split( "," );

var data = [];

while(!recordSet.EOF)
{
    var rowResult = { "length" : fields.length };
    var i = fields.length;
    while(i--)
    {
        var fieldName = fields[i];

        if(fieldName == "directReports" && recordSet.Fields(fieldName).value != null)
            rowResult[fieldName] = true;
        else
            rowResult[fieldName] = recordSet.Fields(fieldName).value;
    }

    data.push(rowResult);
    recordSet.MoveNext;
}

recordSet.Close();

0 个答案:

没有答案