-<?php\r
-namespace dns\system;\r
-\r
-/**\r
- * A SystemException is thrown when an unexpected error occurs.\r
- * \r
- * @author Marcel Werk\r
- * @copyright 2001-2015 WoltLab GmbH\r
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>\r
- * @package com.woltlab.wcf\r
- * @subpackage system.exception\r
- * @category Community Framework\r
- */\r
-// @codingStandardsIgnoreFile\r
-class SystemException extends \Exception {\r
- /**\r
- * error description\r
- * @var string\r
- */\r
- protected $description = null;\r
- \r
- /**\r
- * additional information\r
- * @var string\r
- */\r
- protected $information = '';\r
- \r
- /**\r
- * additional information\r
- * @var string\r
- */\r
- protected $functions = '';\r
- \r
- /**\r
- * exception id\r
- * @var string\r
- */\r
- protected $exceptionID = '';\r
- \r
- /**\r
- * Creates a new SystemException.\r
- * \r
- * @param string $message error message\r
- * @param integer $code error code\r
- * @param string $description description of the error\r
- * @param \Exception $previous repacked Exception\r
- */\r
- public function __construct($message = '', $code = 0, $description = '', \Exception $previous = null) {\r
- parent::__construct((string) $message, (int) $code, $previous);\r
- $this->description = $description;\r
- }\r
- \r
- /**\r
- * Removes database password from stack trace.\r
- * @see \Exception::getTraceAsString()\r
- */\r
- public function __getTraceAsString() {\r
- $e = ($this->getPrevious() ?: $this);\r
- $string = $e->getTraceAsString();\r
- $string = preg_replace('/PDO->__construct\(.*\)/', 'PDO->__construct(...)', $string);\r
- $string = preg_replace('/DB->__construct\(.*\)/', 'DB->__construct(...)', $string);\r
- return $string;\r
- }\r
- \r
- /**\r
- * @see \Exception::getMessage()\r
- */\r
- public function _getMessage() {\r
- $e = ($this->getPrevious() ?: $this);\r
- return $e->getMessage();\r
- }\r
- \r
- /**\r
- * Returns the description of this exception.\r
- * \r
- * @return string\r
- */\r
- public function getDescription() {\r
- return $this->description;\r
- }\r
- \r
- /**\r
- * Returns exception id\r
- * \r
- * @return string\r
- */\r
- public function getExceptionID() {\r
- if (empty($this->exceptionID)) {\r
- $this->logError();\r
- }\r
- \r
- return $this->exceptionID;\r
- }\r
- \r
- /**\r
- * Writes an error to log file.\r
- */\r
- protected function logError() {\r
- if (!empty($this->exceptionID)) {\r
- return;\r
- }\r
- \r
- $logFile = DNS_DIR . '/log/' . gmdate('Y-m-d', time()) . '.txt';\r
- \r
- // try to create file\r
- @touch($logFile);\r
- \r
- // validate if file exists and is accessible for us\r
- if (!file_exists($logFile) || !is_writable($logFile)) {\r
- /*\r
- We cannot recover if we reached this point, the server admin\r
- is urged to fix his pretty much broken configuration.\r
- \r
- GLaDOS: Look at you, sailing through the air majestically, like an eagle... piloting a blimp.\r
- */\r
- return;\r
- }\r
- \r
- $e = ($this->getPrevious() ?: $this);\r
- \r
- // don't forget to update ExceptionLogViewPage, when changing the log file format\r
- $message = gmdate('r', time())."\n".\r
- 'Message: '.$e->getMessage()."\n".\r
- 'File: '.$e->getFile().' ('.$e->getLine().")\n".\r
- 'PHP version: '.phpversion()."\n".\r
- 'DNS version: '.DNS_VERSION."\n".\r
- 'Request URI: '.(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')."\n".\r
- 'Referrer: '.(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')."\n".\r
- 'User-Agent: '.(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')."\n".\r
- 'Information: '.json_encode($this->information)."\n".\r
- "Stacktrace: \n ".implode("\n ", explode("\n", $this->__getTraceAsString()))."\n";\r
- \r
- // calculate Exception-ID\r
- $this->exceptionID = sha1($message);\r
- $message = "<<<<<<<<".$this->exceptionID."<<<<\n".$message."<<<<\n\n";\r
- \r
- // append\r
- @file_put_contents($logFile, $message, FILE_APPEND);\r
- }\r
- \r
- /**\r
- * @see \wcf\system\exception\IPrintableException::show()\r
- */\r
- public function show() {\r
- // send status code\r
- @header('HTTP/1.1 503 Service Unavailable');\r
- \r
- // print report\r
- $e = ($this->getPrevious() ?: $this);\r
- ?><!DOCTYPE html>\r
- <html>\r
- <head>\r
- <title>Fatal error: <?php echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); ?></title>\r
- <meta charset="utf-8" />\r
- <style>\r
- .systemException {\r
- font-family: 'Trebuchet MS', Arial, sans-serif !important;\r
- font-size: 80% !important;\r
- text-align: left !important;\r
- border: 1px solid #036;\r
- border-radius: 7px;\r
- background-color: #eee !important;\r
- overflow: auto !important;\r
- }\r
- .systemException h1 {\r
- font-size: 130% !important;\r
- font-weight: bold !important;\r
- line-height: 1.1 !important;\r
- text-decoration: none !important;\r
- text-shadow: 0 -1px 0 #003 !important;\r
- color: #fff !important;\r
- word-wrap: break-word !important;\r
- border-bottom: 1px solid #036;\r
- border-top-right-radius: 6px;\r
- border-top-left-radius: 6px;\r
- background-color: #369 !important;\r
- margin: 0 !important;\r
- padding: 5px 10px !important;\r
- }\r
- .systemException div {\r
- border-top: 1px solid #fff;\r
- border-bottom-right-radius: 6px;\r
- border-bottom-left-radius: 6px;\r
- padding: 0 10px !important;\r
- }\r
- .systemException h2 {\r
- font-size: 130% !important;\r
- font-weight: bold !important;\r
- color: #369 !important;\r
- text-shadow: 0 1px 0 #fff !important;\r
- margin: 5px 0 !important;\r
- }\r
- .systemException pre, .systemException p {\r
- text-shadow: none !important;\r
- color: #555 !important;\r
- margin: 0 !important;\r
- }\r
- .systemException pre {\r
- font-size: .85em !important;\r
- font-family: "Courier New" !important;\r
- text-overflow: ellipsis;\r
- padding-bottom: 1px;\r
- overflow: hidden !important;\r
- }\r
- .systemException pre:hover{\r
- text-overflow: clip;\r
- overflow: auto !important;\r
- }\r
- </style>\r
- </head>\r
- <body>\r
- <div class="systemException">\r
- <h1>Fatal error: <?php if(!$this->getExceptionID()) { ?>Unable to write log file, please make "<?php echo DNS_DIR; ?>/log/" writable!<?php } else { echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); } ?></h1>\r
- \r
- <?php if (DNS::debugModeIsEnabled()) { ?>\r
- <div>\r
- <?php if ($this->getDescription()) { ?><p><br /><?php echo $this->getDescription(); ?></p><?php } ?>\r
- \r
- <h2>Information:</h2>\r
- <p>\r
- <b>error message:</b> <?php echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); ?><br>\r
- <b>error code:</b> <?php echo intval($e->getCode()); ?><br>\r
- <?php echo $this->information; ?>\r
- <b>file:</b> <?php echo htmlspecialchars($e->getFile(), ENT_COMPAT, 'UTF-8'); ?> (<?php echo $e->getLine(); ?>)<br>\r
- <b>php version:</b> <?php echo htmlspecialchars(phpversion(), ENT_COMPAT, 'UTF-8'); ?><br>\r
- <b>dns version:</b> <?php echo DNS_VERSION; ?><br>\r
- <b>date:</b> <?php echo gmdate('r'); ?><br>\r
- <b>request:</b> <?php if (isset($_SERVER['REQUEST_URI'])) echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_COMPAT, 'UTF-8'); ?><br>\r
- <b>referer:</b> <?php if (isset($_SERVER['HTTP_REFERER'])) echo htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_COMPAT, 'UTF-8'); ?><br>\r
- </p>\r
- \r
- <h2>Stacktrace:</h2>\r
- <pre><?php echo htmlspecialchars($this->__getTraceAsString(), ENT_COMPAT, 'UTF-8'); ?></pre>\r
- </div>\r
- <?php } else { ?>\r
- <div>\r
- <h2>Information:</h2>\r
- <p>\r
- <?php if (!$this->getExceptionID()) { ?>\r
- Unable to write log file, please make "<?php echo DNS_DIR; ?>/log/" writable!\r
- <?php } else { ?>\r
- <b>ID:</b> <code><?php echo $this->getExceptionID(); ?></code><br>\r
- Please send the ID above to the site administrator.\r
- <?php } ?>\r
- </p>\r
- </div>\r
- <?php } ?>\r
- <?php echo $this->functions; ?>\r
- </div>\r
- </body>\r
- </html>\r
- \r
- <?php\r
- }\r
-}\r
+<?php
+namespace dns\system;
+
+/**
+ * A SystemException is thrown when an unexpected error occurs.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2015 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.exception
+ * @category Community Framework
+ */
+// @codingStandardsIgnoreFile
+class SystemException extends \Exception {
+ /**
+ * error description
+ * @var string
+ */
+ protected $description = null;
+
+ /**
+ * additional information
+ * @var string
+ */
+ protected $information = '';
+
+ /**
+ * additional information
+ * @var string
+ */
+ protected $functions = '';
+
+ /**
+ * exception id
+ * @var string
+ */
+ protected $exceptionID = '';
+
+ /**
+ * Creates a new SystemException.
+ *
+ * @param string $message error message
+ * @param integer $code error code
+ * @param string $description description of the error
+ * @param \Exception $previous repacked Exception
+ */
+ public function __construct($message = '', $code = 0, $description = '', \Exception $previous = null) {
+ parent::__construct((string) $message, (int) $code, $previous);
+ $this->description = $description;
+ }
+
+ /**
+ * Removes database password from stack trace.
+ * @see \Exception::getTraceAsString()
+ */
+ public function __getTraceAsString() {
+ $e = ($this->getPrevious() ?: $this);
+ $string = $e->getTraceAsString();
+ $string = preg_replace('/PDO->__construct\(.*\)/', 'PDO->__construct(...)', $string);
+ $string = preg_replace('/DB->__construct\(.*\)/', 'DB->__construct(...)', $string);
+ return $string;
+ }
+
+ /**
+ * @see \Exception::getMessage()
+ */
+ public function _getMessage() {
+ $e = ($this->getPrevious() ?: $this);
+ return $e->getMessage();
+ }
+
+ /**
+ * Returns the description of this exception.
+ *
+ * @return string
+ */
+ public function getDescription() {
+ return $this->description;
+ }
+
+ /**
+ * Returns exception id
+ *
+ * @return string
+ */
+ public function getExceptionID() {
+ if (empty($this->exceptionID)) {
+ $this->logError();
+ }
+
+ return $this->exceptionID;
+ }
+
+ /**
+ * Writes an error to log file.
+ */
+ protected function logError() {
+ if (!empty($this->exceptionID)) {
+ return;
+ }
+
+ $logFile = DNS_DIR . '/log/' . gmdate('Y-m-d', time()) . '.txt';
+
+ // try to create file
+ @touch($logFile);
+
+ // validate if file exists and is accessible for us
+ if (!file_exists($logFile) || !is_writable($logFile)) {
+ /*
+ We cannot recover if we reached this point, the server admin
+ is urged to fix his pretty much broken configuration.
+
+ GLaDOS: Look at you, sailing through the air majestically, like an eagle... piloting a blimp.
+ */
+ return;
+ }
+
+ $e = ($this->getPrevious() ?: $this);
+
+ // don't forget to update ExceptionLogViewPage, when changing the log file format
+ $message = gmdate('r', time())."\n".
+ 'Message: '.$e->getMessage()."\n".
+ 'File: '.$e->getFile().' ('.$e->getLine().")\n".
+ 'PHP version: '.phpversion()."\n".
+ 'DNS version: '.DNS_VERSION."\n".
+ 'Request URI: '.(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')."\n".
+ 'Referrer: '.(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')."\n".
+ 'User-Agent: '.(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')."\n".
+ 'Information: '.json_encode($this->information)."\n".
+ "Stacktrace: \n ".implode("\n ", explode("\n", $this->__getTraceAsString()))."\n";
+
+ // calculate Exception-ID
+ $this->exceptionID = sha1($message);
+ $message = "<<<<<<<<".$this->exceptionID."<<<<\n".$message."<<<<\n\n";
+
+ // append
+ @file_put_contents($logFile, $message, FILE_APPEND);
+ }
+
+ /**
+ * @see \wcf\system\exception\IPrintableException::show()
+ */
+ public function show() {
+ // send status code
+ @header('HTTP/1.1 503 Service Unavailable');
+
+ // print report
+ $e = ($this->getPrevious() ?: $this);
+ ?><!DOCTYPE html>
+ <html>
+ <head>
+ <title>Fatal error: <?php echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); ?></title>
+ <meta charset="utf-8" />
+ <style>
+ .systemException {
+ font-family: 'Trebuchet MS', Arial, sans-serif !important;
+ font-size: 80% !important;
+ text-align: left !important;
+ border: 1px solid #036;
+ border-radius: 7px;
+ background-color: #eee !important;
+ overflow: auto !important;
+ }
+ .systemException h1 {
+ font-size: 130% !important;
+ font-weight: bold !important;
+ line-height: 1.1 !important;
+ text-decoration: none !important;
+ text-shadow: 0 -1px 0 #003 !important;
+ color: #fff !important;
+ word-wrap: break-word !important;
+ border-bottom: 1px solid #036;
+ border-top-right-radius: 6px;
+ border-top-left-radius: 6px;
+ background-color: #369 !important;
+ margin: 0 !important;
+ padding: 5px 10px !important;
+ }
+ .systemException div {
+ border-top: 1px solid #fff;
+ border-bottom-right-radius: 6px;
+ border-bottom-left-radius: 6px;
+ padding: 0 10px !important;
+ }
+ .systemException h2 {
+ font-size: 130% !important;
+ font-weight: bold !important;
+ color: #369 !important;
+ text-shadow: 0 1px 0 #fff !important;
+ margin: 5px 0 !important;
+ }
+ .systemException pre, .systemException p {
+ text-shadow: none !important;
+ color: #555 !important;
+ margin: 0 !important;
+ }
+ .systemException pre {
+ font-size: .85em !important;
+ font-family: "Courier New" !important;
+ text-overflow: ellipsis;
+ padding-bottom: 1px;
+ overflow: hidden !important;
+ }
+ .systemException pre:hover{
+ text-overflow: clip;
+ overflow: auto !important;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="systemException">
+ <h1>Fatal error: <?php if(!$this->getExceptionID()) { ?>Unable to write log file, please make "<?php echo DNS_DIR; ?>/log/" writable!<?php } else { echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); } ?></h1>
+
+ <?php if (DNS::debugModeIsEnabled()) { ?>
+ <div>
+ <?php if ($this->getDescription()) { ?><p><br /><?php echo $this->getDescription(); ?></p><?php } ?>
+
+ <h2>Information:</h2>
+ <p>
+ <b>error message:</b> <?php echo htmlspecialchars($this->_getMessage(), ENT_COMPAT, 'UTF-8'); ?><br>
+ <b>error code:</b> <?php echo intval($e->getCode()); ?><br>
+ <?php echo $this->information; ?>
+ <b>file:</b> <?php echo htmlspecialchars($e->getFile(), ENT_COMPAT, 'UTF-8'); ?> (<?php echo $e->getLine(); ?>)<br>
+ <b>php version:</b> <?php echo htmlspecialchars(phpversion(), ENT_COMPAT, 'UTF-8'); ?><br>
+ <b>dns version:</b> <?php echo DNS_VERSION; ?><br>
+ <b>date:</b> <?php echo gmdate('r'); ?><br>
+ <b>request:</b> <?php if (isset($_SERVER['REQUEST_URI'])) echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_COMPAT, 'UTF-8'); ?><br>
+ <b>referer:</b> <?php if (isset($_SERVER['HTTP_REFERER'])) echo htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_COMPAT, 'UTF-8'); ?><br>
+ </p>
+
+ <h2>Stacktrace:</h2>
+ <pre><?php echo htmlspecialchars($this->__getTraceAsString(), ENT_COMPAT, 'UTF-8'); ?></pre>
+ </div>
+ <?php } else { ?>
+ <div>
+ <h2>Information:</h2>
+ <p>
+ <?php if (!$this->getExceptionID()) { ?>
+ Unable to write log file, please make "<?php echo DNS_DIR; ?>/log/" writable!
+ <?php } else { ?>
+ <b>ID:</b> <code><?php echo $this->getExceptionID(); ?></code><br>
+ Please send the ID above to the site administrator.
+ <?php } ?>
+ </p>
+ </div>
+ <?php } ?>
+ <?php echo $this->functions; ?>
+ </div>
+ </body>
+ </html>
+
+ <?php
+ }
+}