コード例 #1
0
function checksGroups()
{
    $ldap = new ldapAD();
    $sql = "SELECT groupdn FROM activedirectory_groups GROUP BY groupdn";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    echo mysql_num_rows($results) . " groups to parse\n";
    $prefix = "INSERT IGNORE INTO activedirectory_groupsNames (dn,groupname,UsersCount,description) VALUES";
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        //echo $ligne["groupdn"]."\n";
        $hash = $ldap->Ldap_search($ligne["groupdn"], "objectclass=*", array());
        //echo $ligne["groupdn"]."= {$hash["count"]} items\n";
        for ($i = 0; $i < $hash["count"]; $i++) {
            $cn = $hash[$i]["cn"][0];
            $dn = utf8_encode($hash[$i]["dn"]);
            $cn = utf8_encode($cn);
            $UsersCount = $hash[$i]["member"]["count"];
            $description = utf8_encode($hash[$i]["description"][0]);
            $dn = addslashes($dn);
            $cn = addslashes($cn);
            $description = addslashes($description);
            $GLOBALS["MEMORY_COUNT_GROUPS"] = $GLOBALS["MEMORY_COUNT_GROUPS"] + 1;
            $sqli[] = "('{$dn}','{$cn}',{$UsersCount},'{$description}')";
            if (count($sqli) > 500) {
                $sqlfinal = $prefix . " " . @implode(",", $sqli);
                $q->QUERY_SQL($sqlfinal, "artica_backup");
                if (!$q->ok) {
                    echo $q->mysql_error . "\n";
                    return;
                }
                $sqli = array();
            }
        }
    }
    if (count($sqli) > 0) {
        $sqlfinal = $prefix . " " . @implode(",", $sqli);
        $q->QUERY_SQL($sqlfinal, "artica_backup");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            return;
        }
        $sql = array();
    }
}
コード例 #2
0
function aliases_ad()
{
    $ldap = new ldapAD();
    $filter = "(&(objectClass=user)(userPrincipalName=*))";
    $attrs = array("userPrincipalName", "mail");
    $dn = "{$ldap->suffix}";
    $hash = $ldap->Ldap_search($dn, $filter, $attrs);
    for ($i = 0; $i < $hash["count"]; $i++) {
        $mail = trim($hash[$i]["mail"][0]);
        $userPrincipalName = trim($hash[$i]["userprincipalname"][0]);
        $GLOBALS["virtual_alias_maps"][$userPrincipalName] = "{$userPrincipalName}\t{$mail}";
    }
}