Ejemplo n.º 1
0
	/**
	 * @see	wcf\system\exception\IPrintableException::show()
	 */
	public function show() {
		if (WCF::debugModeIsEnabled()) {
			echo '<pre>' . $this->getTraceAsString() . '</pre>';
		}
		else {
			echo '<pre>' . $this->_getMessage() . '</pre>';
		}
	}
Ejemplo n.º 2
0
 /**
  * Suppresses the original error message.
  * 
  * @see		\Exception::getMessage()
  */
 public function _getMessage()
 {
     if (!WCF::debugModeIsEnabled()) {
         return 'An error occured. Sorry.';
     }
     $e = $this->getPrevious() ?: $this;
     return $e->getMessage();
 }
Ejemplo n.º 3
0
 /**
  * @see	\Exception::getMessage()
  */
 public function _getMessage()
 {
     // suppresses the original error message
     if (!WCF::debugModeIsEnabled() && !$this->ignoreDebugMode) {
         return 'An error occured. Sorry.';
     }
     $e = $this->getPrevious() ?: $this;
     return $e->getMessage();
 }
Ejemplo n.º 4
0
    /**
     * @see wcf\system\exception\IPrintableException::show()
     */
    public function show()
    {
        // log error
        $exceptionID = $this->logError();
        // send status code
        @header('HTTP/1.1 503 Service Unavailable');
        // show user-defined system-exception
        if (defined('SYSTEMEXCEPTION_FILE') && file_exists(SYSTEMEXCEPTION_FILE)) {
            require SYSTEMEXCEPTION_FILE;
            return;
        }
        // print report
        echo '<?xml version="1.0" encoding="UTF-8"?>';
        $e = $this->getPrevious() ?: $this;
        ?>

		<!DOCTYPE html>
		<html>
			<head>
				<title>Fatal error: <?php 
        echo StringUtil::encodeHTML($this->_getMessage());
        ?>
</title>
				<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 
        echo StringUtil::encodeHTML($this->_getMessage());
        ?>
</h1>
					
					<?php 
        if (WCF::debugModeIsEnabled()) {
            ?>
						<div>
							<p><?php 
            echo $this->getDescription();
            ?>
</p>
							
							<h2>Information:</h2>
							<p>
								<b>id:</b> <code><?php 
            echo $exceptionID;
            ?>
</code><br>
								<b>error message:</b> <?php 
            echo StringUtil::encodeHTML($this->_getMessage());
            ?>
<br>
								<b>error code:</b> <?php 
            echo intval($e->getCode());
            ?>
<br>
								<?php 
            echo $this->information;
            ?>
								<b>file:</b> <?php 
            echo StringUtil::encodeHTML($e->getFile());
            ?>
 (<?php 
            echo $e->getLine();
            ?>
)<br>
								<b>php version:</b> <?php 
            echo StringUtil::encodeHTML(phpversion());
            ?>
<br>
								<b>wcf version:</b> <?php 
            echo WCF_VERSION;
            ?>
<br>
								<b>date:</b> <?php 
            echo gmdate('r');
            ?>
<br>
								<b>request:</b> <?php 
            if (isset($_SERVER['REQUEST_URI'])) {
                echo StringUtil::encodeHTML($_SERVER['REQUEST_URI']);
            }
            ?>
<br>
								<b>referer:</b> <?php 
            if (isset($_SERVER['HTTP_REFERER'])) {
                echo StringUtil::encodeHTML($_SERVER['HTTP_REFERER']);
            }
            ?>
<br>
							</p>
							
							<h2>Stacktrace:</h2>
							<pre><?php 
            echo StringUtil::encodeHTML($this->__getTraceAsString());
            ?>
</pre>
						</div>
					<?php 
        } else {
            ?>
						<div>
							<h2>Information:</h2>
							<p>
								<b>id:</b> <code><?php 
            echo $exceptionID;
            ?>
</code><br>
								Send this ID to the administrator of this website to report this issue.
							</p>
						</div>
					<?php 
        }
        ?>
					
					<?php 
        echo $this->functions;
        ?>
				</div>
			</body>
		</html>

		<?php 
    }
