TYPO3 CMS  TYPO3_7-6
ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Error;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 {
29  protected $defaultTitle = 'Oops, an error occurred!';
30 
36  protected $defaultMessage = '';
37 
41  public function __construct()
42  {
43  set_exception_handler([$this, 'handleException']);
44  }
45 
53  public function echoExceptionWeb($exception)
54  {
55  $this->sendStatusHeaders($exception);
56  $this->writeLogEntries($exception, self::CONTEXT_WEB);
58  \TYPO3\CMS\Core\Messaging\ErrorpageMessage::class,
59  $this->getMessage($exception),
60  $this->getTitle($exception)
61  );
62  $messageObj->output();
63  }
64 
72  public function echoExceptionCLI($exception)
73  {
74  $filePathAndName = $exception->getFile();
75  $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
76  $this->writeLogEntries($exception, self::CONTEXT_CLI);
77  echo '
78 Uncaught TYPO3 Exception ' . $exceptionCodeNumber . $exception->getMessage() . LF;
79  echo 'thrown in file ' . $filePathAndName . LF;
80  echo 'in line ' . $exception->getLine() . '
81 
82 ';
83  die(1);
84  }
85 
93  protected function discloseExceptionInformation($exception)
94  {
95  // Allow message to be shown in production mode if the exception is about
96  // trusted host configuration. By doing so we do not disclose
97  // any valuable information to an attacker but avoid confusions among TYPO3 admins
98  // in production context.
99  if ($exception->getCode() === 1396795884) {
100  return true;
101  }
102  // Show client error messages 40x in every case
103  if ($exception instanceof Http\AbstractClientErrorException) {
104  return true;
105  }
106  // Only show errors in FE, if a BE user is authenticated
107  if (TYPO3_MODE === 'FE') {
108  return $GLOBALS['TSFE']->beUserLogin;
109  }
110  return true;
111  }
112 
120  protected function getTitle($exception)
121  {
122  if ($this->discloseExceptionInformation($exception) && method_exists($exception, 'getTitle') && $exception->getTitle() !== '') {
123  return htmlspecialchars($exception->getTitle());
124  } else {
125  return $this->defaultTitle;
126  }
127  }
128 
136  protected function getMessage($exception)
137  {
138  if ($this->discloseExceptionInformation($exception)) {
139  // Exception has an error code given
140  if ($exception->getCode() > 0) {
141  $moreInformationLink = '<p>More information regarding this error might be available <a href="'
142  . TYPO3_URL_EXCEPTION . $exception->getCode() . '" target="_blank">online</a>.</p>';
143  } else {
144  $moreInformationLink = '';
145  }
146  return htmlspecialchars($exception->getMessage()) . $moreInformationLink;
147  } else {
148  return $this->defaultMessage;
149  }
150  }
151 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']