log menuaction of eT2 requests, instead of eT2 itself, to do so move update of access-log to destructor of Session class

This commit is contained in:
Ralf Becker 2016-08-18 13:05:18 +02:00
parent e7ff94a153
commit ef1d8c57b7
3 changed files with 58 additions and 29 deletions

View File

@ -317,6 +317,9 @@ class Etemplate extends Etemplate\Widget\Template
throw new Exception\WrongParameter('Can NOT read template '.array2string(self::$request->template)); throw new Exception\WrongParameter('Can NOT read template '.array2string(self::$request->template));
} }
// let session class know, which is the app & method of this request
$GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method);
// Set current app for validation // Set current app for validation
list($app) = explode('.',self::$request->method); list($app) = explode('.',self::$request->method);
if(!$app) list($app) = explode('::',self::$request->method); if(!$app) list($app) = explode('::',self::$request->method);

View File

@ -973,6 +973,9 @@ abstract class Ajax extends Api\Framework
{ {
throw new Api\Exception\WrongParameter(__METHOD__."('$link') no menuaction set!"); throw new Api\Exception\WrongParameter(__METHOD__."('$link') no menuaction set!");
} }
// set session action
$GLOBALS['egw']->session->set_action('Ajax: '.$_GET['menuaction']);
list($app,$class,$method) = explode('.',$_GET['menuaction']); list($app,$class,$method) = explode('.',$_GET['menuaction']);
if (!isset($GLOBALS['egw_info']['user']['apps'][$app])) if (!isset($GLOBALS['egw_info']['user']['apps'][$app]))

View File

@ -182,6 +182,13 @@ class Session
*/ */
var $reason; var $reason;
/**
* Session action set by update_dla or set_action and stored in __destruct
*
* @var string
*/
protected $action;
/** /**
* Constructor just loads up some defaults from cookies * Constructor just loads up some defaults from cookies
* *
@ -260,18 +267,21 @@ class Session
function __wakeup() function __wakeup()
{ {
ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']); ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']);
$this->action = null;
} }
/** /**
* Destructor * Destructor: update access-log and encrypt session
*
*/ */
function __destruct() function __destruct()
{ {
//if (empty($GLOBALS['egw_info']['user']['passwd']) )//|| empty($this->appsession('password','phpgwapi')) // write dla update on destruct, allows to modify session action by calling Session::set_action()
//{ if (!isset($GLOBALS['egw_info']['flags']['no_dla_update']) || !$GLOBALS['egw_info']['flags']['no_dla_update'])
// error_log('__destruct'.'~252'.'->'." REQUEST_URI".$_SERVER['REQUEST_URI']); {
//} $this->update_dla(true);
}
self::encrypt($this->kp3); self::encrypt($this->kp3);
} }
@ -1357,15 +1367,27 @@ class Session
return $domain; return $domain;
} }
/**
* Set action logged in access-log
*
* @param string $action
*/
public function set_action($action)
{
$this->action = $action;
}
/** /**
* Update session_action and session_dla (session last used time) * Update session_action and session_dla (session last used time)
* *
* @param boolean $update_access_log =true false: dont update egw_access_log table * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action
* @return string action as written to egw_access_log.session_action * @return string action as written to egw_access_log.session_action
*/ */
private function update_dla($update_access_log=true) private function update_dla($update_access_log=false)
{ {
// This way XML-RPC users aren't always listed as xmlrpc.php // This way XML-RPC users aren't always listed as xmlrpc.php
if (!$update_access_log)
{
if ($this->xmlrpc_method_called) if ($this->xmlrpc_method_called)
{ {
$action = $this->xmlrpc_method_called; $action = $this->xmlrpc_method_called;
@ -1389,13 +1411,14 @@ class Session
list(,$action) = explode($egw_path,$action,2); list(,$action) = explode($egw_path,$action,2);
} }
} }
$this->set_action($action);
}
// update dla in access-log table, if we have an access-log row (non-anonymous session) // update dla in access-log table, if we have an access-log row (non-anonymous session)
if ($this->sessionid_access_log && $update_access_log) if ($this->sessionid_access_log && $update_access_log)
{ {
$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
'session_dla' => time(), 'session_dla' => time(),
'session_action' => $action, 'session_action' => $this->action,
'lo' => null, // just in case it was (automatic) timed out before 'lo' => null, // just in case it was (automatic) timed out before
),array( ),array(
'sessionid' => $this->sessionid_access_log, 'sessionid' => $this->sessionid_access_log,
@ -1403,10 +1426,10 @@ class Session
} }
$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $action; $_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action;
if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
return $action; return $this->action;
} }
/** /**