Ejemplo n.º 5
0
	/**
	 * Throws a JSON-encoded error message
	 * 
	 * @param	string		$message
	 * @param	boolean		$isDoomsday
	 * @param	string		$stacktrace
	 * @param	array<mixed>	$returnValues
	 */
	public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array()) {
		if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
		
		if (WCF::debugModeIsEnabled()) {
			$responseData = array(
				'message' => $message,
				'stacktrace' => nl2br($stacktrace)
			);
		}
		else {
			$responseData = array(
				'message' => $this->_getMessage()
			);
		}
		
		$responseData['code'] = $errorType;
		$responseData['returnValues'] = $returnValues;
		
		$statusHeader = '';
		switch ($errorType) {
			case self::MISSING_PARAMETERS:
				$statusHeader = 'HTTP/1.0 400 Bad Request';
				$responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.badRequest');
				
				$this->logError();
			break;
			
			case self::SESSION_EXPIRED:
				$statusHeader = 'HTTP/1.0 401 Unauthorized';
			break;
			
			case self::INSUFFICIENT_PERMISSIONS:
				$statusHeader = 'HTTP/1.0 403 Forbidden';
			break;
			
			case self::BAD_PARAMETERS:
				$statusHeader = 'HTTP/1.0 412 Precondition Failed';
			break;
			
			default:
			case self::INTERNAL_ERROR:
				//header('HTTP/1.0 418 I\'m a Teapot');
				header('HTTP/1.0 503 Service Unavailable');
				
				$responseData['code'] = self::INTERNAL_ERROR;
				if (!WCF::debugModeIsEnabled()) {
					$responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.internalError');
				}
				
				$this->logError();
			break;
		}
		
		header($statusHeader);
		header('Content-type: application/json');
		echo JSON::encode($responseData);
		exit;
	}
Ejemplo n.º 6
0
    /**
     * @see	\wcf\system\exception\IPrintableException::show()
     */
    public function show()
    {
        // send status code
        @header('HTTP/1.1 503 Service Unavailable');
        // show user-defined system-exception
        if (defined('SYSTEMEXCEPTION_FILE') && file_exists(SYSTEMEXCEPTION_FILE)) {
            require SYSTEMEXCEPTION_FILE;
            return;
        }
        $innerMessage = '';
        try {
            if (is_object(WCF::getLanguage())) {
                $innerMessage = WCF::getLanguage()->get('wcf.global.error.exception', true);
            }
        } catch (\Exception $e) {
        }
        if (empty($innerMessage)) {
            $innerMessage = 'Please send the ID above to the site administrator.<br />The error message can be looked up at &ldquo;ACP &raquo; Logs &raquo; Errors&rdquo;.';
        }
        // print report
        $e = $this->getPrevious() ?: $this;
        ?>
<!DOCTYPE html>
		<html>
			<head>
				<title>Fatal error: <?php 
        echo StringUtil::encodeHTML($this->_getMessage());
        ?>
</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 &quot;<?php 
            echo FileUtil::unifyDirSeparator(WCF_DIR);
            ?>
log/&quot; writable!<?php 
        } else {
            echo StringUtil::encodeHTML($this->_getMessage());
        }
        ?>
</h1>
					
					<?php 
        if (WCF::debugModeIsEnabled()) {
            ?>
						<div>
							<?php 
            if ($this->getDescription()) {
                ?>
<p><br /><?php 
                echo $this->getDescription();
                ?>
</p><?php 
            }
            ?>
							
							<h2>Information:</h2>
							<p>
								<b>id:</b> <code><?php 
            echo $this->getExceptionID();
            ?>
</code><br>
								<b>error message:</b> <?php 
            echo StringUtil::encodeHTML($this->_getMessage());
            ?>
<br>
								<b>error code:</b> <?php 
            echo intval($e->getCode());
            ?>
<br>
								<?php 
            echo $this->information;
            ?>
								<b>file:</b> <?php 
            echo StringUtil::encodeHTML($e->getFile());
            ?>
 (<?php 
            echo $e->getLine();
            ?>
)<br>
								<b>php version:</b> <?php 
            echo StringUtil::encodeHTML(phpversion());
            ?>
<br>
								<b>wcf version:</b> <?php 
            echo WCF_VERSION;
            ?>
<br>
								<b>date:</b> <?php 
            echo gmdate('r');
            ?>
<br>
								<b>request:</b> <?php 
            if (isset($_SERVER['REQUEST_URI'])) {
                echo StringUtil::encodeHTML($_SERVER['REQUEST_URI']);
            }
            ?>
<br>
								<b>referer:</b> <?php 
            if (isset($_SERVER['HTTP_REFERER'])) {
                echo StringUtil::encodeHTML($_SERVER['HTTP_REFERER']);
            }
            ?>
<br>
							</p>
							
							<h2>Stacktrace:</h2>
							<pre><?php 
            echo StringUtil::encodeHTML($this->__getTraceAsString());
            ?>
</pre>
						</div>
					<?php 
        } else {
            ?>
						<div>
							<h2>Information:</h2>
							<p>
								<?php 
            if (!$this->getExceptionID()) {
                ?>
									Unable to write log file, please make &quot;<?php 
                echo FileUtil::unifyDirSeparator(WCF_DIR);
                ?>
log/&quot; writable!
								<?php 
            } else {
                ?>
									<b>ID:</b> <code><?php 
                echo $this->getExceptionID();
                ?>
</code><br>
									<?php 
                echo $innerMessage;
                ?>
								<?php 
            }
            ?>
							</p>
						</div>
					<?php 
        }
        ?>
					
					<?php 
        echo $this->functions;
        ?>
				</div>
			</body>
		</html>
		
		<?php 
    }
