2.4.15

Javascript MemberOf Group AD, query LDAP ( activeX enabled /!\ and only in IE /!\)


var ldapSearchJs = ldapSearchJs || {};

ldapSearchJs.getUserName = function () {
    var wshNetwork = new ActiveXObject("WScript.Network");
    var userName = wshNetwork.UserName;
    return userName;
}

ldapSearchJs.isMemberOf = function (userName, group) {
    objConnection = new ActiveXObject("ADODB.Connection");
    objConnection.Provider = "ADsDSOObject";
    objConnection.Open("ADs Provider");
    objCommand = new ActiveXObject("ADODB.Command");
    objCommand.ActiveConnection = objConnection;

    objCommand.CommandText = "SELECT distinguishedName, memberOf, primaryGroupID, objectSID FROM 'LDAP://DC=vca-share,DC=local' "
    + " WHERE   sAMAccountName='" + userName + "' and memberof='CN=" + group + ",CN=Users,DC=vca-share,DC=local'"; //(memberOf=cn=adminsp,ou=users,dc=vca-share,DC=local))";

    objRecordSet = objCommand.Execute();

    var userMail, lastName, firstName;
    if (objRecordSet.RecordCount > 0) {
        isMemberOf = 'Yes, ' + userName + ' is memeber of ' + group;
    }
    else {
        isMemberOf = 'No';
    }
    objConnection.Close;

    return isMemberOf;
}


$(document).ready(function () {

    alert(
        ldapSearchJs.isMemberOf(ldapSearchJs.getUserName(), 'adminsp')
        );
});









































No comments:

Post a Comment