Ejemplo n.º 1
0
/**
 * This function returns the user ID of the logged in user on your site.  Technical support will not
 * help you with this for stand-alone installations.  You must purchase the professional installation
 * if you are having trouble.
 *
 * Suggestion: Check out the other integration files in the functions/integrations directory for
 * many examples of how this can be done.  The easiest way is to get the user ID through a cookie.
 *
 * @return the user ID of the logged in user or NULL if not logged in
 */
function get_user_id()
{
    global $db;
    $userid = NULL;
    if (!empty($_COOKIE['PHPSESSID'])) {
        $result = $db->execute("\n\t\t\t\tSELECT data \n\t\t\t\tFROM " . TABLE_PREFIX . "core_session \n\t\t\t\tWHERE id = '" . $db->escape_string($_COOKIE['PHPSESSID']) . "'\n\t\t\t");
        if ($row = $db->fetch_array($result)) {
            $data = $row['data'];
            $data = unserializesession($data);
            if (!empty($data['Zend_Auth']['storage'])) {
                $userid = $data['Zend_Auth']['storage'];
            }
        }
    }
    return $userid;
}
/**
 * This function returns the user ID of the logged in user on your site.  Technical support will not
 * help you with this for stand-alone installations.  You must purchase the professional installation
 * if you are having trouble.
 *
 * Suggestion: Check out the other integration files in the functions/integrations directory for
 * many examples of how this can be done.  The easiest way is to get the user ID through a cookie.
 *
 * @return the user ID of the logged in user or NULL if not logged in
 */
function get_user_id()
{
    global $db;
    $userid = NULL;
    if (!empty($_COOKIE['PHPSESSID'])) {
        $result = $db->execute("\n\t\t\t\tSELECT data, user_id\n\t\t\t\tFROM " . TABLE_PREFIX . "core_session \n\t\t\t\tWHERE id = '" . $db->escape_string($_COOKIE['PHPSESSID']) . "'\n\t\t\t");
        if ($row = $db->fetch_array($result)) {
            // The user ID row still remains even when logged out
            /*if (!empty($row['user_id']))
            		{
            			$userid = $row['user_id'];
            		}
            		else
            		{*/
            $data = $row['data'];
            $data = unserializesession($data);
            if (!empty($data['Zend_Auth']['storage'])) {
                $userid = $data['Zend_Auth']['storage'];
            }
            //}
        }
    }
    return $userid;
}
Ejemplo n.º 3
0
function LogoutNotification($SessionID)
{
    // Delete session of user using $SessionID to locate the user's session file
    // on the file system or in the database
    // Then delete this entry or record to clear the session
    // However, for that to work it is essential that the user's Shibboleth
    // SessionID is stored in the user session data!
    global $ilDB;
    $q = "SELECT session_id, data FROM usr_session WHERE expires > 'NOW()'";
    $r = $ilDB->query($q);
    while ($session_entry = $r->fetchRow(DB_FETCHMODE_ASSOC)) {
        $user_session = unserializesession($session_entry['data']);
        // Look for session with matching Shibboleth session id
        // and then delete this ilias session
        foreach ($user_session as $user_session_entry) {
            if (is_array($user_session_entry) && array_key_exists('shibboleth_session_id', $user_session_entry) && $user_session_entry['shibboleth_session_id'] == $SessionID) {
                // Delete this session entry
                if (db_session_destroy($session_entry['session_id']) !== true) {
                    return new SoapFault('LogoutError', 'Could not delete session entry in database.');
                }
            }
        }
    }
    // If no SoapFault is returned, all is fine
}
Ejemplo n.º 4
0
function LogoutNotification($SessionID)
{
    global $CFG, $SESSION, $DB;
    // Delete session of user using $SessionID
    if (empty($CFG->dbsessions)) {
        // File session
        $dir = $CFG->dataroot . '/sessions';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                // Read all session files
                while (($file = readdir($dh)) !== false) {
                    // Check if it is a file
                    if (is_file($dir . '/' . $file)) {
                        $session_key = preg_replace('/sess_/', '', $file);
                        // Read session file data
                        $data = file($dir . '/' . $file);
                        if (isset($data[0])) {
                            $user_session = unserializesession($data[0]);
                            // Check if we have found session that shall be deleted
                            if (isset($user_session['SESSION']) && isset($user_session['SESSION']->shibboleth_session_id)) {
                                // If there is a match, delete file
                                if ($user_session['SESSION']->shibboleth_session_id == $SessionID) {
                                    // Delete session file
                                    if (!unlink($dir . '/' . $file)) {
                                        return new SoapFault('LogoutError', 'Could not delete Moodle session file.');
                                    }
                                }
                            }
                        }
                    }
                }
                closedir($dh);
            }
        }
    } else {
        // DB Session
        //TODO: this needs to be rewritten to use new session stuff
        if (!empty($CFG->sessiontimeout)) {
            $ADODB_SESS_LIFE = $CFG->sessiontimeout;
        }
        if ($user_session_data = $DB->get_records_sql('SELECT sesskey, sessdata FROM {sessions2} WHERE expiry > NOW()')) {
            foreach ($user_session_data as $session_data) {
                // Get user session
                $user_session = adodb_unserialize(urldecode($session_data->sessdata));
                if (isset($user_session['SESSION']) && isset($user_session['SESSION']->shibboleth_session_id)) {
                    // If there is a match, delete file
                    if ($user_session['SESSION']->shibboleth_session_id == $SessionID) {
                        // Delete this session entry
                        if (ADODB_Session::destroy($session_data->sesskey) !== true) {
                            return new SoapFault('LogoutError', 'Could not delete Moodle session entry in database.');
                        }
                    }
                }
            }
        }
    }
    // If now SoapFault was thrown the function will return OK as the SP assumes
}
Ejemplo n.º 5
0
function migrateSessionTable()
{
    global $sessionObj;
    try {
        createOrAlterSessionVariableTable();
        \Cx\Lib\UpdateUtil::sql('TRUNCATE TABLE `' . DBPREFIX . 'session_variable`');
        $objResult = \Cx\Lib\UpdateUtil::sql('SELECT
                                                `sessionid`,
                                                `datavalue`
                                              FROM
                                                 `' . DBPREFIX . 'sessions`');
        if ($objResult) {
            while (!$objResult->EOF) {
                $sessionId = $objResult->fields['sessionid'];
                if ($sessionId == $sessionObj->sessionid) {
                    $sessionArray = $_SESSION;
                    // migrate the current state into database.
                } else {
                    $sessionArray = unserializesession($objResult->fields['datavalue']);
                }
                insertSessionArray($sessionId, $sessionArray);
                $objResult->MoveNext();
            }
        }
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'sessions', array('sessionid' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'primary' => true), 'remember_me' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'sessionid'), 'startdate' => array('type' => 'VARCHAR(14)', 'notnull' => true, 'default' => '', 'after' => 'remember_me'), 'lastupdated' => array('type' => 'VARCHAR(14)', 'notnull' => true, 'default' => '', 'after' => 'startdate'), 'status' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => '', 'after' => 'lastupdated'), 'user_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'status')), array('LastUpdated' => array('fields' => array('lastupdated'))));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    return true;
}