source: trunk/phpgwapi/inc/class.sessions_php4.inc.php @ 7201

Revision 7201, 7.8 KB checked in by cristiano, 12 years ago (diff)

Ticket #2878 - ExpressoAdmin - Total de Sessões não está funcionando

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare API - Session management                                      *
4  * This file written by Dan Kuykendall <seek3r@phpgroupware.org>            *
5  * and Joseph Engo <jengo@phpgroupware.org>                                 *
6  * and Ralf Becker <ralfbecker@outdoor-training.de>                         *
7  * Copyright (C) 2000, 2001 Dan Kuykendall                                  *
8  * -------------------------------------------------------------------------*
9  * This library is part of the phpGroupWare API                             *
10  * http://www.egroupware.org/api                                            *
11  * ------------------------------------------------------------------------ *
12  * This library is free software; you can redistribute it and/or modify it  *
13  * under the terms of the GNU Lesser General Public License as published by *
14  * the Free Software Foundation; either version 2.1 of the License,         *
15  * or any later version.                                                    *
16  * This library is distributed in the hope that it will be useful, but      *
17  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
19  * See the GNU Lesser General Public License for more details.              *
20  * You should have received a copy of the GNU Lesser General Public License *
21  * along with this library; if not, write to the Free Software Foundation,  *
22  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
23  \**************************************************************************/
24
25
26        class sessions extends sessions_
27        {
28                function sessions()
29                {
30                        $this->sessions_();
31                        //controls the time out for php4 sessions - skwashd 18-May-2003
32                        ini_set('session.gc_maxlifetime', $GLOBALS['phpgw_info']['server']['sessions_timeout']);
33                        session_name('sessionid');
34                }
35
36                function read_session()
37                {
38                        if (!$this->sessionid)
39                        {
40                                return False;
41                        }
42                        session_id($this->sessionid);
43                        session_start();
44                        return $GLOBALS['phpgw_session'] = $_SESSION['phpgw_session'];
45                }
46
47                function set_cookie_params($domain)
48                {
49                        session_set_cookie_params(0,'/',$domain);
50                }
51
52                function new_session_id()
53                {
54                        session_start();
55
56                        return session_id();
57                }
58
59                function register_session($login,$user_ip,$now,$session_flags)
60                {
61                        // session_start() is now called in new_session_id() !!!
62
63                        $GLOBALS['phpgw_session']['session_id'] = $this->sessionid;
64                        $GLOBALS['phpgw_session']['session_lid'] = $login;
65                        $GLOBALS['phpgw_session']['session_ip'] = $user_ip;
66                        $GLOBALS['phpgw_session']['session_logintime'] = $now;
67                        $GLOBALS['phpgw_session']['session_dla'] = $now;
68                        $GLOBALS['phpgw_session']['session_action'] = $_SERVER['PHP_SELF'];
69                        $GLOBALS['phpgw_session']['session_flags'] = $session_flags;
70                        // we need the install-id to differ between serveral installs shareing one tmp-dir
71                        $GLOBALS['phpgw_session']['session_install_id'] = $GLOBALS['phpgw_info']['server']['install_id'];
72
73                        $_SESSION['phpgw_session'] = $GLOBALS['phpgw_session'];
74                }
75
76                // This will update the DateLastActive column, so the login does not expire
77                function update_dla()
78                {
79                        if (@isset($_GET['menuaction']))
80                        {
81                                $action = $_GET['menuaction'];
82                        }
83                        else
84                        {
85                                $action = $_SERVER['PHP_SELF'];
86                        }
87
88                        // This way XML-RPC users aren't always listed as
89                        // xmlrpc.php
90                        if ($this->xmlrpc_method_called)
91                        {
92                                $action = $this->xmlrpc_method_called;
93                        }
94
95                        $GLOBALS['phpgw_session']['session_dla'] = time();
96                        $GLOBALS['phpgw_session']['session_action'] = $action;
97
98                        $_SESSION['phpgw_session'] = $GLOBALS['phpgw_session'];
99
100                        return True;
101                }
102
103                function destroy($sessionid, $kp3)
104                {
105                        if (!$sessionid && $kp3)
106                        {
107                                return False;
108                        }
109
110                        $this->log_access($this->sessionid);    // log logout-time
111
112                        // Only do the following, if where working with the current user
113                        if ($sessionid == $GLOBALS['phpgw_info']['user']['sessionid'])
114                        {
115                                session_unset();
116                                //echo "<p>sessions_php4::destroy: session_destroy() returned ".(session_destroy() ? 'True' : 'False')."</p>\n";
117                                @session_destroy();
118                                if ($GLOBALS['phpgw_info']['server']['usecookies'])
119                                {
120                                        $this->phpgw_setcookie(session_name());
121                                }
122                        }
123                        else
124                        {
125                                if(@opendir($path = ini_get('session.save_path'))){
126                                        $session_file = $path."/sess_".$sessionid;
127                                        if (file_exists($session_file))
128                                                @unlink($session_file);
129                                }
130                        }
131
132                        return True;
133                }
134
135                /*************************************************************************\
136                * Functions for appsession data and session cache                         *
137                \*************************************************************************/
138                function delete_cache($accountid='')
139                {
140                        $account_id = get_account_id($accountid,$this->account_id);
141
142                        $GLOBALS['phpgw_session']['phpgw_app_sessions']['phpgwapi']['phpgw_info_cache'] = '';
143
144                        $_SESSION['phpgw_session'] = $GLOBALS['phpgw_session'];
145                }
146
147                function appsession($location = 'default', $appname = '', $data = '##NOTHING##')
148                {
149                        if (! $appname)
150                        {
151                                $appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
152                        }
153
154                        /* This allows the user to put '' as the value. */
155                        if ($data == '##NOTHING##')
156                        {
157                                // I added these into seperate steps for easier debugging
158                                $data = $GLOBALS['phpgw_session']['phpgw_app_sessions'][$appname][$location]['content'];
159
160                                /* do not decrypt and return if no data (decrypt returning garbage) */
161                                if($data)
162                                {
163                                        $data = $GLOBALS['phpgw']->crypto->decrypt($data);
164                                        //echo "appsession returning: location='$location',app='$appname',data=$data"; _debug_array($data);
165                                        return $data;
166                                }
167                        }
168                        else
169                        {
170                                $encrypteddata = $GLOBALS['phpgw']->crypto->encrypt($data);
171                                $GLOBALS['phpgw_session']['phpgw_app_sessions'][$appname][$location]['content'] = $encrypteddata;
172                                $_SESSION['phpgw_session'] = $GLOBALS['phpgw_session'];
173                                return $data;
174                        }
175                }
176
177                function session_sort($a,$b)
178                {
179                        $sign = strcasecmp($GLOBALS['phpgw']->session->sort_order,'ASC') ? 1 : -1;
180
181                        return strcasecmp(
182                                $a[$GLOBALS['phpgw']->session->sort_by],
183                                $b[$GLOBALS['phpgw']->session->sort_by]
184                        ) * $sign;
185                }
186
187                /*!
188                @function list_sessions
189                @abstract get list of normal / non-anonymous sessions
190                @note The data form the session-files get cached in the app_session phpgwapi/php4_session_cache
191                @author ralfbecker
192                */
193                function list_sessions($start,$order,$sort,$all_no_sort = False)
194                {
195
196                        $values = array();
197                        $maxmatchs = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
198                        $dir = @opendir($path = ini_get('session.save_path'));
199                        if (!$dir)      // eg. openbasedir restrictions
200                        {
201                                return $values;
202                        }
203                        while ($file = readdir($dir))
204                        {
205                                if (substr($file,0,5) != 'sess_' || !is_readable($path. '/' . $file))
206                                {
207                                        continue;
208                                }
209                                $session = '';
210                                if (($fd = fopen ($path . '/' . $file,'r')))
211                                {
212                                        $session = ($size = filesize ($path . '/' . $file)) ? @fread ($fd, $size) : 0;
213                                        fclose ($fd);
214                                }
215                                $session = unserialize(substr($session,(strpos($session, 'phpgw_session|') + 14)));
216                if(is_array($session) && isset($session['session_id']))
217                                    $values[$session['session_id']] = $session;
218                        }
219                        closedir($dir);
220
221                        if(!$all_no_sort)
222                        {
223                                $GLOBALS['phpgw']->session->sort_by = $sort;
224                                $GLOBALS['phpgw']->session->sort_order = $order;
225
226                                uasort($values,array('sessions','session_sort'));
227
228                                $i = 0;
229                                $start = (int)$start;
230                                foreach($values as $id => $data)
231                                {
232                                        if($i < $start || $i > $start+$maxmatchs)
233                                        {
234                                                unset($values[$id]);
235                                        }
236                                        ++$i;
237                                }
238                                reset($values);
239                        }
240
241                        return $values;
242                }
243
244                /*!
245                @function total
246                @abstract get number of normal / non-anonymous sessions
247                @author ralfbecker
248                */
249                function total()
250                {
251                        return count($this->list_sessions(0,'','',True));
252                }
253        }
Note: See TracBrowser for help on using the repository browser.