public function indexAction() { $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; } $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); }
/** * {@inheritdoc} */ public function render() { $repo = new AnnouncementIniRepository(); $etag = $repo->getEtag(); $cookie = new AnnouncementCookie(); if ($cookie->getEtag() !== $etag) { $cookie->setEtag($etag); $cookie->setNextActive($repo->findNextActive()); Icinga::app()->getResponse()->setCookie($cookie); } $acked = array(); foreach ($cookie->getAcknowledged() as $hash) { $acked[] = Filter::expression('hash', '!=', $hash); } $acked = Filter::matchAll($acked); $announcements = $repo->findActive(); $announcements->applyFilter($acked); if ($announcements->hasResult()) { $html = '<ul role="alert" id="announcements">'; foreach ($announcements as $announcement) { $ackForm = new AcknowledgeAnnouncementForm(); $ackForm->populate(array('hash' => $announcement->hash)); $html .= '<li><div>' . $this->view()->escape($announcement->message) . '</div>' . $ackForm . '</li>'; } $html .= '</ul>'; return $html; } // Force container update on XHR return '<div style="display: none;"></div>'; }
/** * {@inheritdoc} */ public function onSuccess() { $cookie = new AnnouncementCookie(); $repo = new AnnouncementIniRepository(); $query = $repo->findActive(); $filter = array(); foreach ($cookie->getAcknowledged() as $hash) { $filter[] = Filter::expression('hash', '=', $hash); } $query->addFilter(Filter::matchAny($filter)); $acknowledged = array(); foreach ($query as $row) { $acknowledged[] = $row->hash; } $acknowledged[] = $this->getElement('hash')->getValue(); $cookie->setAcknowledged($acknowledged); $this->getResponse()->setCookie($cookie); return true; }
/** * List all announcements */ public function indexAction() { $this->getTabs()->add('announcements', array('active' => true, 'label' => $this->translate('Announcements'), 'title' => $this->translate('List All Announcements'), 'url' => Url::fromPath('announcements'))); $repo = new AnnouncementIniRepository(); $this->view->announcements = $repo->select(array('id', 'author', 'message', 'start', 'end'))->order('start'); }