/** * @see \wcf\page\IPage::readData() */ public function readData() { AbstractPage::readData(); $fileNameRegex = new Regex('(?:^|/)\\d{4}-\\d{2}-\\d{2}\\.txt$'); $this->logFiles = DirectoryUtil::getInstance(WCF_DIR . 'log/')->getFiles(SORT_DESC, $fileNameRegex); if ($this->exceptionID) { // search the appropriate file foreach ($this->logFiles as $logFile) { $contents = file_get_contents($logFile); if (mb_strpos($contents, '<<<<<<<<' . $this->exceptionID . '<<<<') !== false) { $fileNameRegex->match($logFile); $matches = $fileNameRegex->getMatches(); $this->logFile = $matches[0]; break; } unset($contents); } if (!isset($contents)) { $this->logFile = ''; return; } } else { if ($this->logFile) { if (!$fileNameRegex->match(basename($this->logFile))) { throw new IllegalLinkException(); } if (!file_exists(WCF_DIR . 'log/' . $this->logFile)) { throw new IllegalLinkException(); } $contents = file_get_contents(WCF_DIR . 'log/' . $this->logFile); } else { return; } } // unify newlines $contents = StringUtil::unifyNewlines($contents); // split contents $split = new Regex('(?:^|\\n<<<<\\n\\n)(?:<<<<<<<<([a-f0-9]{40})<<<<\\n|$)'); $contents = $split->split($contents, Regex::SPLIT_NON_EMPTY_ONLY | Regex::CAPTURE_SPLIT_DELIMITER); // even items become keys, odd items become values try { $this->exceptions = call_user_func_array('array_merge', array_map(function ($v) { return array($v[0] => $v[1]); }, array_chunk($contents, 2))); } catch (\Exception $e) { // logfile contents are pretty malformed, abort return; } if ($this->exceptionID) { $this->searchPage($this->exceptionID); } $this->calculateNumberOfPages(); $i = 0; $exceptionRegex = new Regex('(?P<date>[MTWFS][a-z]{2}, \\d{1,2} [JFMASOND][a-z]{2} \\d{4} \\d{2}:\\d{2}:\\d{2} [+-]\\d{4}) Message: (?P<message>.*?) File: (?P<file>.*?) \\((?P<line>\\d+)\\) PHP version: (?P<phpVersion>.*?) WCF version: (?P<wcfVersion>.*?) Request URI: (?P<requestURI>.*?) Referrer: (?P<referrer>.*?) User-Agent: (?P<userAgent>.*?) Information: (?P<information>.*?) Stacktrace: (?P<stacktrace>.*)', Regex::DOT_ALL); $stackTraceFormatter = new Regex('^\\s+(#\\d+)', Regex::MULTILINE); foreach ($this->exceptions as $key => $val) { $i++; if ($i < $this->startIndex || $i > $this->endIndex) { unset($this->exceptions[$key]); continue; } if (!$exceptionRegex->match($val)) { unset($this->exceptions[$key]); continue; } $this->exceptions[$key] = $exceptionRegex->getMatches(); $this->exceptions[$key]['stacktrace'] = explode("\n", $stackTraceFormatter->replace(StringUtil::encodeHTML($this->exceptions[$key]['stacktrace']), '<strong>\\1</strong>')); $this->exceptions[$key]['information'] = JSON::decode($this->exceptions[$key]['information']); } }