Vergleich inc/class_session.php - 1.8.4 - 1.8.25

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 10Zeile 10

class session
{


class session
{

 
	/**
* @var int
*/

	public $sid = 0;

	public $sid = 0;

 
	/**
* @var int
*/

	public $uid = 0;

	public $uid = 0;

 
	/**
* @var string
*/

	public $ipaddress = '';

	public $ipaddress = '';

 
	/**
* @var string
*/

	public $packedip = '';

	public $packedip = '';

 
	/**
* @var string
*/

	public $useragent = '';

	public $useragent = '';

 
	/**
* @var bool
*/

	public $is_spider = false;

	public $is_spider = false;

 

/**
* Request parameters that are to be ignored for location storage
*
* @var array
*/
public $ignore_parameters = array(
'my_post_key',
'logoutkey',
);


/**
* Initialize a session
*/
function init()
{


/**
* Initialize a session
*/
function init()
{

		global $db, $mybb, $cache;

		global $db, $mybb, $cache, $plugins;


// Get our visitor's IP.
$this->ipaddress = get_ip();


// Get our visitor's IP.
$this->ipaddress = get_ip();

Zeile 35Zeile 63
		if(isset($mybb->cookies['sid']) && !defined('IN_UPGRADE'))
{
$sid = $db->escape_string($mybb->cookies['sid']);

		if(isset($mybb->cookies['sid']) && !defined('IN_UPGRADE'))
{
$sid = $db->escape_string($mybb->cookies['sid']);

			// Load the session
$query = $db->simple_select("sessions", "*", "sid='{$sid}' AND ip=".$db->escape_binary($this->packedip));
$session = $db->fetch_array($query);
if($session['sid'])


// Load the session if not using a bot sid
if(substr($sid, 3, 1) !== '=')


			{

			{

				$this->sid = $session['sid'];






				$query = $db->simple_select("sessions", "*", "sid='{$sid}'");
$session = $db->fetch_array($query);
if($session['sid'])
{
$this->sid = $session['sid'];
}

			}

			}

 
		}

if(isset($plugins))
{
$plugins->run_hooks('pre_session_load', $this);

		}

// If we have a valid session id and user id, load that users session.

		}

// If we have a valid session id and user id, load that users session.

Zeile 72Zeile 109

// Still nothing? JUST A GUEST!
if(!$this->is_spider)


// Still nothing? JUST A GUEST!
if(!$this->is_spider)

			{

			{

				$this->load_guest();
}
}

				$this->load_guest();
}
}

Zeile 87Zeile 124
	/**
* Load a user via the user credentials.
*

	/**
* Load a user via the user credentials.
*

	 * @param int The user id.
* @param string The user's loginkey.


	 * @param int $uid The user id.
* @param string $loginkey The user's loginkey.
* @return bool

	 */
function load_user($uid, $loginkey='')
{

	 */
function load_user($uid, $loginkey='')
{

		global $mybb, $db, $time, $lang, $mybbgroups, $session, $cache;

// Read the banned cache
$bannedcache = $cache->read("banned");

// If the banned cache doesn't exist, update it and re-read it
if(!is_array($bannedcache))
{
$cache->update_banned();
$bannedcache = $cache->read("banned");
}


		global $mybb, $db, $time, $lang, $mybbgroups, $cache;












		$uid = (int)$uid;
$query = $db->query("
SELECT u.*, f.*

		$uid = (int)$uid;
$query = $db->query("
SELECT u.*, f.*

Zeile 114Zeile 142
		");
$mybb->user = $db->fetch_array($query);


		");
$mybb->user = $db->fetch_array($query);


		if(!empty($bannedcache[$uid]))
{
$banned_user = $bannedcache[$uid];
$mybb->user['bandate'] = $banned_user['dateline'];
$mybb->user['banlifted'] = $banned_user['lifted'];
$mybb->user['banoldgroup'] = $banned_user['oldgroup'];
$mybb->user['banolddisplaygroup'] = $banned_user['olddisplaygroup'];
$mybb->user['banoldadditionalgroups'] = $banned_user['oldadditionalgroups'];
}

// Check the password if we're not using a session
if(empty($loginkey) || $loginkey != $mybb->user['loginkey'] || !$mybb->user['uid'])

		// Check the password if we're not using a session
if(empty($loginkey) || $loginkey !== $mybb->user['loginkey'] || !$mybb->user['uid'])











		{
unset($mybb->user);
$this->uid = 0;
return false;
}
$this->uid = $mybb->user['uid'];

		{
unset($mybb->user);
$this->uid = 0;
return false;
}
$this->uid = $mybb->user['uid'];





		// Set the logout key for this user
$mybb->user['logoutkey'] = md5($mybb->user['loginkey']);


		// Set the logout key for this user
$mybb->user['logoutkey'] = md5($mybb->user['loginkey']);


Zeile 145Zeile 163
				$update += 1;
}
if($mybb->user['unreadpms'] == -1)

				$update += 1;
}
if($mybb->user['unreadpms'] == -1)

			{

			{

				$update += 2;
}


				$update += 2;
}


Zeile 160Zeile 178
		$mybb->user['pms_unread'] = $mybb->user['unreadpms'];

if($mybb->user['lastip'] != $this->packedip && array_key_exists('lastip', $mybb->user) && !defined('IN_UPGRADE'))

		$mybb->user['pms_unread'] = $mybb->user['unreadpms'];

if($mybb->user['lastip'] != $this->packedip && array_key_exists('lastip', $mybb->user) && !defined('IN_UPGRADE'))

		{

		{

			$lastip_add = ", lastip=".$db->escape_binary($this->packedip);

			$lastip_add = ", lastip=".$db->escape_binary($this->packedip);

		}

		}

		else
{
$lastip_add = '';

		else
{
$lastip_add = '';

		}


		}


		// If the last visit was over 900 seconds (session time out) ago then update lastvisit.
$time = TIME_NOW;
if($time - $mybb->user['lastactive'] > 900)

		// If the last visit was over 900 seconds (session time out) ago then update lastvisit.
$time = TIME_NOW;
if($time - $mybb->user['lastactive'] > 900)

Zeile 181Zeile 199
		{
$timespent = TIME_NOW - $mybb->user['lastactive'];
$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastactive='$time', timeonline=timeonline+$timespent{$lastip_add} WHERE uid='{$mybb->user['uid']}'");

		{
$timespent = TIME_NOW - $mybb->user['lastactive'];
$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastactive='$time', timeonline=timeonline+$timespent{$lastip_add} WHERE uid='{$mybb->user['uid']}'");

		}

		}


// Sort out the language and forum preferences.
if($mybb->user['language'] && $lang->language_exists($mybb->user['language']))


// Sort out the language and forum preferences.
if($mybb->user['language'] && $lang->language_exists($mybb->user['language']))

Zeile 202Zeile 220
		{
global $time_formats;
if($time_formats[$mybb->user['timeformat']])

		{
global $time_formats;
if($time_formats[$mybb->user['timeformat']])

			{

			{

				$mybb->settings['timeformat'] = $time_formats[$mybb->user['timeformat']];

				$mybb->settings['timeformat'] = $time_formats[$mybb->user['timeformat']];

			}
}

			}
}


// Find out the threads per page preference.
if($mybb->user['tpp'])
{
$mybb->settings['threadsperpage'] = $mybb->user['tpp'];


// Find out the threads per page preference.
if($mybb->user['tpp'])
{
$mybb->settings['threadsperpage'] = $mybb->user['tpp'];

		}

		}


// Find out the posts per page preference.
if($mybb->user['ppp'])
{
$mybb->settings['postsperpage'] = $mybb->user['ppp'];


// Find out the posts per page preference.
if($mybb->user['ppp'])
{
$mybb->settings['postsperpage'] = $mybb->user['ppp'];

		}

		}


// Does this user prefer posts in classic mode?
if($mybb->user['classicpostbit'])
{
$mybb->settings['postlayout'] = 'classic';


// Does this user prefer posts in classic mode?
if($mybb->user['classicpostbit'])
{
$mybb->settings['postlayout'] = 'classic';

		}

		}

		else

		else

		{

		{

			$mybb->settings['postlayout'] = 'horizontal';

			$mybb->settings['postlayout'] = 'horizontal';

 
		}

$usergroups = $cache->read('usergroups');

if(!empty($usergroups[$mybb->user['usergroup']]) && $usergroups[$mybb->user['usergroup']]['isbannedgroup'] == 1)
{
$ban = $db->fetch_array(
$db->simple_select('banned', '*', 'uid='.(int)$mybb->user['uid'], array('limit' => 1))
);

if($ban)
{
$mybb->user['banned'] = 1;
$mybb->user['bandate'] = $ban['dateline'];
$mybb->user['banlifted'] = $ban['lifted'];
$mybb->user['banoldgroup'] = $ban['oldgroup'];
$mybb->user['banolddisplaygroup'] = $ban['olddisplaygroup'];
$mybb->user['banoldadditionalgroups'] = $ban['oldadditionalgroups'];
$mybb->user['banreason'] = $ban['reason'];
}
else
{
$mybb->user['banned'] = 0;
}

		}

// Check if this user is currently banned and if we have to lift it.

		}

// Check if this user is currently banned and if we have to lift it.

Zeile 239Zeile 281
			$mybb->user['usergroup'] = $mybb->user['banoldgroup'];
$mybb->user['displaygroup'] = $mybb->user['banolddisplaygroup'];
$mybb->user['additionalgroups'] = $mybb->user['banoldadditionalgroups'];

			$mybb->user['usergroup'] = $mybb->user['banoldgroup'];
$mybb->user['displaygroup'] = $mybb->user['banolddisplaygroup'];
$mybb->user['additionalgroups'] = $mybb->user['banoldadditionalgroups'];

			$cache->update_banned();

 

$mybbgroups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])


$mybbgroups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])

