icingaweb2/application/controllers/ApplicationStateController.php

60 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Controllers;
use Icinga\Application\Icinga;
2016-11-29 15:12:33 +01:00
use Icinga\Web\Announcement\AnnouncementCookie;
use Icinga\Web\Announcement\AnnouncementIniRepository;
use Icinga\Web\Controller;
use Icinga\Web\Session;
/**
2017-01-12 12:28:40 +01:00
* @TODO(el): https://dev.icinga.com/issues/10646
*/
class ApplicationStateController extends Controller
{
public function indexAction()
{
2016-11-29 15:12:33 +01:00
$this->_helper->layout()->disableLayout();
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,
null,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
$_COOKIE['icingaweb2-session'] = $now;
}
2016-11-29 15:12:33 +01:00
$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);
}
}
$this->getResponse()->setHeader('X-Icinga-Container', 'ignore', true);
}
}