diff --git a/admin/inc/class.bocurrentsessions.inc.php b/admin/inc/class.bocurrentsessions.inc.php index dbaf4fa877..f4357e1a93 100644 --- a/admin/inc/class.bocurrentsessions.inc.php +++ b/admin/inc/class.bocurrentsessions.inc.php @@ -20,19 +20,14 @@ 'kill' => True ); - function bocurrentsessions() - { - $this->so = CreateObject('admin.socurrentsessions'); - } - function total() { - return $this->so->total(); + return $GLOBALS['phpgw']->session->total(); } function list_sessions($start,$order,$sort) { - $values = $this->so->list_sessions($start,$sort,$order); + $values = $GLOBALS['phpgw']->session->list_sessions($start,$sort,$order); while (list(,$value) = @each($values)) { diff --git a/admin/inc/class.socurrentsessions.inc.php b/admin/inc/class.socurrentsessions.inc.php deleted file mode 100644 index 9e64ac266a..0000000000 --- a/admin/inc/class.socurrentsessions.inc.php +++ /dev/null @@ -1,59 +0,0 @@ - * - * -------------------------------------------- * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by the * - * Free Software Foundation; either version 2 of the License, or (at your * - * option) any later version. * - \**************************************************************************/ - - /* $Id$ */ - - class socurrentsessions - { - var $db; - - function socurrentsessions() - { - $this->db = $GLOBALS['phpgw']->db; - } - - 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); - } - - function list_sessions($start,$order,$sort) - { - switch ($GLOBALS['phpgw_info']['server']['sessions_type']) - { - case 'php4': - /* TODO */ - break; - case 'db': - default: - $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; - break; - } - } - } diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index 611f33c9c1..6302927993 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -1233,9 +1233,7 @@ if (!@is_file(PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info' if (isset($GLOBALS['phpgw_ifo']['navbar']['admin']) && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['show_currentusers'])) { - $GLOBALS['phpgw']->db->query('select count(session_id) from phpgw_sessions'); - $GLOBALS['phpgw']->db->next_record(); - $var['current_users'] = lang('Current users') . ': ' . $GLOBALS['phpgw']->db->f(0); + $var['current_users'] = lang('Current users') . ': ' . $GLOBALS['phpgw']->session->total(); $var['url_current_users'] = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicurrentsessions.list_sessions'); } diff --git a/phpgwapi/inc/class.sessions_db.inc.php b/phpgwapi/inc/class.sessions_db.inc.php index 0b42699e31..5a683d631f 100644 --- a/phpgwapi/inc/class.sessions_db.inc.php +++ b/phpgwapi/inc/class.sessions_db.inc.php @@ -47,7 +47,9 @@ var $db2; var $public_functions = array( 'list_methods' => True, - 'update_dla' => True + 'update_dla' => True, + 'list' => True, + 'total' => True ); var $cookie_domain; @@ -1039,5 +1041,38 @@ /* if no extravars then we return the cleaned up url/scriptname */ return $url; } + + function list_sessions($start,$order,$sort) + { + $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); + } } ?> diff --git a/phpgwapi/inc/class.sessions_php4.inc.php b/phpgwapi/inc/class.sessions_php4.inc.php index 0d2b30e5c5..422101efd1 100644 --- a/phpgwapi/inc/class.sessions_php4.inc.php +++ b/phpgwapi/inc/class.sessions_php4.inc.php @@ -45,7 +45,9 @@ var $data; var $public_functions = array( 'list_methods' => True, - 'update_dla' => True + 'update_dla' => True, + 'list' => True, + 'total' => True ); var $cookie_domain; @@ -59,6 +61,7 @@ $this->kp3 = get_var('kp3',Array('COOKIE','GET')); /* Create the crypto object */ $GLOBALS['phpgw']->crypto = CreateObject('phpgwapi.crypto'); + $GLOBALS['phpgw']->datetime = CreateObject('phpgwapi.datetime'); $this->phpgw_set_cookiedomain(); } @@ -291,23 +294,23 @@ $parts = explode('.',$dom); if (count($parts) > 2) { - if (!ereg('[0-9]+',$parts[1])) - { - for($i=1;$icookie_domain .= '.'.$parts[$i]; - } - } - else - { - $this->cookie_domain = ''; - } + if (!ereg('[0-9]+',$parts[1])) + { + for($i=1;$icookie_domain .= '.'.$parts[$i]; + } + } + else + { + $this->cookie_domain = ''; + } } else { $this->cookie_domain = ''; } - print_debug('COOKIE_DOMAIN',$this->cookie_domain,'api'); + print_debug('COOKIE_DOMAIN',$this->cookie_domain,'api'); session_set_cookie_params(0,'/',$this->cookie_domain); } @@ -442,8 +445,8 @@ session_register('phpgw_session'); $GLOBALS['HTTP_SESSION_VARS']['phpgw_session'] = $GLOBALS['phpgw_session']; - //$GLOBALS['phpgw']->db->query('INSERT INTO phpgw_access_log(sessionid,loginid,ip,li,lo,account_id) ' - // ." VALUES ('" . $this->sessionid . "','" . "$login','" . $user_ip . "',".$now.",''," . $this->account_id . ")",__LINE__,__FILE__); + $GLOBALS['phpgw']->db->query('INSERT INTO phpgw_access_log(sessionid,loginid,ip,li,lo,account_id) ' + ." VALUES ('" . $this->sessionid . "','" . "$login','" . $user_ip . "',".$now.",''," . $this->account_id . ")",__LINE__,__FILE__); $this->appsession('account_previous_login','phpgwapi',$GLOBALS['phpgw']->auth->previous_login); $GLOBALS['phpgw']->auth->update_lastlogin($this->account_id,$user_ip); @@ -655,8 +658,8 @@ session_register('phpgw_session'); $GLOBALS['HTTP_SESSION_VARS']['phpgw_session'] = $GLOBALS['phpgw_session']; - //$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_access_log VALUES ('" . $this->sessionid . "','" - // . "$login','" . $user_ip . "','$now','','" . $this->account_id . "')",__LINE__,__FILE__); + $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_access_log VALUES ('" . $this->sessionid . "','" + . "$login','" . $user_ip . "','$now','','" . $this->account_id . "')",__LINE__,__FILE__); $this->appsession('account_previous_login','phpgwapi',$GLOBALS['phpgw']->auth->previous_login); $GLOBALS['phpgw']->auth->update_lastlogin($this->account_id,$user_ip); @@ -693,18 +696,28 @@ return False; } - session_unset(); - session_destroy(); - $this->phpgw_setcookie(session_name()); - //$GLOBALS['phpgw']->db->query("UPDATE phpgw_access_log SET lo='" . time() . "' WHERE sessionid='" - // . $sessionid . "'",__LINE__,__FILE__); + $GLOBALS['phpgw']->db->query("UPDATE phpgw_access_log SET lo='" . $GLOBALS['phpgw']->datetime->gmtnow . "' WHERE sessionid='" + . $sessionid . "'",__LINE__,__FILE__); + $GLOBALS['phpgw']->db->transaction_commit(); // Only do the following, if where working with the current user if ($sessionid == $GLOBALS['phpgw_info']['user']['sessionid']) { $this->clean_sessions(); + session_unset(); + session_destroy(); + $this->phpgw_setcookie(session_name()); + } + else + { + $sessions = $this->list_sessions(0,'','',True); + + if (isset($sessions[$sessionid])) + { + //echo "

