2009-06-30 09:29:51 +00:00
|
|
|
<?php
|
2009-06-30 10:46:00 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/timeout_functions.php,v 1.10 2007/12/15 07:50:33 wurley Exp $
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A collection of functions used throughout phpLDAPadmin for the timeout and automatic logout feature
|
|
|
|
* @author Samuel Tran
|
|
|
|
* @package phpLDAPadmin
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responsible for setting/updating two session-vars that are used for the timeout and auto logout feature:
|
|
|
|
* - "activity" var records the server last activity.
|
|
|
|
* - "rightframe_server_id" var records the ID of the server active on the right frame.
|
|
|
|
* where X is the * ID of the server which the user is working on
|
|
|
|
*
|
|
|
|
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-06-30 10:26:08 +00:00
|
|
|
function set_lastactivity($ldapserver) {
|
2009-06-30 09:40:37 +00:00
|
|
|
if (DEBUG_ENABLED)
|
2009-06-30 10:26:08 +00:00
|
|
|
debug_log('set_lastactivity(): Entered with (%s)',1,$ldapserver->server_id);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
$_SESSION['activity']['server'][$ldapserver->server_id] = time();
|
|
|
|
$_SESSION['activity']['rightframe_server_id'] = $ldapserver->server_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the session-var "lastactivity_X" set by update_lastactivity()
|
|
|
|
* where X is the * ID of the server
|
|
|
|
*
|
|
|
|
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
|
|
|
|
*/
|
2009-06-30 10:26:08 +00:00
|
|
|
function unset_lastactivity($ldapserver) {
|
2009-06-30 09:40:37 +00:00
|
|
|
if (DEBUG_ENABLED)
|
2009-06-30 10:26:08 +00:00
|
|
|
debug_log('unset_lastactivity(): Entered with (%s)',1,$ldapserver->server_id);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
if (isset($_SESSION['activity']['server'][$ldapserver->server_id]))
|
2009-06-30 10:46:00 +00:00
|
|
|
unset($_SESSION['activity']['server'][$ldapserver->server_id]);
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if custom session timeout has been reached for server $ldapserver.
|
|
|
|
* If it has:
|
2009-06-30 10:26:08 +00:00
|
|
|
* - automatically log out user by calling $ldapserver->unsetLoginDN()
|
2009-06-30 09:29:51 +00:00
|
|
|
* - if $server_id is equal to right frame $server_id, load timeout.php page in the right frame
|
|
|
|
* - return true
|
|
|
|
*
|
|
|
|
* @param object $ldapserver The LDAPServer object of the server which the user has logged in.
|
|
|
|
* @return bool true on success, false on failure.
|
|
|
|
*/
|
2009-06-30 10:26:08 +00:00
|
|
|
function session_timed_out($ldapserver) {
|
2009-06-30 09:40:37 +00:00
|
|
|
if (DEBUG_ENABLED)
|
2009-06-30 10:26:08 +00:00
|
|
|
debug_log('session_timed_out(): Entered with (%s)',1,$ldapserver->server_id);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
# If session hasn't expired yet
|
2009-06-30 10:26:08 +00:00
|
|
|
if (isset($_SESSION['activity']['server'][$ldapserver->server_id])) {
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
# If $session_timeout not defined, use (session_cache_expire() - 1)
|
2009-06-30 09:29:51 +00:00
|
|
|
if (! isset($ldapserver->session_timeout))
|
|
|
|
$session_timeout = session_cache_expire()-1;
|
|
|
|
else
|
|
|
|
$session_timeout = $ldapserver->session_timeout;
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
# Get the $last_activity and $rightframe_server_id value
|
2009-06-30 09:29:51 +00:00
|
|
|
$last_activity = $_SESSION['activity']['server'][$ldapserver->server_id];
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
# If diff between current time and last activity greater than $session_timeout, log out user
|
|
|
|
if ((time()-$last_activity) > ($session_timeout*60)) {
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
if (in_array($ldapserver->auth_type,array('cookie','session'))) {
|
2009-06-30 10:26:08 +00:00
|
|
|
syslog_notice('Logout for '.$ldapserver->getLoggedInDN());
|
|
|
|
$ldapserver->unsetLoginDN() or pla_error(_('Could not logout.'));
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
return true;
|
2009-06-30 09:29:51 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
return false;
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
2009-06-30 10:46:00 +00:00
|
|
|
?>
|