Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions doc/80-Upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too.

## Upgrading to Icinga Web 2.14

**Deprecations**

* Providing a custom user or group backend inside a module's configuration.php is deprecated and won't work as of v2.15.
* It will still work as previously under the right circumstances, but will still be broken if it broke beforehand.
* To keep it working as of v2.15 or make it work now, provide the custom backend inside the module's run.php instead.

**Framework changes affecting third-party code**

* Our JavaScript implementation to update relative times in the UI has been removed from Icinga Web, and an updated
Expand Down
29 changes: 28 additions & 1 deletion library/Icinga/Application/EmbeddedWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

require_once dirname(__FILE__) . '/ApplicationBootstrap.php';

use Icinga\Authentication\Auth;
use Icinga\User;
use Icinga\Web\Request;
use Icinga\Web\Response;
use ipl\I18n\NoopTranslator;
Expand Down Expand Up @@ -37,6 +39,13 @@ class EmbeddedWeb extends ApplicationBootstrap
*/
protected $response;

/**
* User object
*
* @var ?User
*/
protected ?User $user = null;

/**
* Get the request
*
Expand Down Expand Up @@ -67,17 +76,19 @@ public function getResponse()
protected function bootstrap()
{
return $this
->setupLogging()
->setupErrorHandling()
->loadLibraries()
->loadConfig()
->setupLogging()
->setupLogger()
->setupRequest()
->setupResponse()
->setupTimezone()
->prepareFakeInternationalization()
->setupModuleManager()
->loadEnabledModules()
->setupUserBackendFactory()
->setupUser()
->registerApplicationHooks();
}

Expand All @@ -103,6 +114,22 @@ protected function setupResponse()
return $this;
}

/**
* Create user object
*
* @return $this
*/
protected function setupUser(): static
{
$auth = Auth::getInstance();
if ($auth->authenticate()->isAuthenticated()) {
$this->user = $auth->getUser();
$this->getRequest()->setUser($this->user);
}

return $this;
}

/**
* Prepare fake internationalization
*
Expand Down
18 changes: 17 additions & 1 deletion library/Icinga/Application/Modules/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Icinga\Application\Modules;

use Fiber;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
Expand Down Expand Up @@ -189,8 +190,23 @@ private function detectEnabledModules()
public function loadEnabledModules()
{
if (! $this->loadedAllEnabledModules) {
$async = ! $this->app->isCli();
foreach ($this->listEnabledModules() as $name) {
$this->loadModule($name);
if ($async) {
// May be suspended during authentication and resumed upon finish
(new Fiber(function () use ($name) {
Logger::debug(
'Loading enabled module "%s" asynchronously (Process %d; Fiber %d)',
$name,
getmypid() ?: 0,
spl_object_id(Fiber::getCurrent())
);

$this->loadModule($name);
}))->start();
} else {
$this->loadModule($name);
}
}

$this->loadedAllEnabledModules = true;
Expand Down
78 changes: 63 additions & 15 deletions library/Icinga/Application/Modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Icinga\Application\Modules;

use Exception;
use Fiber;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config;
use Icinga\Application\Hook;
Expand All @@ -20,7 +21,6 @@
use ipl\I18n\GettextTranslator;
use ipl\I18n\StaticTranslator;
use ipl\I18n\Translation;
use Zend_Controller_Router_Route;
use Zend_Controller_Router_Route_Abstract;
use Zend_Controller_Router_Route_Regex;

Expand Down Expand Up @@ -1085,7 +1085,22 @@ public function getSetupWizard()
*/
public function getUserBackends()
{
$this->launchConfigScript();
// TODO: Remove with v2.15
if (Fiber::getCurrent() === null) {
(new Fiber(function () {
Logger::debug(
'Running config script of module "%s" asynchronously (Process %d; Fiber %d)',
$this->getName(),
getmypid() ?: 0,
spl_object_id(Fiber::getCurrent())
);

$this->launchConfigScript();
}))->start();
} else {
$this->launchConfigScript();
}

return $this->userBackends;
Comment thread
nilmerg marked this conversation as resolved.
}

Expand All @@ -1096,7 +1111,22 @@ public function getUserBackends()
*/
public function getUserGroupBackends()
{
$this->launchConfigScript();
// TODO: Remove with v2.15
if (Fiber::getCurrent() === null) {
(new Fiber(function () {
Logger::debug(
'Running config script of module "%s" asynchronously (Process %d; Fiber %d)',
$this->getName(),
getmypid() ?: 0,
spl_object_id(Fiber::getCurrent())
);

$this->launchConfigScript();
}))->start();
} else {
$this->launchConfigScript();
}

return $this->userGroupBackends;
}
Comment thread
nilmerg marked this conversation as resolved.