session_php4::destroy($session_id): unlink('".$sessions[$sessionid]['php_session_file'].")

\n"; + unlink($sessions[$sessionid]['php_session_file']); + } } - $GLOBALS['phpgw']->db->transaction_commit(); return True; } @@ -996,4 +1009,85 @@ /* if no extravars then we return the cleaned up url/scriptname */ return $url; } + + function session_sort($a,$b) + { + $sign = strcasecmp($GLOBALS['phpgw']->session->sort_order,'ASC') ? 1 : -1; + + return strcasecmp($a[$GLOBALS['phpgw']->session->sort_by], + $b[$GLOBALS['phpgw']->session->sort_by]) * $sign; + } + + /*! + @function list_sessions + @abstract get list of normal / non-anonymous sessions + @author ralfbecker + */ + function list_sessions($start,$order,$sort,$all_no_sort = False) + { + //echo "

session_php4::list_sessions($start,'$order','$sort',$all)

\n"; + $values = array(); + $maxmatchs = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; + $dir = opendir($path = ini_get('session.save_path')); + while ($file = readdir($dir)) + { + if (substr($file,0,5) != 'sess_') + { + continue; + } + list($session) = file($path . '/' . $file); + + if (substr($session,0,14) != 'phpgw_session|') + { + continue; + } + $session = unserialize(substr($session,14)); + list(,$domain) = explode('@',$session['session_lid']); + if (empty($domain)) + { + $domain = $GLOBALS['phpgw_info']['server']['default_domain']; + } + if ($session['session_flags'] == 'A' || $domain != $this->account_domain || !$session['session_id']) + { + continue; // no anonymous sessions or other domains + } + unset($session['phpgw_app_sessions']); // not needed, saves memory + //echo "file='$file'=
"; print_r($session); echo "
"; + + $session['php_session_file'] = $path . '/' . $file; + $values[$session['session_id']] = $session; + } + closedir($dir); + + if (!$all_no_sort) + { + $GLOBALS['phpgw']->session->sort_by = $sort; + $GLOBALS['phpgw']->session->sort_order = $order; + + uasort($values,array('sessions','session_sort')); + + $i = 0; + $start = intval($start); + foreach($values as $id => $data) + { + if ($i < $start || $i > $start+$maxmatchs) + { + unset($values[$id]); + } + ++$i; + } + reset($values); + } + return $values; + } + + /*! + @function total + @abstract get number of normal / non-anonymous sessions + @author ralfbecker + */ + function total() + { + return count($this->list_sessions(0,'','',True)); + } }