Refresh session every 10 minutes

Quick and dirty fix.

fixes #10229
This commit is contained in:
Eric Lippmann 2015-11-16 14:19:33 +01:00
parent 2e3082a75a
commit 0cc54ce34b
6 changed files with 84 additions and 1 deletions

View File

@ -0,0 +1,39 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Controllers;
use Icinga\Application\Icinga;
use Icinga\Web\Controller;
use Icinga\Web\Session;
/**
* @TODO(el): https://dev.icinga.org/issues/10646
*/
class ApplicationStateController extends Controller
{
public function indexAction()
{
if (isset($_COOKIE['icingaweb2-session'])) {
$last = (int) $_COOKIE['icingaweb2-session'];
} else {
$last = 0;
}
$now = time();
if ($last + 60 < $now) {
Session::getSession()->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);
}
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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',

View File

@ -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(
'<div id="application-state" class="container" style="display: none" data-icinga-url="'
+ _this.icinga.loader.baseUrl
+ '/application-state" data-icinga-refresh="60"></div>'
);
}
};
Icinga.Behaviors.ApplicationState = ApplicationState;
})(Icinga, jQuery);