Expand Down Expand Up @@ -1197,6 +1227,21 @@ protected function provideSetupWizard($className)
*/
protected function provideUserBackend($identifier, $className)
{
if ($this->registered) {
trigger_error(sprintf(
'Module "%s" already registered. Providing user backend "%s" in configuration.php'
. ' has no effect as of version 2.15. Put it in run.php instead.',
$this->getName(),
$identifier
), E_USER_DEPRECATED);
Logger::warning(
'Module "%s" already registered. Providing user backend "%s" in configuration.php'
. ' has no effect as of version 2.15. Put it in run.php instead.',
$this->getName(),
$identifier
);
}

$this->userBackends[strtolower($identifier)] = $className;
return $this;
}
Expand All @@ -1211,6 +1256,21 @@ protected function provideUserBackend($identifier, $className)
*/
protected function provideUserGroupBackend($identifier, $className)
{
if ($this->registered) {
trigger_error(sprintf(
'Module "%s" already registered. Providing user group backend "%s" in configuration.php'
. ' has no effect as of version 2.15. Put it in run.php instead.',
$this->getName(),
$identifier
), E_USER_DEPRECATED);
Logger::warning(
'Module "%s" already registered. Providing user group backend "%s" in configuration.php'
. ' has no effect as of version 2.15. Put it in run.php instead.',
$this->getName(),
$identifier
);
}

$this->userGroupBackends[strtolower($identifier)] = $className;
return $this;
}
Expand Down Expand Up @@ -1341,18 +1401,6 @@ protected function registerRoutes()
foreach ($this->routes as $name => $route) {
$router->addRoute($name, $route);
}
$router->addRoute(
$this->name . '_jsprovider',
new Zend_Controller_Router_Route(
'js/' . $this->name . '/:file',
array(
'action' => 'javascript',
'controller' => 'static',
'module' => 'default',
'module_name' => $this->name
)
)
);
$router->addRoute(
$this->name . '_img',
new Zend_Controller_Router_Route_Regex(
Expand Down
92 changes: 14 additions & 78 deletions library/Icinga/Application/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
use ipl\I18n\StaticTranslator;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Front;
use Zend_Controller_Router_Route;
use Zend_Layout;
use Zend_Paginator;
use Zend_View_Helper_PaginationControl;
use Icinga\Authentication\Auth;
use Icinga\User;
use Icinga\Util\DirectoryIterator;
use Icinga\Util\TimezoneDetect;
use Icinga\Web\Controller\Dispatcher;
use Icinga\Web\Navigation\Navigation;
use Icinga\Web\Notification;
use Icinga\Web\Session;
use Icinga\Web\Session\Session as BaseSession;
use Icinga\Web\StyleSheet;
use Icinga\Web\View;

Expand Down Expand Up @@ -54,20 +50,6 @@ class Web extends EmbeddedWeb
*/
private $frontController;

/**
* Session object
*
* @var BaseSession
*/
private $session;

/**
* User object
*
* @var User
*/
private $user;

/** @var array */
protected $accessibleMenuItems;

Expand All @@ -92,15 +74,13 @@ protected function bootstrap()
->loadConfig()
->setupLogger()
->setupRequest()
->setupSession()
->setupNotifications()
->setupResponse()
->setupZendMvc()
->prepareInternationalization()
->setupModuleManager()
->loadSetupModuleIfNecessary()
->loadEnabledModules()
->setupRoute()
->setupPagination()
->setupUserBackendFactory()
->setupUser()
Expand Down Expand Up @@ -137,27 +117,6 @@ public function getThemes()
return array_combine($themes, $themes);
}

/**
* Prepare routing
*
* @return $this
*/
private function setupRoute()
{
$this->frontController->getRouter()->addRoute(
'module_javascript',
new Zend_Controller_Router_Route(
'js/components/:module_name/:file',
array(
'controller' => 'static',
'action' => 'javascript'
)
)
);

return $this;
}

/**
* Getter for frontController
*
Expand Down Expand Up @@ -315,48 +274,25 @@ private function setupZendMvc()
return $this;
}

/**
* Create user object
*
* @return $this
*/
private function setupUser()
protected function setupUser(): static
{
$auth = Auth::getInstance();
if (! $this->request->isXmlHttpRequest() && $this->request->isApiRequest() && ! $auth->isAuthenticated()) {
$auth->authHttp();
}
if ($auth->isAuthenticated()) {
$user = $auth->getUser();
$this->getRequest()->setUser($user);
$this->user = $user;

if ($user->can('user/application/stacktraces')) {
$displayExceptions = $this->user->getPreferences()->getValue(
'icingaweb',
'show_stacktraces'
);
parent::setupUser();

if ($displayExceptions !== null) {
$this->frontController->setParams(
array(
'displayExceptions' => $displayExceptions
)
);
}
if ($this->user !== null && $this->user->can('user/application/stacktraces')) {
$displayExceptions = $this->user->getPreferences()->getValue(
'icingaweb',
'show_stacktraces'
);

if ($displayExceptions !== null) {
$this->frontController->setParams(
array(
'displayExceptions' => $displayExceptions
)
);
}
}
return $this;
}

/**
* Initialize a session provider
*
* @return $this
*/
private function setupSession()
{
$this->session = Session::create();
return $this;
}

Expand Down
Loading
Loading