";
/********************************************************/
// Build the board header
$this_header = $skin_universal->BoardHeader();
// Build the members bar
if ($ibforums->member['id'] == 0)
{
$output_array['MEMBER_BAR'] = $skin_universal->Guest_bar();
}
else if (!$ibforums->member['g_use_pm'])
{
$output_array['MEMBER_BAR'] = $skin_universal->Member_no_usepm_bar();
}
else
{
$pm_js = "";
if ( ($ibforums->vars['max_messages'] != "") and ($ibforums->member['msg_total'] >= $ibforums->vars['max_messages']) )
{
$msg_data['TEXT'] = $ibforums->lang['msg_full'];
}
else
{
$ibforums->member['new_msg'] = $ibforums->member['new_msg'] == "" ? 0 : $ibforums->member['new_msg'];
$msg_data['TEXT'] = sprintf( $ibforums->lang['msg_new'], $ibforums->member['new_msg']);
}
// Do we have a pop up to show?
if ($ibforums->member['show_popup'])
{
$DB->query("UPDATE ibf_members SET show_popup='0' WHERE id='{$ibforums->member['id']}'");
$pm_js = $skin_universal->PM_popup();
}
$output_array['MEMBER_BAR'] = $pm_js . $skin_universal->Member_bar($msg_data);
}
if ($ibforums->vars['board_offline'] == 1)
{
$output_array['TITLE'] = $ibforums->lang['warn_offline']." ".$output_array['TITLE'];
}
// Get the template
$ibforums->skin['template'] = str_replace( "<% CSS %>" , "$css" , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% JAVASCRIPT %>" , "" , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% TITLE %>" , $output_array['TITLE'] , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% BOARD %>" , $this->to_print , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% STATS %>" , $stats , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% GENERATOR %>" , "" , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% COPYRIGHT %>" , $copyright , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% BOARD HEADER %>" , $this_header , $ibforums->skin['template']);
$ibforums->skin['template'] = str_replace( "<% NAVIGATION %>" , $nav , $ibforums->skin['template']);
if ( empty($output_array['OVERRIDE']) )
{
$ibforums->skin['template'] = str_replace( "<% MEMBER BAR %>" , $output_array['MEMBER_BAR'], $ibforums->skin['template']);
}
else
{
$ibforums->skin['template'] = str_replace( "<% MEMBER BAR %>" , " " , $ibforums->skin['template']);
}
// Close this DB connection
$DB->close_db();
// Start GZIP compression
if ($ibforums->vars['disable_gzip'] != 1)
{
ob_start ('ob_gzhandler');
}
$this->do_headers();
print $ibforums->skin['template'];
exit;
}
//-------------------------------------------
// print the headers
//-------------------------------------------
function do_headers() {
global $ibforums;
if ($ibforums->vars['print_headers'])
{
@header("HTTP/1.0 200 OK");
@header("HTTP/1.1 200 OK");
@header("Content-type: text/html");
if ($ibforums->vars['nocache'])
{
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
@header("Cache-Control: no-cache, must-revalidate");
@header("Pragma: no-cache");
}
}
}
//-------------------------------------------
// print a pure redirect screen
//-------------------------------------------
function redirect_screen($text="", $url="") {
global $ibforums, $skin_universal, $DB;
$url = $start . "?s={$ibforums->session_id}&".$url;
$ibforums->lang['stand_by'] = stripslashes($ibforums->lang['stand_by']);
$htm = $skin_universal->Redirect($text, $url);
// Close this DB connection
$DB->close_db();
// Start GZIP compression
if ($ibforums->vars['disable_gzip'] != 1)
{
ob_start ('ob_gzhandler');
}
$this->do_headers();
echo ($htm);
exit;
}
//-------------------------------------------
// print a minimalist screen suitable for small
// pop up windows
//-------------------------------------------
function pop_up_window($title = 'IBForums', $text = "" ) {
global $ibforums, $DB;
$html = "
$title
$text
";
$DB->close_db();
if ($ibforums->vars['disable_gzip'] != 1)
{
ob_start ('ob_gzhandler');
}
$this->do_headers();
echo ($html);
exit;
}
} // END class
//######################################################
// Our "session" class
//######################################################
class session {
var $ip_address = 0;
var $user_agent = "";
var $time_now = 0;
var $session_id = 0;
var $session_dead_id = 0;
var $session_user_id = 0;
var $session_user_pass = "";
var $last_click = 0;
var $location = "";
var $member = array();
// No need for a constructor
function authorise() {
global $DB, $INFO, $ibforums, $std, $HTTP_USER_AGENT;
//-------------------------------------------------
// Before we go any lets check the load settings..
//-------------------------------------------------
if ($ibforums->vars['load_limit'] > 0)
{
if ( file_exists('/proc/loadavg') )
{
if ( $fh = @fopen( '/proc/loadavg', 'r' ) )
{
$data = @fread( $fh, 6 );
@fclose( $fh );
$load_avg = explode( " ", $data );
$ibforums->server_load = trim($load_avg[0]);
if ($ibforums->server_load > $ibforums->vars['load_limit'])
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'server_too_busy' ) );
}
}
}
}
//--------------------------------------------
// Are they banned?
//--------------------------------------------
if ($ibforums->vars['ban_ip'])
{
$ips = explode( "|", $ibforums->vars['ban_ip'] );
foreach ($ips as $ip)
{
$ip = preg_replace( "/\*/", '.*' , $ip );
if (preg_match( "/$ip/", $ibforums->input['IP_ADDRESS'] ))
{
$std->Error( array( LEVEL => 1, MSG => 'you_are_banned' ) );
}
}
}
//--------------------------------------------
$this->member = array( 'id' => 0, 'password' => "", 'name' => "", 'mgroup' => $INFO['guest_group'] );
//-------------------------------------------------
// If we are accessing the registration functions,
// lets not confuse things.
//-------------------------------------------------
// We don't want to check if we're registering and we don't want to start
// any new headers if we're simply viewing an attachment..
if ( $ibforums->input['act'] == 'Reg' or $ibforums->input['act'] == 'Attach' )
{
return $this->member;
}
$this->ip_address = $ibforums->input['IP_ADDRESS'];
$this->user_agent = substr($HTTP_USER_AGENT,0,50);
$this->time_now = time();
$cookie = array();
$cookie['session_id'] = $std->my_getcookie('session_id');
$cookie['member_id'] = $std->my_getcookie('member_id');
$cookie['pass_hash'] = $std->my_getcookie('pass_hash');
if (! empty($cookie['session_id']) )
{
$this->get_session($cookie['session_id']);
}
elseif (! empty($ibforums->input['s']) )
{
$this->get_session($ibforums->input['s']);
}
else
{
$this->session_id = 0;
}
//-------------------------------------------------
// Finalise the incoming data..
//-------------------------------------------------
$ibforums->input['Privacy'] = $std->select_var( array(
1 => $ibforums->input['Privacy'],
2 => $std->my_getcookie('anonlogin')
) );
//-------------------------------------------------
// Do we have a valid session ID?
//-------------------------------------------------
if ( ($this->session_id != 0) and ( ! empty($this->session_id) ) )
{
// We've checked the IP addy and browser, so we can assume that this is
// a valid session.
if ( ($this->session_user_id != 0) and ( ! empty($this->session_user_id) ) )
{
// It's a member session, so load the member.
$this->load_member($this->session_user_id);
// Did we get a member?
if ( (! $this->member['id']) or ($this->member['id'] == 0) )
{
$this->unload_member();
$this->update_guest_session();
}
else
{
$this->update_member_session();
}
}
else
{
$this->update_guest_session();
}
}
else
{
// We didn't have a session, or the session didn't validate
// Do we have cookies stored?
if ($cookie['member_id'] != "" and $cookie['pass_hash'] != "")
{
$this->load_member($cookie['member_id']);
if ( (! $this->member['id']) or ($this->member['id'] == 0) )
{
$this->unload_member();
$this->create_guest_session();
}
else
{
if ($this->member['password'] == $cookie['pass_hash'])
{
$this->create_member_session();
}
else
{
$this->unload_member();
$this->create_guest_session();
}
}
}
else
{
$this->create_guest_session();
}
}
//-------------------------------------------------
// Set up a guest if we get here and we don't have a member ID
//-------------------------------------------------
if (! $this->member['id'])
{
$this->member = $std->set_up_guest();
$DB->query("SELECT * from ibf_groups WHERE g_id='".$INFO['guest_group']."'");
$group = $DB->fetch_row();
foreach ($group as $k => $v)
{
$this->member[ $k ] = $v;
}
}
//------------------------------------------------
// Synchronise the last visit and activity times if
// we have some in the member profile
//-------------------------------------------------
if ($this->member['id'])
{
if ( ! $ibforums->input['last_activity'] )
{
if ($this->member['last_activity'])
{
$ibforums->input['last_activity'] = $this->member['last_activity'];
}
else
{
$ibforums->input['last_activity'] = $this->time_now;
}
}
//------------
if ( ! $ibforums->input['last_visit'] )
{
if ($this->member['last_visit'])
{
$ibforums->input['last_visit'] = $this->member['last_visit'];
}
else
{
$ibforums->input['last_visit'] = $this->time_now;
}
}
//-------------------------------------------------
// If there hasn't been a cookie update in 2 hours,
// we assume that they've gone and come back
//-------------------------------------------------
if (!$this->member['last_visit'])
{
// No last visit set, do so now!
$DB->query("UPDATE ibf_members SET last_visit='".$this->time_now."', last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'");
}
else if ( (time() - $ibforums->input['last_activity']) > 300 )
{
// If the last click was longer than 5 mins ago and this is a member
// Update their profile.
$DB->query("UPDATE ibf_members SET last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'");
}
}
//-------------------------------------------------
// Set a session ID cookie
//-------------------------------------------------
$std->my_setcookie("session_id", $this->session_id, -1);
return $this->member;
}
//+-------------------------------------------------
// Attempt to load a member
//+-------------------------------------------------
function load_member($member_id=0)
{
global $DB, $std, $ibforums;
if ($member_id != 0)
{
$DB->query("SELECT m.id, m.name, m.mgroup, m.password, m.email, m.allow_post, m.view_sigs, m.view_avs, m.view_pop, m.view_img, ".
"m.language, m.skin, m.new_msg, m.show_popup, m.msg_total, m.time_offset, m.posts, m.joined, m.last_post, ".
"m.last_visit, m.last_activity, m.dst_in_use, g.* FROM ibf_members m, ibf_groups g WHERE m.id='".$member_id."' and g.g_id=m.mgroup");
if ( $DB->get_num_rows() )
{
$this->member = $DB->fetch_row();
}
//-------------------------------------------------
// Unless they have a member id, log 'em in as a guest
//-------------------------------------------------
if ( ($this->member['id'] == 0) or (empty($this->member['id'])) )
{
$this->unload_member();
}
}
unset($member_id);
}
//+-------------------------------------------------
// Remove the users cookies
//+-------------------------------------------------
function unload_member()
{
global $DB, $std, $ibforums;
// Boink the cookies
$std->my_setcookie( "member_id" , "0", -1 );
$std->my_setcookie( "pass_hash" , "0", -1 );
$this->member['id'] = 0;
$this->member['name'] = "";
$this->member['password'] = "";
}
//-------------------------------------------
// Updates a current session.
//-------------------------------------------
function update_member_session() {
global $DB, $ibforums;
// Make sure we have a session id.
if ( (empty($this->session_id)) or ($this->session_id == 0) )
{
$this->create_member_session();
return;
}
if (empty($this->member['id']))
{
$this->unload_member();
$this->create_guest_session();
return;
}
$query = "UPDATE ibf_sessions SET " .
"member_name='" .$this->member['name'] ."', ".
"member_pass='', ".
"member_id='" .$this->member['id'] ."', ".
"member_group='".$this->member['mgroup'] ."', ";
// Append the rest of the query
$query .= "login_type='".$ibforums->input['Privacy']."', running_time='".$this->time_now."', location='".$ibforums->input['act'].",".$ibforums->input['f'].",".$ibforums->input['t'].",".$ibforums->input['p'].",".$ibforums->input['CODE']."' ";
$query .= "WHERE id='".$this->session_id."'";
// Update the database
$DB->query($query);
}
//--------------------------------------------------------------------
function update_guest_session() {
global $DB, $ibforums, $INFO;
// Make sure we have a session id.
if ( (empty($this->session_id)) or ($this->session_id == 0) )
{
$this->create_guest_session();
return;
}
$query = "UPDATE ibf_sessions SET member_name='',member_pass='',member_id='0',member_group='".$INFO['guest_group']."'";
$query .= ",login_type='0', running_time='".$this->time_now."', location='".$ibforums->input['act'].",".$ibforums->input['f'].",".$ibforums->input['t'].",".$ibforums->input['p'].",".$ibforums->input['CODE']."' ";
$query .= "WHERE id='".$this->session_id."'";
// Update the database
$DB->query($query);
}
//-------------------------------------------
// Get a session based on the current session ID
//-------------------------------------------
function get_session($session_id="") {
global $DB, $INFO, $std;
$result = array();
$query = "";
$session_id = preg_replace("/([^a-zA-Z0-9])/", "", $session_id);
if ( !empty($session_id) )
{
if ($INFO['match_browser'] == 1)
{
$query = " AND browser='".$this->user_agent."'";
}
$DB->query("SELECT id, member_id, running_time, location FROM ibf_sessions WHERE id='".$session_id."' and ip_address='".$this->ip_address."'".$query);
if ($DB->get_num_rows() != 1)
{
// Either there is no session, or we have more than one session..
$this->session_dead_id = $session_id;
$this->session_id = 0;
$this->session_user_id = 0;
return;
}
else
{
$result = $DB->fetch_row();
if ($result['id'] == "")
{
$this->session_dead_id = $session_id;
$this->session_id = 0;
$this->session_user_id = 0;
unset($result);
return;
}
else
{
$this->session_id = $result['id'];
$this->session_user_id = $result['member_id'];
$this->last_click = $result['running_time'];
$this->location = $result['location'];
unset($result);
return;
}
}
}
}
//-------------------------------------------
// Creates a member session.
//-------------------------------------------
function create_member_session() {
global $DB, $INFO, $std, $ibforums;
if ($this->member['id'])
{
//---------------------------------
// Remove the defunct sessions
//---------------------------------
$INFO['session_expiration'] = $INFO['session_expiration'] ? (time() - $INFO['session_expiration']) : (time() - 3600);
$DB->query( "DELETE FROM ibf_sessions WHERE running_time < {$INFO['session_expiration']} or member_id='".$this->member['id']."'");
$this->session_id = md5( uniqid(microtime()) );
//---------------------------------
// Insert the new session
//---------------------------------
$DB->query("INSERT INTO ibf_sessions (id, member_name, member_pass, member_id, ip_address, browser, running_time, location, login_type, member_group) ".
"VALUES ('".$this->session_id."', '".$this->member['name']."', '', '".$this->member['id']."', '".$this->ip_address."', '".$this->user_agent."', '".$this->time_now."', ".
"',,', '".$ibforums->input['Privacy']."', ".$this->member['mgroup'].")");
// If this is a member, update their last visit times, etc.
if (time() - $this->member['last_activity'] > 300)
{
//---------------------------------
// Reset the topics read cookie..
//---------------------------------
$std->my_setcookie('topicsread', '');
$DB->query("UPDATE ibf_members SET last_visit=last_activity, last_activity='".$this->time_now."' WHERE id='".$this->member['id']."'");
//---------------------------------
// Fix up the last visit/activity times.
//---------------------------------
$ibforums->input['last_visit'] = $this->member['last_activity'];
$ibforums->input['last_activity'] = $this->time_now;
}
}
else
{
$this->create_guest_session();
}
}
//--------------------------------------------------------------------
function create_guest_session() {
global $DB, $INFO, $std, $ibforums;
//---------------------------------
// Remove the defunct sessions
//---------------------------------
if ( ($this->session_dead_id != 0) and ( ! empty($this->session_dead_id) ) )
{
$extra = " or id='".$this->session_dead_id."'";
}
else
{
$extra = "";
}
$INFO['session_expiration'] = $INFO['session_expiration'] ? (time() - $INFO['session_expiration']) : (time() - 3600);
$DB->query( "DELETE FROM ibf_sessions WHERE running_time < {$INFO['session_expiration']} or ip_address='".$this->ip_address."'".$extra);
$this->session_id = md5( uniqid(microtime()) );
//---------------------------------
// Insert the new session
//---------------------------------
$DB->query("INSERT INTO ibf_sessions (id, member_name, member_pass, member_id, ip_address, browser, running_time, location, login_type, member_group) ".
"VALUES ('".$this->session_id."', '', '', '0', '".$this->ip_address."', '".$this->user_agent."', '".$this->time_now."', ".
"',,', '0', ".$INFO['guest_group'].")");
}
//--------------------------------------------------------------------
}
?>