Skip to content
Merged
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
58 changes: 58 additions & 0 deletions library/Icinga/Application/Hook/RequestHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Icinga\Application\Hook;

use Icinga\Application\Hook;
use Icinga\Application\Logger;
use Icinga\Web\Request;
use Throwable;

abstract class RequestHook
{
/**
* Triggered after a request has been dispatched
*
* @param Request $request
*
* @return void
*/
abstract public function onPostDispatch(Request $request): void;

/**
* Call the onPostDispatch() method of all registered RequestHooks
*
* @param Request $request
*
* @return void
*/
final public static function postDispatch(Request $request): void
{
foreach (static::all() as $hook) {
try {
$hook->onPostDispatch($request);
} catch (Throwable $e) {
Comment thread
Al2Klimov marked this conversation as resolved.
Logger::error('Failed to execute hook on request: %s', $e);
}
}
}

/**
* Get all registered implementations
*
* @return static[]
*/
public static function all(): array
{
return Hook::all('RequestHook');
}

/**
* Register the class as a RequestHook implementation
*
* Call this method on your implementation during module initialization to make Icinga Web aware of your hook.
*/
public static function register(): void
{
Hook::register('RequestHook', static::class, static::class, true);
}
}
23 changes: 13 additions & 10 deletions library/Icinga/Web/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@

namespace Icinga\Web\Controller;

use Icinga\Application\Modules\Module;
use Icinga\Common\PdfExport;
use Icinga\File\Pdf;
use Icinga\Util\Csp;
use Icinga\Web\View;
use ipl\I18n\Translation;
use Zend_Controller_Action;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Request_Abstract;
use Zend_Controller_Response_Abstract;
use Icinga\Application\Benchmark;
use Icinga\Application\Config;
use Icinga\Application\Hook\RequestHook;
use Icinga\Application\Modules\Module;
use Icinga\Authentication\Auth;
use Icinga\Common\PdfExport;
use Icinga\Exception\Http\HttpMethodNotAllowedException;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
use Icinga\File\Pdf;
use Icinga\Forms\AutoRefreshForm;
use Icinga\Security\SecurityException;
use Icinga\Util\Csp;
use Icinga\Web\Session;
use Icinga\Web\Url;
use Icinga\Web\UrlParams;
use Icinga\Web\View;
use Icinga\Web\Widget\Tabs;
use Icinga\Web\Window;
use ipl\I18n\Translation;
use Zend_Controller_Action;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Request_Abstract;
use Zend_Controller_Response_Abstract;

/**
* Base class for all core action controllers
Expand Down Expand Up @@ -522,6 +523,8 @@ public function postDispatch()
$this->postDispatchXhr();
}

RequestHook::postDispatch($req);

$this->shutdownSession();
}

Expand Down
14 changes: 12 additions & 2 deletions library/Icinga/Web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace Icinga\Web;

use Icinga\Util\Json;
use Zend_Controller_Request_Http;
use Icinga\Application\Icinga;
use Icinga\User;
use Icinga\Util\Json;
use Zend_Controller_Request_Http;

/**
* A request
Expand Down Expand Up @@ -101,6 +101,16 @@ public function isApiRequest()
return $this->getHeader('Accept') === 'application/json';
}

/**
* Get whether the request is sent by auto refresh
*
* @return bool
*/
public function isAutoRefresh(): bool
{
return $this->getHeader('X-Icinga-Autorefresh');
}

/**
* Makes an ID unique to this request, to prevent id collisions in different containers
*
Expand Down
Loading