init
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Options None
|
||||
<FilesMatch "\.(xml|phtml)$">
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine Off
|
||||
</IfModule>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
require_once 'processorFactory.php';
|
||||
|
||||
$processorFactory = new \Magento\Framework\Error\ProcessorFactory();
|
||||
$processor = $processorFactory->createProcessor();
|
||||
$response = $processor->process404();
|
||||
$response->sendResponse();
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
require_once 'processorFactory.php';
|
||||
|
||||
$processorFactory = new \Magento\Framework\Error\ProcessorFactory();
|
||||
$processor = $processorFactory->createProcessor();
|
||||
$response = $processor->process503();
|
||||
$response->sendResponse();
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
|
||||
<h1>404 error: Page not found.</h1>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
|
||||
<h1>Service Temporarily Unavailable</h1>
|
||||
<p>
|
||||
The server is temporarily unable to service your request due to maintenance downtime or capacity problems.
|
||||
Please try again later.
|
||||
</p>
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
body{background:#fff;color:#333;font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.4;margin:0;padding:0;text-align:left}main{display:block}img{border:0}a{color:#1979c3;text-decoration:underline}a:hover{text-decoration:none}h1{font-size:30px;font-weight:700;margin:0 0 20px}h2{font-size:20px;font-weight:700;margin:0 0 10px}input[type=text],textarea{box-sizing:border-box;background:#fff;border:1px solid #c2c2c2;border-radius:1px;width:100%;font-size:14px;font-family:Arial,Helvetica,sans-serif;line-height:1.42857143;background-clip:padding-box;vertical-align:baseline}input[type=text]{height:32px;padding:0 9px}textarea{height:auto;padding:10px;resize:vertical}input[type=text]:focus,textarea:focus{box-shadow:0 0 3px 1px #68a8e0}button{background:#1979c3;border:none;border-radius:3px;color:#fff;cursor:pointer;display:inline-block;font-size:14px;font-weight:700;line-height:16px;padding:7px 15px;text-align:center}button:hover{background:#006bb4}p{margin:0 0 10px}ol,ul{list-style:none}.page-main{padding:20px 30px}.trace{background:#f1f1f1;min-height:250px;overflow:auto;width:100%}.message{border:1px solid;background-position:10px 11px;background-repeat:no-repeat;margin:20px 0;padding:10px 20px 10px 35px}.error{border-color:#b30000;background-color:#fae5e5;background-image:url(../images/i_msg-error.gif);color:#b30000}.success{border-color:#006400;background-color:#e5efe5;background-image:url(../images/i_msg-success.gif);color:#006400}.info{border-color:#6f4400;background-color:#fdf0d5;background-image:url(../images/i_msg-note.gif);color:#6f4400}.fieldset{border:0;margin:0 0 20px;padding:0}.fieldset .legend{box-sizing:border-box;float:left;font-size:20px;line-height:1.2;margin:0 0 25px;padding:0}.fieldset .legend+br{display:block;clear:both;height:0;overflow:hidden;visibility:hidden}.fieldset:last-child{margin-bottom:0}.fieldset:after{content:attr(data-hasrequired);color:#e02b27;display:block;font-size:12px;letter-spacing:normal;margin:10px 0 0;word-spacing:normal}.field{margin:0 0 20px}.label{font-weight:700}.label:after{content:"*";font-size:12px;color:#e02b27;margin:0 0 0 5px}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1009 B |
Binary file not shown.
|
After Width: | Height: | Size: 1021 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
|
||||
<h1>Service Temporarily Unavailable</h1>
|
||||
<p>The application can't retrieve cached config data. Please try again later.</p>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// phpcs:ignoreFile
|
||||
?>
|
||||
<!doctype html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" >
|
||||
<head>
|
||||
<title><?= $this->pageTitle ?></title>
|
||||
<base href="<?= $this->escaper->escapeHtmlAttr($this->getViewFileUrl()) ?>" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="robots" content="*"/>
|
||||
<link rel="stylesheet" href="css/styles.css" type="text/css" />
|
||||
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
|
||||
</head>
|
||||
<body>
|
||||
<main class="page-main">
|
||||
<?php require $contentTemplate; ?>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
// @codingStandardsIgnoreFile
|
||||
?>
|
||||
|
||||
<h1>There has been an error processing your request</h1>
|
||||
<?php if ($this->showSentMsg): ?>
|
||||
<div class="message success message-success">
|
||||
<div>Your message was submitted and will be responded as soon as possible. Thank you for reporting.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($this->showSendForm): ?>
|
||||
<div class="message info message-info">
|
||||
<div>
|
||||
We are currently experiencing some technical issues. We apologize for the inconvenience and will contact you shortly to resolve the issue. To help us serve you please fill in the form below.
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($this->showErrorMsg): ?>
|
||||
<div class="message error message-error">
|
||||
<div>
|
||||
Please fill all required fields with valid information
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="<?= "{$this->getBaseUrl(true)}errors/report.php?id={$this->reportId}" ?>" method="post" id="form-validate" class="form">
|
||||
<fieldset class="fieldset" data-hasrequired="* Required Fields">
|
||||
<legend class="legend"><span>Personal Information</span></legend><br />
|
||||
<div class="field firstname required">
|
||||
<label for="firstname" class="label">First Name</label>
|
||||
<div class="control">
|
||||
<input type="text" name="firstname" id="firstname" value="<?= $this->postData['firstName'] ?>" title="First Name" class="required-entry input-text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field lastname required">
|
||||
<label for="lastname" class="label">Last Name</label>
|
||||
<div class="control">
|
||||
<input type="text" name="lastname" id="lastname" value="<?= $this->postData['lastName'] ?>" title="Last Name" class="required-entry input-text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field email required">
|
||||
<label for="email_address" class="label">Email Address</label>
|
||||
<div class="control">
|
||||
<input type="text" name="email" id="email_address" value="<?= $this->postData['email'] ?>" title="Email Address" class="validate-email required-entry input-text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field telephone">
|
||||
<label for="telephone" class="label">Telephone</label>
|
||||
<div class="control">
|
||||
<input type="tel" name="telephone" id="telephone" value="<?= $this->postData['telephone'] ?>" title="Telephone" class="input-text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field comment">
|
||||
<label for="comment" class="label">Comment</label>
|
||||
<div class="control">
|
||||
<textarea name="comment" cols="5" rows="3" class="textarea"><?= $this->postData['comment'] ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions-toolbar">
|
||||
<button name="submit" class="action primary" type="submit"><span>Submit</span></button>
|
||||
</div>
|
||||
</form>
|
||||
<?php elseif ('' == $this->reportAction): ?>
|
||||
<p><em>Exception printing is disabled by default for security reasons.</em></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->reportAction == 'print'): ?>
|
||||
<div class="trace-container">
|
||||
<div class="trace">
|
||||
<pre><?= htmlspecialchars($this->reportData[0]) ?></pre>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($this->reportId): ?>
|
||||
<p>Error log record number: <?= $this->reportId ?></p>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config>
|
||||
<skin>default</skin>
|
||||
</config>
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config>
|
||||
<skin>default</skin>
|
||||
<report>
|
||||
<!--
|
||||
"action" can be set to "print" to show exception on screen and "email"
|
||||
to send exception on specified email
|
||||
-->
|
||||
<action>print</action>
|
||||
<!--
|
||||
in "subject" you can set subject of email
|
||||
-->
|
||||
<subject>Store Debug Information</subject>
|
||||
<!--
|
||||
"email_address" admin email address
|
||||
-->
|
||||
<email_address></email_address>
|
||||
<!--
|
||||
"trash" is handle about trace info
|
||||
value "leave" is for store on disk
|
||||
value "delete" is for cleaning
|
||||
-->
|
||||
<trash>leave</trash>
|
||||
<!--
|
||||
The number of subdirectories that will be created to save the report.
|
||||
Valid Values: Integers from 0 to 32
|
||||
|
||||
Example:
|
||||
If we have the report name as hash sha256('') = 44ffb1087a44e61b018b3cdee72284d017f22e52755c24e5c85cbac1647ae7a7
|
||||
|
||||
dir_nesting_level=0 -> <magento_root>/var/report/44ffb1087a44e61b018b3cdee72284d017f22e52755c24e5c85cbac1647ae7a7
|
||||
dir_nesting_level=1 -> <magento_root>/var/report/44/44ffb1087a44e61b018b3cdee72284d017f22e52755c24e5c85cbac1647ae7a7
|
||||
dir_nesting_level=2 -> <magento_root>/var/report/44/ff/44ffb1087a44e61b018b3cdee72284d017f22e52755c24e5c85cbac1647ae7a7
|
||||
...
|
||||
dir_nesting_level=32 -> <magento_root>/var/report/44/ff/b1/08/7a/44/e6/1b/01/8b/3c/de/e7/22/84/d0/17/f2/2e/52/75/5c/24/e5/c8/5c/ba/c1/64/7a/e7/a7/44ffb1087a44e61b018b3cdee72284d017f22e52755c24e5c85cbac1647ae7a7
|
||||
|
||||
If you use an environment variable MAGE_ERROR_REPORT_DIR_NESTING_LEVEL, this property will be ignored.
|
||||
Environment variable has a higher priority.
|
||||
-->
|
||||
<dir_nesting_level>0</dir_nesting_level>
|
||||
</report>
|
||||
</config>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
require_once 'processorFactory.php';
|
||||
|
||||
$processorFactory = new \Magento\Framework\Error\ProcessorFactory();
|
||||
$processor = $processorFactory->createProcessor();
|
||||
$response = $processor->processNoCache();
|
||||
$response->sendResponse();
|
||||
@@ -0,0 +1,768 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Error;
|
||||
|
||||
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\App\Response\Http;
|
||||
|
||||
/**
|
||||
* Error processor
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
* phpcs:ignoreFile
|
||||
*/
|
||||
class Processor
|
||||
{
|
||||
const MAGE_ERRORS_LOCAL_XML = 'local.xml';
|
||||
const MAGE_ERRORS_DESIGN_XML = 'design.xml';
|
||||
const DEFAULT_SKIN = 'default';
|
||||
const ERROR_DIR = 'pub/errors';
|
||||
const NUMBER_SYMBOLS_IN_SUBDIR_NAME = 2;
|
||||
|
||||
/**
|
||||
* Page title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pageTitle;
|
||||
|
||||
/**
|
||||
* Skin URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $skinUrl;
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $baseUrl;
|
||||
|
||||
/**
|
||||
* Post data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $postData;
|
||||
|
||||
/**
|
||||
* Report data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $reportData;
|
||||
|
||||
/**
|
||||
* Report action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $reportAction;
|
||||
|
||||
/**
|
||||
* Report ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $reportId;
|
||||
|
||||
/**
|
||||
* Report file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_reportFile;
|
||||
|
||||
/**
|
||||
* Show error message
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $showErrorMsg;
|
||||
|
||||
/**
|
||||
* Show message after sending email
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $showSentMsg;
|
||||
|
||||
/**
|
||||
* Show form for sending
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $showSendForm;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $reportUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_reportDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_indexDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_errorDir;
|
||||
|
||||
/**
|
||||
* Server script name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_scriptName;
|
||||
|
||||
/**
|
||||
* Is root
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_root;
|
||||
|
||||
/**
|
||||
* Internal config object
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Http response
|
||||
*
|
||||
* @var Http
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* JSON serializer
|
||||
*
|
||||
* @var Json
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* @var DocumentRoot
|
||||
*/
|
||||
private $documentRoot;
|
||||
|
||||
/**
|
||||
* @param Http $response
|
||||
* @param Json $serializer
|
||||
* @param Escaper $escaper
|
||||
* @param DocumentRoot|null $documentRoot
|
||||
*/
|
||||
public function __construct(
|
||||
Http $response,
|
||||
Json $serializer = null,
|
||||
Escaper $escaper = null,
|
||||
DocumentRoot $documentRoot = null
|
||||
) {
|
||||
$this->_response = $response;
|
||||
$this->_errorDir = __DIR__ . '/';
|
||||
$this->_reportDir = dirname(dirname($this->_errorDir)) . '/var/report/';
|
||||
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
|
||||
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
|
||||
$this->documentRoot = $documentRoot ?? ObjectManager::getInstance()->get(DocumentRoot::class);
|
||||
if (!empty($_SERVER['SCRIPT_NAME'])) {
|
||||
if (in_array(basename($_SERVER['SCRIPT_NAME'], '.php'), ['404', '503', 'report'])) {
|
||||
$this->_scriptName = dirname($_SERVER['SCRIPT_NAME']);
|
||||
} else {
|
||||
$this->_scriptName = $_SERVER['SCRIPT_NAME'];
|
||||
}
|
||||
}
|
||||
$this->_indexDir = $this->_getIndexDir();
|
||||
$this->_root = is_dir($this->_indexDir . 'app');
|
||||
$this->_prepareConfig();
|
||||
if (isset($_GET['skin'])) {
|
||||
$this->_setSkin($_GET['skin']);
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
$this->loadReport($_GET['id']);
|
||||
}
|
||||
$response->setMetadata("NotCacheable", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process no cache error
|
||||
*
|
||||
* @return \Magento\Framework\App\Response\Http
|
||||
*/
|
||||
public function processNoCache()
|
||||
{
|
||||
$this->pageTitle = 'Error : cached config data is unavailable';
|
||||
$this->_response->setBody($this->_renderPage('nocache.phtml'));
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process 404 error
|
||||
*
|
||||
* @return \Magento\Framework\App\Response\Http
|
||||
*/
|
||||
public function process404()
|
||||
{
|
||||
$this->pageTitle = 'Error 404: Not Found';
|
||||
$this->_response->setHttpResponseCode(404);
|
||||
$this->_response->setBody($this->_renderPage('404.phtml'));
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process 503 error
|
||||
*
|
||||
* @return \Magento\Framework\App\Response\Http
|
||||
*/
|
||||
public function process503()
|
||||
{
|
||||
$this->pageTitle = 'Error 503: Service Unavailable';
|
||||
$this->_response->setHttpResponseCode(503);
|
||||
$this->_response->setBody($this->_renderPage('503.phtml'));
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process report
|
||||
*
|
||||
* @return \Magento\Framework\App\Response\Http
|
||||
*/
|
||||
public function processReport()
|
||||
{
|
||||
$this->pageTitle = 'There has been an error processing your request';
|
||||
$this->_response->setHttpResponseCode(500);
|
||||
|
||||
$this->showErrorMsg = false;
|
||||
$this->showSentMsg = false;
|
||||
$this->showSendForm = false;
|
||||
$this->reportAction = $this->_config->action;
|
||||
$this->_setReportUrl();
|
||||
|
||||
if ($this->reportAction == 'email') {
|
||||
$this->showSendForm = true;
|
||||
$this->sendReport();
|
||||
}
|
||||
$this->_response->setBody($this->_renderPage('report.phtml'));
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve skin URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewFileUrl()
|
||||
{
|
||||
//The url needs to be updated base on Document root path.
|
||||
$indexDir = str_replace('\\', '/', $this->_indexDir);
|
||||
$errorDir = str_replace('\\', '/', $this->_errorDir);
|
||||
$errorPathSuffix = $this->documentRoot->isPub() ? 'errors/' : 'pub/errors/';
|
||||
$errorPath = strpos($errorDir, $indexDir) === 0 ?
|
||||
str_replace($indexDir, '', $errorDir) : $errorPathSuffix;
|
||||
|
||||
return $this->getBaseUrl() . $errorPath . $this->_config->skin . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve base host URL without path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHostUrl()
|
||||
{
|
||||
/**
|
||||
* Define server http host
|
||||
*/
|
||||
$host = $this->resolveHostName();
|
||||
|
||||
$isSecure = (!empty($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] !== 'off')
|
||||
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https');
|
||||
$url = ($isSecure ? 'https://' : 'http://') . $host;
|
||||
|
||||
$port = explode(':', $host);
|
||||
if (isset($port[1]) && !in_array($port[1], [80, 443])
|
||||
&& !preg_match('/.*?\:[0-9]+$/', $url)
|
||||
) {
|
||||
$url .= ':' . $port[1];
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve hostname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function resolveHostName() : string
|
||||
{
|
||||
if (!empty($_SERVER['HTTP_HOST'])) {
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
} elseif (!empty($_SERVER['SERVER_NAME'])) {
|
||||
$host = $_SERVER['SERVER_NAME'];
|
||||
} else {
|
||||
$host = 'localhost';
|
||||
}
|
||||
return $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve base URL
|
||||
*
|
||||
* @param bool $param
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl($param = false)
|
||||
{
|
||||
$path = $this->_scriptName;
|
||||
|
||||
if ($param && !$this->_root) {
|
||||
$path = dirname($path);
|
||||
}
|
||||
|
||||
$basePath = str_replace('\\', '/', dirname($path));
|
||||
return $this->getHostUrl() . ('/' == $basePath ? '' : $basePath) . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve client IP address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getClientIp()
|
||||
{
|
||||
return (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get index dir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getIndexDir()
|
||||
{
|
||||
$documentRoot = '';
|
||||
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
|
||||
$documentRoot = rtrim(realpath($_SERVER['DOCUMENT_ROOT']), '/');
|
||||
}
|
||||
return dirname($documentRoot . $this->_scriptName) . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare config data
|
||||
*
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function _prepareConfig()
|
||||
{
|
||||
$local = $this->_loadXml(self::MAGE_ERRORS_LOCAL_XML);
|
||||
$design = $this->_loadXml(self::MAGE_ERRORS_DESIGN_XML);
|
||||
|
||||
//initial settings
|
||||
$config = new \stdClass();
|
||||
$config->action = '';
|
||||
$config->subject = 'Store Debug Information';
|
||||
$config->email_address = '';
|
||||
$config->trash = 'leave';
|
||||
$config->skin = self::DEFAULT_SKIN;
|
||||
|
||||
//combine xml data to one object
|
||||
if ($design !== null && (string)$design->skin) {
|
||||
$this->_setSkin((string)$design->skin, $config);
|
||||
}
|
||||
if ($local !== null) {
|
||||
if ((string)$local->report->action) {
|
||||
$config->action = $local->report->action;
|
||||
}
|
||||
if ((string)$local->report->subject) {
|
||||
$config->subject = $local->report->subject;
|
||||
}
|
||||
if ((string)$local->report->email_address) {
|
||||
$config->email_address = $local->report->email_address;
|
||||
}
|
||||
if ((string)$local->report->trash) {
|
||||
$config->trash = $local->report->trash;
|
||||
}
|
||||
if ($local->report->dir_nesting_level) {
|
||||
$config->dir_nesting_level = (int)$local->report->dir_nesting_level;
|
||||
}
|
||||
if ((string)$local->skin) {
|
||||
$this->_setSkin((string)$local->skin, $config);
|
||||
}
|
||||
}
|
||||
if ((string)$config->email_address == '' && (string)$config->action == 'email') {
|
||||
$config->action = '';
|
||||
}
|
||||
|
||||
$this->_config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load xml file
|
||||
*
|
||||
* @param string $xmlFile
|
||||
* @return \SimpleXMLElement
|
||||
*/
|
||||
protected function _loadXml($xmlFile)
|
||||
{
|
||||
$configPath = $this->_getFilePath($xmlFile);
|
||||
return ($configPath) ? simplexml_load_file($configPath) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render page
|
||||
*
|
||||
* @param string $template
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderPage($template)
|
||||
{
|
||||
$baseTemplate = $this->_getTemplatePath('page.phtml');
|
||||
$contentTemplate = $this->_getTemplatePath($template);
|
||||
|
||||
$html = '';
|
||||
if ($baseTemplate && $contentTemplate) {
|
||||
ob_start();
|
||||
require $baseTemplate;
|
||||
$html = ob_get_clean();
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find file path
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $directories
|
||||
* @return string
|
||||
*/
|
||||
protected function _getFilePath($file, $directories = null)
|
||||
{
|
||||
if ($directories === null) {
|
||||
$directories[] = $this->_errorDir;
|
||||
}
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (file_exists($directory . $file)) {
|
||||
return $directory . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find template path
|
||||
*
|
||||
* @param string $template
|
||||
* @return string
|
||||
*/
|
||||
protected function _getTemplatePath($template)
|
||||
{
|
||||
$directories[] = $this->_errorDir . $this->_config->skin . '/';
|
||||
|
||||
if ($this->_config->skin != self::DEFAULT_SKIN) {
|
||||
$directories[] = $this->_errorDir . self::DEFAULT_SKIN . '/';
|
||||
}
|
||||
|
||||
return $this->_getFilePath($template, $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set report data
|
||||
*
|
||||
* @param array $reportData
|
||||
* @return void
|
||||
*/
|
||||
protected function _setReportData($reportData)
|
||||
{
|
||||
$this->reportData = $reportData;
|
||||
|
||||
if (!isset($reportData['url'])) {
|
||||
$this->reportData['url'] = '';
|
||||
} else {
|
||||
$this->reportData['url'] = $this->getHostUrl() . $reportData['url'];
|
||||
}
|
||||
|
||||
if (isset($this->reportData['script_name'])) {
|
||||
$this->_scriptName = $this->reportData['script_name'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create report
|
||||
*
|
||||
* @param array $reportData
|
||||
* @return string
|
||||
*/
|
||||
public function saveReport(array $reportData): string
|
||||
{
|
||||
$this->reportId = $reportData['report_id'];
|
||||
$this->_reportFile = $this->getReportPath(
|
||||
$this->getReportDirNestingLevel($this->reportId),
|
||||
$this->reportId
|
||||
);
|
||||
$reportDirName = dirname($this->_reportFile);
|
||||
if (!file_exists($reportDirName)) {
|
||||
@mkdir($reportDirName, 0777, true);
|
||||
}
|
||||
$this->_setReportData($reportData);
|
||||
|
||||
@file_put_contents($this->_reportFile, $this->serializer->serialize($reportData). PHP_EOL);
|
||||
|
||||
if (isset($reportData['skin']) && self::DEFAULT_SKIN != $reportData['skin']) {
|
||||
$this->_setSkin($reportData['skin']);
|
||||
}
|
||||
$this->_setReportUrl();
|
||||
|
||||
return $this->reportUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get report
|
||||
*
|
||||
* @param string $reportId
|
||||
* @return void
|
||||
*/
|
||||
public function loadReport($reportId)
|
||||
{
|
||||
try {
|
||||
if (!$this->isReportIdValid($reportId)) {
|
||||
throw new \RuntimeException("Report Id is invalid");
|
||||
}
|
||||
$reportFile = $this->findReportFile($reportId);
|
||||
if (!is_readable($reportFile)) {
|
||||
throw new \RuntimeException("Report file cannot be read");
|
||||
}
|
||||
$this->reportId = $reportId;
|
||||
$this->_reportFile = $reportFile;
|
||||
$this->_setReportData($this->serializer->unserialize(file_get_contents($this->_reportFile)));
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->redirectToBaseUrl();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the report file and returns the path to it
|
||||
*
|
||||
* @param string $reportId
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private function findReportFile(string $reportId): string
|
||||
{
|
||||
$reportFile = $this->getReportPath(
|
||||
$this->getReportDirNestingLevel($reportId),
|
||||
$reportId
|
||||
);
|
||||
if (file_exists($reportFile)) {
|
||||
return $reportFile;
|
||||
}
|
||||
$maxReportDirNestingLevel = $this->getMaxReportDirNestingLevel($reportId);
|
||||
for ($i = 0; $i <= $maxReportDirNestingLevel; $i++) {
|
||||
$reportFile = $this->getReportPath($i, $reportId);
|
||||
if (file_exists($reportFile)) {
|
||||
return $reportFile;
|
||||
}
|
||||
}
|
||||
throw new \RuntimeException("Report file not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a base url
|
||||
* @return void
|
||||
*/
|
||||
private function redirectToBaseUrl()
|
||||
{
|
||||
header("Location: " . $this->getBaseUrl());
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks report id
|
||||
*
|
||||
* @param string $reportId
|
||||
* @return bool
|
||||
*/
|
||||
private function isReportIdValid(string $reportId): bool
|
||||
{
|
||||
return (bool)preg_match('/^[a-fA-F0-9]{64}$/', $reportId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to reports
|
||||
*
|
||||
* @param integer $reportDirNestingLevel
|
||||
* @param string $reportId
|
||||
* @return string
|
||||
*/
|
||||
private function getReportPath(int $reportDirNestingLevel, string $reportId): string
|
||||
{
|
||||
$reportDirPath = $this->_reportDir;
|
||||
for ($i = 0, $j = 0; $j < $reportDirNestingLevel; $i += 2, $j++) {
|
||||
$reportDirPath .= $reportId[$i] . $reportId[$i + 1] . '/';
|
||||
}
|
||||
return $reportDirPath . $reportId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns nesting Level for the report files
|
||||
*
|
||||
* @var $reportId
|
||||
* @return int
|
||||
*/
|
||||
private function getReportDirNestingLevel(string $reportId): int
|
||||
{
|
||||
$envName = 'MAGE_ERROR_REPORT_DIR_NESTING_LEVEL';
|
||||
$value = $_ENV[$envName] ?? getenv($envName);
|
||||
if(false === $value && property_exists($this->_config, 'dir_nesting_level')) {
|
||||
$value = $this->_config->dir_nesting_level;
|
||||
}
|
||||
$value = (int)$value;
|
||||
$maxValue= $this->getMaxReportDirNestingLevel($reportId);
|
||||
return 0 < $value && $maxValue >= $value ? $value : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum nesting level directories of report files
|
||||
*
|
||||
* @param string $reportId
|
||||
* @return integer
|
||||
*/
|
||||
private function getMaxReportDirNestingLevel(string $reportId): int
|
||||
{
|
||||
return (int)floor(strlen($reportId) / self::NUMBER_SYMBOLS_IN_SUBDIR_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send report
|
||||
*
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
public function sendReport()
|
||||
{
|
||||
$this->pageTitle = 'Error Submission Form';
|
||||
|
||||
$this->postData['firstName'] = (isset($_POST['firstname']))
|
||||
? trim($this->escaper->escapeHtml($_POST['firstname'])) : '';
|
||||
$this->postData['lastName'] = (isset($_POST['lastname']))
|
||||
? trim($this->escaper->escapeHtml($_POST['lastname'])) : '';
|
||||
$this->postData['email'] = (isset($_POST['email']))
|
||||
? trim($this->escaper->escapeHtml($_POST['email'])) : '';
|
||||
$this->postData['telephone'] = (isset($_POST['telephone']))
|
||||
? trim($this->escaper->escapeHtml($_POST['telephone'])) : '';
|
||||
$this->postData['comment'] = (isset($_POST['comment']))
|
||||
? trim($this->escaper->escapeHtml($_POST['comment'])) : '';
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
if ($this->_validate()) {
|
||||
$msg = "URL: {$this->reportData['url']}\n"
|
||||
. "IP Address: {$this->_getClientIp()}\n"
|
||||
. "First Name: {$this->postData['firstName']}\n"
|
||||
. "Last Name: {$this->postData['lastName']}\n"
|
||||
. "Email Address: {$this->postData['email']}\n";
|
||||
if ($this->postData['telephone']) {
|
||||
$msg .= "Telephone: {$this->postData['telephone']}\n";
|
||||
}
|
||||
if ($this->postData['comment']) {
|
||||
$msg .= "Comment: {$this->postData['comment']}\n";
|
||||
}
|
||||
|
||||
$subject = sprintf('%s [%s]', (string)$this->_config->subject, $this->reportId);
|
||||
@mail((string)$this->_config->email_address, $subject, $msg);
|
||||
|
||||
$this->showSendForm = false;
|
||||
$this->showSentMsg = true;
|
||||
} else {
|
||||
$this->showErrorMsg = true;
|
||||
}
|
||||
} else {
|
||||
$time = gmdate('Y-m-d H:i:s \G\M\T');
|
||||
|
||||
$msg = "URL: {$this->reportData['url']}\n"
|
||||
. "IP Address: {$this->_getClientIp()}\n"
|
||||
. "Time: {$time}\n"
|
||||
. "Error:\n{$this->reportData[0]}\n\n"
|
||||
. "Trace:\n{$this->reportData[1]}";
|
||||
|
||||
$subject = sprintf('%s [%s]', (string)$this->_config->subject, $this->reportId);
|
||||
@mail((string)$this->_config->email_address, $subject, $msg);
|
||||
|
||||
if ($this->_config->trash == 'delete') {
|
||||
@unlink($this->_reportFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate submitted post data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _validate()
|
||||
{
|
||||
$email = preg_match(
|
||||
'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/',
|
||||
$this->postData['email']
|
||||
);
|
||||
return ($this->postData['firstName'] && $this->postData['lastName'] && $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skin setter
|
||||
*
|
||||
* @param string $value
|
||||
* @param \stdClass $config
|
||||
* @return void
|
||||
*/
|
||||
protected function _setSkin($value, \stdClass $config = null)
|
||||
{
|
||||
if (preg_match('/^[a-z0-9_]+$/i', $value) && is_dir($this->_errorDir . $value)) {
|
||||
if (!$config) {
|
||||
if ($this->_config) {
|
||||
$config = $this->_config;
|
||||
}
|
||||
}
|
||||
if ($config) {
|
||||
$config->skin = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current report URL from current params
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setReportUrl()
|
||||
{
|
||||
if ($this->reportId && $this->_config && isset($this->_config->skin)) {
|
||||
$this->reportUrl = "{$this->getBaseUrl(true)}pub/errors/report.php?"
|
||||
. http_build_query(['id' => $this->reportId, 'skin' => $this->_config->skin]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
namespace Magento\Framework\Error;
|
||||
|
||||
// phpcs:ignore Magento2.Functions.DiscouragedFunction,Magento2.Security.IncludeFile
|
||||
require_once realpath(__DIR__) . '/../../app/bootstrap.php';
|
||||
require_once 'processor.php'; // phpcs:ignore Magento2.Security.IncludeFile
|
||||
use Magento\Framework\App\ObjectManager as AppObjectManager;
|
||||
|
||||
/**
|
||||
* Error processor factory
|
||||
*/
|
||||
class ProcessorFactory
|
||||
{
|
||||
/**
|
||||
* Create Processor
|
||||
*
|
||||
* @return Processor
|
||||
*/
|
||||
public function createProcessor()
|
||||
{
|
||||
try {
|
||||
$objectManager = AppObjectManager::getInstance();
|
||||
return $objectManager->create(Processor::class);
|
||||
} catch (\RuntimeException $exception) {
|
||||
// phpcs:ignore Magento2.Security.Superglobal
|
||||
$objectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
|
||||
$objectManager = $objectManagerFactory->create($_SERVER); // phpcs:ignore Magento2.Security.Superglobal
|
||||
$response = $objectManager->create(\Magento\Framework\App\Response\Http::class);
|
||||
return new Processor($response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
require_once 'processorFactory.php';
|
||||
|
||||
$processorFactory = new \Magento\Framework\Error\ProcessorFactory();
|
||||
$processor = $processorFactory->createProcessor();
|
||||
|
||||
if (isset($reportData) && is_array($reportData)) {
|
||||
$reportUrl = $processor->saveReport($reportData);
|
||||
if (headers_sent()) {
|
||||
echo '<script type="text/javascript">';
|
||||
echo "window.location.href = '{$reportUrl}';";
|
||||
echo '</script>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$response = $processor->processReport();
|
||||
$response->sendResponse();
|
||||
Reference in New Issue
Block a user