Ejemplo n.º 7
0
 /**
  * Throws a JSON-encoded error message
  * 
  * @param	string		$message
  * @param	boolean		$isDoomsday
  * @param	string		$stacktrace
  * @param	array		$returnValues
  * @param	string		$exceptionID
  * @param	array<mixed>	$returnValues
  */
 public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array(), $exceptionID = '')
 {
     if ($stacktrace === null) {
         $stacktrace = $this->getTraceAsString();
     }
     $responseData = array('code' => $errorType, 'message' => $message, 'returnValues' => $returnValues);
     // include a stacktrace if:
     // - debug mode is enabled
     // - within ACP and a SystemException was thrown
     if (WCF::debugModeIsEnabled(false) || WCF::debugModeIsEnabled() && self::INTERNAL_ERROR) {
         $responseData['stacktrace'] = nl2br($stacktrace);
     }
     $statusHeader = '';
     switch ($errorType) {
         case self::MISSING_PARAMETERS:
             $statusHeader = 'HTTP/1.0 400 Bad Request';
             $responseData['exceptionID'] = $exceptionID;
             $responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.badRequest');
             break;
         case self::SESSION_EXPIRED:
             $statusHeader = 'HTTP/1.0 409 Conflict';
             break;
         case self::INSUFFICIENT_PERMISSIONS:
             $statusHeader = 'HTTP/1.0 403 Forbidden';
             break;
         case self::BAD_PARAMETERS:
             $statusHeader = 'HTTP/1.0 431 Bad Parameters';
             $responseData['exceptionID'] = $exceptionID;
             break;
         default:
         case self::INTERNAL_ERROR:
             //header('HTTP/1.0 418 I\'m a Teapot');
             header('HTTP/1.0 503 Service Unavailable');
             $responseData['code'] = self::INTERNAL_ERROR;
             $responseData['exceptionID'] = $exceptionID;
             if (!WCF::debugModeIsEnabled()) {
                 $responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.internalError');
             }
             break;
     }
     header($statusHeader);
     header('Content-type: application/json');
     echo JSON::encode($responseData);
     exit;
 }
Ejemplo n.º 8
0
 /**
  * Creates a new instance of memcached.
  */
 public function __construct()
 {
     if (!class_exists('Memcached')) {
         throw new SystemException('memcached support is not enabled.');
     }
     if (!defined('\\Memcached::OPT_REMOVE_FAILED_SERVERS')) {
         throw new SystemException('required \\Memcached::OPT_REMOVE_FAILED_SERVERS option is not available');
     }
     // init memcached
     $this->memcached = new \Memcached();
     // disable broken hosts for the remainder of the execution
     // Note: This may cause outdated entries once the affected memcached
     // server comes back online. But it is better than completely bailing out.
     // If the outage wasn't solely related to networking the cache is flushed
     // on restart of the affected memcached instance anyway.
     $this->memcached->setOption(\Memcached::OPT_REMOVE_FAILED_SERVERS, 1);
     // LIBKETAMA_COMPATIBLE uses consistent hashing, which causes fewer remaps
     // in case a server is added or removed.
     $this->memcached->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
     $this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, WCF_UUID . '_');
     if (!WCF::debugModeIsEnabled()) {
         // use the more efficient binary protocol to communicate with the memcached instance
         // this option is disabled in debug mode to allow for easier debugging
         // with tools, such as strace(1)
         $this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
     }
     // add servers
     $tmp = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHED_HOST));
     $servers = array();
     $defaultWeight = floor(100 / count($tmp));
     $regex = new Regex('^\\[([a-z0-9\\:\\.]+)\\](?::([0-9]{1,5}))?(?::([0-9]{1,3}))?$', Regex::CASE_INSENSITIVE);
     foreach ($tmp as $server) {
         $server = StringUtil::trim($server);
         if (!empty($server)) {
             $host = $server;
             $port = 11211;
             // default memcached port
             $weight = $defaultWeight;
             // check for IPv6
             if ($regex->match($host)) {
                 $matches = $regex->getMatches();
                 $host = $matches[1];
                 if (isset($matches[2])) {
                     $port = $matches[2];
                 }
                 if (isset($matches[3])) {
                     $weight = $matches[3];
                 }
             } else {
                 // IPv4, try to get port and weight
                 if (strpos($host, ':')) {
                     $parsedHost = explode(':', $host);
                     $host = $parsedHost[0];
                     $port = $parsedHost[1];
                     if (isset($parsedHost[2])) {
                         $weight = $parsedHost[2];
                     }
                 }
             }
             $servers[] = array($host, $port, $weight);
         }
     }
     $this->memcached->addServers($servers);
     // test connection, set will fail if no memcached instances are available
     // if only the target for the 'connection_testing' key is unavailable the
     // requests will automatically be mapped to another server
     if (!$this->memcached->set('connection_testing', true)) {
         throw new SystemException('Unable to obtain any valid connection');
     }
 }