phpgw_(app_)sessions --> egw_(app_)sessions

This commit is contained in:
Ralf Becker 2005-11-13 09:16:31 +00:00
parent 8add4f6398
commit f6e4328f85
7 changed files with 132 additions and 164 deletions

View File

@ -444,56 +444,23 @@
// Set group acl // Set group acl
$acl =& CreateObject('phpgwapi.acl',$group_info['account_id']); $acl =& CreateObject('phpgwapi.acl',$group_info['account_id']);
$old_group_list = $acl->get_ids_for_location($group_info['account_id'],1,'phpgw_group'); $old_group_list = $acl->get_ids_for_location($group_info['account_id'],1,'phpgw_group');
@reset($old_group_list); if (is_array($old_group_list))
while($old_group_list && list($key,$user_id) = each($old_group_list))
{ {
$acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id); foreach($old_group_list as $key => $user_id)
if(!$group_info['account_user'][$user_id])
{ {
// If the user is logged in, it will force a refresh of the session_info $acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id);
$GLOBALS['egw']->db->query("update phpgw_sessions set session_action='' "
."where session_lid='" . $GLOBALS['egw']->accounts->id2name($user_id)
. '@' . $GLOBALS['egw_info']['user']['domain'] . "'",__LINE__,__FILE__);
$GLOBALS['egw']->session->delete_cache($user_id);
} }
} }
@reset($group_info['account_user']); if (is_array($group_info['account_user']))
while(list($user_id,$dummy) = each($group_info['account_user']))
{ {
if(!$dummy) foreach($group_info['account_user'] as $user_id => $dummy)
{ {
continue; if(!$dummy)
}
$acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1);
// If the user is logged in, it will force a refresh of the session_info
$GLOBALS['egw']->db->query("update phpgw_sessions set session_action='' "
."where session_lid='" . $GLOBALS['egw']->accounts->id2name($user_id)
. '@' . $GLOBALS['egw_info']['user']['domain'] . "'",__LINE__,__FILE__);
$GLOBALS['egw']->session->delete_cache($user_id);
// The following sets any default preferences needed for new applications..
// This is smart enough to know if previous preferences were selected, use them.
$docommit = False;
if($new_apps)
{
$GLOBALS['pref'] =& CreateObject('phpgwapi.preferences',$user_id);
$t = $GLOBALS['pref']->read_repository();
@reset($new_apps);
while(list($app_key,$app_name) = each($new_apps))
{ {
if (!$t[($app_name=='admin'?'common':$app_name)]) continue;
{
$GLOBALS['egw']->hooks->single('add_def_pref', $app_name);
$docommit = True;
}
} }
} $acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1);
if ($docommit)
{
$GLOBALS['pref']->save_repository();
} }
} }

View File

@ -29,7 +29,7 @@
var $schema_proc; /** schema_proc class */ var $schema_proc; /** schema_proc class */
var $schemas = array(); /** array tablename => schema */ var $schemas = array(); /** array tablename => schema */
var $exclude_tables = array( /** exclude from backup */ var $exclude_tables = array( /** exclude from backup */
'phpgw_sessions','phpgw_app_sessions', // eGW's session-tables 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables
'phpgw_anglemail', // email's cache 'phpgw_anglemail', // email's cache
'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache
); );

View File

