2002-01-02 15:32:22 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
* eGroupWare API - Session management *
|
2002-01-02 15:32:22 +01:00
|
|
|
* This file written by Dan Kuykendall <seek3r@phpgroupware.org> *
|
|
|
|
* and Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* Copyright (C) 2000, 2001 Dan Kuykendall *
|
|
|
|
* -------------------------------------------------------------------------*
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
2002-01-02 15:32:22 +01:00
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
class sessions extends sessions_
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
function sessions()
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->sessions_();
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
2003-05-18 21:16:58 +02:00
|
|
|
|
2003-10-21 12:46:33 +02:00
|
|
|
function read_session()
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
$this->db->query("SELECT * FROM phpgw_sessions WHERE session_id='" . $this->sessionid . "'",__LINE__,__FILE__);
|
|
|
|
$this->db->next_record();
|
2002-01-13 05:06:40 +01:00
|
|
|
|
2003-05-18 21:16:58 +02:00
|
|
|
return $this->db->Record;
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This will remove stale sessions out of the database
|
|
|
|
function clean_sessions()
|
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
// If you plan on using the cron apps, please remove the following lines.
|
|
|
|
// I am going to make this a config option durring 0.9.11, instead of an application (jengo)
|
|
|
|
|
2002-09-24 07:23:30 +02:00
|
|
|
$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_sessions WHERE session_dla <= '" . (time() - $GLOBALS['phpgw_info']['server']['sessions_timeout'])
|
2002-01-02 15:32:22 +01:00
|
|
|
. "' AND session_flags !='A'",__LINE__,__FILE__);
|
|
|
|
|
|
|
|
// This is set a little higher, we don't want to kill session data for anonymous sessions.
|
2003-05-18 21:16:58 +02:00
|
|
|
$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_app_sessions WHERE session_dla <= '" . (time() - $GLOBALS['phpgw_info']['server']['sessions_timeout'])
|
2002-01-02 15:32:22 +01:00
|
|
|
. "'",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
|
2003-10-21 12:46:33 +02:00
|
|
|
function new_session_id()
|
|
|
|
{
|
|
|
|
return md5($GLOBALS['phpgw']->common->randomstring(15));
|
|
|
|
}
|
|
|
|
|
2003-05-18 21:16:58 +02:00
|
|
|
function register_session($login,$user_ip,$now,$session_flags)
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
|
|
|
$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_sessions VALUES ('" . $this->sessionid
|
|
|
|
. "','".$login."','" . $user_ip . "','"
|
2003-08-28 16:31:11 +02:00
|
|
|
. $now . "','" . $now . "','" . $_SERVER['PHP_SELF'] . "','" . $session_flags
|
2002-01-02 15:32:22 +01:00
|
|
|
. "')",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
|
2003-05-18 21:16:58 +02:00
|
|
|
// This will update the DateLastActive column, so the login does not expire
|
|
|
|
function update_dla()
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
if (@isset($_GET['menuaction']))
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
$action = $_GET['menuaction'];
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
$action = $_SERVER['PHP_SELF'];
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
|
|
|
|
2003-05-18 21:16:58 +02:00
|
|
|
// This way XML-RPC users aren't always listed as
|
|
|
|
// xmlrpc.php
|
|
|
|
if ($this->xmlrpc_method_called)
|
2002-01-02 15:32:22 +01:00
|
|
|
{
|
2003-05-18 21:16:58 +02:00
|
|
|
$action = $this->xmlrpc_method_called;
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['phpgw']->db->query("UPDATE phpgw_sessions SET session_dla='" . time() . "', session_action='$action' "
|
|
|
|
. "WHERE session_id='" . $this->sessionid."'",__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$GLOBALS['phpgw']->db->query("UPDATE phpgw_app_sessions SET session_dla='" . time() . "' "
|
|
|
|
. "WHERE sessionid='" . $this->sessionid."'",__LINE__,__FILE__);
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
function destroy($sessionid, $kp3)
|
|
|
|
{
|
|
|
|
if (! $sessionid && $kp3)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['phpgw']->db->transaction_begin();
|
|
|
|
$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_sessions WHERE session_id='"
|
|
|
|
. $sessionid . "'",__LINE__,__FILE__);
|
|
|
|
$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_app_sessions WHERE sessionid='"
|
|
|
|
. $sessionid . "'",__LINE__,__FILE__);
|
2003-05-18 21:16:58 +02:00
|
|
|
$this->log_access($this->sessionid); // log logout-time
|
2002-01-02 15:32:22 +01:00
|
|
|
|
|
|
|
// Only do the following, if where working with the current user
|
|
|
|
if ($sessionid == $GLOBALS['phpgw_info']['user']['sessionid'])
|
|
|
|
{
|
|
|
|
$this->clean_sessions();
|
|
|
|
}
|
|
|
|
$GLOBALS['phpgw']->db->transaction_commit();
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************\
|
|
|
|
* Functions for appsession data and session cache *
|
|
|
|
\*************************************************************************/
|
|
|
|
|
|
|
|
function delete_cache($accountid='')
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid,$this->account_id);
|
|
|
|
|
|
|
|
$query = "DELETE FROM phpgw_app_sessions WHERE loginid = '".$account_id."'"
|
|
|
|
." AND app = 'phpgwapi' AND location = 'phpgw_info_cache'";
|
|
|
|
|
|
|
|
$GLOBALS['phpgw']->db->query($query);
|
|
|
|
}
|
2002-01-13 05:06:40 +01:00
|
|
|
|
2002-01-02 15:32:22 +01:00
|
|
|
function appsession($location = 'default', $appname = '', $data = '##NOTHING##')
|
|
|
|
{
|
|
|
|
if (! $appname)
|
|
|
|
{
|
|
|
|
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This allows the user to put '' as the value. */
|
|
|
|
if ($data == '##NOTHING##')
|
|
|
|
{
|
|
|
|
$query = "SELECT content FROM phpgw_app_sessions WHERE"
|
|
|
|
." sessionid='".$this->sessionid."' AND loginid='".$this->account_id."'"
|
|
|
|
." AND app = '".$appname."' AND location='".$location."'";
|
|
|
|
|
|
|
|
$GLOBALS['phpgw']->db->query($query,__LINE__,__FILE__);
|
|
|
|
$GLOBALS['phpgw']->db->next_record();
|
|
|
|
|
|
|
|
// I added these into seperate steps for easier debugging
|
|
|
|
$data = $GLOBALS['phpgw']->db->f('content');
|
|
|
|
// Changed by Skeeter 2001 Mar 04 0400Z
|
|
|
|
// This was not properly decoding structures saved into session data properly
|
|
|
|
// $data = $GLOBALS['phpgw']->common->decrypt($data);
|
|
|
|
// return stripslashes($data);
|
|
|
|
// Changed by milosch 2001 Dec 20
|
|
|
|
// do not stripslashes here unless this proves to be a problem.
|
|
|
|
// Changed by milosch 2001 Dec 25
|
|
|
|
/* do not decrypt and return if no data (decrypt returning garbage) */
|
|
|
|
if($data)
|
|
|
|
{
|
|
|
|
$data = $GLOBALS['phpgw']->crypto->decrypt($data);
|
2002-01-13 05:06:40 +01:00
|
|
|
// echo 'appsession returning: '; _debug_array($data);
|
2002-01-02 15:32:22 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$GLOBALS['phpgw']->db->query("SELECT content FROM phpgw_app_sessions WHERE "
|
|
|
|
. "sessionid = '".$this->sessionid."' AND loginid = '".$this->account_id."'"
|
|
|
|
. " AND app = '".$appname."' AND location = '".$location."'",__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$encrypteddata = $GLOBALS['phpgw']->crypto->encrypt($data);
|
|
|
|
$encrypteddata = $GLOBALS['phpgw']->db->db_addslashes($encrypteddata);
|
|
|
|
|
|
|
|
if ($GLOBALS['phpgw']->db->num_rows()==0)
|
|
|
|
{
|
|
|
|
$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content,session_dla) "
|
|
|
|
. "VALUES ('".$this->sessionid."','".$this->account_id."','".$appname
|
|
|
|
. "','".$location."','".$encrypteddata."','" . time() . "')",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$GLOBALS['phpgw']->db->query("UPDATE phpgw_app_sessions SET content='".$encrypteddata."'"
|
|
|
|
. "WHERE sessionid = '".$this->sessionid."'"
|
|
|
|
. "AND loginid = '".$this->account_id."' AND app = '".$appname."'"
|
|
|
|
. "AND location = '".$location."'",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
function list_sessions($start, $order, $sort, $all_no_sort = False)
|
2003-03-21 01:47:18 +01:00
|
|
|
{
|
|
|
|
$values = array();
|
|
|
|
|
|
|
|
$ordermethod = 'order by session_dla asc';
|
|
|
|
$this->db->limit_query("select * from phpgw_sessions where session_flags != 'A' order by $sort $order",$start,__LINE__,__FILE__);
|
|
|
|
|
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
$values[] = array(
|
|
|
|
'session_id' => $this->db->f('session_id'),
|
|
|
|
'session_lid' => $this->db->f('session_lid'),
|
|
|
|
'session_ip' => $this->db->f('session_ip'),
|
|
|
|
'session_logintime' => $this->db->f('session_logintime'),
|
|
|
|
'session_action' => $this->db->f('session_action'),
|
|
|
|
'session_dla' => $this->db->f('session_dla')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function total
|
|
|
|
@abstract get number of normal / non-anonymous sessions
|
|
|
|
*/
|
|
|
|
function total()
|
|
|
|
{
|
|
|
|
$this->db->query("select count(*) from phpgw_sessions where session_flags != 'A'",__LINE__,__FILE__);
|
|
|
|
$this->db->next_record();
|
|
|
|
|
|
|
|
return $this->db->f(0);
|
|
|
|
}
|
2002-01-02 15:32:22 +01:00
|
|
|
}
|
2002-09-12 04:27:58 +02:00
|
|
|
?>
|