Zeile 304Zeile 345
		// Set up some defaults
$time = TIME_NOW;
$mybb->user['usergroup'] = 1;

		// Set up some defaults
$time = TIME_NOW;
$mybb->user['usergroup'] = 1;

 
		$mybb->user['additionalgroups'] = '';

		$mybb->user['username'] = '';
$mybb->user['uid'] = 0;
$mybbgroups = 1;

		$mybb->user['username'] = '';
$mybb->user['uid'] = 0;
$mybbgroups = 1;

Zeile 316Zeile 358
			{
$mybb->user['lastactive'] = $time;
$mybb->cookies['mybb']['lastactive'] = $mybb->user['lastactive'];

			{
$mybb->user['lastactive'] = $time;
$mybb->cookies['mybb']['lastactive'] = $mybb->user['lastactive'];

			}

			}

			else
{
$mybb->user['lastactive'] = (int)$mybb->cookies['mybb']['lastactive'];

			else
{
$mybb->user['lastactive'] = (int)$mybb->cookies['mybb']['lastactive'];

Zeile 329Zeile 371
			else
{
$mybb->user['lastvisit'] = (int)$mybb->cookies['mybb']['lastactive'];

			else
{
$mybb->user['lastvisit'] = (int)$mybb->cookies['mybb']['lastactive'];

			}
}

			}
}