@ -36,6 +36,9 @@
class sessions extends sessions_ class sessions extends sessions_
{ {
var $sessions_table = 'egw_sessions';
var $app_sessions_table = 'egw_app_sessions';
function sessions($domain_names=null) function sessions($domain_names=null)
{ {
$this->sessions_($domain_names); $this->sessions_($domain_names);
@ -43,24 +46,25 @@
function read_session() function read_session()
{ {
$this->db->query("SELECT * FROM phpgw_sessions WHERE session_id='" . $this->sessionid . "'",__LINE__,__FILE__); $this->db->select($this->sessions_table,'*',array('session_id' => $this->sessionid),__LINE__,__FILE__);
$this->db->next_record();
return $this->db->Record; return $this->db->row(true);
} }
// This will remove stale sessions out of the database /**
* remove stale sessions out of the database
*/
function clean_sessions() function clean_sessions()
{ {
// If you plan on using the cron apps, please remove the following lines. $this->db->delete($this->sessions_table,array(
// I am going to make this a config option durring 0.9.11, instead of an application (jengo) 'session_dla <= ' . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']),
"session_flags != 'A'",
$GLOBALS['egw']->db->query("DELETE FROM phpgw_sessions WHERE session_dla <= '" . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']) ),__LINE__,__FILE__);
. "' AND session_flags !='A'",__LINE__,__FILE__);
// This is set a little higher, we don't want to kill session data for anonymous sessions. // This is set a little higher, we don't want to kill session data for anonymous sessions.
$GLOBALS['egw']->db->query("DELETE FROM phpgw_app_sessions WHERE session_dla <= '" . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']) $GLOBALS['egw']->db->delete($this->app_sessions_table,array(
. "'",__LINE__,__FILE__); 'session_dla <= ' . (time() - $GLOBALS['egw_info']['server']['sessions_timeout']),
),__LINE__,__FILE__);
} }
function new_session_id() function new_session_id()
@ -70,15 +74,21 @@
function register_session($login,$user_ip,$now,$session_flags) function register_session($login,$user_ip,$now,$session_flags)
{ {
$GLOBALS['egw']->db->query("DELETE FROM phpgw_sessions WHERE session_id='$this->sessionid'",__LINE__,__FILE__); $GLOBALS['egw']->db->insert($this->sessions_table,array(
'session_lid' => $login,
$GLOBALS['egw']->db->query("INSERT INTO phpgw_sessions VALUES ('" . $this->sessionid 'session_ip' => $user_ip,
. "','".$login."','" . $user_ip . "','" 'session_logintime' => $now,
. $now . "','" . $now . "','" . $_SERVER['PHP_SELF'] . "','" . $session_flags 'session_dla' => $now,
. "')",__LINE__,__FILE__); 'session_action' => $_SERVER['PHP_SELF'],
'session_flags' => $session_flags,
),array(
'session_id' => $this->sessionid,
),__LINE__,__FILE__);
} }
// This will update the DateLastActive column, so the login does not expire /**
* update the DateLastActive column, so the login does not expire
*/
function update_dla() function update_dla()
{ {
if (@isset($_GET['menuaction'])) if (@isset($_GET['menuaction']))
@ -97,26 +107,33 @@
$action = $this->xmlrpc_method_called; $action = $this->xmlrpc_method_called;
} }
$GLOBALS['egw']->db->query("UPDATE phpgw_sessions SET session_dla='" . time() . "', session_action='$action' " $GLOBALS['egw']->db->update($this->sessions_table,array(
. "WHERE session_id='" . $this->sessionid."'",__LINE__,__FILE__); 'session_dla' => time(),
'session_action' => $action,
),array(
'session_id' => $this->sessionid,
),__LINE__,__FILE__);
$GLOBALS['egw']->db->update($this->app_sessions_table,array(
'session_dla' => time(),
),array(
'sessionid' => $this->sessionid,
),__LINE__,__FILE__);
$GLOBALS['egw']->db->query("UPDATE phpgw_app_sessions SET session_dla='" . time() . "' "
. "WHERE sessionid='" . $this->sessionid."'",__LINE__,__FILE__);
return True; return True;
} }
function destroy($sessionid, $kp3) function destroy($sessionid, $kp3)
{ {
if (! $sessionid && $kp3) if (!$sessionid && $kp3)
{ {
return False; return False;
} }
$GLOBALS['egw']->db->transaction_begin(); $GLOBALS['egw']->db->transaction_begin();
$GLOBALS['egw']->db->query("DELETE FROM phpgw_sessions WHERE session_id='"
. $sessionid . "'",__LINE__,__FILE__); $GLOBALS['egw']->db->delete($this->sessions_table,array('session_id' => $sessionid),__LINE__,__FILE__);
$GLOBALS['egw']->db->query("DELETE FROM phpgw_app_sessions WHERE sessionid='" $GLOBALS['egw']->db->delete($this->app_sessions_table,array('sessionid' => $sessionid),__LINE__,__FILE__);
. $sessionid . "'",__LINE__,__FILE__);
$this->log_access($this->sessionid); // log logout-time $this->log_access($this->sessionid); // log logout-time
// Only do the following, if where working with the current user // Only do the following, if where working with the current user
@ -133,14 +150,13 @@
* Functions for appsession data and session cache * * Functions for appsession data and session cache *
\*************************************************************************/ \*************************************************************************/
/**
* delete the old phpgw_info cache
*
* @deprecated not longer used
*/
function delete_cache($accountid='') 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['egw']->db->query($query);
} }
function appsession($location = 'default', $appname = '', $data = '##NOTHING##') function appsession($location = 'default', $appname = '', $data = '##NOTHING##')
@ -149,7 +165,7 @@
{ {
return False; // this can happen during login or logout return False; // this can happen during login or logout
} }
if (! $appname) if (!$appname)
{ {
$appname = $GLOBALS['egw_info']['flags']['currentapp']; $appname = $GLOBALS['egw_info']['flags']['currentapp'];
} }
@ -157,87 +173,64 @@
/* This allows the user to put '' as the value. */ /* This allows the user to put '' as the value. */
if ($data == '##NOTHING##') if ($data == '##NOTHING##')
{ {
$query = "SELECT content FROM phpgw_app_sessions WHERE" $GLOBALS['egw']->db->select($this->app_sessions_table,'content',array(
." sessionid='".$this->sessionid."' AND loginid='".$this->account_id."'" 'sessionid' => $this->sessionid,
." AND app = '".$appname."' AND location='".$location."'"; 'loginid' => $this->account_id,
'app' => $appname,
$GLOBALS['egw']->db->query($query,__LINE__,__FILE__); 'location' => $location,
),__LINE__,__FILE__);
$GLOBALS['egw']->db->next_record(); $GLOBALS['egw']->db->next_record();
// I added these into seperate steps for easier debugging // do not decrypt and return if no data (decrypt returning garbage)
$data = $GLOBALS['egw']->db->f('content'); if(($data = $GLOBALS['egw']->db->f('content')))
// Changed by Skeeter 2001 Mar 04 0400Z
// This was not properly decoding structures saved into session data properly
// $data = $GLOBALS['egw']->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['egw']->crypto->decrypt($data); return $GLOBALS['egw']->crypto->decrypt($data);
// echo 'appsession returning: '; _debug_array($data);
return $data;
} }
return null;
} }
else $GLOBALS['egw']->db->insert($this->app_sessions_table,array(
{ 'content' => $GLOBALS['egw']->crypto->encrypt($data),
$GLOBALS['egw']->db->query("SELECT content FROM phpgw_app_sessions WHERE " ),array(
. "sessionid = '".$this->sessionid."' AND loginid = '".$this->account_id."'" 'sessionid' => $this->sessionid,
. " AND app = '".$appname."' AND location = '".$location."'",__LINE__,__FILE__); 'loginid' => $this->account_id,
'app' => $appname,
'location' => $location,
),__LINE__,__FILE__);
$encrypteddata = $GLOBALS['egw']->crypto->encrypt($data); return $data;
$encrypteddata = $GLOBALS['egw']->db->db_addslashes($encrypteddata);
if ($GLOBALS['egw']->db->num_rows()==0)
{
$GLOBALS['egw']->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['egw']->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;
}
} }
/**
* list all sessions
*/
function list_sessions($start, $order, $sort, $all_no_sort = False) function list_sessions($start, $order, $sort, $all_no_sort = False)
{ {
$values = array(); $values = array();
$ordermethod = 'order by session_dla asc'; $order_by = 'ORDER BY '.$sort.' '.$order;
$this->db->limit_query("select * from phpgw_sessions where session_flags != 'A' order by $sort $order",$start,__LINE__,__FILE__); if (!preg_match('/^[a-z_0-9, ]+$/i',$sort) || !preg_match('/^(asc|desc)?$/i',$sort))
while ($this->db->next_record())
{ {
$values[] = array( $order_by = 'ORDER BY session_dla asc';
'session_id' => $this->db->f('session_id'), }
'session_lid' => $this->db->f('session_lid'), $this->db->select($this->sessions_table,'*',"session_flags != 'A'",__LINE__,__FILE__,(int)$start,$order_by);
'session_ip' => $this->db->f('session_ip'),
'session_logintime' => $this->db->f('session_logintime'), while (($row = $this->db->row(true)))
'session_action' => $this->db->f('session_action'), {
'session_dla' => $this->db->f('session_dla') $values[] = $row;
);
} }
return $values; return $values;
} }
/*! /**
@function total * get number of regular / non-anonymous sessions
@abstract get number of normal / non-anonymous sessions *
*/ * @return int
*/
function total() function total()
{ {
$this->db->query("select count(*) from phpgw_sessions where session_flags != 'A'",__LINE__,__FILE__); $this->db->select($this->sessions_table,'COUNT(*)',"session_flags != 'A'",__LINE__,__FILE__);
$this->db->next_record();
return $this->db->f(0); return $this->db->next_record() ? $this->db->f(0) : 0;
} }
} }
?> ?>

