'.$sLogMessage.''.PHP_FATAL_ERROR_TAG.'>'; } function FatalErrorCatcher($sOutput) { if (preg_match('|<'.PHP_FATAL_ERROR_TAG.'>.*'.PHP_FATAL_ERROR_TAG.'>|s', $sOutput, $aMatches)) { header("HTTP/1.0 500 Internal server error."); $errors = ''; foreach ($aMatches as $sMatch) { $errors .= strip_tags($sMatch)."\n"; } $sOutput = "$errors\n"; // Logging to a file does not work if the whole memory is exhausted... //SetupPage::log_error("Fatal error - in $__FILE__ , $errors"); } return $sOutput; } //Define some bogus, invalid HTML tags that no sane //person would ever put in an actual document and tell //PHP to delimit fatal error warnings with them. ini_set('error_prepend_string', '<'.PHP_FATAL_ERROR_TAG.'>'); ini_set('error_append_string', ''.PHP_FATAL_ERROR_TAG.'>'); // callback on errors to log register_shutdown_function('ShutdownCallback'); // Starts the capture of the ouput, and sets a filter to capture the fatal errors. ob_start('FatalErrorCatcher'); // Start capturing the output, and pass it through the fatal error catcher require_once(APPROOT.'/core/config.class.inc.php'); require_once(APPROOT.'/core/log.class.inc.php'); require_once(APPROOT.'/core/kpi.class.inc.php'); require_once(APPROOT.'/core/cmdbsource.class.inc.php'); require_once('./xmldataloader.class.inc.php'); require_once(APPROOT.'/application/ajaxwebpage.class.inc.php'); // Never cache this page header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Fri, 17 Jul 1970 05:00:00 GMT"); // Date in the past /** * Main program */ $sOperation = Utils::ReadParam('operation', ''); try { SetupUtils::CheckSetupToken(); switch($sOperation) { case 'async_action': ini_set('max_execution_time', max(240, ini_get('max_execution_time'))); // While running the setup it is desirable to see any error that may happen ini_set('display_errors', true); ini_set('display_startup_errors', true); require_once(APPROOT.'/setup/wizardcontroller.class.inc.php'); require_once(APPROOT.'/setup/wizardsteps.class.inc.php'); $sClass = utils::ReadParam('step_class', ''); $sState = utils::ReadParam('step_state', ''); $sActionCode = utils::ReadParam('code', ''); $aParams = utils::ReadParam('params', array(), false, 'raw_data'); $oPage = new ajax_page(''); $oDummyController = new WizardController(''); if (is_subclass_of($sClass, 'WizardStep')) { /** @var WizardStep $oStep */ $oStep = new $sClass($oDummyController, $sState); $sConfigFile = utils::GetConfigFilePath(); if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig()) { $sRelativePath = utils::GetConfigFilePathRelative(); $oPage->error("Error: the configuration file '".$sRelativePath."' already exists and cannot be overwritten."); $oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '".$sRelativePath."' can be modified by the web server."); $oPage->output(); } else { $oStep->AsyncAction($oPage, $sActionCode, $aParams); } } $oPage->output(); break; default: throw(new Exception("Error unsupported operation '$sOperation'")); } } catch(Exception $e) { header("HTTP/1.0 500 Internal server error."); echo "
An error happened while processing the installation:
\n"; echo ''.$e."
\n"; SetupPage::log_error("An error happened while processing the installation: ".$e); } if (function_exists('memory_get_peak_usage')) { if ($sOperation == 'file') { SetupPage::log_info("loading file '$sFileName', peak memory usage. ".memory_get_peak_usage()); } else { SetupPage::log_info("operation '$sOperation', peak memory usage. ".memory_get_peak_usage()); } }