28require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
35 const EVENT_ACTION_DICT = array(
36 'USER_LOGIN' =>
'UserLogged',
37 'USER_LOGIN_FAILED' =>
'UserLoginFailed',
38 'USER_LOGOUT' =>
'UserLogoff',
39 'USER_CREATE' =>
'NewUserCreated',
40 'USER_MODIFY' =>
'EventUserModified',
41 'USER_NEW_PASSWORD' =>
'NewUserPassword',
42 'USER_ENABLEDISABLE' =>
'UserEnabledDisabled',
43 'USER_DELETE' =>
'UserDeleted',
44 'USERGROUP_CREATE' =>
'NewGroupCreated',
45 'USERGROUP_MODIFY' =>
'GroupModified',
46 'USERGROUP_DELETE' =>
'GroupDeleted'
68 parent::__construct($db);
70 $this->family =
"core";
71 $this->
description =
"Triggers of this module allows to add security event records inside Dolibarr.";
72 $this->version = self::VERSION_DOLIBARR;
73 $this->picto =
'technic';
74 $this->event_label =
'';
75 $this->event_desc =
'';
76 $this->event_date = 0;
97 $key =
'MAIN_LOGEVENTS_'.$action;
98 if (empty($conf->global->$key)) {
102 if (empty($conf->entity)) {
104 $conf->entity = $entity;
108 dol_syslog(
"Trigger '" . $this->
name .
"' for action '$action' launched by " . __FILE__ .
". id=" . $object->id);
109 $this->
initEventData(InterfaceLogevents::EVENT_ACTION_DICT[$action], $object);
112 include_once DOL_DOCUMENT_ROOT.
'/core/class/events.class.php';
114 $event =
new Events($this->db);
115 $event->type = $action;
116 $event->dateevent = $this->event_date;
117 $event->label = $this->event_label;
118 $event->description = $this->event_desc;
119 $event->user_agent = (empty($_SERVER[
"HTTP_USER_AGENT"]) ?
'' : $_SERVER[
"HTTP_USER_AGENT"]);
120 $event->authentication_method = (empty($object->context[
'authentication_method']) ?
'' : $object->context[
'authentication_method']);
122 $result = $event->create($user);
126 $error =
"Failed to insert security event: ".$event->error;
127 $this->errors[] = $error;
128 $this->error = $error;
130 dol_syslog(get_class($this).
": ".$error, LOG_ERR);
146 $this->event_label = $this->event_desc = $key_text;
147 if (property_exists($object,
'login')) {
148 $this->event_label .=
' : ' . $object->login;
150 if ($key_text == InterfaceLogevents::EVENT_ACTION_DICT[
'USER_ENABLEDISABLE']) {
151 $object->statut ? $this->event_desc .=
' - disabled' : $this->event_desc .=
' - enabled';
154 if (!empty($object->context[
'audit'])) {
155 $this->event_desc .= (empty($this->event_desc) ?
'' :
' - ').$object->context[
'audit'];
167 foreach (InterfaceLogevents::EVENT_ACTION_DICT as $value) {
168 if (str_contains($event_text, $value)) {
Class to stock current configuration.
Class to manage Dolibarr database access.
Class that all the triggers must extend.
Class of triggers for security audit events.
static isEventActionTextKey($event_text)
Check if text contains an event action key.
initEventData($key_text, $object)
Method called by runTrigger to initialize date, label & description data for event.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr security audit event is done.
__construct(DoliDB $db)
Constructor.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.