source: trunk/phpgwapi/inc/class.sessions.inc.php @ 2

Revision 2, 40.9 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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  * Parts Copyright (C) 2003 Free Software Foundation Inc                    *
9  * -------------------------------------------------------------------------*
10  * This library is part of the eGroupWare API                               *
11  * http://www.egroupware.org/api                                            * 
12  * ------------------------------------------------------------------------ *
13  * This library is free software; you can redistribute it and/or modify it  *
14  * under the terms of the GNU Lesser General Public License as published by *
15  * the Free Software Foundation; either version 2.1 of the License,         *
16  * or any later version.                                                    *
17  * This library is distributed in the hope that it will be useful, but      *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
20  * See the GNU Lesser General Public License for more details.              *
21  * You should have received a copy of the GNU Lesser General Public License *
22  * along with this library; if not, write to the Free Software Foundation,  *
23  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
24  \**************************************************************************/
25
26
27        /* sessions_type setup moved after the class below - milosch */
28
29        /**
30        * Session Management Libabray
31        *
32        * This allows eGroupWare to use php4 or database sessions
33        *
34        * @package phpgwapi
35        * @subpackage sessions
36        * @abstract
37        * @author NetUSE AG Boris Erdmann, Kristian Koehntopp <br> hacked on by phpGW
38        * @copyright &copy; 1998-2000 NetUSE AG Boris Erdmann, Kristian Koehntopp <br> &copy; 2003 FreeSoftware Foundation
39        * @license LGPL
40        * @link http://www.sanisoft.com/phplib/manual/DB_sql.php
41        * @uses db
42        */
43
44        class sessions_
45        {
46                /**
47                * @var string current user login
48                */
49                var $login;
50
51                /**
52                * @var string current user password
53                */
54                var $passwd;
55
56                /**
57                * @var int current user db/ldap account id
58                */
59                var $account_id;
60
61                /**
62                * @var string current user account login id - ie user@domain
63                */
64                var $account_lid;
65
66                /**
67                * @var string previous page call id - repost prevention
68                */
69                var $history_id;
70
71                /**
72                * @var string domain for current user
73                */
74                var $account_domain;
75
76                /**
77                * @var session type flag, A - anonymous session, N - None, normal session
78                */
79                var $session_flags;
80
81                /**
82                * @var string current user session id
83                */
84                var $sessionid;
85
86                /**
87                * @var string not sure what this does, but it is important :)
88                */
89                var $kp3;
90
91                /**
92                * @var string encryption key?
93                */
94                var $key;
95
96                /**
97                * @var string iv == ivegotnoidea ;) (skwashd)
98                */
99                var $iv;
100
101                /**
102                * @var session data
103                */
104                var $data;
105       
106                /**
107                * @var object holder for the database object
108                */
109                var $db;
110       
111                /**
112                * @var array publicly available methods
113                */
114                var $public_functions = array(
115                        'list_methods' => True,
116                        'update_dla'   => True,
117                        'list'         => True,
118                        'total'        => True
119                );
120
121                /**
122                * @var string domain for cookies
123                */
124                var $cookie_domain;
125
126                /**
127                * @var name of XML-RPC/SOAP method called
128                */
129                var $xmlrpc_method_called;
130
131                /**
132                * Constructor just loads up some defaults from cookies
133                */
134                function sessions_()
135                {
136                        $this->db = $GLOBALS['phpgw']->db;
137                        $this->sessionid = get_var('sessionid',array('GET','COOKIE'));
138                        $this->kp3       = get_var('kp3',array('GET','COOKIE'));
139                        /* Create the crypto object */
140                        $GLOBALS['phpgw']->crypto = CreateObject('phpgwapi.crypto');
141                        if ($GLOBALS['phpgw_info']['server']['usecookies'])
142                        {
143                                $this->phpgw_set_cookiedomain();
144                        }
145                        // verfiy and if necessary create and save our config settings
146                        //
147                        $save_rep = False;
148                        if (!isset($GLOBALS['phpgw_info']['server']['max_access_log_age']))
149                        {
150                                $GLOBALS['phpgw_info']['server']['max_access_log_age'] = 90;    // default 90 days
151                                $save_rep = True;
152                        }
153                        if (!isset($GLOBALS['phpgw_info']['server']['block_time']))
154                        {
155                                $GLOBALS['phpgw_info']['server']['block_time'] = 30;    // default 30min
156                                $save_rep = True;
157                        }
158                        if (!isset($GLOBALS['phpgw_info']['server']['num_unsuccessful_id']))
159                        {
160                                $GLOBALS['phpgw_info']['server']['num_unsuccessful_id']  = 3;   // default 3 trys per id
161                                $save_rep = True;
162                        }
163                        if (!isset($GLOBALS['phpgw_info']['server']['num_unsuccessful_ip']))
164                        {
165                                $GLOBALS['phpgw_info']['server']['num_unsuccessful_ip']  = $GLOBALS['phpgw_info']['server']['num_unsuccessful_id'];     // default same as for id
166                                $save_rep = True;
167                        }
168                        if (!isset($GLOBALS['phpgw_info']['server']['install_id']))
169                        {
170                                $GLOBALS['phpgw_info']['server']['install_id']  = md5($GLOBALS['phpgw']->common->randomstring(15));
171                                $save_rep = True;
172                        }
173                        if (!isset($GLOBALS['phpgw_info']['server']['sessions_timeout']))
174                        {
175                                $GLOBALS['phpgw_info']['server']['sessions_timeout'] = 14400;
176                                $save_rep = True;
177                        }
178                        if (!isset($GLOBALS['phpgw_info']['server']['sessions_app_timeout']))
179                        {
180                                $GLOBALS['phpgw_info']['server']['sessions_app_timeout'] = 86400;
181                                $save_rep = True;
182                        }
183                        if (!isset($GLOBALS['phpgw_info']['server']['max_history']))
184                        {
185                                $GLOBALS['phpgw_info']['server']['max_history'] = 20;
186                                $save_rep = True;
187                        }
188                        if ($save_rep)
189                        {
190                                $config = CreateObject('phpgwapi.config','phpgwapi');
191                                $config->read_repository();
192                                $config->value('max_access_log_age',$GLOBALS['phpgw_info']['server']['max_access_log_age']);
193                                $config->value('block_time',$GLOBALS['phpgw_info']['server']['block_time']);
194                                $config->value('num_unsuccessful_id',$GLOBALS['phpgw_info']['server']['num_unsuccessful_id']);
195                                $config->value('num_unsuccessful_ip',$GLOBALS['phpgw_info']['server']['num_unsuccessful_ip']);
196                                $config->value('install_id',$GLOBALS['phpgw_info']['server']['install_id']);
197                                $config->value('sessions_timeout',$GLOBALS['phpgw_info']['server']['sessions_timeout']);
198                                $config->value('sessions_app_timeout',$GLOBALS['phpgw_info']['server']['sessions_app_timeout']);
199                                $config->save_repository();
200                                unset($config);
201                        }
202                }
203
204                /**
205                * Introspection for XML-RPC/SOAP
206                * Diabled - why??
207                *
208                * @param string $_type tpye of introspection being sought
209                * @return array available methods and args
210                */
211                function DONTlist_methods($_type)
212                {
213                        if (is_array($_type))
214                        {
215                                $_type = $_type['type'];
216                        }
217
218                        switch($_type)
219                        {
220                                case 'xmlrpc':
221                                        $xml_functions = array(
222                                                'list_methods' => array(
223                                                        'function'  => 'list_methods',
224                                                        'signature' => array(array(xmlrpcStruct,xmlrpcString)),
225                                                        'docstring' => lang('Read this list of methods.')
226                                                ),
227                                                'update_dla' => array(
228                                                        'function'  => 'update_dla',
229                                                        'signature' => array(array(xmlrpcBoolean)),
230                                                        'docstring' => lang('Returns an array of todo items')
231                                                )
232                                        );
233                                        return $xml_functions;
234                                        break;
235                                case 'soap':
236                                        return $this->soap_functions;
237                                        break;
238                                default:
239                                        return array();
240                                        break;
241                        }
242                }
243
244                function split_login_domain($both,&$login,&$domain)
245                {
246                        $parts = explode('@',$both);
247                        $domain = count($parts) > 1 ? array_pop($parts) :
248                                $GLOBALS['phpgw_info']['server']['default_domain'];
249                        $login = implode('@',$parts);
250                }
251
252                /**
253                * Check to see if a session is still current and valid
254                *
255                * @param string $sessionid session id to be verfied
256                * @param string $kp3 ?? to be verified
257                * @return bool is the session valid?
258                */
259                function verify($sessionid='',$kp3='')
260                {
261                        if(empty($sessionid) || !$sessionid)
262                        {
263                                $sessionid = get_var('sessionid',array('GET','COOKIE'));
264                                $kp3       = get_var('kp3',array('GET','COOKIE'));
265                        }
266
267                        $this->sessionid = $sessionid;
268                        $this->kp3       = $kp3;
269
270                        $session = $this->read_session();
271                        //echo "<pre>session::verify(id='$sessionid'): \n".print_r($session,True)."</pre>\n";
272                        /*
273                        $fp = fopen('/tmp/session_verify','a+');
274                        fwrite($fp,"session::verify(id='$sessionid'): \n".print_r($session,True)."\n\n");
275                        fclose($fp);
276                        */
277                        if ($session['session_dla'] <= (time() - $GLOBALS['phpgw_info']['server']['sessions_timeout']))
278                        {
279                                $this->destroy($sessionid,$kp3);
280                                return False;
281                        }
282
283                        $this->session_flags = $session['session_flags'];
284
285                        sessions_::split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
286
287                        $GLOBALS['phpgw_info']['user']['kp3'] = $this->kp3;
288
289                        $this->update_dla();
290                        $this->account_id = $GLOBALS['phpgw']->accounts->name2id($this->account_lid);
291                        if (!$this->account_id)
292                        {
293                                return False;
294                        }
295
296                        $GLOBALS['phpgw_info']['user']['account_id'] = $this->account_id;
297
298                        /* init the crypto object before appsession call below */
299                        $this->key = md5($this->kp3 . $this->sessionid . @$GLOBALS['phpgw_info']['server']['encryptkey']);
300                        $this->iv  = $GLOBALS['phpgw_info']['server']['mcrypt_iv'];
301                        $GLOBALS['phpgw']->crypto->init(array($this->key,$this->iv));
302
303                        $this->read_repositories(@$GLOBALS['phpgw_info']['server']['cache_phpgw_info']);
304                       
305                        if ($this->user['expires'] != -1 && $this->user['expires'] < time())
306                        {
307                                if(is_object($GLOBALS['phpgw']->log))
308                                {
309                                        $GLOBALS['phpgw']->log->message(array(
310                                                'text' => 'W-VerifySession, account loginid %1 is expired',
311                                                'p1'   => $this->account_lid,
312                                                'line' => __LINE__,
313                                                'file' => __FILE__
314                                        ));
315                                        $GLOBALS['phpgw']->log->commit();
316                                }
317                                return False;
318                        }
319
320                        $GLOBALS['phpgw_info']['user']  = $this->user;
321                        $GLOBALS['phpgw_info']['hooks'] = $this->hooks;
322
323                        $GLOBALS['phpgw_info']['user']['session_ip'] = $session['session_ip'];
324                        $GLOBALS['phpgw_info']['user']['passwd']     = base64_decode($this->appsession('password','phpgwapi'));
325
326                        if ($this->account_domain != $GLOBALS['phpgw_info']['user']['domain'])
327                        {
328                                if(is_object($GLOBALS['phpgw']->log))
329                                {
330                                        $GLOBALS['phpgw']->log->message(array(
331                                                'text' => 'W-VerifySession, the domains %1 and %2 don\'t match',
332                                                'p1'   => $userid_array[1],
333                                                'p2'   => $GLOBALS['phpgw_info']['user']['domain'],
334                                                'line' => __LINE__,
335                                                'file' => __FILE__
336                                        ));
337                                        $GLOBALS['phpgw']->log->commit();
338                                }
339                                return False;
340                        }
341
342                        /* ExpressoLivre
343                           Necessário comentar para que o redirecionamento de uma sessão
344                           https para uma http funcionasse atrás de um proxy
345                        */
346
347                        /*
348                        if (@$GLOBALS['phpgw_info']['server']['sessions_checkip'])
349                        {
350                                if((PHP_OS != 'Windows') && (PHP_OS != 'WINNT') &&
351                                        (!$GLOBALS['phpgw_info']['user']['session_ip'] || $GLOBALS['phpgw_info']['user']['session_ip'] != $this->getuser_ip())
352                                )
353                                {
354                                        //echo "IP do cliente com https   ---->  ".$GLOBALS['phpgw_info']['user']['session_ip'];
355                                        //echo "<BR>IP do cliente com http ---->  ".$this->getuser_ip();
356                                        if(is_object($GLOBALS['phpgw']->log))
357                                        {
358                                                // This needs some better wording
359                                                $GLOBALS['phpgw']->log->message(array(
360                                                        'text' => 'W-VerifySession, IP %1 doesn\'t match IP %2 in session table',
361                                                        'p1'   => $this->getuser_ip(),
362                                                        'p2'   => $GLOBALS['phpgw_info']['user']['session_ip'],
363                                                        'line' => __LINE__,
364                                                        'file' => __FILE__
365                                                ));
366                                                $GLOBALS['phpgw']->log->commit();
367                                        }
368                                        return False;
369                                }
370                        }
371                        */
372
373                        $GLOBALS['phpgw']->acl->acl($this->account_id);
374                        $GLOBALS['phpgw']->accounts->accounts($this->account_id);
375                        $GLOBALS['phpgw']->preferences->preferences($this->account_id);
376                        $GLOBALS['phpgw']->applications->applications($this->account_id);
377
378                        if (! $this->account_lid)
379                        {
380                                if(is_object($GLOBALS['phpgw']->log))
381                                {
382                                        // This needs some better wording
383                                        $GLOBALS['phpgw']->log->message(array(
384                                                'text' => 'W-VerifySession, account_id is empty',
385                                                'line' => __LINE__,
386                                                'file' => __FILE__
387                                        ));
388                                        $GLOBALS['phpgw']->log->commit();
389                                }
390                                //echo 'DEBUG: Sessions: account_id is empty!<br>'."\n";
391                                return False;
392                        }
393                        return True;
394                }
395
396                /**
397                * Functions for creating and verifying the session
398                */
399       
400                /**
401                * Get the ip address of current users
402                *
403                * @return string ip address
404                */
405                function getuser_ip()
406                {
407                /*
408                        if (getenv(HTTP_X_FORWARDED_FOR))
409                        {
410                                if (getenv(HTTP_CLIENT_IP))
411                                {
412                                        $ip=getenv(HTTP_CLIENT_IP);
413                                }
414                                else
415                                {
416                                        $ip=getenv(HTTP_X_FORWARDED_FOR);
417                                }
418                                $ip_proxy=getenv(REMOTE_ADDR);
419                        }
420                        else
421                        {
422                                $ip=getenv(REMOTE_ADDR);
423                        }
424                        return $ip;
425                */
426                        return (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
427                }
428
429                /**
430                * Set the domain used for cookies
431                *
432                * @return string domain
433                */
434                function phpgw_set_cookiedomain()
435                {
436                        // Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
437                        $this->cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
438
439                        // remove port from HTTP_HOST
440                        if (preg_match("/^(.*):(.*)$/",$this->cookie_domain,$arr))
441                        {
442                                $this->cookie_domain = $arr[1];
443                        }
444                        if (count(explode('.',$this->cookie_domain)) <= 1)
445                        {
446                                // setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
447                                $this->cookie_domain = '';
448                        }
449                        print_debug('COOKIE_DOMAIN',$this->cookie_domain,'api');
450
451                        $this->set_cookie_params($this->cookie_domain); // for php4 sessions necessary
452                }
453
454                /**
455                * Set a cookie
456                *
457                * @param string $cookiename name of cookie to be set
458                * @param string $cookievalue value to be used, if unset cookie is cleared (optional)
459                * @param int $cookietime when cookie should expire, 0 for session only (optional)
460                */
461                function phpgw_setcookie($cookiename,$cookievalue='',$cookietime=0)
462                {
463                        if (!$this->cookie_domain)
464                        {
465                                $this->phpgw_set_cookiedomain();
466                        }
467                        setcookie($cookiename,$cookievalue,$cookietime,'/',$this->cookie_domain);
468                }
469
470                /**
471                * Create a new session
472                *
473                * @param string $login user login
474                * @param string $passwd user password
475                * @param string $passwd_type type of password being used, ie plaintext, md5, sha1
476                * @return string session id
477                */
478                function create($login,$passwd = '',$passwd_type = '')
479                {
480                        if (is_array($login))
481                        {
482                                $this->login       = $login['login'];
483                                $this->passwd      = $login['passwd'];
484                                $this->passwd_type = $login['passwd_type'];
485                                $login             = $this->login;
486                        }
487                        else
488                        {
489                                $this->login       = $login;
490                                $this->passwd      = $passwd;
491                                $this->passwd_type = $passwd_type;
492                        }
493
494                        $this->clean_sessions();
495                        sessions_::split_login_domain($login,$this->account_lid,$this->account_domain);
496
497                        $now = time();
498
499                        //echo "<p>session::create(login='$login'): lid='$this->account_lid', domain='$this->account_domain'</p>\n";
500                        $user_ip = $this->getuser_ip();
501                               
502                        $this->account_id = $GLOBALS['phpgw']->accounts->name2id($this->account_lid);
503
504                        if (($blocked = $this->login_blocked($login,$user_ip)) ||       // too many unsuccessful attempts
505                                $GLOBALS['phpgw_info']['server']['global_denied_users'][$this->account_lid] ||
506                                !$GLOBALS['phpgw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
507                                $this->account_id && $GLOBALS['phpgw']->accounts->get_type($this->account_id) == 'g')
508                        {
509                                $this->reason = $blocked ? 'blocked, too many attempts' : 'bad login or password';
510                                $this->cd_reason = $blocked ? 99 : 5;
511
512                                $this->log_access($this->reason,$login,$user_ip,0);     // log unsuccessfull login
513                                return False;
514                        }
515
516                        if (!$this->account_id && $GLOBALS['phpgw_info']['server']['auto_create_acct'] == True)
517                        {
518                                $this->account_id = $GLOBALS['phpgw']->accounts->auto_add($this->account_lid, $passwd);
519                        }
520
521                        $GLOBALS['phpgw_info']['user']['account_id'] = $this->account_id;
522                        $GLOBALS['phpgw']->accounts->accounts($this->account_id);
523                        $this->sessionid = $this->new_session_id();
524                        $this->kp3       = md5($GLOBALS['phpgw']->common->randomstring(15));
525
526                        if ($GLOBALS['phpgw_info']['server']['usecookies'])
527                        {
528                                $this->phpgw_setcookie('sessionid',$this->sessionid);
529                                $this->phpgw_setcookie('kp3',$this->kp3);
530                                $this->phpgw_setcookie('domain',$this->account_domain);
531                        }
532                        if ($GLOBALS['phpgw_info']['server']['usecookies'] || isset($_COOKIE['last_loginid']))
533                        {
534                                $this->phpgw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
535                                $this->phpgw_setcookie('last_domain',$this->account_domain,$now+1209600);
536                                $this->phpgw_setcookie('last_organization',$_POST['organization'],$now+1209600);
537                        }
538                        unset($GLOBALS['phpgw_info']['server']['default_domain']); /* we kill this for security reasons */
539
540                        /* init the crypto object */
541                        $this->key = md5($this->kp3 . $this->sessionid . $GLOBALS['phpgw_info']['server']['encryptkey']);
542                        $this->iv  = $GLOBALS['phpgw_info']['server']['mcrypt_iv'];
543                        $GLOBALS['phpgw']->crypto->init(array($this->key,$this->iv));
544
545                        $this->read_repositories(False);
546                        if ($this->user['expires'] != -1 && $this->user['expires'] < time())
547                        {
548                                if(is_object($GLOBALS['phpgw']->log))
549                                {
550                                        $GLOBALS['phpgw']->log->message(array(
551                                                'text' => 'W-LoginFailure, account loginid %1 is expired',
552                                                'p1'   => $this->account_lid,
553                                                'line' => __LINE__,
554                                                'file' => __FILE__
555                                        ));
556                                        $GLOBALS['phpgw']->log->commit();
557                                }
558                                $this->reason = 'account is expired';
559                                $this->cd_reason = 98;
560
561                                return False;
562                        }
563
564                        $GLOBALS['phpgw_info']['user']  = $this->user;
565                        $GLOBALS['phpgw_info']['hooks'] = $this->hooks;
566
567                        $this->appsession('password','phpgwapi',base64_encode($this->passwd));
568                        if ($GLOBALS['phpgw']->acl->check('anonymous',1,'phpgwapi'))
569                        {
570                                $session_flags = 'A';
571                        }
572                        else
573                        {
574                                $session_flags = 'N';
575                        }
576
577                        $GLOBALS['phpgw']->db->transaction_begin();
578                        $this->register_session($login,$user_ip,$now,$session_flags);
579                        if ($session_flags != 'A')              // dont log anonymous sessions
580                        {
581                                $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
582                        }
583                        $this->appsession('account_previous_login','phpgwapi',$GLOBALS['phpgw']->auth->previous_login);
584                        // Expresso
585                        //$GLOBALS['phpgw']->auth->update_lastlogin($this->account_id,$user_ip);
586                        $GLOBALS['phpgw']->db->transaction_commit();
587
588                        //if (!$this->sessionid) echo "<p>session::create(login='$login') = '$this->sessionid': lid='$this->account_lid', domain='$this->account_domain'</p>\n";
589
590                        return $this->sessionid;
591                }
592
593                /**
594        * Write or update (for logout) the access_log
595                *
596                * @param string $sessionid id of session or 0 for unsuccessful logins
597                * @param string $login account_lid (evtl. with domain) or '' for settion the logout-time
598                * @param string $user_ip ip to log
599                * @param int $account_id numerical account_id
600                */
601                function log_access($sessionid,$login='',$user_ip='',$account_id='')
602                {
603                        $now = time();
604
605                        if ($login != '')
606                        {
607                                if (strlen($login) > 30)
608                                {
609                                        $login = substr($login,0,30);
610                                }
611                                $GLOBALS['phpgw']->db->query('INSERT INTO phpgw_access_log(sessionid,loginid,ip,li,lo,account_id)'
612                                        . " VALUES ('" . $sessionid . "','" . $this->db->db_addslashes($login). "','"
613                                        . $this->db->db_addslashes($user_ip) . "',$now,0," . (int)$account_id .')',__LINE__,__FILE__);
614                        }
615                        else
616                        {
617                                $GLOBALS['phpgw']->db->query("UPDATE phpgw_access_log SET lo=" . $now . " WHERE sessionid='"
618                                        . $sessionid . "'",__LINE__,__FILE__);
619                        }
620                        if ($GLOBALS['phpgw_info']['server']['max_access_log_age'])
621                        {
622                                $max_age = $now - $GLOBALS['phpgw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
623
624                                $GLOBALS['phpgw']->db->query("DELETE FROM phpgw_access_log WHERE li < $max_age");
625                        }
626                }
627
628                /**
629                * Protect against brute force attacks, block login if too many unsuccessful login attmepts
630        *
631                * @param string $login account_lid (evtl. with domain)
632                * @param string $ip ip of the user
633                * @returns bool login blocked?
634                */
635                function login_blocked($login,$ip)
636                {
637                        $blocked = False;
638                        $block_time = time() - $GLOBALS['phpgw_info']['server']['block_time'] * 60;
639                       
640                        $ip = $this->db->db_addslashes($ip);
641                        $this->db->query("SELECT count(*) FROM phpgw_access_log WHERE account_id=0 AND ip='$ip' AND li > $block_time",__LINE__,__FILE__);
642                        $this->db->next_record();
643                        if (($false_ip = $this->db->f(0)) > $GLOBALS['phpgw_info']['server']['num_unsuccessful_ip'])
644                        {
645                                //echo "<p>login_blocked: ip='$ip' ".$this->db->f(0)." trys (".$GLOBALS['phpgw_info']['server']['num_unsuccessful_ip']." max.) since ".date('Y/m/d H:i',$block_time)."</p>\n";
646                                $blocked = True;
647                        }
648                        $login = $this->db->db_addslashes($login);
649                        $this->db->query("SELECT count(*) FROM phpgw_access_log WHERE account_id=0 AND (loginid='$login' OR loginid LIKE '$login@%') AND li > $block_time",__LINE__,__FILE__);
650                        $this->db->next_record();
651                        if (($false_id = $this->db->f(0)) > $GLOBALS['phpgw_info']['server']['num_unsuccessful_id'])
652                        {
653                                //echo "<p>login_blocked: login='$login' ".$this->db->f(0)." trys (".$GLOBALS['phpgw_info']['server']['num_unsuccessful_id']." max.) since ".date('Y/m/d H:i',$block_time)."</p>\n";
654                                $blocked = True;
655                        }
656                        if ($blocked && $GLOBALS['phpgw_info']['server']['admin_mails'] &&
657                                // max. one mail each 5mins
658                                $GLOBALS['phpgw_info']['server']['login_blocked_mail_time'] < time()-5*60)
659                        {
660                                // notify admin(s) via email
661                                $from    = 'eGroupWare@'.$GLOBALS['phpgw_info']['server']['mail_suffix'];
662                                $subject = lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip);
663                                $body    = lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip);
664                               
665                                if(!is_object($GLOBALS['phpgw']->send))
666                                {
667                                        $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
668                                }
669                                $subject = $GLOBALS['phpgw']->send->encode_subject($subject);
670                                $admin_mails = explode(',',$GLOBALS['phpgw_info']['server']['admin_mails']);
671                                foreach($admin_mails as $to)
672                                {
673                                        $GLOBALS['phpgw']->send->msg('email',$to,$subject,$body,'','','',$from,$from);
674                                }
675                                // save time of mail, to not send to many mails
676                                $config = CreateObject('phpgwapi.config','phpgwapi');
677                                $config->read_repository();
678                                $config->value('login_blocked_mail_time',time());
679                                $config->save_repository();
680                        }
681                        return $blocked;
682                }
683
684                /**
685                * Verfy a peer server access request
686                *
687                * @param string $sessionid session id to verfiy
688                * @param string $kp3 ??
689                * @return bool verfied?
690                */
691                function verify_server($sessionid, $kp3)
692                {
693                        $GLOBALS['phpgw']->interserver = CreateObject('phpgwapi.interserver');
694                        $this->sessionid = $sessionid;
695                        $this->kp3       = $kp3;
696
697                        $session = $this->read_session();
698                        $this->session_flags = $session['session_flags'];
699
700                        list($this->account_lid,$this->account_domain) = explode('@', $session['session_lid']);
701                       
702                        if ($this->account_domain == '')
703                        {
704                                $this->account_domain = $GLOBALS['phpgw_info']['server']['default_domain'];
705                        }
706
707                        $GLOBALS['phpgw_info']['user']['kp3'] = $this->kp3;
708                        $phpgw_info_flags = $GLOBALS['phpgw_info']['flags'];
709
710                        $GLOBALS['phpgw_info']['flags'] = $phpgw_info_flags;
711
712                        $this->update_dla();
713                        $this->account_id = $GLOBALS['phpgw']->interserver->name2id($this->account_lid);
714
715                        if (!$this->account_id)
716                        {
717                                return False;
718                        }
719
720                        $GLOBALS['phpgw_info']['user']['account_id'] = $this->account_id;
721
722                        $this->read_repositories(@$GLOBALS['phpgw_info']['server']['cache_phpgw_info']);
723
724                        /* init the crypto object before appsession call below */
725                        $this->key = md5($this->kp3 . $this->sessionid . $GLOBALS['phpgw_info']['server']['encryptkey']);
726                        $this->iv  = $GLOBALS['phpgw_info']['server']['mcrypt_iv'];
727                        $GLOBALS['phpgw']->crypto->init(array($this->key,$this->iv));
728
729                        $GLOBALS['phpgw_info']['user']  = $this->user;
730                        $GLOBALS['phpgw_info']['hooks'] = $this->hooks;
731
732                        $GLOBALS['phpgw_info']['user']['session_ip'] = $session['session_ip'];
733                        $GLOBALS['phpgw_info']['user']['passwd'] = base64_decode($this->appsession('password','phpgwapi'));
734
735                        if ($userid_array[1] != $GLOBALS['phpgw_info']['user']['domain'])
736                        {
737                                if(is_object($GLOBALS['phpgw']->log))
738                                {
739                                        $GLOBALS['phpgw']->log->message(array(
740                                                'text' => 'W-VerifySession, the domains %1 and %2 don\t match',
741                                                'p1'   => $userid_array[1],
742                                                'p2'   => $GLOBALS['phpgw_info']['user']['domain'],
743                                                'line' => __LINE__,
744                                                'file' => __FILE__
745                                        ));
746                                        $GLOBALS['phpgw']->log->commit();
747                                }
748
749                                if(is_object($GLOBALS['phpgw']->crypto))
750                                {
751                                        $GLOBALS['phpgw']->crypto->cleanup();
752                                        unset($GLOBALS['phpgw']->crypto);
753                                }
754                                return False;
755                        }
756
757                        if(@$GLOBALS['phpgw_info']['server']['sessions_checkip'])
758                        {
759                                if((PHP_OS != 'Windows') && (PHP_OS != 'WINNT') &&
760                                        (!$GLOBALS['phpgw_info']['user']['session_ip'] || $GLOBALS['phpgw_info']['user']['session_ip'] != $this->getuser_ip())
761                                )
762                                {
763                                        if(is_object($GLOBALS['phpgw']->log))
764                                        {
765                                                // This needs some better wording
766                                                $GLOBALS['phpgw']->log->message(array(
767                                                        'text' => 'W-VerifySession, IP %1 doesn\'t match IP %2 in session table',
768                                                        'p1'   => $this->getuser_ip(),
769                                                        'p2'   => $GLOBALS['phpgw_info']['user']['session_ip'],
770                                                        'line' => __LINE__,
771                                                        'file' => __FILE__
772                                                ));
773                                                $GLOBALS['phpgw']->log->commit();
774                                        }
775
776                                        if(is_object($GLOBALS['phpgw']->crypto))
777                                        {
778                                                $GLOBALS['phpgw']->crypto->cleanup();
779                                                unset($GLOBALS['phpgw']->crypto);
780                                        }
781                                        return False;
782                                }
783                        }
784
785                        $GLOBALS['phpgw']->acl->acl($this->account_id);
786                        $GLOBALS['phpgw']->accounts->accounts($this->account_id);
787                        $GLOBALS['phpgw']->preferences->preferences($this->account_id);
788                        $GLOBALS['phpgw']->applications->applications($this->account_id);
789
790                        if (! $this->account_lid)
791                        {
792                                if(is_object($GLOBALS['phpgw']->log))
793                                {
794                                        // This needs some better wording
795                                        $GLOBALS['phpgw']->log->message(array(
796                                                'text' => 'W-VerifySession, account_id is empty',
797                                                'line' => __LINE__,
798                                                'file' => __FILE__
799                                        ));
800                                        $GLOBALS['phpgw']->log->commit();
801                                }
802
803                                if(is_object($GLOBALS['phpgw']->crypto))
804                                {
805                                        $GLOBALS['phpgw']->crypto->cleanup();
806                                        unset($GLOBALS['phpgw']->crypto);
807                                }
808                                return False;
809                        }
810                        else
811                        {
812                                return True;
813                        }
814                }
815
816                /**
817                * Validate a peer server login request
818                *
819                * @param string $login login name
820                * @param string $password password
821                * @return bool login ok?
822                */
823                function create_server($login,$passwd)
824                {
825                        $GLOBALS['phpgw']->interserver = CreateObject('phpgwapi.interserver');
826                        $this->login  = $login;
827                        $this->passwd = $passwd;
828                        $this->clean_sessions();
829                        $login_array = explode('@', $login);
830                        $this->account_lid = $login_array[0];
831                        $now = time();
832
833                        if ($login_array[1] != '')
834                        {
835                                $this->account_domain = $login_array[1];
836                        }
837                        else
838                        {
839                                $this->account_domain = $GLOBALS['phpgw_info']['server']['default_domain'];
840                        }
841
842                        $serverdata = array(
843                                'server_name' => $this->account_domain,
844                                'username'    => $this->account_lid,
845                                'password'    => $passwd
846                        );
847                        if (!$GLOBALS['phpgw']->interserver->auth($serverdata))
848                        {
849                                return False;
850                                exit;
851                        }
852
853                        if (!$GLOBALS['phpgw']->interserver->exists($this->account_lid))
854                        {
855                                $this->account_id = $GLOBALS['phpgw']->interserver->name2id($this->account_lid);
856                        }
857                        $GLOBALS['phpgw_info']['user']['account_id'] = $this->account_id;
858                        $GLOBALS['phpgw']->interserver->serverid = $this->account_id;
859
860                        $this->sessionid = md5($GLOBALS['phpgw']->common->randomstring(10));
861                        $this->kp3       = md5($GLOBALS['phpgw']->common->randomstring(15));
862
863                        /* re-init the crypto object */
864                        $this->key = md5($this->kp3 . $this->sessionid . $GLOBALS['phpgw_info']['server']['encryptkey']);
865                        $this->iv  = $GLOBALS['phpgw_info']['server']['mcrypt_iv'];
866                        $GLOBALS['phpgw']->crypto->init(array($this->key,$this->iv));
867
868                        //$this->read_repositories(False);
869
870                        $GLOBALS['phpgw_info']['user']  = $this->user;
871                        $GLOBALS['phpgw_info']['hooks'] = $this->hooks;
872
873                        $this->appsession('password','phpgwapi',base64_encode($this->passwd));
874                        $session_flags = 'S';
875
876                        $user_ip = $this->getuser_ip();
877
878                        $GLOBALS['phpgw']->db->transaction_begin();
879                        $this->register_session($login,$user_ip,$now,$session_flags);
880
881                        $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
882
883                        $this->appsession('account_previous_login','phpgwapi',$GLOBALS['phpgw']->auth->previous_login);
884                        $GLOBALS['phpgw']->auth->update_lastlogin($this->account_id,$user_ip);
885                        $GLOBALS['phpgw']->db->transaction_commit();
886
887                        return array($this->sessionid,$this->kp3);
888                }
889
890                /**
891                * Functions for appsession data and session cache
892                */
893
894                /**
895                * Is this also useless?? (skwashd)
896                */
897                function read_repositories($cached='',$write_cache=True)
898                {
899                        $GLOBALS['phpgw']->acl->acl($this->account_id);
900                        $GLOBALS['phpgw']->accounts->accounts($this->account_id);
901                        $GLOBALS['phpgw']->preferences->preferences($this->account_id);
902                        $GLOBALS['phpgw']->applications->applications($this->account_id);
903
904                        if(@$cached)
905                        {
906                                $this->user = $this->appsession('phpgw_info_cache','phpgwapi');
907                                if(!empty($this->user))
908                                {
909                                        $GLOBALS['phpgw']->preferences->data = $this->user['preferences'];
910                                        if (!isset($GLOBALS['phpgw_info']['apps']) || !is_array($GLOBALS['phpgw_info']['apps']))
911                                        {
912                                                $GLOBALS['phpgw']->applications->read_installed_apps();
913                                        }
914                                }
915                                else
916                                {
917                                        $this->setup_cache($write_cache);
918                                }
919                        }
920                        else
921                        {
922                                $this->setup_cache($write_cache);
923                        }
924                        $this->hooks = $GLOBALS['phpgw']->hooks->read();
925                }
926
927                /**
928                * Is this also useless?? (skwashd)
929                */
930                function setup_cache($write_cache=True)
931                {
932                        $this->user                = $GLOBALS['phpgw']->accounts->read_repository();
933                        $this->user['acl']         = $GLOBALS['phpgw']->acl->read_repository();
934                        $this->user['preferences'] = $GLOBALS['phpgw']->preferences->read_repository();
935                        $this->user['apps']        = $GLOBALS['phpgw']->applications->read_repository();
936                        //@reset($this->data['user']['apps']);
937
938                        $this->user['domain']      = $this->account_domain;
939                        $this->user['sessionid']   = $this->sessionid;
940                        $this->user['kp3']         = $this->kp3;
941                        $this->user['session_ip']  = $this->getuser_ip();
942                        $this->user['session_lid'] = $this->account_lid.'@'.$this->account_domain;
943                        $this->user['account_id']  = $this->account_id;
944                        $this->user['account_lid'] = $this->account_lid;
945                        $this->user['userid']      = $this->account_lid;
946                        $this->user['passwd']      = @$this->passwd;
947                        if(@$GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $write_cache)
948                        {
949                                $this->delete_cache();
950                                $this->appsession('phpgw_info_cache','phpgwapi',$this->user);
951                        }
952                }
953       
954                /**
955                * This looks to be useless
956                * This will capture everything in the $GLOBALS['phpgw_info'] including server info,
957                * and store it in appsessions.  This is really incompatible with any type of restoring
958                * from appsession as the saved user info is really in ['user'] rather than the root of
959                * the structure, which is what this class likes.
960                */
961                function save_repositories()
962                {
963                        $phpgw_info_temp = $GLOBALS['phpgw_info'];
964                        $phpgw_info_temp['user']['kp3'] = '';
965                        $phpgw_info_temp['flags'] = array();
966
967                        if ($GLOBALS['phpgw_info']['server']['cache_phpgw_info'])
968                        {
969                                $this->appsession('phpgw_info_cache','phpgwapi',$phpgw_info_temp);
970                        }
971                }
972
973                function restore()
974                {
975                        $sessionData = $this->appsession('sessiondata');
976
977                        if (!empty($sessionData) && is_array($sessionData))
978                        {
979                                foreach($sessionData as $key => $value)
980                                {
981                                        global $$key;
982                                        $$key = $value;
983                                        $this->variableNames[$key] = 'registered';
984                                        // echo 'restored: '.$key.', ' . $value . '<br>';
985                                }
986                        }
987                }
988
989                /**
990                * Save the current values of all registered variables
991                */
992                function save()
993                {
994                        if (is_array($this->variableNames))
995                        {
996                                reset($this->variableNames);
997                                while(list($key, $value) = each($this->variableNames))
998                                {
999                                        if ($value == 'registered')
1000                                        {
1001                                                global $$key;
1002                                                $sessionData[$key] = $$key;
1003                                        }
1004                                }
1005                                $this->appsession('sessiondata','',$sessionData);
1006                        }
1007                }
1008
1009                /**
1010                * Create a list a variable names, which data needs to be restored
1011                *
1012                * @param string $_variableName name of variable to be registered
1013                */
1014                function register($_variableName)
1015                {
1016                        $this->variableNames[$_variableName]='registered';
1017                        #print 'registered '.$_variableName.'<br>';
1018                }
1019
1020                /**
1021                * Mark variable as unregistered
1022                *
1023                * @param string $_variableName name of variable to deregister
1024                */
1025                function unregister($_variableName)
1026                {
1027                        $this->variableNames[$_variableName]='unregistered';
1028                        #print 'unregistered '.$_variableName.'<br>';
1029                }
1030
1031                /**
1032                * Check if we have a variable registred already
1033                *
1034                * @param string $_variableName name of variable to check
1035                * @return bool was the variable found?
1036                */
1037                function is_registered($_variableName)
1038                {
1039                        if ($this->variableNames[$_variableName] == 'registered')
1040                        {
1041                                return True;
1042                        }
1043                        else
1044                        {
1045                                return False;
1046                        }
1047                }
1048                /**
1049                * Additional tracking of user actions - prevents reposts/use of back button
1050                *
1051                * @author skwashd
1052                * @return string current history id
1053                */
1054                function generate_click_history()
1055                {
1056                        if(!isset($this->history_id))
1057                        {
1058                                $this->history_id = md5($this->login . time());
1059                                $history = $this->appsession($location = 'history', $appname = 'phpgwapi');
1060                               
1061                                if(count($history) >= $GLOBALS['phpgw_info']['server']['max_history'])
1062                                {
1063                                        array_shift($history);
1064                                        $this->appsession($location = 'history', $appname = 'phpgwapi', $history);
1065                                }
1066                        }
1067                        return $this->history_id;
1068                }
1069               
1070                /**
1071                * Detects if the page has already been called before - good for forms
1072                *
1073                * @author skwashd
1074                * @param bool $diplay_error when implemented will use the generic error handling code
1075                * @return True if called previously, else False - call ok
1076                */
1077                function is_repost($display_error = False)
1078                {
1079                        $history = $this->appsession($location = 'history', $appname = 'phpgwapi');
1080                        if(isset($history[$_GET['click_history']]))
1081                        {
1082                                if($display_error)
1083                                {
1084                                        $GLOBALS['phpgw']->redirect_link('/error.php', 'type=repost');//more on this later :)
1085                                }
1086                                else
1087                                {
1088                                        return True; //handled by the app
1089                                }
1090                        }
1091                        else
1092                        {
1093                                $history[$_GET['click_history']] = True;
1094                                $this->appsession($location = 'history', $appname = 'phpgwapi', $history);
1095                                return False;
1096                        }
1097                }
1098
1099                /**
1100                * Generate a url which supports url or cookies based sessions
1101                *
1102                * @param string $url a url relative to the egroupware install root
1103                * @param array $extravars query string arguements
1104                * @return string generated url
1105                */
1106                function link($url, $extravars = '')
1107                {
1108                        //echo "<p>session::link(url='".print_r($url,True)."',extravars='".print_r($extravars,True)."')";
1109                        /* first we process the $url to build the full scriptname */
1110                        $full_scriptname = True;
1111
1112                        $url_firstchar = substr($url ,0,1);
1113                        if ($url_firstchar == '/' && $GLOBALS['phpgw_info']['server']['webserver_url'] == '/')
1114                        {
1115                                $full_scriptname = False;
1116                        }
1117
1118                        if ($url_firstchar != '/')
1119                        {
1120                                $app = $GLOBALS['phpgw_info']['flags']['currentapp'];
1121                                if ($app != 'home' && $app != 'login' && $app != 'logout')
1122                                {
1123                                        $url = $app.'/'.$url;
1124                                }
1125                        }
1126
1127                        if($full_scriptname)
1128                        {
1129                                $webserver_url_count = strlen($GLOBALS['phpgw_info']['server']['webserver_url'])-1;
1130                                if(substr($GLOBALS['phpgw_info']['server']['webserver_url'] ,$webserver_url_count,1) != '/' && $url_firstchar != '/')
1131                                {
1132                                        $url = $GLOBALS['phpgw_info']['server']['webserver_url'] .'/'. $url;
1133                                }
1134                                else
1135                                {
1136                                        $url = $GLOBALS['phpgw_info']['server']['webserver_url'] . $url;
1137                                }
1138                        }
1139
1140                        if(@isset($GLOBALS['phpgw_info']['server']['enforce_ssl']) && $GLOBALS['phpgw_info']['server']['enforce_ssl']) // && !$_SERVER['HTTPS']) imho https should always be a full path - skwashd
1141                        {
1142                                if(substr($url ,0,4) != 'http')
1143                                {
1144                                        $url = 'https://'.$GLOBALS['phpgw_info']['server']['hostname'].$url;
1145                                }
1146                                else
1147                                {
1148                                        $url = str_replace ( 'http:', 'https:', $url);
1149                                }
1150                        }
1151
1152                        /* Now we process the extravars into a proper url format */
1153                        /* if its not an array, then we turn it into one */
1154                        /* We do this to help prevent any duplicates from being sent. */
1155                        if (!is_array($extravars) && $extravars != '')
1156                        {
1157                                $new_extravars = Array();
1158
1159                                $a = explode('&', $extravars);
1160                                $i = 0;
1161                                while ($i < count($a))
1162                                {
1163                                        $b = split('=', $a[$i],2);
1164                                        // Check if this value doesn't already exist in new_extravars
1165                                        if(array_key_exists($b[0], $new_extravars))
1166                                        {
1167                                                // print "Debug::Error !!! " . $b[0] . " ($i) already exists<br>";
1168                                                if( eregi("\[\]", $b[0]) )
1169                                                {
1170                                                        $b[0] = eregi_replace("\[\]", "[$i]", $b[0]);
1171                                                }
1172                                        }
1173
1174                                        $new_extravars[$b[0]] = $b[1];
1175                                        $i++;
1176                                }
1177                                $extravars = $new_extravars;
1178                                unset($new_extravars);
1179                        }
1180
1181                        /* if using frames we make sure there is a framepart */
1182                        if(@defined('PHPGW_USE_FRAMES') && PHPGW_USE_FRAMES)
1183                        {
1184                                if (!isset($extravars['framepart']))
1185                                {
1186                                        $extravars['framepart']='body';
1187                                }
1188                        }
1189
1190                        /* add session params if not using cookies */
1191                        if (@!$GLOBALS['phpgw_info']['server']['usecookies'])
1192                        {
1193                                $extravars['sessionid'] = $this->sessionid;
1194                                $extravars['kp3'] = $this->kp3;
1195                                $extravars['domain'] = $this->account_domain;
1196                        }
1197
1198                        //used for repost prevention
1199//                      $extravars['click_history'] = $this->generate_click_history();
1200
1201                        /* if we end up with any extravars then we generate the url friendly string */
1202                        if (is_array($extravars))
1203                        {
1204                                $new_extravars = '';
1205                                foreach($extravars as $key => $value)
1206                                {
1207                                        if (!empty($new_extravars))
1208                                        {
1209                                                $new_extravars .= '&';
1210                                        }
1211                                        $new_extravars .= $key.'='.urlencode($value);
1212                                }
1213                                $url .= '?' . $new_extravars;
1214                        }
1215                        //echo " = '$url'</p>\n";
1216                        return $url;
1217                }
1218
1219                /**
1220                * The remaining methods are abstract - as they are unique for each session handler
1221                */
1222
1223                /**
1224                * Load user's session information
1225                *
1226                * The sessionid of the session to read is passed in the class-var $this->sessionid
1227                *
1228                * @return mixed the session data
1229                */
1230                function read_session()
1231                {}
1232
1233                /**
1234                * Remove stale sessions out of the database
1235                */
1236                function clean_sessions()
1237                {}
1238
1239                /**
1240                * Set paramaters for cookies - only implemented in PHP4 sessions
1241                *
1242                * @param string $domain domain name to use in cookie
1243                */
1244
1245                function set_cookie_params($domain)
1246                {}
1247
1248                /**
1249                * Create a new session id
1250                *
1251                * @return string a new session id
1252                */
1253                function new_session_id()
1254                {}
1255
1256                /**
1257                * Create a new session
1258                *
1259                * @param string $login user login
1260                * @param string $user_ip users ip address
1261                * @param int $now time now as a unix timestamp
1262                * @param string $session_flags A = Anonymous, N = Normal
1263                */
1264                function register_session($login,$user_ip,$now,$session_flags)
1265                {}
1266
1267                /**
1268                * Update the date last active info for the session, so the login does not expire
1269                *
1270                * @return bool did it suceed?
1271                */
1272                function update_dla()
1273                {}
1274
1275                /**
1276                * Terminate a session
1277                *
1278                * @param string $sessionid the id of the session to be terminated
1279                * @param string $kp3 - NOT SURE
1280                * @return bool did it suceed?
1281                */
1282                function destroy($sessionid, $kp3)
1283                {}
1284
1285                /**
1286                * Functions for appsession data and session cache
1287                */
1288       
1289                /**
1290                * Delete all data from the session cache for a user
1291                *
1292                * @param int $accountid user account id, defaults to current user (optional)
1293                */
1294                function delete_cache($accountid='')
1295                {}
1296
1297                /**
1298                * Stores or retrieves information from the sessions cache
1299                *
1300                * @param string $location identifier for data
1301                * @param string $appname name of app which is responsbile for the data
1302                * @param mixed $data data to be stored, if left blank data is retreived (optional)
1303                * @return mixed data from cache, only returned if $data arg is not used
1304                */
1305                function appsession($location = 'default', $appname = '', $data = '##NOTHING##')
1306                {}
1307
1308                /**
1309                * Get list of normal / non-anonymous sessions
1310                * Note: The data from the session-files get cached in the app_session phpgwapi/php4_session_cache
1311                *
1312                * @author ralfbecker
1313                * @param int $start session to start at
1314                * @param string $order field to sort on
1315                * @param string $sort sort order
1316                * @param bool $all_no_sort list all with out sorting (optional) default False
1317                * @return array info for all current sessions
1318                */
1319                function list_sessions($start,$order,$sort,$all_no_sort = False)
1320                {}
1321               
1322                /**
1323                * Get the number of normal / non-anonymous sessions
1324                *
1325                * @author ralfbecker
1326                * @return int number of sessions
1327                */
1328                function total()
1329                {}
1330        }
1331
1332        if(empty($GLOBALS['phpgw_info']['server']['sessions_type']))
1333        {
1334                $GLOBALS['phpgw_info']['server']['sessions_type'] = 'php4';     // the more performant default
1335        }
1336        // for php4 sessions, check if the extension is loaded, try loading it and fallback to db sessions if not
1337        if ($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4' && !extension_loaded('session'))
1338        {
1339                // some constanst for pre php4.3
1340                if (!defined('PHP_SHLIB_SUFFIX'))
1341                {
1342                        define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
1343                }
1344                if (!defined('PHP_SHLIB_PREFIX'))
1345                {
1346                        define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
1347                }
1348                if (!function_exists('dl') || !@dl(PHP_SHLIB_PREFIX.'session'.'.'.PHP_SHLIB_SUFFIX))
1349                {
1350                        $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db';       // fallback if we have no php4 sessions support
1351                }
1352        }
1353        include_once(PHPGW_API_INC.'/class.sessions_'.$GLOBALS['phpgw_info']['server']['sessions_type'].'.inc.php');
Note: See TracBrowser for help on using the repository browser.