View File

@ -14,7 +14,7 @@
/* Basic information about this app */ /* Basic information about this app */
$setup_info['phpgwapi']['name'] = 'phpgwapi'; $setup_info['phpgwapi']['name'] = 'phpgwapi';
$setup_info['phpgwapi']['title'] = 'eGroupWare API'; $setup_info['phpgwapi']['title'] = 'eGroupWare API';
$setup_info['phpgwapi']['version'] = '1.0.1.023'; $setup_info['phpgwapi']['version'] = '1.0.1.024';
$setup_info['phpgwapi']['versions']['current_header'] = '1.28'; $setup_info['phpgwapi']['versions']['current_header'] = '1.28';
$setup_info['phpgwapi']['enable'] = 3; $setup_info['phpgwapi']['enable'] = 3;
$setup_info['phpgwapi']['app_order'] = 1; $setup_info['phpgwapi']['app_order'] = 1;
@ -25,8 +25,8 @@
$setup_info['phpgwapi']['tables'][] = 'egw_acl'; $setup_info['phpgwapi']['tables'][] = 'egw_acl';
$setup_info['phpgwapi']['tables'][] = 'egw_accounts'; $setup_info['phpgwapi']['tables'][] = 'egw_accounts';
$setup_info['phpgwapi']['tables'][] = 'egw_preferences'; $setup_info['phpgwapi']['tables'][] = 'egw_preferences';
$setup_info['phpgwapi']['tables'][] = 'phpgw_sessions'; $setup_info['phpgwapi']['tables'][] = 'egw_sessions';
$setup_info['phpgwapi']['tables'][] = 'phpgw_app_sessions'; $setup_info['phpgwapi']['tables'][] = 'egw_app_sessions';
$setup_info['phpgwapi']['tables'][] = 'phpgw_access_log'; $setup_info['phpgwapi']['tables'][] = 'phpgw_access_log';
$setup_info['phpgwapi']['tables'][] = 'egw_hooks'; $setup_info['phpgwapi']['tables'][] = 'egw_hooks';
$setup_info['phpgwapi']['tables'][] = 'egw_languages'; $setup_info['phpgwapi']['tables'][] = 'egw_languages';

