2
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/timeout_functions.php,v 1.10.2.4 2008/12/13 08:57:09 wurley Exp $
5
* A collection of functions used throughout phpLDAPadmin for the timeout and automatic logout feature
7
* @package phpLDAPadmin
12
* Responsible for setting/updating two session-vars that are used for the timeout and auto logout feature:
13
* - "activity" var records the server last activity.
14
* where X is the * ID of the server which the user is working on
16
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
19
function set_lastactivity($ldapserver) {
21
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
23
$_SESSION['activity']['server'][$ldapserver->server_id] = time();
28
* Remove the session-var "lastactivity_X" set by update_lastactivity()
29
* where X is the * ID of the server
31
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
33
function unset_lastactivity($ldapserver) {
35
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
37
if (isset($_SESSION['activity']['server'][$ldapserver->server_id]))
38
unset($_SESSION['activity']['server'][$ldapserver->server_id]);
42
* Check if custom session timeout has been reached for server $ldapserver.
44
* - automatically log out user by calling $ldapserver->unsetLoginDN()
47
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
48
* @return bool true on success, false on failure.
50
function session_timed_out($ldapserver) {
52
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
54
# If session hasn't expired yet
55
if (isset($_SESSION['activity']['server'][$ldapserver->server_id])) {
57
# If $session_timeout not defined, use (session_cache_expire() - 1)
58
if (! isset($ldapserver->session_timeout))
59
$session_timeout = session_cache_expire()-1;
61
$session_timeout = $ldapserver->session_timeout;
63
# Get the $last_activity value
64
$last_activity = $_SESSION['activity']['server'][$ldapserver->server_id];
66
# If diff between current time and last activity greater than $session_timeout, log out user
67
if ((time()-$last_activity) > ($session_timeout*60)) {
69
if (in_array($ldapserver->auth_type,array('cookie','session'))) {
70
syslog_notice('Logout for '.$ldapserver->getLoggedInDN());
71
$ldapserver->unsetLoginDN() or error(_('Could not logout.'),'error','index.php');