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); }
/** * Remove all messages from the current user, return them and commit * changes to the underlying session. * * @return array The messages */ protected function getAndClearMessages() { $messages = $this->user->getMessages(); $this->user->clearMessages(); Session::getSession()->write(); return $messages; }
private final function __construct() { if (Platform::isCli()) { $this->isCli = true; return; } $this->session = Session::getSession(); $stored = $this->session->get('messages'); if (is_array($stored)) { $this->messages = $stored; $this->session->set('messages', array()); $this->session->write(); } }
/** * Create the notification instance */ private final function __construct() { if (Platform::isCli()) { $this->isCli = true; return; } $this->session = Session::getSession(); $messages = $this->session->get(self::SESSION_KEY); if (is_array($messages)) { $this->messages = $messages; $this->session->delete(self::SESSION_KEY); $this->session->write(); } }
public function indexAction() { 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; } Icinga::app()->getResponse()->setHeader('X-Icinga-Container', 'ignore', true); }
public function redirectAndExit($url) { if (!$url instanceof Url) { $url = Url::fromPath($url); } $url->getParams()->setSeparator('&'); if (Icinga::app()->getFrontController()->getRequest()->isXmlHttpRequest()) { $this->setHeader('X-Icinga-Redirect', rawurlencode($url->getAbsoluteUrl())); } else { $this->setRedirect($url->getAbsoluteUrl()); } $session = Session::getSession(); if ($session->hasChanged()) { $session->write(); } $this->sendHeaders(); exit; }
/** * Adjust preferences and persist them * * @see Form::onSuccess() */ public function onSuccess() { /** @var Preferences $preferences */ $preferences = $this->getRequest()->getUser()->getPreferences(); $icingaweb = $preferences->get('icingaweb'); if ((bool) $preferences->getValue('icingaweb', 'auto_refresh', true) === false) { $icingaweb['auto_refresh'] = '1'; $notification = $this->translate('Auto refresh successfully enabled'); } else { $icingaweb['auto_refresh'] = '0'; $notification = $this->translate('Auto refresh successfully disabled'); } $preferences->icingaweb = $icingaweb; Session::getSession()->user->setPreferences($preferences); Notification::success($notification); $this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes'); $this->setRedirectUrl(Url::fromRequest()->without('renderLayout')); }
/** * Return a window-aware session by using the given prefix * * @param string $prefix The prefix to use * @param bool $reset Whether to reset any existing session-data * * @return SessionNamespace */ public function getSessionNamespace($prefix, $reset = false) { $session = Session::getSession(); $identifier = $prefix . '_' . $this->id; if ($reset && $session->hasNamespace($identifier)) { $session->removeNamespace($identifier); } $namespace = $session->getNamespace($identifier); $nsUndef = $prefix . '_' . self::UNDEFINED; if (!$reset && $this->id !== self::UNDEFINED && $session->hasNamespace($nsUndef)) { // We do not have any window-id on the very first request. Now we add // all values from the namespace, that has been created in this case, // to the new one and remove it afterwards. foreach ($session->getNamespace($nsUndef) as $name => $value) { $namespace->set($name, $value); } $session->removeNamespace($nsUndef); } return $namespace; }
protected function savePreferences(array $preferences) { $session = Session::getSession(); $currentPreferences = $session->user->getPreferences(); foreach ($preferences as $key => $value) { if ($value === null) { $currentPreferences->remove($key); } else { $currentPreferences->{$key} = $value; } } $session->write(); if (($preferencesConfig = IcingaConfig::app()->preferences) === null) { throw new ConfigurationError('Cannot save preferences changes since you\'ve not configured a preferences backend'); } $store = PreferencesStore::create($preferencesConfig, $session->user); $store->load(); // Necessary for patching existing preferences $store->save($currentPreferences); }
/** * Adjust preferences and persist them * * @see Form::onSuccess() */ public function onSuccess() { $this->preferences = new Preferences($this->store ? $this->store->load() : array()); $webPreferences = $this->preferences->get('icingaweb', array()); foreach ($this->getValues() as $key => $value) { if ($value === null || $value === 'autodetect') { if (isset($webPreferences[$key])) { unset($webPreferences[$key]); } } else { $webPreferences[$key] = $value; } } $this->preferences->icingaweb = $webPreferences; Session::getSession()->user->setPreferences($this->preferences); try { if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { $this->save(); Notification::success($this->translate('Preferences successfully saved')); } else { Notification::success($this->translate('Preferences successfully saved for the current session')); } } catch (Exception $e) { Logger::error($e); Notification::error($e->getMessage()); } }
protected function getIdoVersion() { if (self::$idoVersion === null) { $dbconf = $this->db->getConfig(); $id = $dbconf['host'] . '/' . $dbconf['dbname']; $session = null; if (Icinga::app()->isWeb()) { // TODO: Once we have version per connection we should choose a // namespace based on resource name $session = Session::getSession()->getNamespace('monitoring/ido/' . $id); if (isset($session->version)) { self::$idoVersion = $session->version; return self::$idoVersion; } } self::$idoVersion = $this->db->fetchOne($this->db->select()->from($this->prefix . 'dbversion', 'version')); if ($session !== null) { $session->version = self::$idoVersion; } } return self::$idoVersion; }
protected function shutdownSession() { $session = Session::getSession(); if ($session->hasChanged()) { $session->write(); } }
/** * Tries to authenticate the user with the current session **/ public function authenticateFromSession() { $this->user = Session::getSession()->get('user'); }
private final function __construct() { $session = Session::getSession(); if (!is_array($session->get('messages'))) { $session->messages = array(); } if (Platform::isCli()) { $this->is_cli = true; } }
/** * Return a session to be used by this wizard * * @return SessionNamespace */ public function getSession() { if ($this->parent) { return $this->parent->getSession(); } return Session::getSession()->getNamespace(get_class($this)); }
/** * Redirect to the given URL and exit immediately * * @param string|Url $url */ public function redirectAndExit($url) { $this->setRedirectUrl($url); $session = Session::getSession(); if ($session->hasChanged()) { $session->write(); } $this->sendHeaders(); exit; }
/** * Purges the current authorization information and session */ public function removeAuthorization() { $this->user = null; Session::getSession()->purge(); }
/** * Return a window-aware session by using the given prefix * * @param string $prefix The prefix to use * @param bool $reset Whether to reset any existing session-data * * @return SessionNamespace */ public function getWindowSession($prefix, $reset = false) { $session = Session::getSession(); $windowId = $this->getWindowId(); $identifier = $prefix . '_' . $windowId; if ($reset && $session->hasNamespace($identifier)) { $session->removeNamespace($identifier); } $namespace = $session->getNamespace($identifier); if (!$reset && $windowId !== 'undefined' && $session->hasNamespace($prefix . '_undefined')) { // We do not have any window-id on the very first request. Now we add all values from the // namespace, that has been created in this case, to the new one and remove it afterwards. foreach ($session->getNamespace($prefix . '_undefined') as $name => $value) { $namespace->set($name, $value); } $session->removeNamespace($prefix . '_undefined'); } return $namespace; }
/** * Generate a new (seed, token) pair * * @return string */ protected function generateCsrfToken() { $seed = mt_rand(); $hash = hash('sha256', Session::getSession()->getId() . $seed); return sprintf('%s|%s', $seed, $hash); }
/** * Send a message with the logging level Zend_Log::ERR to the current user and * commit the changes to the underlying session. * * @param $msg The message content */ protected function addErrorMessage($msg) { AuthenticationManager::getInstance()->getUser()->addMessage(new Message($msg, Zend_Log::ERR)); Session::getSession()->write(); }
/** * Adjust preferences and persist them * * @see Form::onSuccess() */ public function onSuccess() { $this->preferences = new Preferences($this->store ? $this->store->load() : array()); $oldTheme = $this->preferences->getValue('icingaweb', 'theme'); $webPreferences = $this->preferences->get('icingaweb', array()); foreach ($this->getValues() as $key => $value) { if ($value === '' || $value === 'autodetect' || $key === 'theme' && $value === Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME)) { if (isset($webPreferences[$key])) { unset($webPreferences[$key]); } } else { $webPreferences[$key] = $value; } } $this->preferences->icingaweb = $webPreferences; Session::getSession()->user->setPreferences($this->preferences); if (($theme = $this->getElement('theme')) !== null && ($theme = $theme->getValue()) !== $oldTheme) { $this->getResponse()->setReloadCss(true); } try { if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { $this->save(); Notification::success($this->translate('Preferences successfully saved')); } else { Notification::success($this->translate('Preferences successfully saved for the current session')); } } catch (Exception $e) { Logger::error($e); Notification::error($e->getMessage()); } }