1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Controllers;
use Icinga\Forms\AcknowledgeApplicationStateMessageForm;
use Icinga\Web\Announcement\AnnouncementCookie;
use Icinga\Web\Announcement\AnnouncementIniRepository;
use Icinga\Web\Controller;
use Icinga\Web\RememberMe;
use Icinga\Web\Session;
use Icinga\Web\Widget;
/**
* @TODO(el): https://dev.icinga.com/issues/10646
*/
class ApplicationStateController extends Controller
{
protected $requiresAuthentication = false;
protected $autorefreshInterval = 60;
public function init()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
public function indexAction()
{
if ($this->Auth()->isAuthenticated()) {
if (isset($_COOKIE['icingaweb2-session'])) {
$last = (int) $_COOKIE['icingaweb2-session'];
} else {
$last = 0;
}
$now = time();
if ($last + 600 < $now) {
Session::getSession()->write();
$params = session_get_cookie_params();
setcookie(
'icingaweb2-session',
$now,
0,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
$_COOKIE['icingaweb2-session'] = $now;
}
$announcementCookie = new AnnouncementCookie();
$announcementRepo = new AnnouncementIniRepository();
if ($announcementCookie->getEtag() !== $announcementRepo->getEtag()) {
$announcementCookie
->setEtag($announcementRepo->getEtag())
->setNextActive($announcementRepo->findNextActive());
$this->getResponse()->setCookie($announcementCookie);
$this->getResponse()->setHeader('X-Icinga-Announcements', 'refresh', true);
} else {
$nextActive = $announcementCookie->getNextActive();
if ($nextActive && $nextActive <= $now) {
$announcementCookie->setNextActive($announcementRepo->findNextActive());
$this->getResponse()->setCookie($announcementCookie);
$this->getResponse()->setHeader('X-Icinga-Announcements', 'refresh', true);
}
}
}
RememberMe::removeExpired();
}
public function summaryAction()
{
if ($this->Auth()->isAuthenticated()) {
$this->getResponse()->setBody((string) Widget::create('ApplicationStateMessages'));
}
}
public function acknowledgeMessageAction()
{
if (! $this->Auth()->isAuthenticated()) {
$this->getResponse()
->setHttpResponseCode(401)
->sendHeaders();
exit;
}
$this->assertHttpMethod('POST');
$this->getResponse()->setHeader('X-Icinga-Container', 'ignore', true);
(new AcknowledgeApplicationStateMessageForm())->handleRequest();
}
}
|