[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.sessions_db.inc.php (source)

   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      * Copyright (C) 2000, 2001 Dan Kuykendall                                  *
   7      * -------------------------------------------------------------------------*
   8      * This library is part of the eGroupWare API                               *
   9      * http://www.egroupware.org/api                                            * 
  10      * ------------------------------------------------------------------------ *
  11      * This library is free software; you can redistribute it and/or modify it  *
  12      * under the terms of the GNU Lesser General Public License as published by *
  13      * the Free Software Foundation; either version 2.1 of the License,         *
  14      * or any later version.                                                    *
  15      * This library is distributed in the hope that it will be useful, but      *
  16      * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  17      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  18      * See the GNU Lesser General Public License for more details.              *
  19      * You should have received a copy of the GNU Lesser General Public License *
  20      * along with this library; if not, write to the Free Software Foundation,  *
  21      * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  22      \**************************************************************************/
  23  
  24      /* $Id: class.sessions_db.inc.php 20295 2006-02-15 12:31:25Z  $ */
  25  
  26      /**
  27      * Session Management via database (based on phplib sessions)
  28      *
  29      * @package api
  30      * @subpackage sessions
  31      * @author NetUSE AG Boris Erdmann, Kristian Koehntopp <br> hacked on by phpGW
  32      * @copyright &copy; 1998-2000 NetUSE AG Boris Erdmann, Kristian Koehntopp <br> &copy; 2003 FreeSoftware Foundation
  33      * @license LGPL
  34      * @link http://www.sanisoft.com/phplib/manual/DB_sql.php
  35      */
  36  
  37      class sessions extends sessions_
  38      {
  39          var $sessions_table = 'egw_sessions';
  40          var $app_sessions_table = 'egw_app_sessions';
  41  
  42  		function sessions($domain_names=null)
  43          {
  44              $this->sessions_($domain_names);
  45          }
  46          
  47  		function read_session()
  48          {
  49              $this->db->select($this->sessions_table,'*',array('session_id' => $this->sessionid),__LINE__,__FILE__);
  50              
  51              return $this->db->row(true);
  52          }
  53  
  54          /**
  55           * remove stale sessions out of the database
  56           */
  57  		function clean_sessions()
  58          {
  59              $this->db->delete($this->sessions_table,array(
  60                  'session_dla <= ' . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']),
  61                  "session_flags != 'A'",
  62              ),__LINE__,__FILE__);
  63  
  64              // This is set a little higher, we don't want to kill session data for anonymous sessions.
  65              $GLOBALS['egw']->db->delete($this->app_sessions_table,array(
  66                  'session_dla <= ' . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']),
  67              ),__LINE__,__FILE__);
  68          }
  69  
  70  		function new_session_id()
  71          {
  72              return md5($GLOBALS['egw']->common->randomstring(15));
  73          }
  74  
  75  		function register_session($login,$user_ip,$now,$session_flags)
  76          {
  77              $GLOBALS['egw']->db->insert($this->sessions_table,array(
  78                  'session_lid'       => $login,
  79                  'session_ip'        => $user_ip,
  80                  'session_logintime' => $now,
  81                  'session_dla'       => $now,
  82                  'session_action'    => $_SERVER['PHP_SELF'],
  83                  'session_flags'     => $session_flags,
  84              ),array(
  85                  'session_id'        => $this->sessionid,
  86              ),__LINE__,__FILE__);
  87          }
  88  
  89          /**
  90           * update the DateLastActive column, so the login does not expire
  91           */
  92  		function update_dla()
  93          {
  94              if (@isset($_GET['menuaction']))
  95              {
  96                  $action = $_GET['menuaction'];
  97              }
  98              else
  99              {
 100                  $action = $_SERVER['PHP_SELF'];
 101              }
 102  
 103              // This way XML-RPC users aren't always listed as
 104              // xmlrpc.php
 105              if ($this->xmlrpc_method_called)
 106              {
 107                  $action = $this->xmlrpc_method_called;
 108              }
 109  
 110              $GLOBALS['egw']->db->update($this->sessions_table,array(
 111                  'session_dla'    => time(),
 112                  'session_action' => $action,
 113              ),array(
 114                  'session_id'     => $this->sessionid,
 115              ),__LINE__,__FILE__);
 116  
 117              $GLOBALS['egw']->db->update($this->app_sessions_table,array(
 118                  'session_dla'    => time(),
 119              ),array(
 120                  'sessionid'     => $this->sessionid,
 121              ),__LINE__,__FILE__);
 122  
 123              return True;
 124          }
 125  
 126  		function destroy($sessionid, $kp3)
 127          {
 128              if (!$sessionid && $kp3)
 129              {
 130                  return False;
 131              }
 132              $GLOBALS['egw']->db->transaction_begin();
 133  
 134              $GLOBALS['egw']->db->delete($this->sessions_table,array('session_id' => $sessionid),__LINE__,__FILE__);
 135              $GLOBALS['egw']->db->delete($this->app_sessions_table,array('sessionid' => $sessionid),__LINE__,__FILE__);
 136  
 137              $this->log_access($this->sessionid);    // log logout-time
 138  
 139              // Only do the following, if where working with the current user
 140              if ($sessionid == $GLOBALS['egw_info']['user']['sessionid'])
 141              {
 142                  $this->clean_sessions();
 143              }
 144              $GLOBALS['egw']->db->transaction_commit();
 145  
 146              return True;
 147          }
 148  
 149          /*************************************************************************\
 150          * Functions for appsession data and session cache                         *
 151          \*************************************************************************/
 152  
 153          /**
 154           * delete the old phpgw_info cache
 155           *
 156           * @deprecated not longer used
 157           */
 158  		function delete_cache($accountid='')
 159          {
 160          }
 161  
 162  		function appsession($location = 'default', $appname = '', $data = '##NOTHING##')
 163          {
 164              if (!$this->account_id || !$this->sessionid)
 165              {
 166                  return False;    // this can happen during login or logout
 167              }
 168              if (!$appname)
 169              {
 170                  $appname = $GLOBALS['egw_info']['flags']['currentapp'];
 171              }
 172              
 173              /* This allows the user to put '' as the value. */
 174              if ($data == '##NOTHING##')
 175              {
 176                  $GLOBALS['egw']->db->select($this->app_sessions_table,'content',array(
 177                      'sessionid' => $this->sessionid,
 178                      'loginid'   => $this->account_id,
 179                      'app'       => $appname,
 180                      'location'  => $location,
 181                  ),__LINE__,__FILE__);
 182                  $GLOBALS['egw']->db->next_record();
 183  
 184                  // do not decrypt and return if no data (decrypt returning garbage)
 185                  if(($data = $GLOBALS['egw']->db->f('content')))
 186                  {
 187                      return $GLOBALS['egw']->crypto->decrypt($data);
 188                  }
 189                  return null;
 190              }
 191              $GLOBALS['egw']->db->insert($this->app_sessions_table,array(
 192                  'content'   => $GLOBALS['egw']->crypto->encrypt($data),
 193              ),array(
 194                  'sessionid' => $this->sessionid,
 195                  'loginid'   => $this->account_id,
 196                  'app'       => $appname,
 197                  'location'  => $location,
 198              ),__LINE__,__FILE__);
 199  
 200              return $data;
 201          }
 202  
 203          /**
 204           * list all sessions
 205           */
 206  		function list_sessions($start, $order, $sort, $all_no_sort = False)
 207          {
 208              $values = array();
 209              
 210              $order_by = 'ORDER BY '.$sort.' '.$order;
 211              if (!preg_match('/^[a-z_0-9, ]+$/i',$sort) || !preg_match('/^(asc|desc)?$/i',$sort))
 212              {
 213                  $order_by = 'ORDER BY session_dla asc';
 214              }
 215              $this->db->select($this->sessions_table,'*',"session_flags != 'A'",__LINE__,__FILE__,(int)$start,$order_by);
 216  
 217              while (($row = $this->db->row(true)))
 218              {
 219                  $values[] = $row;
 220              }
 221              return $values;
 222          }
 223          
 224          /**
 225           * get number of regular / non-anonymous sessions
 226           *
 227           * @return int
 228           */
 229  		function total()
 230          {
 231              $this->db->select($this->sessions_table,'COUNT(*)',"session_flags != 'A'",__LINE__,__FILE__);
 232  
 233              return $this->db->next_record() ? $this->db->f(0) : 0;
 234          }
 235      }
 236  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7