Browse Source

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)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1073 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 years ago
parent
commit
37447c1a17
3 changed files with 49 additions and 0 deletions
  1. 10 0
      application/loginwebpage.class.inc.php
  2. 8 0
      core/config.class.inc.php
  3. 31 0
      core/event.class.inc.php

+ 10 - 0
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
 					// 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
 					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['auth_user'] = $sAuthUser;
 					$_SESSION['login_mode'] = $sLoginMode;
 					$_SESSION['login_mode'] = $sLoginMode;
 				}
 				}

+ 8 - 0
core/config.class.inc.php

@@ -205,6 +205,14 @@ class Config
 			'source_of_value' => '',
 			'source_of_value' => '',
 			'show_in_conf_sample' => true,
 			'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)
 	public function IsProperty($sPropCode)

+ 31 - 0
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
+	}
+}
+
 ?>
 ?>