2013-06-14 13:51:44 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-04-02 13:23:18 +02:00
|
|
|
// namespace Icinga\Application\Controllers;
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2014-10-31 10:27:17 +01:00
|
|
|
use Icinga\Application\Logger;
|
2014-03-25 13:10:02 +01:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
|
|
|
use Icinga\Application\Icinga;
|
2013-06-14 13:51:44 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-16 14:56:23 +02:00
|
|
|
* Application wide controller for displaying exceptions
|
2013-06-14 13:51:44 +02:00
|
|
|
*/
|
|
|
|
class ErrorController extends ActionController
|
|
|
|
{
|
2014-02-14 12:12:46 +01:00
|
|
|
protected $requiresAuthentication = false;
|
|
|
|
|
2013-06-14 13:51:44 +02:00
|
|
|
/**
|
2013-08-16 14:56:23 +02:00
|
|
|
* Display exception
|
2013-06-14 13:51:44 +02:00
|
|
|
*/
|
|
|
|
public function errorAction()
|
|
|
|
{
|
2014-01-23 16:03:47 +01:00
|
|
|
$error = $this->_getParam('error_handler');
|
|
|
|
$exception = $error->exception;
|
2014-08-29 10:57:05 +02:00
|
|
|
|
|
|
|
Logger::error($exception);
|
|
|
|
Logger::error('Stacktrace: %s', $exception->getTraceAsString());
|
|
|
|
|
2014-01-22 14:57:54 +01:00
|
|
|
switch ($error->type) {
|
2013-06-14 13:51:44 +02:00
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
|
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
|
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
|
2014-03-25 13:10:02 +01:00
|
|
|
$modules = Icinga::app()->getModuleManager();
|
|
|
|
$path = ltrim($this->_request->get('PATH_INFO'), '/');
|
|
|
|
$path = preg_split('~/~', $path);
|
|
|
|
$path = array_shift($path);
|
2013-06-14 13:51:44 +02:00
|
|
|
$this->getResponse()->setHttpResponseCode(404);
|
2014-03-25 13:10:02 +01:00
|
|
|
$this->view->message = $this->translate('Page not found.');
|
|
|
|
if ($modules->hasInstalled($path) && ! $modules->hasEnabled($path)) {
|
|
|
|
$this->view->message .= ' ' . sprintf(
|
|
|
|
$this->translate('Enabling the "%s" module might help!'),
|
|
|
|
$path
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:51:44 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-05-20 15:40:52 +02:00
|
|
|
$title = preg_replace('/\r?\n.*$/s', '', $exception->getMessage());
|
2013-06-14 13:51:44 +02:00
|
|
|
$this->getResponse()->setHttpResponseCode(500);
|
2014-05-20 15:40:52 +02:00
|
|
|
$this->view->title = 'Server error: ' . $title;
|
2014-01-23 16:03:47 +01:00
|
|
|
$this->view->message = $exception->getMessage();
|
2014-03-25 13:10:02 +01:00
|
|
|
if ($this->getInvokeArg('displayExceptions') == true) {
|
|
|
|
$this->view->stackTrace = $exception->getTraceAsString();
|
|
|
|
}
|
2013-06-14 13:51:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-01-22 14:57:54 +01:00
|
|
|
$this->view->request = $error->request;
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
|
|
|
}
|