diff --git a/index.php b/index.php index 15be026dcd..49b1094adf 100644 --- a/index.php +++ b/index.php @@ -53,6 +53,9 @@ if (! empty($_REQUEST['target']) exit; } +if (isset($_REQUEST['ajax_request']) && ! empty($_REQUEST['access_time'])) { + exit; +} /** * Check if it is an ajax request to reload the recent tables list. */ diff --git a/js/functions.js b/js/functions.js index 41cfed39ba..26d6246efb 100644 --- a/js/functions.js +++ b/js/functions.js @@ -676,6 +676,60 @@ var last_clicked_row = -1; */ var last_shift_clicked_row = -1; +var _idleSecondsCounter = 0; +var IncInterval; +var updateInterval; +AJAX.registerTeardown('functions.js', function () { + clearInterval(updateInterval); + clearInterval(IncInterval); +}); + +AJAX.registerOnload('functions.js', function () { + document.onclick = function() { + _idleSecondsCounter = 0; + }; + document.onmousemove = function() { + _idleSecondsCounter = 0; + }; + document.onkeypress = function() { + _idleSecondsCounter = 0; + }; + + function SetIdleTime() { + _idleSecondsCounter++; + } + function UpdateIdleTime() { + var href = 'index.php'; + var params = { + 'ajax_request' : true, + 'token' : PMA_commonParams.get('token'), + 'db' : PMA_commonParams.get('db'), + 'access_time':_idleSecondsCounter + }; + $.ajax({ + type: 'POST', + url: href, + data: params, + success: function (data) { + clearInterval(updateInterval); + if (data.success) { + if (PMA_commonParams.get('LoginCookieValidity')-_idleSecondsCounter > 5) { + updateInterval = window.setInterval(UpdateIdleTime, (PMA_commonParams.get('LoginCookieValidity')-_idleSecondsCounter-5)*1000); + } else { + updateInterval = window.setInterval(UpdateIdleTime, 2000); + } + } else { //timeout occured + window.location.reload(true); + clearInterval(IncInterval); + } + } + }); + } + if (PMA_commonParams.get('logged_in')) { + IncInterval = window.setInterval(SetIdleTime, 1000); + updateInterval = window.setInterval(UpdateIdleTime, (PMA_commonParams.get('LoginCookieValidity')-5)*1000); + } +}); /** * Unbind all event handlers before tearing down a page */ diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 1d88d90290..61f1a3836e 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -237,7 +237,9 @@ class PMA_Header ), 'LimitChars' => $GLOBALS['cfg']['LimitChars'], 'pftext' => $pftext, - 'confirm' => $GLOBALS['cfg']['Confirm'] + 'confirm' => $GLOBALS['cfg']['Confirm'], + 'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'], + 'logged_in' => isset($GLOBALS['userlink']) ? true : false ); } diff --git a/libraries/plugins/auth/AuthenticationConfig.class.php b/libraries/plugins/auth/AuthenticationConfig.class.php index 0528e757fe..c6ec919715 100644 --- a/libraries/plugins/auth/AuthenticationConfig.class.php +++ b/libraries/plugins/auth/AuthenticationConfig.class.php @@ -49,7 +49,11 @@ class AuthenticationConfig extends AuthenticationPlugin { // try to workaround PHP 5 session garbage collection which // looks at the session file's last modified time - $_SESSION['last_access_time'] = time(); + if (isset($_REQUEST['access_time'])) { + $_SESSION['last_access_time'] = time()- $_REQUEST['access_time']; + } else { + $_SESSION['last_access_time'] = time(); + } return true; } diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index 625d67344f..a53f511685 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -554,8 +554,11 @@ class AuthenticationCookie extends AuthenticationPlugin // Avoid showing the password in phpinfo()'s output unset($GLOBALS['PHP_AUTH_PW']); unset($_SERVER['PHP_AUTH_PW']); - - $_SESSION['last_access_time'] = time(); + if (isset($_REQUEST['access_time'])) { + $_SESSION['last_access_time'] = time() - $_REQUEST['access_time']; + } else { + $_SESSION['last_access_time'] = time(); + } $this->createIV();