More fixes

git-svn-id: file:///svn/phpbb/trunk@594 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2001-07-07 00:17:51 +00:00
parent 99fcfdbb32
commit 0955639395
2 changed files with 83 additions and 48 deletions

View file

@ -70,14 +70,14 @@ include('includes/db.'.$phpEx);
// //
if(!empty($HTTP_CLIENT_IP)) if(!empty($HTTP_CLIENT_IP))
{ {
if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER)) if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_CLIENT_IP))
{ {
$client_ip = $HTTP_CLIENT_IP; $client_ip = $HTTP_CLIENT_IP;
} }
} }
else if(!empty($HTTP_X_FORWARDED_FOR)) else if(!empty($HTTP_X_FORWARDED_FOR))
{ {
if(strstr(",", $HTTP_X_FORWARDED_FOR)) if(ereg(",", $HTTP_X_FORWARDED_FOR))
{ {
list($client_ip) = explode(",", $HTTP_X_FORWARDED_FOR); list($client_ip) = explode(",", $HTTP_X_FORWARDED_FOR);
} }
@ -88,14 +88,14 @@ else if(!empty($HTTP_X_FORWARDED_FOR))
} }
else if(!empty($HTTP_VIA)) else if(!empty($HTTP_VIA))
{ {
if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER)) if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_VIA))
{ {
$client_ip = $HTTP_VIA; $client_ip = $HTTP_VIA;
} }
} }
else if(!empty($HTTP_PROXY_USER)) else if(!empty($HTTP_PROXY_USER))
{ {
if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER)) if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER))
{ {
$client_ip = $HTTP_PROXY_USER; $client_ip = $HTTP_PROXY_USER;
} }
@ -106,27 +106,15 @@ else
} }
$user_ip = encode_ip($client_ip); $user_ip = encode_ip($client_ip);
// //
// Setup forum wide options. // Setup forum wide options, if this fails
// This is also the first DB query/connect // then we output a CRITICAL_ERROR since
// basic forum information is not available
// //
$sql = "SELECT * $sql = "SELECT *
FROM " . CONFIG_TABLE; FROM " . CONFIG_TABLE;
if(!$result = $db->sql_query($sql)) if(!$result = $db->sql_query($sql))
{ {
//
// Define some basic configuration
// vars, necessary since we haven't
// been able to get them from the DB
//
$board_config['default_template'] = "Default";
$board_config['default_timezone'] = 0;
$board_config['default_dateformat'] = "d M Y H:i";
$board_config['default_theme'] = 1;
$board_config['default_lang'] = "english";
$board_config['gzip_compress'] = 0;
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql); message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
} }
else else
@ -170,7 +158,6 @@ else
$board_config['gzip_compress'] = $config['gzip_compress']; $board_config['gzip_compress'] = $config['gzip_compress'];
$board_config['smtp_delivery'] = $config['smtp_delivery']; $board_config['smtp_delivery'] = $config['smtp_delivery'];
$board_config['smtp_host'] = $config['smtp_host']; $board_config['smtp_host'] = $config['smtp_host'];
} }
include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx); include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx);

View file