View File

@ -83,29 +83,29 @@
'ix' => array(), 'ix' => array(),
'uc' => array() 'uc' => array()
), ),
'phpgw_sessions' => array( 'egw_sessions' => array(
'fd' => array( 'fd' => array(
'session_id' => array('type' => 'varchar','precision' => '128','nullable' => False), 'session_id' => array('type' => 'varchar','precision' => '128','nullable' => False),
'session_lid' => array('type' => 'varchar','precision' => '128'), 'session_lid' => array('type' => 'varchar','precision' => '128'),
'session_ip' => array('type' => 'varchar','precision' => '40'), 'session_ip' => array('type' => 'varchar','precision' => '40'),
'session_logintime' => array('type' => 'int','precision' => '4'), 'session_logintime' => array('type' => 'int','precision' => '8'),
'session_dla' => array('type' => 'int','precision' => '4'), 'session_dla' => array('type' => 'int','precision' => '8'),
'session_action' => array('type' => 'varchar','precision' => '255'), 'session_action' => array('type' => 'varchar','precision' => '255'),
'session_flags' => array('type' => 'char','precision' => '2') 'session_flags' => array('type' => 'char','precision' => '2')
), ),
'pk' => array(), 'pk' => array('session_id'),
'fk' => array(), 'fk' => array(),
'ix' => array(array('session_flags','session_dla')), 'ix' => array(array('session_flags','session_dla')),
'uc' => array('session_id') 'uc' => array()
), ),
'phpgw_app_sessions' => array( 'egw_app_sessions' => array(
'fd' => array( 'fd' => array(
'sessionid' => array('type' => 'varchar','precision' => '128','nullable' => False), 'sessionid' => array('type' => 'varchar','precision' => '128','nullable' => False),
'loginid' => array('type' => 'int','precision' => '4','nullable' => False), 'loginid' => array('type' => 'int','precision' => '4','nullable' => False),
'app' => array('type' => 'varchar','precision' => '25','nullable' => False), 'app' => array('type' => 'varchar','precision' => '25','nullable' => False),
'location' => array('type' => 'varchar','precision' => '128','nullable' => False), 'location' => array('type' => 'varchar','precision' => '128','nullable' => False),
'content' => array('type' => 'longtext'), 'content' => array('type' => 'longtext'),
'session_dla' => array('type' => 'int','precision' => '4') 'session_dla' => array('type' => 'int','precision' => '8')
), ),
'pk' => array('sessionid','loginid','app','location'), 'pk' => array('sessionid','loginid','app','location'),
'fk' => array(), 'fk' => array(),

View File

@ -838,4 +838,27 @@
return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.023'; return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.023';
} }
$test[] = '1.0.1.023';
function phpgwapi_upgrade1_0_1_023()
{
$GLOBALS['egw_setup']->oProc->RenameTable('phpgw_sessions','egw_sessions');
$GLOBALS['egw_setup']->oProc->AlterColumn('egw_sessions','session_dla',array(
'type' => 'int',
'precision' => '8', // timestamps need to be 64bit since the 32bit overflow in 2003
));
$GLOBALS['egw_setup']->oProc->AlterColumn('egw_sessions','session_logintime',array(
'type' => 'int',
'precision' => '8', // timestamps need to be 64bit since the 32bit overflow in 2003
));
$GLOBALS['egw_setup']->oProc->RenameTable('phpgw_app_sessions','egw_app_sessions');
$GLOBALS['egw_setup']->oProc->AlterColumn('egw_app_sessions','session_dla',array(
'type' => 'int',
'precision' => '8', // timestamps need to be 64bit since the 32bit overflow in 2003
));
return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.024';
}
?> ?>

View File

@ -410,25 +410,10 @@
/** /**
* Clear system/user level cache so as to have it rebuilt with the next access * Clear system/user level cache so as to have it rebuilt with the next access
* *
* AFAIK this code is not used anymore -- RalfBecker 2005/11/04 * @deprecated AFAIK this code is not used anymore -- RalfBecker 2005/11/04
*/ */
function clear_session_cache() function clear_session_cache()
{ {
return; // AFAIK this code is not used anymore -- RalfBecker 2005/11/04
$tables = Array();
$tablenames = $this->db->table_names();
foreach($tablenames as $key => $val)
{
$tables[] = $val['table_name'];
}
if(in_array('phpgw_app_sessions',$tables))
{
$this->db->lock(array('phpgw_app_sessions'));
@$this->db->query("DELETE FROM phpgw_app_sessions WHERE sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'",__LINE__,__FILE__);
@$this->db->query("DELETE FROM phpgw_app_sessions WHERE app = 'phpgwapi' and location = 'phpgw_info_cache'",__LINE__,__FILE__);
$this->db->unlock();
}
} }
/** /**