2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
namespace Icinga\Application;
|
|
|
|
|
2015-08-06 15:08:41 +02:00
|
|
|
require_once __DIR__ . '/EmbeddedWeb.php';
|
2014-03-31 18:35:28 +02:00
|
|
|
|
2018-02-07 10:45:20 +01:00
|
|
|
use ErrorException;
|
2021-05-20 09:09:41 +02:00
|
|
|
use ipl\I18n\GettextTranslator;
|
|
|
|
use ipl\I18n\Locale;
|
|
|
|
use ipl\I18n\StaticTranslator;
|
2015-03-11 22:08:28 +01:00
|
|
|
use Zend_Controller_Action_HelperBroker;
|
|
|
|
use Zend_Controller_Front;
|
|
|
|
use Zend_Controller_Router_Route;
|
2014-03-31 18:35:28 +02:00
|
|
|
use Zend_Layout;
|
|
|
|
use Zend_Paginator;
|
|
|
|
use Zend_View_Helper_PaginationControl;
|
2015-07-28 17:08:55 +02:00
|
|
|
use Icinga\Authentication\Auth;
|
2015-03-11 22:08:28 +01:00
|
|
|
use Icinga\User;
|
2015-11-26 14:49:49 +01:00
|
|
|
use Icinga\Util\DirectoryIterator;
|
2014-09-05 15:03:45 +02:00
|
|
|
use Icinga\Util\TimezoneDetect;
|
2015-08-17 12:59:44 +02:00
|
|
|
use Icinga\Web\Controller\Dispatcher;
|
2015-09-04 10:53:01 +02:00
|
|
|
use Icinga\Web\Navigation\Navigation;
|
2015-03-13 13:49:45 +01:00
|
|
|
use Icinga\Web\Notification;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\Web\Session;
|
2015-03-11 22:08:28 +01:00
|
|
|
use Icinga\Web\Session\Session as BaseSession;
|
2015-11-27 16:40:17 +01:00
|
|
|
use Icinga\Web\StyleSheet;
|
2015-03-11 22:08:28 +01:00
|
|
|
use Icinga\Web\View;
|
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>
|
2015-08-06 15:08:41 +02:00
|
|
|
* use Icinga\Application\Web;
|
|
|
|
* Web::start();
|
2013-06-07 11:44:37 +02:00
|
|
|
* </code>
|
|
|
|
*/
|
2015-08-06 15:08:41 +02:00
|
|
|
class Web extends EmbeddedWeb
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* View object
|
|
|
|
*
|
|
|
|
* @var View
|
|
|
|
*/
|
|
|
|
private $viewRenderer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Zend front controller instance
|
|
|
|
*
|
|
|
|
* @var Zend_Controller_Front
|
|
|
|
*/
|
|
|
|
private $frontController;
|
|
|
|
|
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
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-07 11:44:37 +02:00
|
|
|
protected function bootstrap()
|
|
|
|
{
|
2014-02-12 14:51:04 +01:00
|
|
|
return $this
|
2014-03-03 19:03:39 +01:00
|
|
|
->setupLogging()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupErrorHandling()
|
2020-11-10 14:07:00 +01:00
|
|
|
->loadLibraries()
|
2014-02-12 14:51:04 +01:00
|
|
|
->loadConfig()
|
2018-10-08 14:03:34 +02:00
|
|
|
->setupLogger()
|
2016-02-26 14:26:10 +01:00
|
|
|
->setupRequest()
|
2014-01-23 12:09:48 +01:00
|
|
|
->setupSession()
|
2015-03-13 13:49:45 +01:00
|
|
|
->setupNotifications()
|
2015-07-30 13:47:54 +02:00
|
|
|
->setupResponse()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupZendMvc()
|
2021-05-20 09:09:41 +02:00
|
|
|
->prepareInternationalization()
|
2018-07-18 15:29:55 +02:00
|
|
|
->setupModuleManager()
|
|
|
|
->loadSetupModuleIfNecessary()
|
|
|
|
->loadEnabledModules()
|
2013-07-26 15:58:16 +02:00
|
|
|
->setupRoute()
|
2016-02-18 10:16:22 +01:00
|
|
|
->setupPagination()
|
|
|
|
->setupUserBackendFactory()
|
|
|
|
->setupUser()
|
|
|
|
->setupTimezone()
|
2018-02-07 10:45:20 +01:00
|
|
|
->setupInternationalization()
|
2018-07-18 15:29:55 +02:00
|
|
|
->setupFatalErrorHandling();
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-11-26 14:49:49 +01:00
|
|
|
/**
|
|
|
|
* Get themes provided by Web 2 and all enabled modules
|
|
|
|
*
|
|
|
|
* @return string[] Array of theme names as keys and values
|
|
|
|
*/
|
|
|
|
public function getThemes()
|
|
|
|
{
|
2015-11-27 16:40:17 +01:00
|
|
|
$themes = array(StyleSheet::DEFAULT_THEME);
|
2015-11-26 14:49:49 +01:00
|
|
|
$applicationThemePath = $this->getBaseDir('public/css/themes');
|
|
|
|
if (DirectoryIterator::isReadable($applicationThemePath)) {
|
|
|
|
foreach (new DirectoryIterator($applicationThemePath, 'less') as $name => $theme) {
|
|
|
|
$themes[] = substr($name, 0, -5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mm = $this->getModuleManager();
|
|
|
|
foreach ($mm->listEnabledModules() as $moduleName) {
|
|
|
|
$moduleThemePath = $mm->getModule($moduleName)->getCssDir() . '/themes';
|
|
|
|
if (! DirectoryIterator::isReadable($moduleThemePath)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach (new DirectoryIterator($moduleThemePath, 'less') as $name => $theme) {
|
|
|
|
$themes[] = $moduleName . '/' . substr($name, 0, -5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array_combine($themes, $themes);
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Prepare routing
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-04 11:01:35 +01:00
|
|
|
private function hasAccessToSharedNavigationItem(&$config, Config $navConfig)
|
2015-09-07 13:22:02 +02:00
|
|
|
{
|
|
|
|
// TODO: Provide a more sophisticated solution
|
|
|
|
|
2016-02-10 16:22:51 +01:00
|
|
|
if (isset($config['owner']) && strtolower($config['owner']) === strtolower($this->user->getUsername())) {
|
2015-09-07 13:22:02 +02:00
|
|
|
unset($config['owner']);
|
2015-11-13 15:28:23 +01:00
|
|
|
unset($config['users']);
|
|
|
|
unset($config['groups']);
|
2015-09-07 13:22:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-13 15:28:23 +01:00
|
|
|
if (isset($config['parent']) && $navConfig->hasSection($config['parent'])) {
|
|
|
|
unset($config['owner']);
|
|
|
|
if (isset($this->accessibleMenuItems[$config['parent']])) {
|
|
|
|
return $this->accessibleMenuItems[$config['parent']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$parentConfig = $navConfig->getSection($config['parent']);
|
|
|
|
$this->accessibleMenuItems[$config['parent']] = $this->hasAccessToSharedNavigationItem(
|
|
|
|
$parentConfig,
|
|
|
|
$navConfig
|
|
|
|
);
|
|
|
|
return $this->accessibleMenuItems[$config['parent']];
|
|
|
|
}
|
|
|
|
|
2015-09-07 13:22:02 +02:00
|
|
|
if (isset($config['users'])) {
|
|
|
|
$users = array_map('trim', explode(',', strtolower($config['users'])));
|
2016-02-10 16:22:51 +01:00
|
|
|
if (in_array('*', $users, true) || in_array(strtolower($this->user->getUsername()), $users, true)) {
|
2015-11-13 15:28:23 +01:00
|
|
|
unset($config['owner']);
|
2015-09-07 13:22:02 +02:00
|
|
|
unset($config['users']);
|
2015-11-13 15:28:23 +01:00
|
|
|
unset($config['groups']);
|
2015-09-07 13:22:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['groups'])) {
|
|
|
|
$groups = array_map('trim', explode(',', strtolower($config['groups'])));
|
2015-10-01 13:56:28 +02:00
|
|
|
if (in_array('*', $groups, true)) {
|
2015-11-13 15:28:23 +01:00
|
|
|
unset($config['owner']);
|
|
|
|
unset($config['users']);
|
2015-10-01 13:56:28 +02:00
|
|
|
unset($config['groups']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-07 13:22:02 +02:00
|
|
|
$userGroups = array_map('strtolower', $this->user->getGroups());
|
|
|
|
$matches = array_intersect($userGroups, $groups);
|
|
|
|
if (! empty($matches)) {
|
2015-11-13 15:28:23 +01:00
|
|
|
unset($config['owner']);
|
|
|
|
unset($config['users']);
|
2015-09-07 13:22:02 +02:00
|
|
|
unset($config['groups']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load and return the shared navigation of the given type
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return Navigation
|
|
|
|
*/
|
|
|
|
public function getSharedNavigation($type)
|
|
|
|
{
|
2015-09-30 11:38:51 +02:00
|
|
|
$config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type);
|
2015-09-07 13:22:02 +02:00
|
|
|
|
|
|
|
if ($type === 'dashboard-pane') {
|
|
|
|
$panes = array();
|
2015-09-30 11:38:51 +02:00
|
|
|
foreach ($config as $dashletName => $dashletConfig) {
|
2015-09-07 13:22:02 +02:00
|
|
|
if ($this->hasAccessToSharedNavigationItem($dashletConfig)) {
|
|
|
|
// TODO: Throw ConfigurationError if pane or url is missing
|
|
|
|
$panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:40:40 +02:00
|
|
|
$navigation = new Navigation();
|
2015-09-07 13:22:02 +02:00
|
|
|
foreach ($panes as $paneName => $dashlets) {
|
|
|
|
$navigation->addItem(
|
|
|
|
$paneName,
|
|
|
|
array(
|
|
|
|
'type' => 'dashboard-pane',
|
|
|
|
'dashlets' => $dashlets
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-17 13:40:40 +02:00
|
|
|
$items = array();
|
2015-09-30 11:38:51 +02:00
|
|
|
foreach ($config as $name => $typeConfig) {
|
2015-11-13 15:28:23 +01:00
|
|
|
if (isset($this->accessibleMenuItems[$name])) {
|
|
|
|
if ($this->accessibleMenuItems[$name]) {
|
|
|
|
$items[$name] = $typeConfig;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($this->hasAccessToSharedNavigationItem($typeConfig, $config)) {
|
|
|
|
$this->accessibleMenuItems[$name] = true;
|
|
|
|
$items[$name] = $typeConfig;
|
|
|
|
} else {
|
|
|
|
$this->accessibleMenuItems[$name] = false;
|
|
|
|
}
|
2015-09-07 13:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 13:40:40 +02:00
|
|
|
|
|
|
|
$navigation = Navigation::fromConfig($items);
|
2015-09-07 13:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $navigation;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Dispatch public interface
|
|
|
|
*/
|
|
|
|
public function dispatch()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2015-07-30 13:47:54 +02:00
|
|
|
$this->frontController->dispatch($this->getRequest(), $this->getResponse());
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare Zend MVC Base
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-06-07 11:44:37 +02:00
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
private function setupZendMvc()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
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
|
|
|
)
|
|
|
|
);
|
2015-11-12 17:34:11 +01: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
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
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
|
|
|
{
|
2015-07-28 17:08:55 +02:00
|
|
|
$auth = Auth::getInstance();
|
2016-11-07 10:40:38 +01:00
|
|
|
if (! $this->request->isXmlHttpRequest() && $this->request->isApiRequest() && ! $auth->isAuthenticated()) {
|
|
|
|
$auth->authHttp();
|
|
|
|
}
|
2015-03-11 22:26:03 +01:00
|
|
|
if ($auth->isAuthenticated()) {
|
2015-07-29 17:22:10 +02:00
|
|
|
$user = $auth->getUser();
|
2015-08-06 15:08:41 +02:00
|
|
|
$this->getRequest()->setUser($user);
|
2015-07-29 17:22:10 +02:00
|
|
|
$this->user = $user;
|
2017-11-15 17:22:54 +01:00
|
|
|
|
2021-02-18 08:52:57 +01:00
|
|
|
if ($user->can('user/application/stacktraces')) {
|
2017-11-15 17:22:54 +01:00
|
|
|
$displayExceptions = $this->user->getPreferences()->getValue(
|
|
|
|
'icingaweb',
|
|
|
|
'show_stacktraces'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($displayExceptions !== null) {
|
|
|
|
$this->frontController->setParams(
|
|
|
|
array(
|
|
|
|
'displayExceptions' => $displayExceptions
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 17:36:20 +01: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
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2014-01-23 12:09:48 +01:00
|
|
|
*/
|
|
|
|
private function setupSession()
|
|
|
|
{
|
|
|
|
$this->session = Session::create();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-30 16:02:05 +02:00
|
|
|
/**
|
2015-03-13 13:49:45 +01:00
|
|
|
* Initialize notifications to remove them immediately from session
|
2013-07-30 16:02:05 +02:00
|
|
|
*
|
2015-03-13 13:49:45 +01:00
|
|
|
* @return $this
|
2013-07-30 16:02:05 +02:00
|
|
|
*/
|
2015-03-13 13:49:45 +01:00
|
|
|
private function setupNotifications()
|
2013-07-30 16:02:05 +02:00
|
|
|
{
|
2015-03-13 13:49:45 +01:00
|
|
|
Notification::getInstance();
|
2013-07-26 15:58:16 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate front controller
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
private function setupFrontController()
|
|
|
|
{
|
|
|
|
$this->frontController = Zend_Controller_Front::getInstance();
|
2014-12-18 17:12:11 +01:00
|
|
|
$this->frontController->setDispatcher(new Dispatcher());
|
2015-08-06 15:08:41 +02:00
|
|
|
$this->frontController->setRequest($this->getRequest());
|
2013-07-26 15:58:16 +02:00
|
|
|
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
|
2015-08-24 14:44:54 +02:00
|
|
|
|
|
|
|
$displayExceptions = $this->config->get('global', 'show_stacktraces', true);
|
|
|
|
|
2013-06-14 13:51:44 +02:00
|
|
|
$this->frontController->setParams(
|
|
|
|
array(
|
2015-08-24 14:44:54 +02:00
|
|
|
'displayExceptions' => $displayExceptions
|
2013-06-14 13:51:44 +02:00
|
|
|
)
|
|
|
|
);
|
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
|
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
private function setupViewRenderer()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2015-03-11 22:03:49 +01:00
|
|
|
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
|
2013-07-26 15:58:16 +02:00
|
|
|
/** @var \Zend_Controller_Action_Helper_ViewRenderer $view */
|
|
|
|
$view->setView(new View());
|
|
|
|
$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-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
|
|
|
*
|
2015-03-11 21:58:41 +01:00
|
|
|
* @return $this
|
2013-06-07 11:44:37 +02:00
|
|
|
*/
|
2013-07-26 15:58:16 +02:00
|
|
|
private function setupPagination()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2015-11-15 23:34:44 +01:00
|
|
|
// TODO: document what we need for whatever reason?!
|
|
|
|
Zend_Paginator::addScrollingStylePrefixPath(
|
|
|
|
'Icinga_Web_Paginator_ScrollingStyle_',
|
|
|
|
$this->getLibraryDir('Icinga/Web/Paginator/ScrollingStyle')
|
|
|
|
);
|
|
|
|
|
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'
|
|
|
|
);
|
2015-11-15 23:34:44 +01:00
|
|
|
|
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
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
2013-08-28 13:34:49 +02:00
|
|
|
|
2018-02-07 10:45:20 +01:00
|
|
|
/**
|
|
|
|
* Fatal error handling configuration
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
protected function setupFatalErrorHandling()
|
|
|
|
{
|
|
|
|
register_shutdown_function(function () {
|
|
|
|
$error = error_get_last();
|
|
|
|
|
|
|
|
if ($error !== null && $error['type'] === E_ERROR) {
|
|
|
|
$frontController = Icinga::app()->getFrontController();
|
|
|
|
$response = $frontController->getResponse();
|
|
|
|
|
|
|
|
$response->setException(new ErrorException(
|
|
|
|
$error['message'],
|
|
|
|
0,
|
|
|
|
$error['type'],
|
|
|
|
$error['file'],
|
|
|
|
$error['line']
|
|
|
|
));
|
|
|
|
|
|
|
|
// Clean PHP's fatal error stack trace and replace it with ours
|
|
|
|
ob_end_clean();
|
|
|
|
$frontController->dispatch($frontController->getRequest(), $response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-07-28 17:08:55 +02:00
|
|
|
$auth = Auth::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
|
|
|
|
*
|
2015-03-11 21:55:04 +01:00
|
|
|
* Uses the preferred user language or the browser suggested language or our default.
|
2014-01-29 16:25:08 +01:00
|
|
|
*
|
2021-05-20 09:47:17 +02:00
|
|
|
* @return string Detected locale code
|
2014-01-29 16:25:08 +01:00
|
|
|
*/
|
2014-11-13 18:02:03 +01:00
|
|
|
protected function detectLocale()
|
2014-01-29 16:25:08 +01:00
|
|
|
{
|
2015-07-28 17:08:55 +02:00
|
|
|
$auth = Auth::getInstance();
|
2015-03-11 20:50:05 +01:00
|
|
|
if ($auth->isAuthenticated()
|
|
|
|
&& ($locale = $auth->getUser()->getPreferences()->getValue('icingaweb', 'language')) !== null
|
2014-02-14 17:28:11 +01:00
|
|
|
) {
|
2015-03-11 20:50:05 +01:00
|
|
|
return $locale;
|
2014-01-29 16:25:08 +01:00
|
|
|
}
|
2021-05-20 09:47:17 +02:00
|
|
|
|
|
|
|
/** @var GettextTranslator $translator */
|
|
|
|
$translator = StaticTranslator::$instance;
|
|
|
|
|
2017-09-08 12:56:09 +02:00
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
2021-05-20 09:47:17 +02:00
|
|
|
return (new Locale())->getPreferred($_SERVER['HTTP_ACCEPT_LANGUAGE'], $translator->listLocales());
|
2015-03-11 20:50:05 +01:00
|
|
|
}
|
2021-05-20 09:47:17 +02:00
|
|
|
|
|
|
|
return $translator->getDefaultLocale();
|
2014-01-29 16:25:08 +01:00
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|