@ -22,28 +22,47 @@
* *
***************************************************************************/ ***************************************************************************/
//
// This function gets called to output any message or error
// that doesn't require additional output from the calling
// page.
//
// $msg_code takes one of four constant values:
//
// GENERAL_MESSAGE -> Use for any simple text message, eg.
// results of an operation, authorisation failures, etc.
//
// GENERAL ERROR -> Use for any error which occurs _AFTER_
// the common.php include and session code, ie. most errors
// in pages/functions
//
// CRITICAL_MESSAGE -> Only currently used to announce a user
// has been banned, can be used where session results cannot
// be relied upon to exist
//
// CRITICAL_ERROR -> Used whenever a DB connection cannot be
// guaranteed and/or sessions have failed. Shouldn't be used
// in general pages/functions (it results in a simple echo'd
// statement, no templates are used)
//
function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "", $err_file = "", $sql = "") function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "", $err_file = "", $sql = "")
{ {
global $db, $template, $board_config, $theme, $lang, $phpEx; global $db, $template, $board_config, $theme, $lang, $phpEx;
global $userdata, $user_ip, $session_length; global $userdata, $user_ip, $session_length;
global $starttime; global $starttime;
if(empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) ) if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
{ {
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length); $userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
init_userprefs($userdata); init_userprefs($userdata);
//
// End session management
//
} }
if(!defined("HEADER_INC")) //
// If the header hasn't been output then do it
//
if( !defined("HEADER_INC") && $msg_code != CRITICAL_ERROR )
{ {
if(!empty($board_config['default_lang'])) if( !empty($board_config['default_lang']) )
{ {
include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx); include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx);
} }
@ -51,18 +70,21 @@ function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "",
{ {
include('language/lang_english.'.$phpEx); include('language/lang_english.'.$phpEx);
} }
if(!$template)
if( empty($template) )
{ {
$template = new Template("templates/Default"); $template = new Template("templates/Default");
} }
if(!$theme)
if( empty($theme) )
{ {
$theme = setuptheme(1); $theme = setuptheme(1);
} }
if($msg_code != CRITICAL_ERROR)
{ //
include('includes/page_header.'.$phpEx); // Load the Page Header
} //
include('includes/page_header.'.$phpEx);
} }
switch($msg_code) switch($msg_code)
@ -86,57 +108,83 @@ function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "",
{ {
$msg_text = $lang['An_error_occured']; $msg_text = $lang['An_error_occured'];
} }
if($msg_title == "") if($msg_title == "")
{ {
$msg_title = $lang['General_Error']; $msg_title = $lang['General_Error'];
} }
case CRITICAL_ERROR: case CRITICAL_ERROR:
//
// Critical errors mean we cannot rely on _ANY_ DB information being
// available so we're going to dump out a simple echo'd statement
//
include('language/lang_english.'.$phpEx);
if($msg_text == "") if($msg_text == "")
{ {
$msg_text = $lang['A_critical_error']; $msg_text = $lang['A_critical_error'];
} }
if($msg_title == "") if($msg_title == "")
{ {
$msg_title = $lang['Critical_Error']; $msg_title = "phpBB : <b>" . $lang['Critical_Error'] . "</b>";
} }
break; break;
} }
//
// Add on DEBUG info if we've enabled debug mode and this is an error. This
// prevents debug info being output for general messages should DEBUG be
// set TRUE by accident (preventing confusion for the end user!)
//
if(DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) ) if(DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
{ {
$sql_error = $db->sql_error(); $sql_error = $db->sql_error();
$debug_text = ""; $debug_text = "";
if($sql_error['message'] != "") if($sql_error['message'] != "")
{ {
$debug_text .= "<br /><br />SQL Error : " . $sql_error['code'] . " " . $sql_error['message']; $debug_text .= "<br /><br />SQL Error : " . $sql_error['code'] . " " . $sql_error['message'];
} }
if($sql != "") if($sql != "")
{ {
$debug_text .= "<br /><br />$sql"; $debug_text .= "<br /><br />$sql";
} }
if($err_line != "" && $err_file != "") if($err_line != "" && $err_file != "")
{ {
$debug_text .= "</br /><br />Line : " . $err_line . "<br />File : " . $err_file; $debug_text .= "</br /><br />Line : " . $err_line . "<br />File : " . $err_file;
} }
if($debug_text != "") if($debug_text != "")
{ {
$msg_text = $msg_text . "<br /><br /><b><u>DEBUG MODE</u></b>" . $debug_text; $msg_text = $msg_text . "<br /><br /><b><u>DEBUG MODE</u></b>" . $debug_text;
} }
} }
$template->set_filenames(array( if( $msg_code != CRITICAL_ERROR )
"message_body" => "message_body.tpl") {
); $template->set_filenames(array(
$template->assign_vars(array( "message_body" => "message_body.tpl")
"MESSAGE_TITLE" => $msg_title, );
"MESSAGE_TEXT" => $msg_text) $template->assign_vars(array(
); "MESSAGE_TITLE" => $msg_title,
$template->pparse("message_body"); "MESSAGE_TEXT" => $msg_text)
);
$template->pparse("message_body");
include('includes/page_tail.'.$phpEx); include('includes/page_tail.'.$phpEx);
}
else
{
echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>";
}
exit;
exit();
} }
?> ?>