2002-07-14 14:32:45 +00:00
< ? php
/***************************************************************************
* session . php
* -------------------
* begin : Saturday , Feb 13 , 2001
* copyright : ( C ) 2002 The phpBB Group
* email : support @ phpbb . com
*
* $Id $
*
***************************************************************************/
/***************************************************************************
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
***************************************************************************/
class session {
2002-08-06 16:56:14 +00:00
var $session_id = '' ;
2002-07-14 14:32:45 +00:00
var $load ;
function start ( $update = true )
{
global $SID , $db , $board_config , $user_ip ;
global $HTTP_SERVER_VARS , $HTTP_ENV_VARS , $HTTP_COOKIE_VARS , $HTTP_GET_VARS ;
2002-08-06 16:56:14 +00:00
$user_browser = ( ! empty ( $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ]) ) ? $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ] : $HTTP_ENV_VARS [ 'HTTP_USER_AGENT' ];
$user_page = ( ! empty ( $HTTP_SERVER_VARS [ 'PHP_SELF' ]) ) ? $HTTP_SERVER_VARS [ 'PHP_SELF' ] : $HTTP_ENV_VARS [ 'PHP_SELF' ];
$user_page .= '&' . ( ( ! empty ( $HTTP_SERVER_VARS [ 'QUERY_STRING' ]) ) ? $HTTP_SERVER_VARS [ 'QUERY_STRING' ] : $HTTP_ENV_VARS [ 'QUERY_STRING' ] );
2002-07-14 14:32:45 +00:00
$current_time = time ();
if ( isset ( $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_sid' ]) || isset ( $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_data' ]) )
{
$sessiondata = ( isset ( $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_data' ]) ) ? unserialize ( stripslashes ( $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_data' ])) : '' ;
2002-08-06 16:56:14 +00:00
$this -> session_id = ( isset ( $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_sid' ]) ) ? $HTTP_COOKIE_VARS [ $board_config [ 'cookie_name' ] . '_sid' ] : '' ;
$SID = '?sid=' ;
2002-07-14 14:32:45 +00:00
}
else
{
$sessiondata = '' ;
2002-08-06 16:56:14 +00:00
$this -> session_id = ( isset ( $HTTP_GET_VARS [ 'sid' ]) ) ? $HTTP_GET_VARS [ 'sid' ] : '' ;
$SID = '?sid=' . $this -> session_id ;
2002-07-14 14:32:45 +00:00
}
//
// Load limit check (if applicable)
//
if ( ! empty ( $board_config [ 'limit_load' ]) && file_exists ( '/proc/loadavg' ) )
{
if ( $load = @ file ( '/proc/loadavg' ) )
{
list ( $this -> load ) = explode ( ' ' , $load [ 0 ]);
if ( $this -> load > $board_config [ 'limit_load' ] )
{
message_die ( MESSAGE , 'Board_unavailable' );
}
}
}
2002-08-06 16:56:14 +00:00
//
// session_id exists so go ahead and attempt to grab all data in preparation
//
if ( ! empty ( $this -> session_id ) )
2002-07-14 14:32:45 +00:00
{
$sql = " SELECT u.*, s.*
FROM " . SESSIONS_TABLE . " s , " . USERS_TABLE . " u
2002-08-06 16:56:14 +00:00
WHERE s . session_id = '" . $this->session_id . "'
2002-07-14 14:32:45 +00:00
AND u . user_id = s . session_user_id " ;
$result = $db -> sql_query ( $sql );
2002-08-06 16:56:14 +00:00
$userdata = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2002-07-14 14:32:45 +00:00
//
// Did the session exist in the DB?
//
2002-08-06 16:56:14 +00:00
if ( isset ( $userdata [ 'user_id' ]) )
2002-07-14 14:32:45 +00:00
{
//
// Do not check IP assuming equivalence, if IPv4 we'll check only first 24
2002-08-13 16:34:17 +00:00
// bits ... I've been told (by vHiker) this should alleviate problems with
2002-07-14 14:32:45 +00:00
// load balanced et al proxies while retaining some reliance on IP security.
//
2002-08-06 16:56:14 +00:00
$ip_check_s = explode ( '.' , $userdata [ 'session_ip' ]);
2002-07-14 14:32:45 +00:00
$ip_check_u = explode ( '.' , $user_ip );
if ( $ip_check_s [ 0 ] . '.' . $ip_check_s [ 1 ] . '.' . $ip_check_s [ 2 ] == $ip_check_u [ 0 ] . '.' . $ip_check_u [ 1 ] . '.' . $ip_check_u [ 2 ] )
{
//
// Only update session DB a minute or so after last update or if page changes
//
2002-08-06 16:56:14 +00:00
if ( ( $current_time - $userdata [ 'session_time' ] > 60 || $userdata [ 'session_page' ] != $user_page ) && $update )
2002-07-14 14:32:45 +00:00
{
2002-08-13 16:34:17 +00:00
$sql = " UPDATE " . SESSIONS_TABLE . "
SET session_time = $current_time , session_page = '$user_page'
2002-08-06 16:56:14 +00:00
WHERE session_id = '" . $this->session_id . "' " ;
2002-07-14 14:32:45 +00:00
$db -> sql_query ( $sql );
//
// Garbage collection ... remove old sessions updating user information
2002-08-06 16:56:14 +00:00
// if necessary. It means (potentially) lots of queries but only infrequently
2002-07-14 14:32:45 +00:00
//
if ( $current_time - $board_config [ 'session_gc' ] > $board_config [ 'session_last_gc' ] )
{
$this -> gc ( $current_time );
}
}
2002-08-06 16:56:14 +00:00
return $userdata ;
2002-07-14 14:32:45 +00:00
}
}
}
//
// If we reach here then no (valid) session exists. So we'll create a new one,
// using the cookie user_id if available to pull basic user prefs.
//
$autologin = ( isset ( $sessiondata [ 'autologinid' ]) ) ? $sessiondata [ 'autologinid' ] : '' ;
2002-07-25 15:18:00 +00:00
$user_id = ( isset ( $sessiondata [ 'userid' ]) ) ? intval ( $sessiondata [ 'userid' ]) : ANONYMOUS ;
2002-07-14 14:32:45 +00:00
2002-08-06 16:56:14 +00:00
return $this -> create ( $user_id , $autologin , $user_page , $user_browser );
2002-07-14 14:32:45 +00:00
}
2002-08-06 16:56:14 +00:00
//
// Create a new session
//
function create ( & $user_id , & $autologin , & $user_page , & $user_browser )
2002-07-14 14:32:45 +00:00
{
global $SID , $db , $board_config , $user_ip ;
$sessiondata = array ();
$current_time = time ();
//
2002-08-07 00:02:08 +00:00
// Limit sessions in 1 minute period
2002-07-14 14:32:45 +00:00
//
2002-08-13 16:34:17 +00:00
$sql = " SELECT COUNT(*) AS sessions
FROM " . SESSIONS_TABLE . "
2002-08-07 00:02:08 +00:00
WHERE session_time >= " . ( $current_time - 60 );
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow [ $result ];
2002-08-06 16:56:14 +00:00
$db -> sql_freeresult ( $result );
2002-07-14 14:32:45 +00:00
2002-08-07 00:02:08 +00:00
if ( intval ( $board_config [ 'active_sessions' ]) && intval ( $row [ 'sessions' ]) > intval ( $board_config [ 'active_sessions' ]) )
2002-07-14 14:32:45 +00:00
{
2002-08-06 16:56:14 +00:00
message_die ( MESSAGE , 'Board_unavailable' );
2002-07-14 14:32:45 +00:00
}
2002-08-06 16:56:14 +00:00
//
// Grab user data
//
2002-08-13 16:34:17 +00:00
$sql = " SELECT *
FROM " . USERS_TABLE . "
2002-07-14 14:32:45 +00:00
WHERE user_id = $user_id " ;
$result = $db -> sql_query ( $sql );
2002-08-06 16:56:14 +00:00
$userdata = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2002-07-14 14:32:45 +00:00
//
// Check autologin request, is it valid?
//
2002-08-06 16:56:14 +00:00
if ( $userdata [ 'user_password' ] != $autologin || ! $userdata [ 'user_active' ] || $user_id == ANONYMOUS )
2002-07-14 14:32:45 +00:00
{
$autologin = '' ;
2002-08-13 16:34:17 +00:00
$userdata [ 'user_id' ] = $user_id = ANONYMOUS ;
2002-07-14 14:32:45 +00:00
}
2002-08-13 16:34:17 +00:00
$sql = " SELECT ban_ip, ban_userid, ban_email
FROM " . BANLIST_TABLE . "
WHERE ban_end >= $current_time
2002-08-06 16:56:14 +00:00
OR ban_end = 0 " ;
2002-07-14 14:32:45 +00:00
$result = $db -> sql_query ( $sql );
2002-08-06 16:56:14 +00:00
if ( $row = $db -> sql_fetchrow ( $result ) )
2002-07-14 14:32:45 +00:00
{
2002-08-06 16:56:14 +00:00
do
2002-07-14 14:32:45 +00:00
{
2002-08-13 16:34:17 +00:00
if ( ( $row [ 'user_id' ] == $userdata [ 'user_id' ] ||
2002-08-06 16:56:14 +00:00
( $row [ 'ban_ip' ] && preg_match ( '#^' . str_replace ( '*' , '.*?' , $row [ 'ban_ip' ]) . '$#i' , $user_ip ) ) ||
2002-08-13 16:34:17 +00:00
( $row [ 'ban_email' ] && preg_match ( '#^' . str_replace ( '*' , '.*?' , $row [ 'ban_email' ]) . '$#i' , $userdata [ 'user_email' ]) ) )
2002-08-06 16:56:14 +00:00
&& ! $userdata [ 'user_founder' ] )
{
message_die ( MESSAGE , 'You_been_banned' );
}
2002-07-14 14:32:45 +00:00
}
2002-08-06 16:56:14 +00:00
while ( $row = $db -> sql_fetchrow ( $result ) );
2002-07-14 14:32:45 +00:00
}
2002-08-06 16:56:14 +00:00
$db -> sql_freeresult ( $result );
2002-07-14 14:32:45 +00:00
//
// Create or update the session
//
$db -> sql_return_on_error ( true );
$sql = " UPDATE " . SESSIONS_TABLE . "
2002-08-06 16:56:14 +00:00
SET session_user_id = $user_id , session_start = $current_time , session_time = $current_time , session_browser = '$user_browser' , session_page = '$user_page'
WHERE session_id = '" . $this->session_id . "' " ;
if ( ! ( $result = $db -> sql_query ( $sql )) || ! $db -> sql_affectedrows () )
2002-07-14 14:32:45 +00:00
{
$db -> sql_return_on_error ( false );
2002-08-06 16:56:14 +00:00
$this -> session_id = md5 ( uniqid ( $user_ip ));
2002-07-14 14:32:45 +00:00
$sql = " INSERT INTO " . SESSIONS_TABLE . "
( session_id , session_user_id , session_start , session_time , session_ip , session_browser , session_page )
2002-08-06 16:56:14 +00:00
VALUES ( '" . $this->session_id . "' , $user_id , $current_time , $current_time , '$user_ip' , '$user_browser' , '$user_page' ) " ;
2002-07-14 14:32:45 +00:00
$db -> sql_query ( $sql );
}
$db -> sql_return_on_error ( false );
2002-08-06 16:56:14 +00:00
$userdata [ 'session_id' ] = $session_id ;
2002-07-14 14:32:45 +00:00
$sessiondata [ 'autologinid' ] = ( $autologin && $user_id != ANONYMOUS ) ? $autologin : '' ;
$sessiondata [ 'userid' ] = $user_id ;
setcookie ( $board_config [ 'cookie_name' ] . '_data' , serialize ( $sessiondata ), $current_time + 31536000 , $board_config [ 'cookie_path' ], $board_config [ 'cookie_domain' ], $board_config [ 'cookie_secure' ]);
2002-08-06 16:56:14 +00:00
setcookie ( $board_config [ 'cookie_name' ] . '_sid' , $this -> session_id , 0 , $board_config [ 'cookie_path' ], $board_config [ 'cookie_domain' ], $board_config [ 'cookie_secure' ]);
$SID = '?sid=' . $this -> session_id ;
2002-07-14 14:32:45 +00:00
2002-08-06 16:56:14 +00:00
return $userdata ;
2002-07-14 14:32:45 +00:00
}
2002-08-06 16:56:14 +00:00
//
// Destroy a session
//
2002-07-14 14:32:45 +00:00
function destroy ( & $userdata )
{
2002-08-06 16:56:14 +00:00
global $SID , $db , $board_config ;
global $HTTP_COOKIE_VARS , $HTTP_GET_VARS ;
2002-07-14 14:32:45 +00:00
$current_time = time ();
2002-08-06 16:56:14 +00:00
setcookie ( $board_config [ 'cookie_name' ] . '_data' , '' , $current_time - 31536000 , $board_config [ 'cookie_path' ], $board_config [ 'cookie_domain' ], $board_config [ 'cookie_secure' ]);
setcookie ( $board_config [ 'cookie_name' ] . '_sid' , '' , $current_time - 31536000 , $board_config [ 'cookie_path' ], $board_config [ 'cookie_domain' ], $board_config [ 'cookie_secure' ]);
2002-07-14 14:32:45 +00:00
//
// Delete existing session, update last visit info first!
//
2002-08-13 16:34:17 +00:00
$sql = " UPDATE " . USERS_TABLE . "
SET user_lastvisit = " . $userdata['session_time'] . " , user_session_page = '" . $userdata[' session_page '] . "'
2002-07-14 14:32:45 +00:00
WHERE user_id = " . $userdata['user_id'] ;
$db -> sql_query ( $sql );
2002-08-13 16:34:17 +00:00
$sql = " DELETE FROM " . SESSIONS_TABLE . "
WHERE session_id = '" . $this->session_id . "'
2002-07-14 14:32:45 +00:00
AND session_user_id = " . $userdata['user_id'] ;
$db -> sql_query ( $sql );
$SID = '?sid=' ;
2002-08-06 16:56:14 +00:00
$this -> session_id = '' ;
2002-07-14 14:32:45 +00:00
return true ;
}
2002-08-06 16:56:14 +00:00
//
// Garbage collection
//
2002-07-14 14:32:45 +00:00
function gc ( & $current_time )
{
global $db , $board_config , $user_ip ;
2002-08-13 16:34:17 +00:00
$sql = " SELECT *
FROM " . SESSIONS_TABLE . "
WHERE session_time < " . ( $current_time - $board_config['session_length'] ) . "
LIMIT 10 " ;
2002-07-14 14:32:45 +00:00
$result = $db -> sql_query ( $sql );
$del_session_id = '' ;
while ( $row = $db -> sql_fetchrow ( $result ) )
{
if ( $row [ 'user_id' ] != ANONYMOUS )
{
2002-08-13 16:34:17 +00:00
$sql = " UPDATE " . USERS_TABLE . "
SET user_lastvisit = " . $row['session_time'] . " , user_session_page = '" . $row[' session_page '] . "'
2002-07-14 14:32:45 +00:00
WHERE user_id = " . $row['session_user_id'] ;
$db -> sql_query ( $sql );
}
$del_session_id .= ( ( $del_session_id != '' ) ? ', ' : '' ) . '\'' . $row [ 'session_id' ] . '\'' ;
}
if ( $del_session_id != '' )
{
//
// Delete expired sessions
//
2002-08-13 16:34:17 +00:00
$sql = " DELETE FROM " . SESSIONS_TABLE . "
2002-07-14 14:32:45 +00:00
WHERE session_id IN ( $del_session_id ) " ;
$db -> sql_query ( $sql );
}
2002-08-13 16:34:17 +00:00
$sql = " UPDATE " . CONFIG_TABLE . "
SET config_value = '$current_time'
2002-07-14 14:32:45 +00:00
WHERE config_name = 'session_last_gc' " ;
$db -> sql_query ( $sql );
return ;
}
2002-08-06 16:56:14 +00:00
//
//
//
2002-07-14 14:32:45 +00:00
function configure ( $userdata , $lang_set = false )
{
global $db , $template , $lang , $board_config , $theme , $images ;
global $phpEx , $phpbb_root_path ;
if ( $userdata [ 'user_id' ] != ANONYMOUS )
{
$board_config [ 'default_lang' ] = $userdata [ 'user_lang' ];
$board_config [ 'default_dateformat' ] = $userdata [ 'user_dateformat' ];
$board_config [ 'board_timezone' ] = $userdata [ 'user_timezone' ];
}
if ( ! file_exists ( $phpbb_root_path . 'language/lang_' . $board_config [ 'default_lang' ] . '/lang_main.' . $phpEx ) )
{
$board_config [ 'default_lang' ] = 'english' ;
}
include ( $phpbb_root_path . 'language/lang_' . $board_config [ 'default_lang' ] . '/lang_main.' . $phpEx );
if ( defined ( 'IN_ADMIN' ) )
{
if ( ! file_exists ( $phpbb_root_path . 'language/lang_' . $board_config [ 'default_lang' ] . '/lang_admin.' . $phpEx ) )
{
$board_config [ 'default_lang' ] = 'english' ;
}
include ( $phpbb_root_path . 'language/lang_' . $board_config [ 'default_lang' ] . '/lang_admin.' . $phpEx );
}
//
// Set up style
//
$style = ( ! $board_config [ 'override_user_style' ] && $userdata [ 'user_id' ] != ANONYMOUS ) ? $userdata [ 'user_style' ] : $board_config [ 'default_style' ];
2002-08-13 16:34:17 +00:00
$sql = " SELECT t.template_path, t.poll_length, t.pm_box_length, c.css_data, c.css_external, i.*
FROM " . STYLES_TABLE . " s , " . STYLES_TPL_TABLE . " t , " . STYLES_CSS_TABLE . " c , " . STYLES_IMAGE_TABLE . " i
WHERE s . style_id = $style
AND t . template_id = s . template_id
AND c . theme_id = s . style_id
2002-07-14 14:32:45 +00:00
AND i . imageset_id = s . imageset_id " ;
$result = $db -> sql_query ( $sql );
if ( ! ( $theme = $db -> sql_fetchrow ( $result )) )
{
message_die ( ERROR , 'Could not get style data [ id ' . $style . ' ]' );
}
if ( $template = new Template ( $theme [ 'template_path' ]) )
{
$img_lang = ( file_exists ( 'imageset/' . $theme [ 'imageset_path' ] . '/lang_' . $board_config [ 'default_lang' ]) ) ? $board_config [ 'default_lang' ] : 'english' ;
$i10n = array ( 'post_new' , 'post_locked' , 'post_pm' , 'reply_new' , 'reply_pm' , 'reply_locked' , 'icon_quote' , 'icon_edit' , 'icon_search' , 'icon_profile' , 'icon_pm' , 'icon_email' , 'icon_www' , 'icon_icq' , 'icon_aim' , 'icon_yim' , 'icon_msnm' , 'icon_delete' , 'icon_ip' , 'icon_no_email' , 'icon_no_www' , 'icon_no_icq' , 'icon_no_aim' , 'icon_no_yim' , 'icon_no_msnm' );
for ( $i = 0 ; $i < sizeof ( $i10n ); $i ++ )
{
$theme [ $i10n [ $i ]] = str_replace ( '{LANG}' , 'lang_' . $img_lang , $theme [ $i10n [ $i ]]);
}
}
return ;
}
}
//
2002-08-13 16:34:17 +00:00
// Will be keeping my eye of 'other products' to ensure these things don't
2002-07-14 14:32:45 +00:00
// mysteriously appear elsewhere, think up your own solutions!
//
2002-08-13 16:34:17 +00:00
class acl
{
function acl ( $mode , $userdata , $forum_id = false )
2002-07-14 14:32:45 +00:00
{
global $db ;
switch ( $mode )
{
2002-08-13 16:34:17 +00:00
case 'admin' :
$and_sql = " ao.auth_type LIKE 'admin' " ;
break ;
2002-07-14 14:32:45 +00:00
case 'list' :
2002-08-13 16:34:17 +00:00
$and_sql = " ao.auth_option LIKE 'list' OR ao.auth_type LIKE 'admin' " ;
2002-07-14 14:32:45 +00:00
break ;
2002-08-01 16:41:04 +00:00
case 'read' :
2002-08-13 16:34:17 +00:00
$and_sql = " ao.auth_option LIKE 'read' OR ao.auth_type LIKE 'admin' " ;
2002-08-01 16:41:04 +00:00
break ;
2002-07-14 14:32:45 +00:00
case 'forum' :
2002-08-13 16:34:17 +00:00
$and_sql = " ( a.forum_id = $forum_id ) OR ( a.forum_id <> $forum_id AND ( ao.auth_option LIKE 'list' OR ao.auth_type LIKE 'mod' OR ao.auth_type LIKE 'admin' ) ) " ;
2002-07-14 14:32:45 +00:00
break ;
case 'listmod' :
2002-08-13 16:34:17 +00:00
$and_sql = " ao.auth_option LIKE 'list' OR ao.auth_type LIKE 'mod' OR ao.auth_type LIKE 'admin' " ;
2002-07-14 14:32:45 +00:00
break ;
}
2002-08-13 16:34:17 +00:00
$sql = " SELECT a.forum_id, a.auth_allow_deny, ao.auth_type, ao.auth_option
FROM " . ACL_GROUPS_TABLE . " a , " . ACL_OPTIONS_TABLE . " ao , " . USER_GROUP_TABLE . " ug
WHERE ug . user_id = " . $userdata['user_id'] . "
AND a . group_id = ug . group_id
AND ao . auth_option_id = a . auth_option_id
AND ( $and_sql ) " ;
$result = $db -> sql_query ( $sql );
if ( $row = $db -> sql_fetchrow ( $result ) )
{
do
{
$this -> acl [ $row [ 'forum_id' ]][ $row [ 'auth_type' ]][ $row [ 'auth_option' ]] = $row [ 'auth_allow_deny' ];
}
while ( $row = $db -> sql_fetchrow ( $result ) );
}
$db -> sql_freeresult ( $result );
$sql = " SELECT a.forum_id, a.auth_allow_deny, ao.auth_type, ao.auth_option
FROM " . ACL_USERS_TABLE . " a , " . ACL_OPTIONS_TABLE . " ao
WHERE a . user_id = " . $userdata['user_id'] . "
AND ao . auth_option_id = a . auth_option_id
AND ( $and_sql ) " ;
2002-07-14 14:32:45 +00:00
$result = $db -> sql_query ( $sql );
if ( $row = $db -> sql_fetchrow ( $result ) )
{
do
{
$this -> acl [ $row [ 'forum_id' ]][ $row [ 'auth_type' ]][ $row [ 'auth_option' ]] = $row [ 'auth_allow_deny' ];
}
while ( $row = $db -> sql_fetchrow ( $result ) );
}
$db -> sql_freeresult ( $result );
return ;
}
2002-08-06 16:56:14 +00:00
function get_acl ( $forum_id , $auth_main = false , $auth_type = false )
2002-07-14 14:32:45 +00:00
{
if ( $auth_main && $auth_type )
{
return $this -> acl [ $forum_id ][ $auth_main ][ $auth_type ];
}
else if ( ! $auth_type && is_array ( $this -> acl [ $forum_id ][ $auth_main ]) )
{
return ( array_sum ( $this -> acl [ $forum_id ][ $auth_main ]) ) ? true : false ;
}
return $this -> acl [ $forum_id ];
}
function get_acl_admin ( $auth_type = false )
{
2002-08-06 16:56:14 +00:00
return $this -> get_acl ( 0 , 'admin' , $auth_type );
}
2002-07-14 14:32:45 +00:00
2002-08-01 16:41:04 +00:00
function set_acl ( $forum_id , $user_id = false , $group_id = false , $auth = false , $dependencies = array ())
2002-07-14 14:32:45 +00:00
{
global $db ;
2002-08-01 16:41:04 +00:00
if ( ! $auth || ( $user_id && $group_id ) )
{
return ;
}
$forum_sql = ( $forum_id ) ? " AND a.forum_id IN ( $forum_id , 0) " : '' ;
//
//
//
2002-08-06 16:56:14 +00:00
$sql = ( $user_id !== false ) ? " SELECT a.user_id, o.auth_type, o.auth_option_id, o.auth_option, a.auth_allow_deny FROM " . ACL_USERS_TABLE . " a, " . ACL_OPTIONS_TABLE . " o, " . USERS_TABLE . " u WHERE a.auth_option_id = o.auth_option_id $forum_sql AND u.user_id = a.user_id AND a.user_id = $user_id " : " SELECT ug.user_id, o.auth_type, o.auth_option, a.auth_allow_deny FROM " . USER_GROUP_TABLE . " ug, " . ACL_USERS_TABLE . " a, " . ACL_OPTIONS_TABLE . " o, " . USERS_TABLE . " u WHERE a.auth_option_id = o.auth_option_id $forum_sql AND u.user_id = a.user_id AND a.user_id = ug.user_id AND ug.group_id = $group_id " ;
2002-08-01 16:41:04 +00:00
$result = $db -> sql_query ( $sql );
2002-08-13 16:34:17 +00:00
$user_auth = array ();
2002-08-01 16:41:04 +00:00
if ( $row = $db -> sql_fetchrow ( $result ) )
{
do
{
2002-08-13 16:34:17 +00:00
$user_auth [ $row [ 'user_id' ]][ $row [ 'auth_type' ]][ $row [ 'auth_option_id' ]] = $row [ 'auth_allow_deny' ];
2002-08-01 16:41:04 +00:00
}
while ( $row = $db -> sql_fetchrow ( $result ) );
}
$db -> sql_freeresult ( $result );
2002-08-06 16:56:14 +00:00
$sql = ( $group_id !== false ) ? " SELECT a.group_id, o.auth_type, o.auth_option_id, o.auth_option, a.auth_allow_deny FROM " . ACL_GROUPS_TABLE . " a, " . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $forum_sql AND a.group_id = $group_id " : " SELECT ug.group_id, o.auth_type, o.auth_option, a.auth_allow_deny FROM " . USER_GROUP_TABLE . " ug, " . ACL_GROUPS_TABLE . " a, " . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $forum_sql AND a.group_id = ug.group_id AND ug.user_id = $user_id " ;
2002-08-01 16:41:04 +00:00
$result = $db -> sql_query ( $sql );
2002-08-13 16:34:17 +00:00
$group_auth = array ();
2002-08-01 16:41:04 +00:00
if ( $row = $db -> sql_fetchrow ( $result ) )
{
do
{
2002-08-13 16:34:17 +00:00
$group_auth [ $row [ 'group_id' ]][ $row [ 'auth_type' ]][ $row [ 'auth_option_id' ]] = $row [ 'auth_allow_deny' ];
2002-08-01 16:41:04 +00:00
}
while ( $row = $db -> sql_fetchrow ( $result ) );
}
$db -> sql_freeresult ( $result );
foreach ( $auth as $auth_type => $auth_option_ary )
{
foreach ( $auth_option_ary as $auth_option => $allow )
{
if ( $user_id !== false )
{
2002-08-13 16:34:17 +00:00
if ( ! empty ( $user_auth ) )
2002-08-01 16:41:04 +00:00
{
2002-08-13 16:34:17 +00:00
foreach ( $user_auth as $user => $user_auth_ary )
2002-08-01 16:41:04 +00:00
{
2002-08-13 16:34:17 +00:00
$user_auth [ $user ][ $auth_type ][ $auth_option ] = $allow ;
2002-08-06 16:56:14 +00:00
$sql_ary [] = ( ! isset ( $user_auth_ary [ $auth_type ][ $auth_option ]) ) ? " INSERT INTO " . ACL_USERS_TABLE . " (user_id, forum_id, auth_option_id, auth_allow_deny) VALUES ( $user_id , $forum_id , $auth_option , $allow ) " : ( ( $user_auth_ary [ $auth_type ][ $auth_option ] != $allow ) ? " UPDATE " . ACL_USERS_TABLE . " SET auth_allow_deny = $allow WHERE user_id = $user_id AND forum_id = $forum_id and auth_option_id = $auth_option " : '' );
2002-08-01 16:41:04 +00:00
}
}
else
{
2002-08-13 16:34:17 +00:00
$user_auth [ $user_id ][ $auth_type ][ $auth_option ] = $allow ;
2002-08-06 16:56:14 +00:00
$sql_ary [] = " INSERT INTO " . ACL_USERS_TABLE . " (user_id, forum_id, auth_option_id, auth_allow_deny) VALUES ( $user_id , $forum_id , $auth_option , $allow ) " ;
2002-08-01 16:41:04 +00:00
}
}
if ( $group_id !== false )
{
2002-08-13 16:34:17 +00:00
if ( ! empty ( $group_auth ) )
2002-08-01 16:41:04 +00:00
{
2002-08-13 16:34:17 +00:00
foreach ( $group_auth as $group => $group_auth_ary )
2002-08-01 16:41:04 +00:00
{
2002-08-13 16:34:17 +00:00
$group_auth [ $group ][ $auth_type ][ $auth_option ] = $allow ;
2002-08-06 16:56:14 +00:00
$sql_ary [] = ( ! isset ( $group_auth_ary [ $auth_type ][ $auth_option ]) ) ? " INSERT INTO " . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_allow_deny) VALUES ( $group_id , $forum_id , $auth_option , $allow ) " : ( ( $group_auth_ary [ $auth_type ][ $auth_option ] != $allow ) ? " UPDATE " . ACL_GROUPS_TABLE . " SET auth_allow_deny = $allow WHERE group_id = $group_id AND forum_id = $forum_id and auth_option_id = $auth_option " : '' );
2002-08-01 16:41:04 +00:00
}
}
else
{
2002-08-13 16:34:17 +00:00
$group_auth [ $group_id ][ $auth_type ][ $auth_option ] = $allow ;
2002-08-06 16:56:14 +00:00
$sql_ary [] = " INSERT INTO " . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_allow_deny) VALUES ( $group_id , $forum_id , $auth_option , $allow ) " ;
2002-08-01 16:41:04 +00:00
}
}
}
}
2002-08-13 16:34:17 +00:00
foreach ( $sql_ary as $sql )
2002-08-01 16:41:04 +00:00
{
2002-08-13 16:34:17 +00:00
$db -> sql_query ( $sql );
2002-08-01 16:41:04 +00:00
}
2002-08-13 16:34:17 +00:00
unset ( $group_auth );
unset ( $user_auth );
2002-07-14 14:32:45 +00:00
}
}
//
2002-08-06 16:56:14 +00:00
// Authentication plug-ins is largely down to
2002-08-13 16:34:17 +00:00
// Sergey Kanareykin, our thanks to him.
2002-07-14 14:32:45 +00:00
//
2002-08-06 16:56:14 +00:00
class login
2002-07-14 14:32:45 +00:00
{
2002-08-06 16:56:14 +00:00
function login ( $username , $password , $autologin = false )
{
global $SID , $db , $board_config , $lang , $user_ip , $session ;
global $HTTP_SERVER_VARS , $HTTP_ENV_VARS , $phpEx ;
2002-07-14 14:32:45 +00:00
2002-08-06 16:56:14 +00:00
$user_page = ( ! empty ( $HTTP_SERVER_VARS [ 'PHP_SELF' ]) ) ? $HTTP_SERVER_VARS [ 'PHP_SELF' ] : $HTTP_ENV_VARS [ 'PHP_SELF' ];
$user_page .= '&' . ( ( ! empty ( $HTTP_SERVER_VARS [ 'QUERY_STRING' ]) ) ? $HTTP_SERVER_VARS [ 'QUERY_STRING' ] : $HTTP_ENV_VARS [ 'QUERY_STRING' ] );
$this_browser = ( ! empty ( $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ]) ) ? $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ] : $HTTP_ENV_VARS [ 'HTTP_USER_AGENT' ];
2002-07-14 14:32:45 +00:00
2002-08-06 16:56:14 +00:00
$method = trim ( $board_config [ 'auth_method' ]);
2002-07-14 14:32:45 +00:00
2002-08-06 16:56:14 +00:00
if ( file_exists ( 'includes/auth/auth_' . $method . '.' . $phpEx ) )
2002-07-14 14:32:45 +00:00
{
2002-08-06 16:56:14 +00:00
include_once ( 'includes/auth/auth_' . $method . '.' . $phpEx );
$method = 'login_' . $method ;
if ( function_exists ( $method ) )
2002-07-14 14:32:45 +00:00
{
2002-08-06 16:56:14 +00:00
if ( ! ( $user = $method ( $username , $password )) )
{
return false ;
}
2002-07-14 14:32:45 +00:00
$autologin = ( isset ( $autologin ) ) ? md5 ( $password ) : '' ;
2002-08-06 16:56:14 +00:00
return ( $user [ 'user_active' ] ) ? $session -> create ( $user [ 'user_id' ], $autologin , $user_page , $this_browser ) : false ;
2002-07-14 14:32:45 +00:00
}
}
2002-08-06 16:56:14 +00:00
message_die ( ERROR , 'Authentication method not found' );
}
2002-07-14 14:32:45 +00:00
}
?>