146 $this->_errorDir =
__DIR__ .
'/';
147 $this->_reportDir = dirname(dirname($this->_errorDir)) .
'/var/report/';
150 if (!empty($_SERVER[
'SCRIPT_NAME'])) {
151 if (in_array(basename($_SERVER[
'SCRIPT_NAME'],
'.php'), [
'404',
'503',
'report'])) {
152 $this->_scriptName = dirname($_SERVER[
'SCRIPT_NAME']);
154 $this->_scriptName = $_SERVER[
'SCRIPT_NAME'];
158 $reportId = (isset($_GET[
'id'])) ? (
int)$_GET[
'id'] :
null;
164 $this->_root =
is_dir($this->_indexDir .
'app');
167 if (isset($_GET[
'skin'])) {
179 $this->pageTitle =
'Error : cached config data is unavailable';
180 $this->_response->setBody($this->
_renderPage(
'nocache.phtml'));
191 $this->pageTitle =
'Error 404: Not Found';
192 $this->_response->setHttpResponseCode(404);
193 $this->_response->setBody($this->
_renderPage(
'404.phtml'));
204 $this->pageTitle =
'Error 503: Service Unavailable';
205 $this->_response->setHttpResponseCode(503);
206 $this->_response->setBody($this->
_renderPage(
'503.phtml'));
217 $this->pageTitle =
'There has been an error processing your request';
218 $this->_response->setHttpResponseCode(500);
220 $this->showErrorMsg =
false;
221 $this->showSentMsg =
false;
222 $this->showSendForm =
false;
223 $this->reportAction = $this->_config->action;
226 if ($this->reportAction ==
'email') {
227 $this->showSendForm =
true;
230 $this->_response->setBody($this->
_renderPage(
'report.phtml'));
244 str_replace(
'\\',
'/', $this->_indexDir),
246 str_replace(
'\\',
'/', $this->_errorDir)
247 ) . $this->_config->skin .
'/';
260 if (!empty($_SERVER[
'HTTP_HOST'])) {
261 $host = $_SERVER[
'HTTP_HOST'];
262 }
elseif (!empty($_SERVER[
'SERVER_NAME'])) {
263 $host = $_SERVER[
'SERVER_NAME'];
268 $isSecure = (!empty($_SERVER[
'HTTPS'])) && ($_SERVER[
'HTTPS'] !=
'off');
269 $url = ($isSecure ?
'https://' :
'http://') . $host;
271 if (!empty($_SERVER[
'SERVER_PORT']) && !in_array($_SERVER[
'SERVER_PORT'], [80, 443])
272 && !preg_match(
'/.*?\:[0-9]+$/',
$url)
274 $url .=
':' . $_SERVER[
'SERVER_PORT'];
289 if ($param && !$this->_root) {
293 $basePath = str_replace(
'\\',
'/', dirname(
$path));
294 return $this->
getHostUrl() . (
'/' == $basePath ?
'' : $basePath) .
'/';
304 return (isset($_SERVER[
'REMOTE_ADDR'])) ? $_SERVER[
'REMOTE_ADDR'] :
'undefined';
315 if (!empty($_SERVER[
'DOCUMENT_ROOT'])) {
316 $documentRoot = rtrim(realpath($_SERVER[
'DOCUMENT_ROOT']),
'/');
318 return dirname($documentRoot . $this->_scriptName) .
'/';
330 $local = $this->
_loadXml(self::MAGE_ERRORS_LOCAL_XML);
331 $design = $this->
_loadXml(self::MAGE_ERRORS_DESIGN_XML);
336 $config->subject =
'Store Debug Information';
342 if ($design !==
null && (
string)$design->skin) {
345 if ($local !==
null) {
346 if ((
string)$local->report->action) {
347 $config->action = $local->report->action;
349 if ((
string)$local->report->subject) {
350 $config->subject = $local->report->subject;
352 if ((
string)$local->report->email_address) {
353 $config->email_address = $local->report->email_address;
355 if ((
string)$local->report->trash) {
356 $config->trash = $local->report->trash;
358 if ((
string)$local->skin) {
362 if ((
string)
$config->email_address ==
'' && (
string)
$config->action ==
'email') {
378 return ($configPath) ? simplexml_load_file($configPath) :
null;
391 if ($baseTemplate && $contentTemplate) {
393 require_once $baseTemplate;
394 $html = ob_get_clean();
408 if ($directories ===
null) {
409 $directories[] = $this->_errorDir;
412 foreach ($directories as $directory) {
413 if (file_exists($directory . $file)) {
414 return $directory . $file;
427 $directories[] = $this->_errorDir . $this->_config->skin .
'/';
429 if ($this->_config->skin != self::DEFAULT_SKIN) {
430 $directories[] = $this->_errorDir . self::DEFAULT_SKIN .
'/';
447 $this->reportData[
'url'] =
'';
452 if ($this->reportData[
'script_name']) {
453 $this->_scriptName = $this->reportData[
'script_name'];
466 $this->reportId = abs(intval(microtime(
true) * random_int(100, 1000)));
470 if (!file_exists($this->_reportDir)) {
471 @
mkdir($this->_reportDir, 0777,
true);
494 $this->_reportFile = $this->_reportDir .
'/' .
$reportId;
496 if (!file_exists($this->_reportFile) || !
is_readable($this->_reportFile)) {
512 $this->pageTitle =
'Error Submission Form';
514 $this->postData[
'firstName'] = (isset($_POST[
'firstname'])) ? trim(htmlspecialchars($_POST[
'firstname'])) :
'';
515 $this->postData[
'lastName'] = (isset($_POST[
'lastname'])) ? trim(htmlspecialchars($_POST[
'lastname'])) :
'';
516 $this->postData[
'email'] = (isset($_POST[
'email'])) ? trim(htmlspecialchars($_POST[
'email'])) :
'';
517 $this->postData[
'telephone'] = (isset($_POST[
'telephone'])) ? trim(htmlspecialchars($_POST[
'telephone'])) :
'';
518 $this->postData[
'comment'] = (isset($_POST[
'comment'])) ? trim(htmlspecialchars($_POST[
'comment'])) :
'';
520 if (isset($_POST[
'submit'])) {
522 $msg =
"URL: {$this->reportData['url']}\n" 523 .
"IP Address: {$this->_getClientIp()}\n" 524 .
"First Name: {$this->postData['firstName']}\n" 525 .
"Last Name: {$this->postData['lastName']}\n" 526 .
"Email Address: {$this->postData['email']}\n";
527 if ($this->postData[
'telephone']) {
528 $msg .=
"Telephone: {$this->postData['telephone']}\n";
530 if ($this->postData[
'comment']) {
531 $msg .=
"Comment: {$this->postData['comment']}\n";
534 $subject = sprintf(
'%s [%s]', (
string)$this->_config->subject, $this->reportId);
535 @mail((
string)$this->_config->email_address, $subject, $msg);
537 $this->showSendForm =
false;
538 $this->showSentMsg =
true;
540 $this->showErrorMsg =
true;
543 $time =
gmdate(
'Y-m-d H:i:s \G\M\T');
545 $msg =
"URL: {$this->reportData['url']}\n" 546 .
"IP Address: {$this->_getClientIp()}\n" 548 .
"Error:\n{$this->reportData[0]}\n\n" 549 .
"Trace:\n{$this->reportData[1]}";
551 $subject = sprintf(
'%s [%s]', (
string)$this->_config->subject, $this->reportId);
552 @mail((
string)$this->_config->email_address, $subject, $msg);
554 if ($this->_config->trash ==
'delete') {
555 @
unlink($this->_reportFile);
568 '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/',
569 $this->postData[
'email']
571 return ($this->postData[
'firstName'] && $this->postData[
'lastName'] &&
$email);
585 if ($this->_config) {
602 if ($this->reportId && $this->_config && isset($this->_config->skin)) {
603 $this->reportUrl =
"{$this->getBaseUrl(true)}pub/errors/report.php?" 604 . http_build_query([
'id' => $this->reportId,
'skin' => $this->_config->skin]);
_setSkin($value, \stdClass $config=null)
elseif(isset( $params[ 'redirect_parent']))
defined('TESTS_BP')||define('TESTS_BP' __DIR__
const MAGE_ERRORS_LOCAL_XML
_getTemplatePath($template)
__construct(\Magento\Framework\App\Response\Http $response, Json $serializer=null)
_setReportData($reportData)
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
_getFilePath($file, $directories=null)
const MAGE_ERRORS_DESIGN_XML