2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2013-06-14 13:51:44 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
namespace Icinga\Application;
|
|
|
|
|
2014-03-31 18:35:28 +02:00
|
|
|
require_once __DIR__ . '/ApplicationBootstrap.php';
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Authentication\Manager as AuthenticationManager;
|
2014-11-12 12:16:05 +01:00
|
|
|
use Icinga\Authentication\Manager;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
2014-02-20 13:53:28 +01:00
|
|
|
use Icinga\Exception\NotReadableError;
|
2014-10-31 10:27:17 +01:00
|
|
|
use Icinga\Application\Logger;
|
2014-09-05 15:03:45 +02:00
|
|
|
use Icinga\Util\TimezoneDetect;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Web\Request;
|
2014-06-22 13:49:21 +02:00
|
|
|
use Icinga\Web\Response;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Web\View;
|
2014-03-25 11:12:55 +01:00
|
|
|
use Icinga\Web\Session\Session as BaseSession;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Web\Session;
|
2014-03-31 18:35:28 +02:00
|
|
|
use Icinga\User;
|
2014-01-29 16:25:08 +01:00
|
|
|
use Icinga\Util\Translator;
|
2014-03-31 18:35:28 +02:00
|
|
|
use Icinga\Util\DateTimeFactory;
|
|
|
|
use DateTimeZone;
|
|
|
|
use Exception;
|
|
|
|
use Zend_Layout;
|
|
|
|
use Zend_Paginator;
|
|
|
|
use Zend_View_Helper_PaginationControl;
|
2014-06-22 13:49:21 +02:00
|
|
|
use Zend_Controller_Action_HelperBroker as ActionHelperBroker;
|
2014-03-31 18:35:28 +02:00
|
|
|
use Zend_Controller_Router_Route;
|
|
|
|
use Zend_Controller_Front;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-22 16:29:54 +02:00
|
|
|
* Use this if you want to make use of Icinga functionality in other web projects
|
2013-06-07 11:44:37 +02:00
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
* <code>
|
|
|
|
* use Icinga\Application\EmbeddedWeb;
|
|
|
|
* EmbeddedWeb::start();
|
|
|
|
* </code>
|
|
|
|
*/
|
|
|
|
class Web extends ApplicationBootstrap
|
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* View object
|
|
|
|
*
|
|
|
|
* @var View
|
|
|
|
*/
|
|
|
|
private $viewRenderer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Zend front controller instance
|
|
|
|
*
|
|
|
|
* @var Zend_Controller_Front
|
|
|
|
*/
|
|
|
|
private $frontController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request object
|
|
|
|
*
|
|
|
|
* @var Request
|
|
|
|
*/
|
|
|
|
private $request;
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
|
|
|
* Session object
|
|
|
|
*
|
|
|
|
* @var BaseSession
|
|
|
|
*/
|
|
|
|
private $session;
|
|
|
|
|
2013-08-22 16:29:54 +02:00
|
|
|
/**
|
|
|
|
* User object
|
|
|
|
*
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
private $user;
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Identify web bootstrap
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
protected $isWeb = true;
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Initialize all together
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
protected function bootstrap()
|
|
|
|
{
|
2014-02-12 14:51:04 +01:00
|
|
|
return $this
|
2014-11-14 14:07:13 +01:00
|
|
|
->setupZendAutoloader()
|
2014-03-03 19:03:39 +01:00
|
|
|
->setupLogging()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupErrorHandling()
|
2014-02-12 14:51:04 +01:00
|
|
|
->loadConfig()
|
2013-09-24 15:26:10 +02:00
|
|
|
->setupResourceFactory()
|
2014-01-23 12:09:48 +01:00
|
|
|
->setupSession()
|
2013-08-22 16:29:54 +02:00
|
|
|
->setupUser()
|
2013-08-28 13:34:49 +02:00
|
|
|
->setupTimezone()
|
2014-02-14 10:48:17 +01:00
|
|
|
->setupLogger()
|
2014-02-12 14:51:04 +01:00
|
|
|
->setupInternationalization()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupRequest()
|
|
|
|
->setupZendMvc()
|
2014-06-22 13:49:21 +02:00
|
|
|
->setupFormNamespace()
|
2014-01-22 18:11:26 +01:00
|
|
|
->setupModuleManager()
|
2014-11-10 17:34:49 +01:00
|
|
|
->loadCoreModules()
|
2014-01-22 18:11:26 +01:00
|
|
|
->loadEnabledModules()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupRoute()
|
|
|
|
->setupPagination();
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Prepare routing
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupRoute()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-21 11:36:12 +02:00
|
|
|
$this->frontController->getRouter()->addRoute(
|
|
|
|
'module_javascript',
|
2013-07-26 15:58:16 +02:00
|
|
|
new Zend_Controller_Router_Route(
|
2013-09-03 18:43:17 +02:00
|
|
|
'js/components/:module_name/:file',
|
2013-06-21 11:36:12 +02:00
|
|
|
array(
|
|
|
|
'controller' => 'static',
|
2013-07-26 15:58:16 +02:00
|
|
|
'action' => 'javascript'
|
2013-06-21 11:36:12 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for frontController
|
|
|
|
*
|
|
|
|
* @return Zend_Controller_Front
|
|
|
|
*/
|
|
|
|
public function getFrontController()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
return $this->frontController;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Getter for view
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function getViewRenderer()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
return $this->viewRenderer;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Dispatch public interface
|
|
|
|
*/
|
|
|
|
public function dispatch()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-06-22 14:13:00 +02:00
|
|
|
$this->frontController->dispatch($this->request, new Response());
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare Zend MVC Base
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
private function setupZendMvc()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
// TODO: Replace Zend_Application:
|
2013-07-26 15:58:16 +02:00
|
|
|
Zend_Layout::startMvc(
|
2013-06-07 11:44:37 +02:00
|
|
|
array(
|
2013-07-26 15:58:16 +02:00
|
|
|
'layout' => 'layout',
|
|
|
|
'layoutPath' => $this->getApplicationDir('/layouts/scripts')
|
2013-06-07 11:44:37 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
$this->setupFrontController();
|
|
|
|
$this->setupViewRenderer();
|
|
|
|
|
|
|
|
return $this;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-08-02 14:58:36 +02:00
|
|
|
/**
|
2014-06-03 14:14:30 +02:00
|
|
|
* Create user object
|
2013-08-02 14:58:36 +02:00
|
|
|
*
|
2013-08-22 16:29:54 +02:00
|
|
|
* @return self
|
2013-08-02 14:58:36 +02:00
|
|
|
*/
|
2013-07-30 16:02:05 +02:00
|
|
|
private function setupUser()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-06-03 14:14:30 +02:00
|
|
|
$authenticationManager = AuthenticationManager::getInstance();
|
|
|
|
|
|
|
|
if ($authenticationManager->isAuthenticated() === true) {
|
|
|
|
$this->user = $authenticationManager->getUser();
|
2014-02-26 17:36:20 +01:00
|
|
|
}
|
2014-06-03 14:14:30 +02:00
|
|
|
|
2013-08-22 16:29:54 +02:00
|
|
|
return $this;
|
2013-07-30 16:02:05 +02:00
|
|
|
}
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
|
|
|
* Initialize a session provider
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupSession()
|
|
|
|
{
|
|
|
|
$this->session = Session::create();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-30 16:02:05 +02:00
|
|
|
/**
|
|
|
|
* Inject dependencies into request
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupRequest()
|
|
|
|
{
|
|
|
|
$this->request = new Request();
|
|
|
|
|
2013-08-22 16:29:54 +02:00
|
|
|
if ($this->user instanceof User) {
|
|
|
|
$this->request->setUser($this->user);
|
2013-07-26 15:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate front controller
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupFrontController()
|
|
|
|
{
|
|
|
|
$this->frontController = Zend_Controller_Front::getInstance();
|
|
|
|
|
|
|
|
$this->frontController->setRequest($this->request);
|
|
|
|
|
|
|
|
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
|
2013-06-14 13:51:44 +02:00
|
|
|
|
|
|
|
$this->frontController->setParams(
|
|
|
|
array(
|
|
|
|
'displayExceptions' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Register helper paths and views for renderer
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupViewRenderer()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/** @var \Zend_Controller_Action_Helper_ViewRenderer $view */
|
2014-06-22 13:49:21 +02:00
|
|
|
$view = ActionHelperBroker::getStaticHelper('viewRenderer');
|
2013-07-26 15:58:16 +02:00
|
|
|
$view->setView(new View());
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
$view->view->addHelperPath($this->getApplicationDir('/views/helpers'));
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
$view->view->setEncoding('UTF-8');
|
2014-11-18 13:11:52 +01:00
|
|
|
$view->view->headTitle()->prepend($this->config->get('global', 'project', 'Icinga'));
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
$view->view->headTitle()->setSeparator(' :: ');
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
$this->viewRenderer = $view;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure pagination settings
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-06-07 11:44:37 +02:00
|
|
|
* @return self
|
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
private function setupPagination()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-21 11:36:12 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
Zend_Paginator::addScrollingStylePrefixPath(
|
2013-06-07 11:44:37 +02:00
|
|
|
'Icinga_Web_Paginator_ScrollingStyle',
|
|
|
|
'Icinga/Web/Paginator/ScrollingStyle'
|
|
|
|
);
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
Zend_Paginator::setDefaultScrollingStyle('SlidingWithBorder');
|
|
|
|
Zend_View_Helper_PaginationControl::setDefaultViewPartial(
|
2013-06-14 13:51:44 +02:00
|
|
|
array('mixedPagination.phtml', 'default')
|
2013-06-07 11:44:37 +02:00
|
|
|
);
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2013-08-28 13:34:49 +02:00
|
|
|
|
|
|
|
/**
|
2014-11-13 17:07:36 +01:00
|
|
|
* (non-PHPDoc)
|
|
|
|
* @see ApplicationBootstrap::detectTimezone() For the method documentation.
|
2013-08-28 13:34:49 +02:00
|
|
|
*/
|
2014-11-13 17:07:36 +01:00
|
|
|
protected function detectTimezone()
|
2013-08-28 13:34:49 +02:00
|
|
|
{
|
2014-11-12 12:16:05 +01:00
|
|
|
$auth = Manager::getInstance();
|
2014-11-13 17:07:36 +01:00
|
|
|
if (! $auth->isAuthenticated()
|
|
|
|
|| ($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) === null
|
2014-11-12 12:16:05 +01:00
|
|
|
) {
|
2014-11-13 17:07:36 +01:00
|
|
|
$detect = new TimezoneDetect();
|
|
|
|
$timezone = $detect->getTimezoneName();
|
2014-02-14 17:28:11 +01:00
|
|
|
}
|
2014-11-13 17:07:36 +01:00
|
|
|
return $timezone;
|
2013-08-28 13:34:49 +02:00
|
|
|
}
|
2014-01-29 16:25:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup internationalization using gettext
|
|
|
|
*
|
|
|
|
* Uses the preferred user language or the configured default and system default, respectively.
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2014-11-13 18:02:03 +01:00
|
|
|
protected function detectLocale()
|
2014-01-29 16:25:08 +01:00
|
|
|
{
|
2014-11-12 12:16:05 +01:00
|
|
|
$auth = Manager::getInstance();
|
2014-11-13 18:02:03 +01:00
|
|
|
if (! $auth->isAuthenticated()
|
|
|
|
|| ($locale = $auth->getUser()->getPreferences()->getValue('icingaweb', 'language')) === null
|
|
|
|
&& isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])
|
2014-02-14 17:28:11 +01:00
|
|
|
) {
|
2014-11-13 18:02:03 +01:00
|
|
|
$locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
2014-01-29 16:25:08 +01:00
|
|
|
}
|
2014-11-13 18:02:03 +01:00
|
|
|
return $locale;
|
2014-01-29 16:25:08 +01:00
|
|
|
}
|
2014-06-05 00:46:16 +02:00
|
|
|
|
|
|
|
/**
|
2014-11-14 10:57:14 +01:00
|
|
|
* Setup an autoloader namespace for Icinga\Forms
|
2014-06-05 00:46:16 +02:00
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
private function setupFormNamespace()
|
|
|
|
{
|
|
|
|
$this->getLoader()->registerNamespace(
|
2014-11-14 10:57:14 +01:00
|
|
|
'Icinga\\Forms',
|
2014-06-05 00:46:16 +02:00
|
|
|
$this->getApplicationDir('forms')
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2014-04-28 14:03:52 +02:00
|
|
|
// @codeCoverageIgnoreEnd
|