/** * Check for minimal requirements. * if BX_DISABLE_REQUIREMENTS_CHECK is defined then this requirements checking is skipped. * @param $bShowHttpError show 503 HTTP error if site doesn't meet minimal requirements * @return false if requirements are met, or array of errors of requirements aren't met */ function bx_check_minimal_requirements($bShowHttpError = false) { if (defined('BX_DISABLE_REQUIREMENTS_CHECK')) { return false; } $aErrors = array(); $aErrors[] = ini_get('register_globals') == 0 ? '' : '<b>register_globals</b> is on (you need to disable it, or your site will be unsafe)'; $aErrors[] = ini_get('safe_mode') == 0 ? '' : '<b>safe_mode</b> is on (you need to disable it)'; $aErrors[] = version_compare(PHP_VERSION, '5.3.0', '<') ? 'PHP version is too old (please update to <b>PHP 5.3.0</b> at least)' : ''; $aErrors[] = !extension_loaded('mbstring') ? '<b>mbstring</b> extension not installed (the script cannot work without it)' : ''; $aErrors[] = ini_get('allow_url_include') == 0 ? '' : '<b>allow_url_include</b> is on (you need to disable it, or your site will be unsafe)'; $aErrors = array_diff($aErrors, array('')); // delete empty $bFailedMinimalRequirements = !empty($aErrors); if ($bFailedMinimalRequirements && $bShowHttpError) { $sErrors = implode(" <br /> ", $aErrors); bx_show_service_unavailable_error_and_exit($sErrors); } return $bFailedMinimalRequirements ? $aErrors : false; }
/** * @param Throwable $e * @param boolean $bFullMsg display full error message with back trace */ protected function render(Throwable $e, $bFullMsg = false) { if (php_sapi_name() === 'cli') { // don't render errors when invoking from cli // they should get an email for errors return; } ob_start(); ?> <html> <body> <?php if (!$bFullMsg) { ?> <div style="border:2px solid red;padding:4px;width:600px;margin:0px auto;"> <div style="text-align:center;background-color:transparent;color:#000;font-weight:bold;"> <?php echo _t('_Exception_user_msg'); ?> </div> </div> <?php } else { ?> <div style="border:2px solid red;padding:10px;width:90%;margin:0px auto;"> <h2 style="margin-top: 0px;"><?php echo _t('_Exception_uncaught_msg'); ?> </h2> <h3>Details</h3> <table style="table-layout: fixed;"> <tr> <td style="font-weight: bold;">Type</td> <td><?php echo get_class($e); ?> </td> </tr> <tr> <td style="font-weight: bold;">Message</td> <td><?php echo $e->getMessage(); ?> </td> </tr> <tr> <td style="font-weight: bold;">File</td> <td><?php echo $e->getFile(); ?> </td> </tr> <tr> <td style="font-weight: bold;">Line</td> <td><?php echo $e->getLine(); ?> </td> </tr> </table> <h3>Trace</h3> <code> <?php echo nl2br($e->getTraceAsString()); ?> </code> </div> <?php } ?> </body> </html> <?php $sOutput = ob_get_clean(); bx_show_service_unavailable_error_and_exit($sOutput); }
function genMySQLErr($sOutput, $query = '') { $sParamsOutput = false; $sFoundError = ''; $aBackTrace = debug_backtrace(); unset($aBackTrace[0]); if ($query) { //try help to find error $aFoundError = array(); foreach ($aBackTrace as $aCall) { // truncating global settings since it repeated many times and output it separately if (isset($aCall['object']) && property_exists($aCall['object'], '_aParams')) { if (false === $sParamsOutput) { $sParamsOutput = var_export($aCall['object']->_aParams, true); } $aCall['object']->_aParams = '[truncated]'; } if (isset($aCall['args']) && is_array($aCall['args'])) { foreach ($aCall['args'] as $argNum => $argVal) { if (is_string($argVal) and strcmp($argVal, $query) == 0) { $aFoundError['file'] = isset($aCall['file']) ? $aCall['file'] : (isset($aCall['class']) ? 'class: ' . $aCall['class'] : 'undefined'); $aFoundError['line'] = isset($aCall['line']) ? $aCall['line'] : 'undefined'; $aFoundError['function'] = $aCall['function']; $aFoundError['arg'] = $argNum; } } } } if ($aFoundError) { $sFoundError = <<<EOJ Found error in the file '<b>{$aFoundError['file']}</b>' at line <b>{$aFoundError['line']}</b>.<br /> Called '<b>{$aFoundError['function']}</b>' function with erroneous argument #<b>{$aFoundError['arg']}</b>.<br /><br /> EOJ; } } bx_import('BxDolConfig'); if (defined('BX_DB_FULL_VISUAL_PROCESSING') && BX_DB_FULL_VISUAL_PROCESSING) { ob_start(); ?> <div style="border:2px solid red;padding:4px;width:600px;margin:0px auto;"> <div style="text-align:center;background-color:red;color:white;font-weight:bold;">Error</div> <div style="text-align:center;"><?php echo $sOutput; ?> </div> <?php if (defined('BX_DB_FULL_DEBUG_MODE') && BX_DB_FULL_DEBUG_MODE) { if (!empty($query)) { echo "<div><b>Query:</b><br />{$query}</div>"; } if ($this->_rLink) { echo '<div><b>Mysql error:</b><br />' . $this->getErrorMessage() . '</div>'; } echo '<div style="overflow:scroll;height:300px;border:1px solid gray;">'; echo $sFoundError; echo "<b>Debug backtrace:</b><br />"; $sBackTrace = print_r($aBackTrace, true); $sBackTrace = str_replace('[password] => ' . BX_DATABASE_PASS, '[password] => *****', $sBackTrace); $sBackTrace = str_replace('[user] => ' . BX_DATABASE_USER, '[user] => *****', $sBackTrace); echo '<pre>' . $sBackTrace . '</pre>'; if ($sParamsOutput) { echo '<hr />'; echo "<b>Settings:</b><br />"; echo '<pre>' . htmlspecialchars_adv($sParamsOutput) . '</pre>'; } echo "<b>Called script:</b> " . $_SERVER['PHP_SELF'] . "<br />"; echo "<b>Request parameters:</b><br />"; echoDbg($_REQUEST); echo '</div>'; } ?> </div> <?php $sOutput = ob_get_clean(); } if (defined('BX_DB_DO_EMAIL_ERROR_REPORT') && BX_DB_DO_EMAIL_ERROR_REPORT) { $sSiteTitle = $this->getParam('site_title'); $sMailBody = "Database error in " . $sSiteTitle . "<br /><br /> \n"; if (strlen($query)) { $sMailBody .= "Query: <pre>" . htmlspecialchars_adv($query) . "</pre> "; } if ($this->_rLink) { $sMailBody .= "Mysql error: " . $this->getErrorMessage() . "<br /><br /> "; } $sMailBody .= $sFoundError . '<br /> '; $sBackTrace = print_r($aBackTrace, true); $sBackTrace = str_replace('[password] => ' . BX_DATABASE_PASS, '[password] => *****', $sBackTrace); $sBackTrace = str_replace('[user] => ' . BX_DATABASE_USER, '[user] => *****', $sBackTrace); $sMailBody .= "Debug backtrace:\n <pre>" . htmlspecialchars_adv($sBackTrace) . "</pre> "; if ($sParamsOutput) { $sMailBody .= "<hr />Settings:\n <pre>" . htmlspecialchars_adv($sParamsOutput) . "</pre> "; } $sMailBody .= "<hr />Called script: " . $_SERVER['PHP_SELF'] . "<br /> "; $sMailBody .= "<hr />Request parameters: <pre>" . print_r($_REQUEST, true) . " </pre>"; $sMailBody .= "--\nAuto-report system\n"; sendMail($this->getParam('site_email'), "Database error in " . $sSiteTitle, $sMailBody, 0, array(), BX_EMAIL_SYSTEM, 'html', true); } bx_show_service_unavailable_error_and_exit($sOutput); }
function genMySQLErr($sOutput, $query = '') { $sParamsOutput = false; $sFoundError = ''; $aBackTrace = debug_backtrace(); unset($aBackTrace[0]); if ($query) { //try help to find error $aFoundError = array(); foreach ($aBackTrace as $aCall) { // truncating global settings since it repeated many times and output it separately if (isset($aCall['object']) && is_a($aCall['object'], 'BxDolDb')) { if (false === $sParamsOutput) { $sParamsOutput = var_export($aCall['object']->_aParams, true); } $aCall['object']->_aParams = '[truncated]'; } if (isset($aCall['args']) && is_array($aCall['args'])) { foreach ($aCall['args'] as $argNum => $argVal) { if (is_string($argVal) and strcmp($argVal, $query) == 0) { $aFoundError['file'] = isset($aCall['file']) ? $aCall['file'] : (isset($aCall['class']) ? 'class: ' . $aCall['class'] : 'undefined'); $aFoundError['line'] = isset($aCall['line']) ? $aCall['line'] : 'undefined'; $aFoundError['function'] = $aCall['function']; $aFoundError['arg'] = $argNum; } } } } if ($aFoundError) { $sFoundError = <<<EOJ Found error in the file '<b>{$aFoundError['file']}</b>' at line <b>{$aFoundError['line']}</b>.<br /> Called '<b>{$aFoundError['function']}</b>' function.<br /><br /> EOJ; } } if (defined('BX_DB_FULL_VISUAL_PROCESSING') && BX_DB_FULL_VISUAL_PROCESSING) { ob_start(); ?> <div style="border:2px solid red;padding:4px;width:600px;margin:0px auto;"> <div style="text-align:center;background-color:red;color:white;font-weight:bold;">Error</div> <div style="text-align:center;"><?php echo $sOutput; ?> </div> <?php if (defined('BX_DB_FULL_DEBUG_MODE') && BX_DB_FULL_DEBUG_MODE) { echo $this->verboseErrorOutput($query, $sFoundError, $aBackTrace, $sParamsOutput); } ?> </div> <?php $sOutput = ob_get_clean(); } if (defined('BX_DB_DO_EMAIL_ERROR_REPORT') && BX_DB_DO_EMAIL_ERROR_REPORT) { $sSiteTitle = $this->getParam('site_title'); $sMailBody = "Database error in " . $sSiteTitle . "<br /><br /> \n"; $sMailBody .= $this->verboseErrorOutput($query, $sFoundError, $aBackTrace, $sParamsOutput); $sMailBody .= "<hr />Auto-report system"; sendMail($this->getParam('site_email'), "Database error in " . $sSiteTitle, $sMailBody, 0, array(), BX_EMAIL_SYSTEM, 'html', true); } bx_show_service_unavailable_error_and_exit($sOutput); }