~ubuntu-branches/ubuntu/utopic/phpldapadmin/utopic

« back to all changes in this revision

Viewing changes to lib/timeout_functions.php

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2010-05-10 06:15:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100510061532-s4m6ytom0eb7oam1
Tags: 1.2.0.5-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Merged call to dh_install to install debian/additional-templates/*
  - added groupOfNames.xml
  - Adds php_value memory_limit 32M to the apache.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/timeout_functions.php,v 1.10.2.4 2008/12/13 08:57:09 wurley Exp $
3
 
 
4
 
/**
5
 
 * A collection of functions used throughout phpLDAPadmin for the timeout and automatic logout feature
6
 
 * @author Samuel Tran
7
 
 * @package phpLDAPadmin
8
 
 *
9
 
 */
10
 
 
11
 
/**
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
15
 
 *
16
 
 * @param object $ldapserver The LDAPServer object of the server which the user has logged in.
17
 
 * @return bool
18
 
 */
19
 
function set_lastactivity($ldapserver) {
20
 
        if (DEBUG_ENABLED)
21
 
                debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
22
 
 
23
 
        $_SESSION['activity']['server'][$ldapserver->server_id] = time();
24
 
        return true;
25
 
}
26
 
 
27
 
/**
28
 
 * Remove the session-var "lastactivity_X" set by update_lastactivity()
29
 
 * where X is the * ID of the server
30
 
 *
31
 
 * @param object $ldapserver The LDAPServer object of the server which the user has logged in.
32
 
 */
33
 
function unset_lastactivity($ldapserver) {
34
 
        if (DEBUG_ENABLED)
35
 
                debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
36
 
 
37
 
        if (isset($_SESSION['activity']['server'][$ldapserver->server_id]))
38
 
                unset($_SESSION['activity']['server'][$ldapserver->server_id]);
39
 
}
40
 
 
41
 
/**
42
 
 * Check if custom session timeout has been reached for server $ldapserver.
43
 
 * If it has:
44
 
 *      - automatically log out user by calling $ldapserver->unsetLoginDN()
45
 
 *      - return true
46
 
 *
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.
49
 
 */
50
 
function session_timed_out($ldapserver) {
51
 
        if (DEBUG_ENABLED)
52
 
                debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$ldapserver->server_id);
53
 
 
54
 
        # If session hasn't expired yet
55
 
        if (isset($_SESSION['activity']['server'][$ldapserver->server_id])) {
56
 
 
57
 
                # If $session_timeout not defined, use (session_cache_expire() - 1)
58
 
                if (! isset($ldapserver->session_timeout))
59
 
                        $session_timeout = session_cache_expire()-1;
60
 
                else
61
 
                        $session_timeout = $ldapserver->session_timeout;
62
 
 
63
 
                # Get the $last_activity value
64
 
                $last_activity = $_SESSION['activity']['server'][$ldapserver->server_id];
65
 
 
66
 
                # If diff between current time and last activity greater than $session_timeout, log out user
67
 
                if ((time()-$last_activity) > ($session_timeout*60)) {
68
 
 
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');
72
 
                        }
73
 
 
74
 
                        return true;
75
 
 
76
 
                }
77
 
        }
78
 
 
79
 
        return false;
80
 
}
81
 
?>