示例#1
0
 public function testDebug()
 {
     // Line 1799
     $dummy = array('Letter 1' => 'a', 'Letter 2' => 'b');
     $retval = '<ul><pre><p>---- DEBUG ----</p>';
     foreach ($dummy as $k => $v) {
         $retval .= sprintf("<li>%13s [%s]</li>\n", $k, $v);
     }
     $retval .= '<p>---------------</p></pre></ul>';
     $compare = COM_debug($dummy);
     $this->assertEquals($retval, $compare, "Error asserting {$output} matched {$compare}");
 }
示例#2
0
/**
* This gets the state for the user
*
* Much of this code if from phpBB (www.phpbb.org).  This checks the session
* cookie and long term cookie to get the users state.
*
* @return   array   returns $_USER array
*
*/
function SESS_sessionCheck()
{
    global $_CONF, $_TABLES, $_USER, $_SESS_VERBOSE;
    if ($_SESS_VERBOSE) {
        COM_errorLog("***Inside SESS_sessionCheck***", 1);
    }
    unset($_USER);
    // We MUST do this up here, so it's set even if the cookie's not present.
    $user_logged_in = 0;
    $logged_in = 0;
    $userdata = array();
    // Check for a cookie on the users's machine.  If the cookie exists, build
    // an array of the users info and setup the theme.
    if (isset($_COOKIE[$_CONF['cookie_session']])) {
        $sessid = COM_applyFilter($_COOKIE[$_CONF['cookie_session']]);
        if ($_SESS_VERBOSE) {
            COM_errorLog("got {$sessid} as the session id from lib-sessions.php", 1);
        }
        $userid = SESS_getUserIdFromSession($sessid, $_CONF['session_cookie_timeout'], $_SERVER['REMOTE_ADDR'], $_CONF['cookie_ip']);
        if ($_SESS_VERBOSE) {
            COM_errorLog("Got {$userid} as User ID from the session ID", 1);
        }
        if ($userid > 1) {
            // Check user status
            $status = SEC_checkUserStatus($userid);
            if ($status == USER_ACCOUNT_ACTIVE || $status == USER_ACCOUNT_AWAITING_ACTIVATION) {
                $user_logged_in = 1;
                SESS_updateSessionTime($sessid, $_CONF['cookie_ip']);
                $userdata = SESS_getUserDataFromId($userid);
                if ($_SESS_VERBOSE) {
                    COM_errorLog("Got " . count($userdata) . " pieces of data from userdata", 1);
                    COM_errorLog(COM_debug($userdata), 1);
                }
                $_USER = $userdata;
                $_USER['auto_login'] = false;
            }
        } else {
            // Session probably expired, now check permanent cookie
            if (isset($_COOKIE[$_CONF['cookie_name']])) {
                $userid = $_COOKIE[$_CONF['cookie_name']];
                if (empty($userid) || $userid == 'deleted') {
                    unset($userid);
                } else {
                    $userid = COM_applyFilter($userid, true);
                    $cookie_password = '';
                    $userpass = '';
                    if ($userid > 1 && isset($_COOKIE[$_CONF['cookie_password']])) {
                        $cookie_password = $_COOKIE[$_CONF['cookie_password']];
                        $userpass = DB_getItem($_TABLES['users'], 'passwd', "uid = {$userid}");
                    }
                    if (empty($cookie_password) || $cookie_password != $userpass) {
                        // User may have modified their UID in cookie, ignore them
                    } else {
                        if ($userid > 1) {
                            // Check user status
                            $status = SEC_checkUserStatus($userid);
                            if ($status == USER_ACCOUNT_ACTIVE || $status == USER_ACCOUNT_AWAITING_ACTIVATION) {
                                $user_logged_in = 1;
                                $sessid = SESS_newSession($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']);
                                SESS_setSessionCookie($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']);
                                $userdata = SESS_getUserDataFromId($userid);
                                $_USER = $userdata;
                                $_USER['auto_login'] = true;
                            }
                        }
                    }
                }
            }
        }
    } else {
        if ($_SESS_VERBOSE) {
            COM_errorLog('session cookie not found from lib-sessions.php', 1);
        }
        // Check if the persistent cookie exists
        if (isset($_COOKIE[$_CONF['cookie_name']])) {
            // Session cookie doesn't exist but a permanent cookie does.
            // Start a new session cookie;
            if ($_SESS_VERBOSE) {
                COM_errorLog('perm cookie found from lib-sessions.php', 1);
            }
            $userid = $_COOKIE[$_CONF['cookie_name']];
            if (empty($userid) || $userid == 'deleted') {
                unset($userid);
            } else {
                $userid = COM_applyFilter($userid, true);
                $cookie_password = '';
                $userpass = '';
                if ($userid > 1 && isset($_COOKIE[$_CONF['cookie_password']])) {
                    $userpass = DB_getItem($_TABLES['users'], 'passwd', "uid = {$userid}");
                    $cookie_password = $_COOKIE[$_CONF['cookie_password']];
                }
                if (empty($cookie_password) || $cookie_password != $userpass) {
                    // User could have modified UID in cookie, don't do shit
                } else {
                    if ($userid > 1) {
                        // Check user status
                        $status = SEC_checkUserStatus($userid);
                        if ($status == USER_ACCOUNT_ACTIVE || $status == USER_ACCOUNT_AWAITING_ACTIVATION) {
                            $user_logged_in = 1;
                            // Create new session and write cookie
                            $sessid = SESS_newSession($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']);
                            SESS_setSessionCookie($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']);
                            $userdata = SESS_getUserDataFromId($userid);
                            $_USER = $userdata;
                            $_USER['auto_login'] = true;
                        }
                    }
                }
            }
        }
    }
    if ($_SESS_VERBOSE) {
        COM_errorLog("***Leaving SESS_sessionCheck***", 1);
    }
    // Ensure $_USER is set to avoid warnings (path exposure...)
    if (isset($_USER)) {
        return $_USER;
    } else {
        return NULL;
    }
}