From 2d65325f6f325080ce518a233f50698613d07dcd Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Mon, 7 Feb 2011 15:55:39 +0000 Subject: [PATCH] New configuration setting (and new class of Log objects) to keep track of the application's usage: an entry in the log is added each time a user connects to the application. (This feature is disabled by default) SVN:trunk[1073] --- application/loginwebpage.class.inc.php | 10 +++++++++ core/config.class.inc.php | 8 +++++++ core/event.class.inc.php | 31 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index 320a77073..5e7ed9f25 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -326,6 +326,16 @@ EOF { // User is Ok, let's save it in the session and proceed with normal login UserRights::Login($sAuthUser, $sAuthentication); // Login & set the user's language + + if (MetaModel::GetConfig()->Get('log_usage')) + { + $oLog = new EventLoginUsage(); + $oLog->Set('userinfo', UserRights::GetUser()); + $oLog->Set('user_id', UserRights::GetUserObject()->GetKey()); + $oLog->Set('message', 'Successful login'); + $oLog->DBInsertNoReload(); + } + $_SESSION['auth_user'] = $sAuthUser; $_SESSION['login_mode'] = $sLoginMode; } diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 1e721177e..04f0045ec 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -205,6 +205,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => true, ), + 'log_usage' => array( + 'type' => 'bool', + 'description' => 'Log the usage of the application (i.e. the date/time and the user name of each login)', + 'default' => false, + 'value' => false, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), ); public function IsProperty($sPropCode) diff --git a/core/event.class.inc.php b/core/event.class.inc.php index f49ef6bce..6aa58b314 100644 --- a/core/event.class.inc.php +++ b/core/event.class.inc.php @@ -258,4 +258,35 @@ class EventWebService extends Event } } +class EventLoginUsage extends Event +{ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb,view_in_gui", + "key_type" => "autoincrement", + "name_attcode" => "", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_event_loginusage", + "db_key_field" => "id", + "db_finalclass_field" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + + MetaModel::Init_AddAttribute(new AttributeExternalKey("user_id", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"user_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalField("contact_name", array("allowed_values"=>null, "extkey_attcode"=>"user_id", "target_attcode"=>"contactid", "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalField("contact_email", array("allowed_values"=>null, "extkey_attcode"=>"user_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array()))); + + // Display lists + MetaModel::Init_SetZListItems('details', array('date', 'user_id', 'contact_name', 'contact_email', 'userinfo', 'message')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('date', 'user_id', 'contact_name', 'contact_email', 'userinfo')); // Attributes to be displayed for a list + // Search criteria + MetaModel::Init_SetZListItems('standard_search', array('date', 'user_id', 'contact_name', 'contact_email')); // Criteria of the std search form +// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form + } +} + ?>