2013-06-03 17:02:08 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-08-16 15:05:03 +02:00
|
|
|
|
2013-08-12 15:58:26 +02:00
|
|
|
namespace Icinga\Web\Controller;
|
2013-06-03 17:02:08 +02:00
|
|
|
|
2014-02-18 19:42:06 +01:00
|
|
|
use Exception;
|
2014-01-23 16:03:47 +01:00
|
|
|
use Icinga\Application\Benchmark;
|
2014-02-18 19:42:06 +01:00
|
|
|
use Icinga\Application\Config;
|
2015-01-30 09:34:19 +01:00
|
|
|
use Icinga\Authentication\Manager;
|
2014-08-27 16:03:15 +02:00
|
|
|
use Icinga\Exception\IcingaException;
|
2015-01-30 09:34:19 +01:00
|
|
|
use Icinga\Exception\ProgrammingError;
|
|
|
|
use Icinga\File\Pdf;
|
|
|
|
use Icinga\Security\SecurityException;
|
2014-01-29 16:25:08 +01:00
|
|
|
use Icinga\Util\Translator;
|
2014-03-08 00:15:51 +01:00
|
|
|
use Icinga\Web\Notification;
|
2014-03-25 10:31:52 +01:00
|
|
|
use Icinga\Web\Session;
|
2015-01-30 09:34:19 +01:00
|
|
|
use Icinga\Web\Url;
|
2014-06-17 14:58:04 +02:00
|
|
|
use Icinga\Web\UrlParams;
|
2015-01-30 09:34:19 +01:00
|
|
|
use Icinga\Web\Widget\Tabs;
|
|
|
|
use Icinga\Web\Window;
|
2014-06-22 13:49:21 +02:00
|
|
|
use Zend_Controller_Action;
|
|
|
|
use Zend_Controller_Action_HelperBroker as ActionHelperBroker;
|
|
|
|
use Zend_Controller_Request_Abstract as Request;
|
|
|
|
use Zend_Controller_Response_Abstract as Response;
|
2014-01-29 18:09:26 +01:00
|
|
|
|
2013-06-03 17:02:08 +02:00
|
|
|
/**
|
|
|
|
* Base class for all core action controllers
|
|
|
|
*
|
|
|
|
* All Icinga Web core controllers should extend this class
|
|
|
|
*/
|
2013-08-30 15:50:49 +02:00
|
|
|
class ActionController extends Zend_Controller_Action
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
2013-08-08 16:22:22 +02:00
|
|
|
/**
|
2013-09-02 18:33:19 +02:00
|
|
|
* Whether the controller requires the user to be authenticated
|
2013-08-16 15:05:03 +02:00
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-08-30 15:50:49 +02:00
|
|
|
protected $requiresAuthentication = true;
|
2013-08-08 16:22:22 +02:00
|
|
|
|
2014-03-04 12:37:54 +01:00
|
|
|
private $autorefreshInterval;
|
|
|
|
|
2014-03-26 08:58:00 +01:00
|
|
|
private $reloadCss = false;
|
|
|
|
|
2014-06-22 13:09:48 +02:00
|
|
|
private $window;
|
2014-03-21 14:27:44 +01:00
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
private $rerenderLayout = false;
|
2014-05-26 16:41:47 +02:00
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
private $xhrLayout = 'inline';
|
2014-06-17 14:58:04 +02:00
|
|
|
|
2015-01-23 09:36:05 +01:00
|
|
|
/**
|
|
|
|
* Authentication manager
|
|
|
|
*
|
2015-01-30 09:34:19 +01:00
|
|
|
* @type Manager|null
|
2015-01-23 09:36:05 +01:00
|
|
|
*/
|
2014-06-22 12:06:09 +02:00
|
|
|
private $auth;
|
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
protected $params;
|
|
|
|
|
2013-06-03 17:02:08 +02:00
|
|
|
/**
|
|
|
|
* The constructor starts benchmarking, loads the configuration and sets
|
|
|
|
* other useful controller properties
|
|
|
|
*
|
2014-06-22 13:49:21 +02:00
|
|
|
* @param Request $request
|
|
|
|
* @param Response $response
|
|
|
|
* @param array $invokeArgs Any additional invocation arguments
|
2013-06-03 17:02:08 +02:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2014-06-22 13:49:21 +02:00
|
|
|
Request $request,
|
|
|
|
Response $response,
|
2013-06-03 17:02:08 +02:00
|
|
|
array $invokeArgs = array()
|
|
|
|
) {
|
2014-06-17 14:58:04 +02:00
|
|
|
$this->params = UrlParams::fromQueryString();
|
|
|
|
|
2013-08-30 15:50:49 +02:00
|
|
|
$this->setRequest($request)
|
|
|
|
->setResponse($response)
|
|
|
|
->_setInvokeArgs($invokeArgs);
|
2014-06-22 13:49:21 +02:00
|
|
|
$this->_helper = new ActionHelperBroker($this);
|
2014-03-21 14:27:44 +01:00
|
|
|
|
2014-06-22 13:49:21 +02:00
|
|
|
$this->handlerBrowserWindows();
|
|
|
|
$this->view->translationDomain = 'icinga';
|
2014-11-23 20:07:30 +01:00
|
|
|
$this->_helper->layout()->isIframe = $request->getUrl()->shift('isIframe');
|
2014-07-04 12:33:49 +02:00
|
|
|
$this->_helper->layout()->moduleName = false;
|
|
|
|
|
2014-11-23 20:07:30 +01:00
|
|
|
if ($this->rerenderLayout = $request->getUrl()->shift('renderLayout')) {
|
2014-06-22 20:06:45 +02:00
|
|
|
$this->xhrLayout = 'body';
|
|
|
|
}
|
2014-06-22 13:52:40 +02:00
|
|
|
|
|
|
|
if ($this->requiresLogin()) {
|
|
|
|
$this->redirectToLogin(Url::fromRequest());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->tabs = new Tabs();
|
2014-09-16 09:28:10 +02:00
|
|
|
$this->prepareInit();
|
2014-06-22 13:52:40 +02:00
|
|
|
$this->init();
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:28:10 +02:00
|
|
|
/**
|
|
|
|
* Prepare controller initialization
|
|
|
|
*
|
|
|
|
* As it should not be required for controllers to call the parent's init() method, base controllers should use
|
|
|
|
* prepareInit() in order to prepare the controller initialization.
|
|
|
|
*
|
2014-09-16 18:43:14 +02:00
|
|
|
* @see \Zend_Controller_Action::init() For the controller initialization method.
|
2014-09-16 09:28:10 +02:00
|
|
|
*/
|
|
|
|
protected function prepareInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-23 09:36:05 +01:00
|
|
|
/**
|
|
|
|
* Get the authentication manager
|
|
|
|
*
|
|
|
|
* @return Manager
|
|
|
|
*/
|
|
|
|
public function Auth()
|
|
|
|
{
|
|
|
|
if ($this->auth === null) {
|
|
|
|
$this->auth = Manager::getInstance();
|
|
|
|
}
|
|
|
|
return $this->auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the current user has the given permission
|
|
|
|
*
|
|
|
|
* @param string $permission Name of the permission
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasPermission($permission)
|
|
|
|
{
|
|
|
|
return $this->Auth()->hasPermission($permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-30 09:34:19 +01:00
|
|
|
* Assert that the current user has the given permission
|
|
|
|
*
|
|
|
|
* @param string $permission Name of the permission
|
2015-01-23 09:36:05 +01:00
|
|
|
*
|
2015-01-30 09:34:19 +01:00
|
|
|
* @throws SecurityException If the current user lacks the given permission
|
2015-01-23 09:36:05 +01:00
|
|
|
*/
|
2015-01-30 09:34:19 +01:00
|
|
|
public function assertPermission($permission)
|
2015-01-23 09:36:05 +01:00
|
|
|
{
|
2015-01-30 09:34:19 +01:00
|
|
|
if (! $this->Auth()->hasPermission($permission)) {
|
|
|
|
throw new SecurityException('No permission for %s', $permission);
|
2015-01-23 09:36:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 12:07:50 +02:00
|
|
|
public function Config($file = null)
|
|
|
|
{
|
|
|
|
if ($file === null) {
|
2014-09-19 14:44:21 +02:00
|
|
|
return Config::app();
|
2014-06-22 12:07:50 +02:00
|
|
|
} else {
|
2014-09-19 14:44:21 +02:00
|
|
|
return Config::app($file);
|
2014-06-22 12:07:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 13:09:48 +02:00
|
|
|
public function Window()
|
|
|
|
{
|
|
|
|
if ($this->window === null) {
|
|
|
|
$this->window = new Window(
|
|
|
|
$this->_request->getHeader('X-Icinga-WindowId', Window::UNDEFINED)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->window;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function handlerBrowserWindows()
|
2014-03-21 14:27:44 +01:00
|
|
|
{
|
2014-06-22 15:36:41 +02:00
|
|
|
if ($this->isXhr()) {
|
2014-06-22 13:09:48 +02:00
|
|
|
$id = $this->_request->getHeader('X-Icinga-WindowId', null);
|
|
|
|
|
|
|
|
if ($id === Window::UNDEFINED) {
|
|
|
|
$this->window = new Window($id);
|
2014-06-22 12:55:44 +02:00
|
|
|
$this->_response->setHeader('X-Icinga-WindowId', Window::generateId());
|
|
|
|
}
|
2014-03-21 14:27:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:58:00 +01:00
|
|
|
protected function reloadCss()
|
|
|
|
{
|
|
|
|
$this->reloadCss = true;
|
2014-06-22 20:06:45 +02:00
|
|
|
return $this;
|
2014-03-26 08:58:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 15:47:16 +01:00
|
|
|
/**
|
|
|
|
* Respond with HTTP 405 if the current request's method is not one of the given methods
|
|
|
|
*
|
|
|
|
* @param string $httpMethod Unlimited number of allowed HTTP methods
|
|
|
|
*
|
|
|
|
* @throws \Zend_Controller_Action_Exception If the request method is not one of the given methods
|
|
|
|
*/
|
|
|
|
public function assertHttpMethod($httpMethod)
|
|
|
|
{
|
|
|
|
$httpMethods = array_flip(array_map('strtoupper', func_get_args()));
|
|
|
|
if (! isset($httpMethods[$this->getRequest()->getMethod()])) {
|
|
|
|
$this->getResponse()->setHeader('Allow', implode(', ', array_keys($httpMethods)));
|
|
|
|
throw new \Zend_Controller_Action_Exception($this->translate('Method Not Allowed'), 405);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-22 14:06:59 +01:00
|
|
|
/**
|
|
|
|
* Return restriction information for an eventually authenticated user
|
|
|
|
*
|
|
|
|
* @param string $name Permission name
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public function getRestrictions($name)
|
|
|
|
{
|
2014-06-22 12:06:09 +02:00
|
|
|
return $this->Auth()->getRestrictions($name);
|
2014-01-22 14:06:59 +01:00
|
|
|
}
|
|
|
|
|
2013-09-02 18:33:19 +02:00
|
|
|
/**
|
|
|
|
* Check whether the controller requires a login. That is when the controller requires authentication and the
|
|
|
|
* user is currently not authenticated
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @see requiresAuthentication
|
|
|
|
*/
|
|
|
|
protected function requiresLogin()
|
2013-08-30 15:50:49 +02:00
|
|
|
{
|
|
|
|
if (!$this->requiresAuthentication) {
|
2013-09-02 18:33:19 +02:00
|
|
|
return false;
|
2013-08-30 15:50:49 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 12:06:09 +02:00
|
|
|
return !$this->Auth()->isAuthenticated();
|
2013-08-30 15:50:49 +02:00
|
|
|
}
|
2013-09-02 18:33:19 +02:00
|
|
|
|
2013-06-03 17:02:08 +02:00
|
|
|
/**
|
2013-08-16 15:05:03 +02:00
|
|
|
* Return the tabs
|
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @return Tabs
|
2013-08-16 15:05:03 +02:00
|
|
|
*/
|
2013-08-08 16:22:22 +02:00
|
|
|
public function getTabs()
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
2013-08-08 16:22:22 +02:00
|
|
|
return $this->view->tabs;
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-29 16:25:08 +01:00
|
|
|
* Translate a string
|
2013-06-03 17:02:08 +02:00
|
|
|
*
|
2014-01-29 16:25:08 +01:00
|
|
|
* Autoselects the module domain, if any, and falls back to the global one if no translation could be found.
|
2013-06-03 17:02:08 +02:00
|
|
|
*
|
2014-09-16 15:19:23 +02:00
|
|
|
* @param string $text The string to translate
|
|
|
|
* @param string|null $context Optional parameter for context based translation
|
2014-01-29 16:25:08 +01:00
|
|
|
*
|
2014-09-16 15:19:23 +02:00
|
|
|
* @return string The translated string
|
2013-06-03 17:02:08 +02:00
|
|
|
*/
|
2014-09-16 15:19:23 +02:00
|
|
|
public function translate($text, $context = null)
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
2014-09-16 15:19:23 +02:00
|
|
|
return Translator::translate($text, $this->view->translationDomain, $context);
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
2014-09-11 18:04:10 +02:00
|
|
|
/**
|
|
|
|
* Translate a plural string
|
|
|
|
*
|
2014-09-16 15:19:23 +02:00
|
|
|
* @param string $textSingular The string in singular form to translate
|
|
|
|
* @param string $textPlural The string in plural form to translate
|
|
|
|
* @param string $number The number to get the plural or singular string
|
|
|
|
* @param string|null $context Optional parameter for context based translation
|
2014-09-11 18:04:10 +02:00
|
|
|
*
|
2014-09-16 15:19:23 +02:00
|
|
|
* @return string The translated string
|
2014-09-11 18:04:10 +02:00
|
|
|
*/
|
2014-09-16 15:19:23 +02:00
|
|
|
public function translatePlural($textSingular, $textPlural, $number, $context = null)
|
2014-09-11 18:04:10 +02:00
|
|
|
{
|
2014-09-16 15:19:23 +02:00
|
|
|
return Translator::translatePlural($textSingular, $textPlural, $number, $this->view->translationDomain, $context);
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-08 12:07:03 +01:00
|
|
|
protected function ignoreXhrBody()
|
|
|
|
{
|
2014-06-22 15:36:41 +02:00
|
|
|
if ($this->isXhr()) {
|
2014-06-22 15:33:38 +02:00
|
|
|
$this->getResponse()->setHeader('X-Icinga-Container', 'ignore');
|
|
|
|
}
|
2014-03-08 12:07:03 +01:00
|
|
|
}
|
|
|
|
|
2014-03-04 12:37:54 +01:00
|
|
|
public function setAutorefreshInterval($interval)
|
|
|
|
{
|
|
|
|
if (! is_int($interval) || $interval < 1) {
|
|
|
|
throw new ProgrammingError(
|
|
|
|
'Setting autorefresh interval smaller than 1 second is not allowed'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$this->autorefreshInterval = $interval;
|
2014-06-21 01:54:32 +02:00
|
|
|
$this->_helper->layout()->autorefreshInterval = $interval;
|
2014-06-20 13:17:11 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function disableAutoRefresh()
|
|
|
|
{
|
|
|
|
$this->autorefreshInterval = null;
|
2014-06-21 01:54:32 +02:00
|
|
|
$this->_helper->layout()->autorefreshInterval = null;
|
2014-06-20 13:17:11 +02:00
|
|
|
return $this;
|
2014-03-04 12:37:54 +01:00
|
|
|
}
|
|
|
|
|
2013-06-03 17:02:08 +02:00
|
|
|
/**
|
2013-08-30 15:50:49 +02:00
|
|
|
* Redirect to the login path
|
2013-10-04 12:54:42 +02:00
|
|
|
*
|
2014-12-29 16:27:28 +01:00
|
|
|
* @param Url $afterLogin The action to call when the login was successful. Defaults to '/index/welcome'
|
2013-10-04 12:54:42 +02:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
2013-06-03 17:02:08 +02:00
|
|
|
*/
|
2014-08-19 12:28:24 +02:00
|
|
|
protected function redirectToLogin($afterLogin = null)
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
2014-08-19 12:28:24 +02:00
|
|
|
$redir = null;
|
|
|
|
if ($afterLogin !== null) {
|
|
|
|
if (! $afterLogin instanceof Url) {
|
|
|
|
$afterLogin = Url::fromPath($afterLogin);
|
|
|
|
}
|
|
|
|
if ($this->isXhr()) {
|
|
|
|
$redir = '__SELF__';
|
|
|
|
} else {
|
|
|
|
// TODO: Ignore /?
|
|
|
|
$redir = $afterLogin->getRelativeUrl();
|
|
|
|
}
|
2014-08-19 09:54:24 +02:00
|
|
|
}
|
2014-08-19 12:28:24 +02:00
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
$url = Url::fromPath('authentication/login');
|
2014-08-19 12:28:24 +02:00
|
|
|
|
2014-08-19 09:54:24 +02:00
|
|
|
if ($redir) {
|
|
|
|
$url->setParam('redirect', $redir);
|
|
|
|
}
|
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
$this->rerenderLayout()->redirectNow($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function rerenderLayout()
|
|
|
|
{
|
|
|
|
$this->rerenderLayout = true;
|
|
|
|
$this->xhrLayout = 'layout';
|
|
|
|
return $this;
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 15:36:41 +02:00
|
|
|
public function isXhr()
|
|
|
|
{
|
|
|
|
return $this->getRequest()->isXmlHttpRequest();
|
|
|
|
}
|
|
|
|
|
2014-08-19 09:54:24 +02:00
|
|
|
protected function redirectXhr($url)
|
|
|
|
{
|
|
|
|
if (! $url instanceof Url) {
|
|
|
|
$url = Url::fromPath($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->rerenderLayout) {
|
|
|
|
$this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes');
|
|
|
|
}
|
|
|
|
if ($this->reloadCss) {
|
|
|
|
$this->getResponse()->setHeader('X-Icinga-Reload-Css', 'now');
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:42:56 +02:00
|
|
|
$this->shutdownSession();
|
|
|
|
|
2014-08-19 09:54:24 +02:00
|
|
|
$this->getResponse()
|
|
|
|
->setHeader('X-Icinga-Redirect', rawurlencode($url->getAbsoluteUrl()))
|
|
|
|
->sendHeaders();
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:42:56 +02:00
|
|
|
protected function redirectHttp($url)
|
|
|
|
{
|
|
|
|
if (! $url instanceof Url) {
|
|
|
|
$url = Url::fromPath($url);
|
|
|
|
}
|
|
|
|
$this->shutdownSession();
|
|
|
|
$this->_helper->Redirector->gotoUrlAndExit($url->getRelativeUrl());
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:22:22 +02:00
|
|
|
/**
|
|
|
|
* Redirect to a specific url, updating the browsers URL field
|
2013-08-16 15:05:03 +02:00
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @param Url|string $url The target to redirect to
|
2013-08-08 16:22:22 +02:00
|
|
|
**/
|
|
|
|
public function redirectNow($url)
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
2014-06-22 15:36:41 +02:00
|
|
|
if ($this->isXhr()) {
|
2014-08-19 09:54:24 +02:00
|
|
|
$this->redirectXhr($url);
|
2013-08-21 09:37:16 +02:00
|
|
|
} else {
|
2014-09-17 10:42:56 +02:00
|
|
|
$this->redirectHttp($url);
|
2013-07-12 11:58:58 +02:00
|
|
|
}
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-08 16:22:22 +02:00
|
|
|
* Detect whether the current request requires changes in the layout and apply them before rendering
|
2013-06-03 17:02:08 +02:00
|
|
|
*
|
2014-03-25 08:52:48 +01:00
|
|
|
* @see Zend_Controller_Action::postDispatch()
|
2013-06-03 17:02:08 +02:00
|
|
|
*/
|
2014-03-25 08:52:48 +01:00
|
|
|
public function postDispatch()
|
2013-06-03 17:02:08 +02:00
|
|
|
{
|
|
|
|
Benchmark::measure('Action::postDispatch()');
|
2013-06-07 13:29:11 +02:00
|
|
|
|
2014-06-22 15:08:20 +02:00
|
|
|
$req = $this->getRequest();
|
2014-03-17 17:11:08 +01:00
|
|
|
$layout = $this->_helper->layout();
|
2014-03-06 12:13:07 +01:00
|
|
|
|
2014-06-22 15:08:20 +02:00
|
|
|
if ($user = $req->getUser()) {
|
2014-06-02 13:33:55 +02:00
|
|
|
// Cast preference app.show_benchmark to bool because preferences loaded from a preferences storage are
|
2014-03-06 12:15:28 +01:00
|
|
|
// always strings
|
2014-09-26 14:15:50 +02:00
|
|
|
if ((bool) $user->getPreferences()->getValue('icingaweb', 'show_benchmark', false) === true) {
|
2014-09-02 16:49:28 +02:00
|
|
|
if (!$this->_helper->viewRenderer->getNoRender()) {
|
|
|
|
$layout->benchmark = $this->renderBenchmark();
|
|
|
|
}
|
2014-03-06 12:15:28 +01:00
|
|
|
}
|
2015-02-12 15:12:10 +01:00
|
|
|
|
|
|
|
if ((bool) $user->getPreferences()->getValue('icingaweb', 'auto_refresh', true) === false) {
|
|
|
|
$this->disableAutoRefresh();
|
|
|
|
}
|
2014-03-06 12:15:28 +01:00
|
|
|
}
|
|
|
|
|
2014-06-22 15:08:20 +02:00
|
|
|
if ($req->getParam('format') === 'pdf') {
|
2014-10-15 13:15:30 +02:00
|
|
|
$this->shutdownSession();
|
2014-03-06 12:15:28 +01:00
|
|
|
$this->sendAsPdf();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2014-06-22 15:36:41 +02:00
|
|
|
if ($this->isXhr()) {
|
2014-06-22 15:15:32 +02:00
|
|
|
$this->postDispatchXhr();
|
|
|
|
}
|
2014-10-15 13:15:30 +02:00
|
|
|
|
|
|
|
$this->shutdownSession();
|
2014-06-22 15:15:32 +02:00
|
|
|
}
|
2014-03-08 00:15:51 +01:00
|
|
|
|
2014-06-22 15:15:32 +02:00
|
|
|
protected function postDispatchXhr()
|
|
|
|
{
|
|
|
|
$layout = $this->_helper->layout();
|
2014-06-22 20:06:45 +02:00
|
|
|
$layout->setLayout($this->xhrLayout);
|
2014-06-22 15:15:32 +02:00
|
|
|
$resp = $this->getResponse();
|
2014-03-26 08:58:00 +01:00
|
|
|
|
2014-06-22 15:15:32 +02:00
|
|
|
$notifications = Notification::getInstance();
|
|
|
|
if ($notifications->hasMessages()) {
|
|
|
|
$notificationList = array();
|
|
|
|
foreach ($notifications->getMessages() as $m) {
|
|
|
|
$notificationList[] = rawurlencode($m->type . ' ' . $m->message);
|
2014-06-22 15:08:20 +02:00
|
|
|
}
|
2014-06-22 20:06:45 +02:00
|
|
|
$resp->setHeader('X-Icinga-Notification', implode('&', $notificationList));
|
2014-06-22 15:15:32 +02:00
|
|
|
}
|
2014-03-08 12:07:03 +01:00
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
if ($this->reloadCss) {
|
2014-06-22 15:15:32 +02:00
|
|
|
$resp->setHeader('X-Icinga-CssReload', 'now');
|
|
|
|
}
|
2014-06-22 15:08:20 +02:00
|
|
|
|
2014-06-22 15:15:32 +02:00
|
|
|
if ($this->view->title) {
|
|
|
|
if (preg_match('~[\r\n]~', $this->view->title)) {
|
|
|
|
// TODO: Innocent exception and error log for hack attempts
|
2014-08-27 16:03:15 +02:00
|
|
|
throw new IcingaException('No way, guy');
|
2014-03-04 12:37:54 +01:00
|
|
|
}
|
2014-06-22 15:15:32 +02:00
|
|
|
$resp->setHeader(
|
|
|
|
'X-Icinga-Title',
|
|
|
|
rawurlencode($this->view->title . ' :: Icinga Web')
|
|
|
|
);
|
2014-07-31 17:04:26 +02:00
|
|
|
} else {
|
|
|
|
$resp->setHeader('X-Icinga-Title', rawurlencode('Icinga Web'));
|
2014-06-22 15:15:32 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 20:06:45 +02:00
|
|
|
if ($this->rerenderLayout) {
|
|
|
|
$this->getResponse()->setHeader('X-Icinga-Container', 'layout');
|
2014-06-22 15:15:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->autorefreshInterval !== null) {
|
2014-11-18 10:48:33 +01:00
|
|
|
$resp->setHeader('X-Icinga-Refresh', $this->autorefreshInterval);
|
2014-03-04 12:37:54 +01:00
|
|
|
}
|
2014-03-06 12:13:07 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 12:14:21 +01:00
|
|
|
protected function sendAsPdf()
|
2014-01-29 18:09:26 +01:00
|
|
|
{
|
2014-03-06 12:21:11 +01:00
|
|
|
$pdf = new Pdf();
|
|
|
|
$pdf->renderControllerAction($this);
|
2014-01-24 12:20:13 +01:00
|
|
|
}
|
|
|
|
|
2014-09-17 10:42:56 +02:00
|
|
|
protected function shutdownSession()
|
|
|
|
{
|
|
|
|
$session = Session::getSession();
|
|
|
|
if ($session->hasChanged()) {
|
|
|
|
$session->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 12:20:13 +01:00
|
|
|
/**
|
|
|
|
* Render the benchmark
|
|
|
|
*
|
|
|
|
* @return string Benchmark HTML
|
|
|
|
*/
|
|
|
|
protected function renderBenchmark()
|
|
|
|
{
|
2014-06-25 20:34:33 +02:00
|
|
|
$this->render();
|
|
|
|
Benchmark::measure('Response ready');
|
2014-01-24 12:20:13 +01:00
|
|
|
return Benchmark::renderToHtml();
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|
2013-08-27 17:49:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to call compatible methods from older zend versions
|
|
|
|
*
|
|
|
|
* Methods like getParam and redirect are _getParam/_redirect in older Zend versions (which reside for example
|
|
|
|
* in Debian Wheezy). Using those methods without the "_" causes the application to fail on those platforms, but
|
|
|
|
* using the version with "_" forces us to use deprecated code. So we try to catch this issue by looking for methods
|
|
|
|
* with the same name, but with a "_" prefix prepended.
|
|
|
|
*
|
2013-09-24 12:48:30 +02:00
|
|
|
* @param string $name The method name to check
|
|
|
|
* @param mixed $params The method parameters
|
|
|
|
* @return mixed Anything the method returns
|
2013-08-27 17:49:25 +02:00
|
|
|
*/
|
|
|
|
public function __call($name, $params)
|
|
|
|
{
|
2013-09-24 12:48:30 +02:00
|
|
|
$deprecatedMethod = '_' . $name;
|
2013-08-27 17:49:25 +02:00
|
|
|
|
|
|
|
if (method_exists($this, $deprecatedMethod)) {
|
|
|
|
return call_user_func_array(array($this, $deprecatedMethod), $params);
|
|
|
|
}
|
2013-09-24 12:48:30 +02:00
|
|
|
|
2014-01-24 16:41:37 +01:00
|
|
|
return parent::__call($name, $params);
|
2013-08-27 17:49:25 +02:00
|
|
|
}
|
2013-06-03 17:02:08 +02:00
|
|
|
}
|