From 0cc54ce34b2f747adb4b333f9c549025c1fe87cc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 16 Nov 2015 14:19:33 +0100 Subject: [PATCH] Refresh session every 10 minutes Quick and dirty fix. fixes #10229 --- .../ApplicationStateController.php | 39 +++++++++++++++++++ .../scripts/application-state/index.phtml | 0 library/Icinga/Authentication/Auth.php | 11 ++++++ library/Icinga/Web/Controller/Dispatcher.php | 3 +- library/Icinga/Web/JavaScript.php | 1 + .../js/icinga/behavior/application-state.js | 31 +++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 application/controllers/ApplicationStateController.php create mode 100644 application/views/scripts/application-state/index.phtml create mode 100644 public/js/icinga/behavior/application-state.js diff --git a/application/controllers/ApplicationStateController.php b/application/controllers/ApplicationStateController.php new file mode 100644 index 000000000..545f7993f --- /dev/null +++ b/application/controllers/ApplicationStateController.php @@ -0,0 +1,39 @@ +refreshId(); + $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); + } +} diff --git a/application/views/scripts/application-state/index.phtml b/application/views/scripts/application-state/index.phtml new file mode 100644 index 000000000..e69de29bb diff --git a/library/Icinga/Authentication/Auth.php b/library/Icinga/Authentication/Auth.php index 9b1360a60..2f02adb22 100644 --- a/library/Icinga/Authentication/Auth.php +++ b/library/Icinga/Authentication/Auth.php @@ -341,6 +341,17 @@ class Auth */ public function persistCurrentUser() { + // @TODO(el): https://dev.icinga.org/issues/10646 + $params = session_get_cookie_params(); + setcookie( + 'icingaweb2-session', + time(), + null, + $params['path'], + $params['domain'], + $params['secure'], + $params['httponly'] + ); Session::getSession()->set('user', $this->user)->refreshId(); } diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index ff3c98848..171302e34 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -4,6 +4,7 @@ namespace Icinga\Web\Controller; use Exception; +use Icinga\Util\String; use Zend_Controller_Action; use Zend_Controller_Action_Interface; use Zend_Controller_Dispatcher_Exception; @@ -43,7 +44,7 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard parent::dispatch($request, $response); return; } - $controllerName = ucfirst($controllerName) . 'Controller'; + $controllerName = String::cname($controllerName, '-') . 'Controller'; $moduleName = $request->getModuleName(); if ($moduleName === null || $moduleName === $this->_defaultModule) { $controllerClass = 'Icinga\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName; diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 6c53d6700..3b2b16d30 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -22,6 +22,7 @@ class JavaScript 'js/icinga/history.js', 'js/icinga/module.js', 'js/icinga/timezone.js', + 'js/icinga/behavior/application-state.js', 'js/icinga/behavior/tooltip.js', 'js/icinga/behavior/sparkline.js', 'js/icinga/behavior/tristate.js', diff --git a/public/js/icinga/behavior/application-state.js b/public/js/icinga/behavior/application-state.js new file mode 100644 index 000000000..e989da389 --- /dev/null +++ b/public/js/icinga/behavior/application-state.js @@ -0,0 +1,31 @@ +/*! Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ + +// @TODO(el): https://dev.icinga.org/issues/10646 +(function(Icinga, $) { + + 'use strict'; + + Icinga.Behaviors = Icinga.Behaviors || {}; + + var ApplicationState = function (icinga) { + Icinga.EventListener.call(this, icinga); + this.on('rendered', this.onRendered, this); + this.icinga = icinga; + }; + + ApplicationState.prototype = new Icinga.EventListener(); + + ApplicationState.prototype.onRendered = function(e) { + var _this = e.data.self; + if (! $('#application-state').length) { + $('#layout').append( + '' + ); + } + }; + + Icinga.Behaviors.ApplicationState = ApplicationState; + +})(Icinga, jQuery);