dolibarr 18.0.6
interface_20_all_Logevents.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
27
28
33{
39 public function __construct($db)
40 {
41 $this->db = $db;
42
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.";
46 // 'development', 'experimental', 'dolibarr' or version
47 $this->version = self::VERSION_DOLIBARR;
48 $this->picto = 'technic';
49 }
50
62 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
63 {
64 if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) {
65 return 0; // Log events is disabled (hidden features)
66 }
67
68 $key = 'MAIN_LOGEVENTS_'.$action;
69 //dol_syslog("xxxxxxxxxxx".$key);
70 if (empty($conf->global->$key)) {
71 return 0; // Log events not enabled for this action
72 }
73
74 if (empty($conf->entity)) {
75 $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form)
76 }
77
78 $date = dol_now();
79
80 $text = '';
81 $desc = '';
82
83 // Actions
84 if ($action == 'USER_LOGIN') {
85 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
86
87 $langs->load("users");
88 // Initialisation donnees (date,duree,texte,desc)
89 $text = "(UserLogged,".$object->login.")";
90 $desc = "(UserLogged,".$object->login.")";
91 } elseif ($action == 'USER_LOGIN_FAILED') {
92 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
93 } elseif ($action == 'USER_LOGOUT') {
94 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
95
96 $langs->load("users");
97 // Initialisation donnees (date,duree,texte,desc)
98 $text = "(UserLogoff,".$object->login.")";
99 $desc = "(UserLogoff,".$object->login.")";
100 } elseif ($action == 'USER_CREATE') {
101 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
102 $langs->load("users");
103
104 // Initialisation donnees (date,duree,texte,desc)
105 $text = $langs->transnoentities("NewUserCreated", $object->login);
106 $desc = $langs->transnoentities("NewUserCreated", $object->login);
107 } elseif ($action == 'USER_MODIFY') {
108 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
109 $langs->load("users");
110
111 // Initialisation donnees (date,duree,texte,desc)
112 $text = $langs->transnoentities("EventUserModified", $object->login);
113 $desc = $langs->transnoentities("EventUserModified", $object->login);
114 } elseif ($action == 'USER_NEW_PASSWORD') {
115 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
116 $langs->load("users");
117
118 // Initialisation donnees (date,duree,texte,desc)
119 $text = $langs->transnoentities("NewUserPassword", $object->login);
120 $desc = $langs->transnoentities("NewUserPassword", $object->login);
121 } elseif ($action == 'USER_ENABLEDISABLE') {
122 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
123 $langs->load("users");
124 // Initialisation donnees (date,duree,texte,desc)
125 if ($object->statut == 0) {
126 $text = $langs->transnoentities("UserEnabled", $object->login);
127 $desc = $langs->transnoentities("UserEnabled", $object->login);
128 }
129 if ($object->statut == 1) {
130 $text = $langs->transnoentities("UserDisabled", $object->login);
131 $desc = $langs->transnoentities("UserDisabled", $object->login);
132 }
133 } elseif ($action == 'USER_DELETE') {
134 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
135 $langs->load("users");
136 // Initialisation donnees (date,duree,texte,desc)
137 $text = $langs->transnoentities("UserDeleted", $object->login);
138 $desc = $langs->transnoentities("UserDeleted", $object->login);
139 } elseif ($action == 'USERGROUP_CREATE') {
140 // Groups
141 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
142 $langs->load("users");
143 // Initialisation donnees (date,duree,texte,desc)
144 $text = $langs->transnoentities("NewGroupCreated", $object->name);
145 $desc = $langs->transnoentities("NewGroupCreated", $object->name);
146 } elseif ($action == 'USERGROUP_MODIFY') {
147 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
148 $langs->load("users");
149 // Initialisation donnees (date,duree,texte,desc)
150 $text = $langs->transnoentities("GroupModified", $object->name);
151 $desc = $langs->transnoentities("GroupModified", $object->name);
152 } elseif ($action == 'USERGROUP_DELETE') {
153 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
154 $langs->load("users");
155 // Initialisation donnees (date,duree,texte,desc)
156 $text = $langs->transnoentities("GroupDeleted", $object->name);
157 $desc = $langs->transnoentities("GroupDeleted", $object->name);
158 }
159
160 // If not found
161 /*
162 else
163 {
164 dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
165 return 0;
166 }
167 */
168
169 // Add more information into desc from the context property
170 if (!empty($object->context['audit'])) {
171 $desc .= (empty($desc) ? '' : ' - ').$object->context['audit'];
172 }
173
174 // Add entry in event table
175 include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
176
177 $event = new Events($this->db);
178 $event->type = $action;
179 $event->dateevent = $date;
180 $event->label = $text;
181 $event->description = $desc;
182 $event->user_agent = (empty($_SERVER["HTTP_USER_AGENT"]) ? '' : $_SERVER["HTTP_USER_AGENT"]);
183 $event->authentication_method = (empty($object->context['authentication_method']) ? '' : $object->context['authentication_method']);
184
185 $result = $event->create($user);
186 if ($result > 0) {
187 return 1;
188 } else {
189 $error = "Failed to insert security event: ".$event->error;
190 $this->errors[] = $error;
191 $this->error = $error;
192
193 dol_syslog(get_class($this).": ".$error, LOG_ERR);
194 return -1;
195 }
196 }
197}
Class to stock current configuration.
Class that all the triggers must extend.
Events class.
Class of triggers for security audit events.
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 $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.
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.
Definition repair.php:123