// No last visit cookie, create one.
else
{
my_setcookie("mybb[lastvisit]", $time);
$mybb->user['lastvisit'] = $time;


// No last visit cookie, create one.
else
{
my_setcookie("mybb[lastvisit]", $time);
$mybb->user['lastvisit'] = $time;

		}

		}


// Update last active cookie.
my_setcookie("mybb[lastactive]", $time);


// Update last active cookie.
my_setcookie("mybb[lastactive]", $time);

Zeile 345Zeile 387
		// Gather a full permission set for this guest
$mybb->usergroup = usergroup_permissions($mybbgroups);
$mydisplaygroup = usergroup_displaygroup($mybb->user['displaygroup']);

		// Gather a full permission set for this guest
$mybb->usergroup = usergroup_permissions($mybbgroups);
$mydisplaygroup = usergroup_displaygroup($mybb->user['displaygroup']);


$mybb->usergroup = array_merge($mybb->usergroup, $mydisplaygroup);



		if(is_array($mydisplaygroup))
{
$mybb->usergroup = array_merge($mybb->usergroup, $mydisplaygroup);
}


// Update the online data.
if(!defined("NO_ONLINE") && !defined('IN_UPGRADE'))
{
if(!empty($this->sid))


// Update the online data.
if(!defined("NO_ONLINE") && !defined('IN_UPGRADE'))
{
if(!empty($this->sid))

			{

			{

				$this->update_session($this->sid);
}
else

				$this->update_session($this->sid);
}
else

Zeile 365Zeile 409
	/**
* Load a search engine spider.
*

	/**
* Load a search engine spider.
*

	 * @param int The ID of the search engine spider

	 * @param int $spider_id The ID of the search engine spider

	 */
function load_spider($spider_id)
{

	 */
function load_spider($spider_id)
{

Zeile 374Zeile 418
		// Fetch the spider preferences from the database
$query = $db->simple_select("spiders", "*", "sid='{$spider_id}'");
$spider = $db->fetch_array($query);

		// Fetch the spider preferences from the database
$query = $db->simple_select("spiders", "*", "sid='{$spider_id}'");
$spider = $db->fetch_array($query);





		// Set up some defaults
$time = TIME_NOW;
$this->is_spider = true;

		// Set up some defaults
$time = TIME_NOW;
$this->is_spider = true;

Zeile 389Zeile 433
		$mybb->user['username'] = '';
$mybb->user['uid'] = 0;
$mybb->user['displaygroup'] = $mybb->user['usergroup'];

		$mybb->user['username'] = '';
$mybb->user['uid'] = 0;
$mybb->user['displaygroup'] = $mybb->user['usergroup'];





		// Set spider language
if($spider['language'] && $lang->language_exists($spider['language']))
{

		// Set spider language
if($spider['language'] && $lang->language_exists($spider['language']))
{

Zeile 405Zeile 449
		// Gather a full permission set for this spider.
$mybb->usergroup = usergroup_permissions($mybb->user['usergroup']);
$mydisplaygroup = usergroup_displaygroup($mybb->user['displaygroup']);

		// Gather a full permission set for this spider.
$mybb->usergroup = usergroup_permissions($mybb->user['usergroup']);
$mydisplaygroup = usergroup_displaygroup($mybb->user['displaygroup']);

		$mybb->usergroup = array_merge($mybb->usergroup, $mydisplaygroup);




		if(is_array($mydisplaygroup))
{
$mybb->usergroup = array_merge($mybb->usergroup, $mydisplaygroup);
}


// Update spider last minute (only do so on two minute intervals - decrease load for quick spiders)
if($spider['lastvisit'] < TIME_NOW-120)


// Update spider last minute (only do so on two minute intervals - decrease load for quick spiders)
if($spider['lastvisit'] < TIME_NOW-120)

Zeile 428Zeile 475
	/**
* Update a user session.
*

	/**
* Update a user session.
*

	 * @param int The session id.
* @param int The user id.

	 * @param int $sid The session id.
* @param int $uid The user id.

	 */

	 */

	function update_session($sid, $uid='')

	function update_session($sid, $uid=0)

	{
global $db;


	{
global $db;


Zeile 446Zeile 493
			$onlinedata['uid'] = 0;
}
$onlinedata['time'] = TIME_NOW;

			$onlinedata['uid'] = 0;
}
$onlinedata['time'] = TIME_NOW;

		
$onlinedata['location'] = $db->escape_string(substr(get_current_location(), 0, 150));
$onlinedata['useragent'] = $db->escape_string(my_substr($this->useragent, 0, 100));


$onlinedata['location'] = $db->escape_string(substr(get_current_location(false, $this->ignore_parameters), 0, 150));
$onlinedata['useragent'] = $db->escape_string(my_substr($this->useragent, 0, 200));

		
$onlinedata['location1'] = (int)$speciallocs['1'];
$onlinedata['location2'] = (int)$speciallocs['2'];

		
$onlinedata['location1'] = (int)$speciallocs['1'];
$onlinedata['location2'] = (int)$speciallocs['2'];

Zeile 461Zeile 508
	/**
* Create a new session.
*

	/**
* Create a new session.
*

	 * @param int The user id to bind the session to.

	 * @param int $uid The user id to bind the session to.

	 */
function create_session($uid=0)
{

	 */
function create_session($uid=0)
{

Zeile 479Zeile 526
		{
$db->delete_query("sessions", "sid='{$this->sid}'");
}

		{
$db->delete_query("sessions", "sid='{$this->sid}'");
}

		// Else delete by ip.

 
		else
{

		else
{

			$db->delete_query("sessions", "ip=".$db->escape_binary($this->packedip));

 
			$onlinedata['uid'] = 0;

			$onlinedata['uid'] = 0;

		}


		}


		// If the user is a search enginge spider, ...
if($this->is_spider == true)
{

		// If the user is a search enginge spider, ...
if($this->is_spider == true)
{

Zeile 493Zeile 538
		}
else
{

		}
else
{

			$onlinedata['sid'] = md5(uniqid(microtime(true), true));

			$onlinedata['sid'] = md5(random_str(50));

		}
$onlinedata['time'] = TIME_NOW;
$onlinedata['ip'] = $db->escape_binary($this->packedip);

		}
$onlinedata['time'] = TIME_NOW;
$onlinedata['ip'] = $db->escape_binary($this->packedip);

		
$onlinedata['location'] = $db->escape_string(substr(get_current_location(), 0, 150));
$onlinedata['useragent'] = $db->escape_string(my_substr($this->useragent, 0, 100));


$onlinedata['location'] = $db->escape_string(substr(get_current_location(false, $this->ignore_parameters), 0, 150));
$onlinedata['useragent'] = $db->escape_string(my_substr($this->useragent, 0, 200));

		
$onlinedata['location1'] = (int)$speciallocs['1'];
$onlinedata['location2'] = (int)$speciallocs['2'];

		
$onlinedata['location1'] = (int)$speciallocs['1'];
$onlinedata['location2'] = (int)$speciallocs['2'];

Zeile 518Zeile 563
	{
global $mybb;
$array = array('1' => '', '2' => '');

	{
global $mybb;
$array = array('1' => '', '2' => '');

		if(preg_match("#forumdisplay.php#", $_SERVER['PHP_SELF']) && $mybb->get_input('fid', MyBB::INPUT_INT) > 0)

		if(preg_match("#forumdisplay.php#", $_SERVER['PHP_SELF']) && $mybb->get_input('fid', MyBB::INPUT_INT) > 0 && $mybb->get_input('fid', MyBB::INPUT_INT) < 4294967296)

		{
$array[1] = $mybb->get_input('fid', MyBB::INPUT_INT);
$array[2] = '';

		{
$array[1] = $mybb->get_input('fid', MyBB::INPUT_INT);
$array[2] = '';

Zeile 527Zeile 572
		{
global $db;


		{
global $db;


			if($mybb->get_input('tid', MyBB::INPUT_INT) > 0)

			if($mybb->get_input('tid', MyBB::INPUT_INT) > 0 && $mybb->get_input('tid', MyBB::INPUT_INT) < 4294967296)

			{
$array[2] = $mybb->get_input('tid', MyBB::INPUT_INT);
}

			{
$array[2] = $mybb->get_input('tid', MyBB::INPUT_INT);
}