示例#1
0
function update_user($username, $id)
{
    $up = new Ldap();
    $up->load_config();
    $up->ldap_conn() or error_log("Unable to connect LDAP server : " . $up->getErrorString());
    // update user piwigo rights / access according to ldap. Only if it's webmaster / admin, so no normal !
    if ($up->ldap_status($username) != 'normal') {
        single_update(USER_INFOS_TABLE, array('status' => $up->ldap_status($username)), array('user_id' => $id));
    }
    // search groups
    $group_query = 'SELECT name, id FROM ' . GROUPS_TABLE . ';';
    $result = pwg_query($group_query);
    $inserts = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($up->user_membership($username, $up->ldap_group($row['name']))) {
            $inserts[] = array('user_id' => $id, 'group_id' => $row['id']);
        }
    }
    if (count($inserts) > 0) {
        mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $inserts, array('ignore' => true));
    }
}
示例#2
0
// Check LDAP configuration
// the user need to have saved his config to do that.
if (isset($_POST['check_ldap'])) {
    if ($me->config['users_group']) {
        if ($me->user_membership($_POST['USERNAME'], $me->ldap_group($me->config['users_group']))) {
            if ($me->ldap_bind_as($_POST['USERNAME'], $_POST['PASSWORD'])) {
                // search groups
                $group_query = 'SELECT name, id FROM ' . GROUPS_TABLE . ';';
                $groups = pwg_query($group_query);
                $sentence = '';
                foreach ($groups as $group) {
                    if ($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) {
                        $sentence = $sentence . ', ' . $group['name'];
                    }
                }
                $template->assign('LD_CHECK_LDAP', '<p style="color:green;">Configuration LDAP OK : ' . $_POST['USERNAME'] . ' is in users' . $sentence . ' group(s) and can auth. He is a ' . $me->ldap_status($_POST['USERNAME']) . ' user according to the plugin.</p>');
            } else {
                $template->assign('LD_CHECK_LDAP', '<p style="color:red;">Error : test ' . $me->config['uri'] . ' ' . $me->ldap_name($_POST['USERNAME']) . '</p>');
            }
        }
    } else {
        if ($me->ldap_bind_as($_POST['USERNAME'], $_POST['PASSWORD'])) {
            // search groups
            $group_query = 'SELECT name, id FROM ' . GROUPS_TABLE . ';';
            $groups = pwg_query($group_query);
            $sentence = '';
            foreach ($groups as $group) {
                if ($me->user_membership($_POST['USERNAME'], $me->ldap_group($group['name']))) {
                    $sentence = $sentence . ', ' . $group['name'];
                }
            }