Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

log exception when bad link detected #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/presenters/ErrorPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ public function renderDefault($exception)
$code = $exception->getCode();
// load template 403.latte or 404.latte or ... 4xx.latte
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx');
// log to access.log
$this->logger->log("HTTP code $code: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", 'access');

if ($code === 404 && ($referer = $this->getHttpRequest()->getHeader('referer')) !== NULL
&& preg_match(sprintf("#^https?://[\\.a-z0-9]++(?<=[/\\.]%s)#", preg_quote($this->getHttpRequest()->getUrl()->getHost())), $referer)
) {
// bad link - log exception
$this->logger->log($exception, ILogger::EXCEPTION);
} else {
// log to access.log
$this->logger->log("HTTP code $code: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", 'access');
}

} else {
$this->setView('500'); // load template 500.latte
Expand Down