Example #1
0
function updateLDAPUser($authtype, $userid)
{
    global $authMechs;
    $esc_userid = mysql_real_escape_string($userid);
    $userData = getLDAPUserData($authtype, $userid);
    if (is_null($userData)) {
        return NULL;
    }
    $affilid = $authMechs[$authtype]['affiliationid'];
    $now = unixToDatetime(time());
    // select desired data from db
    $qbase = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "af.shibonly, " . "u.emailnotices, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "COALESCE(u.rdpport, 3389) AS rdpport, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "af.id = {$affilid} AND ";
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
        $query = $qbase . "u.uid = {$userData['numericid']}";
    } else {
        $query = $qbase . "u.unityid = '{$esc_userid}' AND " . "u.affiliationid = {$affilid}";
    }
    $qh = doQuery($query, 255);
    $updateuid = 0;
    # check to see if there is a matching entry where uid is NULL but unityid and affiliationid match
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid']) && !mysql_num_rows($qh)) {
        $updateuid = 1;
        $query = $qbase . "u.unityid = '{$esc_userid}' AND " . "u.affiliationid = {$affilid}";
        $qh = doQuery($query, 255);
    }
    // if get a row
    //    update db
    //    update results from select
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$esc_userid}', " . "firstname = '{$userData['first']}', " . "lastname = '{$userData['last']}', " . "email = '{$userData['email']}', ";
        if ($updateuid) {
            $query .= "uid = {$userData['numericid']}, ";
        }
        $query .= "lastupdated = '{$now}' ";
        if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid']) && !$updateuid) {
            $query .= "WHERE uid = {$userData['numericid']}";
        } else {
            $query .= "WHERE unityid = '{$esc_userid}' AND " . "affiliationid = {$affilid}";
        }
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addLDAPUser
        $id = addLDAPUser($authtype, $userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "COALESCE(u.rdpport, 3389) AS rdpport, " . "u.showallgroups, " . "u.usepublickeys, " . "u.sshpublickeys, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        if (!($user = mysql_fetch_assoc($qh))) {
            return NULL;
        }
        $user['sshpublickeys'] = htmlspecialchars($user['sshpublickeys']);
    }
    // TODO handle generic updating of groups
    switch (getAffiliationName($affilid)) {
        case 'EXAMPLE1':
            updateEXAMPLE1Groups($user);
            break;
        default:
            //TODO possibly add to a default group
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    $user["groupperms"] = getUsersGroupPerms(array_keys($user['groups']));
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $user['login'] = $user['unityid'];
    return $user;
}
Example #2
0
function updateLDAPUser($authtype, $userid)
{
    global $authMechs;
    $userData = getLDAPUserData($authtype, $userid);
    if (is_null($userData)) {
        return NULL;
    }
    $affilid = $authMechs[$authtype]['affiliationid'];
    $now = unixToDatetime(time());
    // select desired data from db
    $query = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "af.shibonly, " . "u.emailnotices, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "adminlevel a, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "af.id = {$affilid} AND ";
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
        $query .= "u.uid = " . $userData["numericid"];
    } else {
        $query .= "u.unityid = '{$userid}' AND " . "u.affiliationid = {$affilid}";
    }
    $qh = doQuery($query, 255);
    // if get a row
    //    update db
    //    update results from select
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$userid}', " . "firstname = '{$userData['first']}', " . "lastname = '{$userData['last']}', " . "email = '{$userData['email']}', " . "lastupdated = '{$now}' ";
        if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
            $query .= "WHERE uid = " . $userData["numericid"];
        } else {
            $query .= "WHERE unityid = '{$userid}' AND " . "affiliationid = {$affilid}";
        }
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addLDAPUser
        $id = addLDAPUser($authtype, $userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        if (!($user = mysql_fetch_assoc($qh))) {
            return NULL;
        }
    }
    // TODO handle generic updating of groups
    switch (getAffiliationName($affilid)) {
        case 'EXAMPLE1':
            updateEXAMPLE1Groups($user);
            break;
        default:
            //TODO possibly add to a default group
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $user['login'] = $user['unityid'];
    return $user;
}