26 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
43 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
44 $this->family =
"core";
45 $this->
description =
"Triggers of this module allows to add security event records inside Dolibarr.";
47 $this->version = self::VERSION_DOLIBARR;
48 $this->picto =
'technic';
64 if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) {
68 $key =
'MAIN_LOGEVENTS_'.$action;
70 if (empty($conf->global->$key)) {
74 if (empty($conf->entity)) {
75 $conf->entity = $entity;
81 if ($action ==
'USER_LOGIN') {
82 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
84 $langs->load(
"users");
86 $text =
"(UserLogged,".$object->login.
")";
87 $text .= (empty($object->trigger_mesg) ?
'' :
' - '.$object->trigger_mesg);
88 $desc =
"(UserLogged,".$object->login.
")";
89 $desc .= (empty($object->trigger_mesg) ?
'' :
' - '.$object->trigger_mesg);
90 } elseif ($action ==
'USER_LOGIN_FAILED') {
91 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
94 $text = $object->trigger_mesg;
95 $desc = $object->trigger_mesg;
96 } elseif ($action ==
'USER_LOGOUT') {
97 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
99 $langs->load(
"users");
101 $text =
"(UserLogoff,".$object->login.
")";
102 $desc =
"(UserLogoff,".$object->login.
")";
103 } elseif ($action ==
'USER_CREATE') {
104 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
105 $langs->load(
"users");
108 $text = $langs->transnoentities(
"NewUserCreated", $object->login);
109 $desc = $langs->transnoentities(
"NewUserCreated", $object->login);
110 } elseif ($action ==
'USER_MODIFY') {
111 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
112 $langs->load(
"users");
115 $text = $langs->transnoentities(
"EventUserModified", $object->login);
116 $desc = $langs->transnoentities(
"EventUserModified", $object->login);
117 } elseif ($action ==
'USER_NEW_PASSWORD') {
118 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
119 $langs->load(
"users");
122 $text = $langs->transnoentities(
"NewUserPassword", $object->login);
123 $desc = $langs->transnoentities(
"NewUserPassword", $object->login);
124 } elseif ($action ==
'USER_ENABLEDISABLE') {
125 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
126 $langs->load(
"users");
128 if ($object->statut == 0) {
129 $text = $langs->transnoentities(
"UserEnabled", $object->login);
130 $desc = $langs->transnoentities(
"UserEnabled", $object->login);
132 if ($object->statut == 1) {
133 $text = $langs->transnoentities(
"UserDisabled", $object->login);
134 $desc = $langs->transnoentities(
"UserDisabled", $object->login);
136 } elseif ($action ==
'USER_DELETE') {
137 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
138 $langs->load(
"users");
140 $text = $langs->transnoentities(
"UserDeleted", $object->login);
141 $desc = $langs->transnoentities(
"UserDeleted", $object->login);
142 } elseif ($action ==
'USERGROUP_CREATE') {
144 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
145 $langs->load(
"users");
147 $text = $langs->transnoentities(
"NewGroupCreated", $object->name);
148 $desc = $langs->transnoentities(
"NewGroupCreated", $object->name);
149 } elseif ($action ==
'USERGROUP_MODIFY') {
150 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
151 $langs->load(
"users");
153 $text = $langs->transnoentities(
"GroupModified", $object->name);
154 $desc = $langs->transnoentities(
"GroupModified", $object->name);
155 } elseif ($action ==
'USERGROUP_DELETE') {
156 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
157 $langs->load(
"users");
159 $text = $langs->transnoentities(
"GroupDeleted", $object->name);
160 $desc = $langs->transnoentities(
"GroupDeleted", $object->name);
173 if (!empty($desc) && !empty($object->context[
'audit'])) {
174 $desc .=
' - '.$object->context[
'audit'];
178 include_once DOL_DOCUMENT_ROOT.
'/core/class/events.class.php';
181 $event->type = $action;
182 $event->dateevent = $date;
183 $event->label = $text;
184 $event->description = $desc;
185 $event->user_agent = (empty($_SERVER[
"HTTP_USER_AGENT"]) ?
'' : $_SERVER[
"HTTP_USER_AGENT"]);
187 $result = $event->create($user);
191 $error =
"Failed to insert security event: ".$event->error;
192 $this->errors[] = $error;
193 $this->error = $error;
195 dol_syslog(get_class($this).
": ".$error, LOG_ERR);
Class to stock current configuration.
Class that all the triggers must extend.
Class of triggers for security audit events.
__construct($db)
Constructor.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr security audit event is done.
Class to manage translations.
Class to manage Dolibarr users.
print *****$script_file(".$version.") pid 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.
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.
$conf db
API class for accounts.