display_errors);
ini_set('log_errors', '1');
if (is_dir($CFG->log_directory) && is_writable($CFG->log_directory)) {
ini_set('error_log', $CFG->log_directory . '/php_error_log');
}
/******************************************************************************
* DATABASE STUFF
*****************************************************************************/
if ($CFG->enable_mysql) { // use mysql database _______________________________
// MySQL connection parameters.
if (!empty($_SERVER['DB_NAME']) && !empty($_SERVER['DB_USER']) && !empty($_SERVER['DB_PASS'])) {
// We set DB passwords as environment variables in the httpd.conf file,
// which is readable only by root.
$CFG->database = $_SERVER['DB_NAME'];
$CFG->username = $_SERVER['DB_USER'];
$CFG->password = $_SERVER['DB_PASS'];
} else {
// For CLI scripts that do not get httpd.conf ENV variables we load a
// config file with the credentials. This file must be readable only by the
// user that is executing the CLI application! NOT apache, unless the CLI is
// spawned as a background process from an apache executed script, in which
// case that is the only option.
include SITE_BASE . '/../config/db_auth.inc.php';
}
if (empty($CFG->database) || empty($CFG->username) || empty($CFG->password)) {
logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
}
// Connect to MySQL
$dbh = mysql_connect('localhost', $CFG->username, $CFG->password);
// Select database
mysql_select_db($CFG->database, $dbh);
// Connection errors.
if (!$dbh || mysql_error($dbh)) {
$mysql_error_msg = $dbh ? 'Codebase MySQL error: (' . mysql_errno($dbh) . ') ' . mysql_error($dbh) : 'Codebase MySQL error: Could not connect to server.';
if ($CFG->db_debug) {
echo $mysql_error_msg . "\n";
} else {
echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
}
logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
die;
}
/**
* A wrapper for mysql_query. Allows us to set the database link_identifier,
* to trap errors and ease debugging.
*
* @param string $query The SQL query to execute
* @param bool $debug If true, prints debugging info
* @return resource Query identifier
*/
function dbQuery($query, $debug=false)
{
global $CFG, $dbh;
$debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
if ($CFG->db_always_debug || $debug) {
echo "";
}
$qid = mysql_query($query, $dbh);
if (!$qid || mysql_error($dbh)) {
if ($CFG->db_debug) {
echo '
'; echo 'ERRONEOUS QUERY:' . htmlspecialchars($debugqry); echo ''; } else { echo _("This page is temporarily unavailable. It should be back up in a few minutes."); } logMsg('Query failed: ' . preg_replace('/[\s]+/', ' ', $debugqry) . ' with MySQL error: (' . mysql_errno($dbh) . ') ' . mysql_error($dbh), LOG_EMERG, __FILE__, __LINE__); if ($CFG->db_die_on_failure) { echo "\n\n"; die; } } return $qid; } } // End enable MySQL._________________________________________________________ /****************************************************************************** * SESSION HANDLER INITIALIZATION, AND STARTUP *****************************************************************************/ // Skip sessions for some scripts, like the cron executed scripts. if (true === $CFG->enable_session) { //________________________________________ // Set the session ID to one provided in GET/POST. This is necessary for linking // between domains and keeping the same session. if ($ses = getFormData($CFG->session_name, false)) { session_id($ses); } // Session parameters. ini_set('session.use_cookies', $CFG->session_use_cookies); ini_set('session.use_trans_sid', false); ini_set('session.entropy_file', '/dev/urandom'); ini_set('session.entropy_length', '512'); session_name($CFG->session_name); if (true === $CFG->enable_mysql_session_handler && true === $CFG->enable_mysql) { // Database session handling. require_once CODE_BASE . '/lib/MySQLSessionHandler.inc.php'; $sess_mysql['dbh'] =& $dbh; // MySQL link identifyer, if we are already connected to the database $sess_mysql['hostname'] = 'localhost'; // MySQL hostname $sess_mysql['user'] = $CFG->username; // MySQL username $sess_mysql['password'] = $CFG->password; // MySQL password $sess_mysql['db'] = $CFG->database; // Database where to store the sessions $sess_mysql['table'] = 'session_tbl'; // Table where to store the sessions ini_set('session.save_handler', 'user'); session_set_save_handler('mysqlSessionOpen', 'mysqlSessionClose', 'mysqlSessionRead', 'mysqlSessionWrite', 'mysqlSessionDestroy', 'mysqlSessionGarbage'); } // Start the session. Access session data using: $_SESSION['...'] session_start(); // if (isset($_COOKIE[session_name()])) { // logMsg(sprintf('Found session in cookie: %s=%s', session_name(), $_COOKIE[session_name()]), LOG_DEBUG, __FILE__, __LINE__); // } // if (getPost(session_name())) { // logMsg(sprintf('Found session in post: %s=%s', session_name(), getPost(session_name())), LOG_DEBUG, __FILE__, __LINE__); // } // if (getGet(session_name())) { // logMsg(sprintf('Found session in get: %s=%s', session_name(), getGet(session_name())), LOG_DEBUG, __FILE__, __LINE__); // } // logMsg(sprintf('Using session %s=%s', session_name(), session_id()), LOG_DEBUG, __FILE__, __LINE__); /****************************************************************************** * LANGUAGE *****************************************************************************/ // Set the language. if ($lang = getFormData('lang')) { $_SESSION['_language'] = $lang; } else if (!isset($_SESSION['_language'])) { preg_match('/^([-[:alpha:]]+)/i', getenv('HTTP_ACCEPT_LANGUAGE'), $lang); if (isset($CFG->site_langs[$lang[0]])) { $_SESSION['_language'] = $lang[0]; } else { $_SESSION['_language'] = 'en'; } } } // end enable sessions ______________________________________________________ /****************************************************************************** * AUTHENTICATION *****************************************************************************/ if (!isset($_admin)) { $_admin = new AuthSQL(array( 'auth_name' => 'admin', 'user_tbl' => 'admin_tbl', 'user_id_column' => 'admin_id', 'login_url' => $CFG->admin_url . '/login.php' )); } if (!isset($_user)) { $_user = new AuthSQL(array( 'auth_name' => 'user', 'db_table' => 'user_tbl', 'user_id_column' => 'user_id', 'login_tbl' => 'login_tbl', 'login_url' => $CFG->site_url . '/login.php', 'features' => array('blocking'=>true, 'abuse_detection'=>true), )); } /****************************************************************************** * ET CETERA *****************************************************************************/ // Character set. This will also be printed in the html head. header('Content-type: text/html; charset=' . $CFG->character_set); // Capture the ultimate referrer. Used? Not yet. if (!isset($_SESSION['_ultimate_referrer'])) { $_SESSION['_ultimate_referrer'] = getenv('HTTP_REFERER'); } // The include path is set for the templates. // We split them between shared and site specific directories. $inc_lang = isset($_SESSION['_language']) ? $_SESSION['_language'] : 'en'; ini_set('include_path', '/usr/local/lib/php' . PATH_SEPARATOR . SITE_BASE . '/_templates/' . $inc_lang . PATH_SEPARATOR . CODE_BASE . '/templates/' . $inc_lang . PATH_SEPARATOR . SITE_BASE . '/_templates/en' . PATH_SEPARATOR . CODE_BASE . '/templates/en' . PATH_SEPARATOR . SITE_BASE . '/_templates' . PATH_SEPARATOR . CODE_BASE . '/templates' ); ?>
THE PROBLEM:
' . wordwrap(mysql_error($dbh)) . '