183
183
// Add forum to the page for tracking online users - also adding a "x" to the end to properly identify the number
184
184
$this->page['page'] .= (isset($_REQUEST['f'])) ? ((strpos($this->page['page'], '?') !== false) ? '&' : '?') . '_f_=' . (int) $_REQUEST['f'] . 'x' : '';
186
if (isset($_COOKIE[$config['cookie_name'] . '_sid']) || isset($_COOKIE[$config['cookie_name'] . '_u']))
188
$this->cookie_data['u'] = request_var($config['cookie_name'] . '_u', 0, false, true);
189
$this->cookie_data['k'] = request_var($config['cookie_name'] . '_k', '', false, true);
190
$this->session_id = request_var($config['cookie_name'] . '_sid', '', false, true);
192
$SID = (defined('NEED_SID')) ? '?sid=' . $this->session_id : '?sid=';
193
$_SID = (defined('NEED_SID')) ? $this->session_id : '';
195
if (empty($this->session_id))
197
$this->session_id = $_SID = request_var('sid', '');
198
$SID = '?sid=' . $this->session_id;
199
$this->cookie_data = array('u' => 0, 'k' => '');
204
$this->session_id = $_SID = request_var('sid', '');
205
$SID = '?sid=' . $this->session_id;
187
if (isset($_COOKIE[$config['cookie_name'] . '_sid']) ||
188
isset($_COOKIE[$config['cookie_name'] . '_u']))
190
$this->cookie_data['u'] = request_var($config['cookie_name'] . '_u', 0,
192
$this->cookie_data['k'] = request_var($config['cookie_name'] . '_k', '',
194
$this->session_id = request_var($config['cookie_name'] . '_sid', '',
197
$SID = (defined('NEED_SID')) ? '?sid=' . $this->session_id : '?sid=';
198
$_SID = (defined('NEED_SID')) ? $this->session_id : '';
200
if (empty($this->session_id))
202
$this->session_id = $_SID = request_var('sid', '');
203
$SID = '?sid=' . $this->session_id;
204
$this->cookie_data = array('u' => 0, 'k' => '');
209
$this->session_id = $_SID = request_var('sid', '');
210
$SID = '?sid=' . $this->session_id;
208
213
$_EXTRA_URL = array();
234
239
FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
235
240
WHERE s.session_id = '" . $db->sql_escape($this->session_id) . "'
236
241
AND u.user_id = s.session_user_id";
237
$result = $db->sql_query($sql);
242
$result = $db->sql_query($sql);
238
243
$this->data = $db->sql_fetchrow($result);
239
244
$db->sql_freeresult($result);
247
$ivle_userid = $this->ivle_auth();
248
if ($ivle_userid and $ivle_userid != $this->data['user_id']) {
249
#$this->session_kill();
250
#trigger_error($ivle_userid);
251
return $this->session_create($ivle_userid);
241
254
// Did the session exist in the DB?
242
255
if (isset($this->data['user_id']))
244
257
// Validate IP length according to admin ... enforces an IP
245
258
// check on bots if admin requires this
246
// $quadcheck = ($config['ip_check_bot'] && $this->data['user_type'] & USER_BOT) ? 4 : $config['ip_check'];
259
// $quadcheck = ($config['ip_check_bot'] && $this->data['user_type'] & USER_BOT) ? 4 : $config['ip_check'];
248
261
if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false)
1954
* This function attempts to authenticate from a signed cookie provided by
1955
* IVLE. If it does it will return either the forum user_id for the logged in
1956
* IVLE user or will create a new one on-the-fly.
1958
* If a bad authentication is given then the ANONAMOUS user will be returned
1960
function ivle_auth()
1964
// Get the shared secret between IVLE and the Forum
1965
require($phpbb_root_path . 'config.' . $phpEx);
1968
$ivle_cookie = explode(':',$_COOKIE['ivleforumcookie']);
1970
if ($ivle_cookie == "NONE") {
1974
// Decode and unescape the Cookie contents
1975
$ivle_uid = urldecode($ivle_cookie[0]);
1976
$ivle_nick = urldecode($ivle_cookie[1]);
1977
$ivle_email = urldecode($ivle_cookie[2]);
1978
$ivle_role = urldecode($ivle_cookie[3]);
1979
$ivle_hash = $ivle_cookie[4];
1981
// Check if uid + nick + email + secret is the same as the hash
1982
//$ivle_auth = False; // Flag just incase anything else need to know
1983
if(md5($ivle_cookie[0].$ivle_cookie[1].$ivle_cookie[2].$ivle_cookie[3].$forum_secret)
1985
//$ivle_auth = True;
1987
// Check if the user exists in the database
1988
$sql = 'SELECT user_id
1989
FROM ' . USERS_TABLE . "
1990
WHERE username = '" . $db->sql_escape($ivle_uid) . "';";
1991
$result = $db->sql_query($sql);
1992
$row = $db->sql_fetchrow($result);
1993
$user_id = $row['user_id'];
1994
$db->sql_freeresult($result);
1996
// If no user_id is found for the username, create a new user
1998
// Needed for IVLE auth overide
1999
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
2001
// Add all users to the Registered Group
2002
$sql = 'SELECT group_id
2003
FROM ' . GROUPS_TABLE . "
2004
WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
2005
AND group_type = " . GROUP_SPECIAL;
2006
$result = $db->sql_query($sql);
2007
$row = $db->sql_fetchrow($result);
2008
$db->sql_freeresult($result);
2010
trigger_error('NO_GROUP');
2013
$group_id = $row['group_id'];
2015
// Get the Time and Timezone
2016
$timezone = date('Z') / 3600;
2017
$is_dst = date('I');
2018
$timezone = ($is_dst) ? $timezone - 1 : $timezone;
2022
'username' => $ivle_uid,
2023
'user_password' => '', # Not a valid hash
2024
'user_email' => $ivle_email,
2025
'group_id' => (int) $group_id,
2026
'user_timezone' => (float) $timezone,
2027
'user_dst' => $is_dst,
2028
'user_lang' => 'en',
2029
'user_type' => USER_NORMAL,
2030
'user_actkey' => '',
2031
'user_ip' => $this->ip,
2032
'user_regdate' => time(),
2033
'user_inactive_reason' => 0,
2034
'user_inactive_time' => 0,
2038
$user_id = user_add($user_row);
2040
// Add any aditional groups
2041
// Select the equvialent group
2043
switch($ivle_role) {
2045
$group = 'ADMINISTRATORS';
2048
$group = 'GLOBAL_MODERATORS';
2052
// Find the group_id
2053
$sql = 'SELECT group_id
2054
FROM ' . GROUPS_TABLE . "
2055
WHERE group_name = '" . $db->sql_escape($group) . "'
2056
AND group_type = " . GROUP_SPECIAL;
2058
$result = $db->sql_query($sql);
2059
$row = $db->sql_fetchrow($result);
2060
$db->sql_freeresult($result);
2063
trigger_error('NO_GROUP');
2066
$group_id = $row['group_id'];
2068
group_user_add($group_id,Array($user_id));
b'\\ No newline at end of file'