1 | <?php |
||||
2 | /* Copyright (C) 2005-2009 Laurent Destailleur <[email protected]> |
||||
3 | * Copyright (C) 2009-2017 Regis Houssin <[email protected]> |
||||
4 | * Copyright (C) 2014 Marcos García <[email protected]> |
||||
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 <http://www.gnu.org/licenses/>. |
||||
18 | */ |
||||
19 | |||||
20 | /** |
||||
21 | * \file htdocs/core/triggers/interface_20_all_Logevents.class.php |
||||
22 | * \ingroup core |
||||
23 | * \brief Trigger file for |
||||
24 | */ |
||||
25 | |||||
26 | require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; |
||||
27 | |||||
28 | |||||
29 | /** |
||||
30 | * Class of triggers for security events |
||||
31 | */ |
||||
32 | class InterfaceLogevents extends DolibarrTriggers |
||||
33 | { |
||||
34 | /** |
||||
35 | * @var string Image of the trigger |
||||
36 | */ |
||||
37 | public $picto = 'technic'; |
||||
38 | |||||
39 | public $family = 'core'; |
||||
40 | |||||
41 | public $description = "Triggers of this module allows to add security event records inside Dolibarr."; |
||||
42 | |||||
43 | /** |
||||
44 | * Version of the trigger |
||||
45 | * @var string |
||||
46 | */ |
||||
47 | public $version = self::VERSION_DOLIBARR; |
||||
48 | |||||
49 | /** |
||||
50 | * Function called when a Dolibarrr business event is done. |
||||
51 | * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
||||
52 | * |
||||
53 | * @param string $action Event action code |
||||
54 | * @param Object $object Object |
||||
55 | * @param User $user Object user |
||||
56 | * @param Translate $langs Object langs |
||||
57 | * @param conf $conf Object conf |
||||
58 | * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
||||
59 | */ |
||||
60 | public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
||||
61 | { |
||||
62 | if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features) |
||||
63 | |||||
64 | $key='MAIN_LOGEVENTS_'.$action; |
||||
65 | //dol_syslog("xxxxxxxxxxx".$key); |
||||
66 | if (empty($conf->global->$key)) return 0; // Log events not enabled for this action |
||||
67 | |||||
68 | if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) |
||||
69 | |||||
70 | $date = dol_now(); |
||||
71 | |||||
72 | // Actions |
||||
73 | if ($action == 'USER_LOGIN') |
||||
74 | { |
||||
75 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
76 | |||||
77 | $langs->load("users"); |
||||
78 | // Initialisation donnees (date,duree,texte,desc) |
||||
79 | $text="(UserLogged,".$object->login.")"; |
||||
80 | $text.=(empty($object->trigger_mesg)?'':' - '.$object->trigger_mesg); |
||||
81 | $desc="(UserLogged,".$object->login.")"; |
||||
82 | $desc.=(empty($object->trigger_mesg)?'':' - '.$object->trigger_mesg); |
||||
83 | } |
||||
84 | if ($action == 'USER_LOGIN_FAILED') |
||||
85 | { |
||||
86 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
87 | |||||
88 | // Initialisation donnees (date,duree,texte,desc) |
||||
89 | $text=$object->trigger_mesg; // Message direct |
||||
90 | $desc=$object->trigger_mesg; // Message direct |
||||
91 | } |
||||
92 | if ($action == 'USER_LOGOUT') |
||||
93 | { |
||||
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 | } |
||||
101 | if ($action == 'USER_CREATE') |
||||
102 | { |
||||
103 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
104 | $langs->load("users"); |
||||
105 | |||||
106 | // Initialisation donnees (date,duree,texte,desc) |
||||
107 | $text=$langs->transnoentities("NewUserCreated",$object->login); |
||||
108 | $desc=$langs->transnoentities("NewUserCreated",$object->login); |
||||
109 | } |
||||
110 | elseif ($action == 'USER_MODIFY') |
||||
111 | { |
||||
112 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
113 | $langs->load("users"); |
||||
114 | |||||
115 | // Initialisation donnees (date,duree,texte,desc) |
||||
116 | $text=$langs->transnoentities("EventUserModified",$object->login); |
||||
117 | $desc=$langs->transnoentities("EventUserModified",$object->login); |
||||
118 | } |
||||
119 | elseif ($action == 'USER_NEW_PASSWORD') |
||||
120 | { |
||||
121 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
122 | $langs->load("users"); |
||||
123 | |||||
124 | // Initialisation donnees (date,duree,texte,desc) |
||||
125 | $text=$langs->transnoentities("NewUserPassword",$object->login); |
||||
126 | $desc=$langs->transnoentities("NewUserPassword",$object->login); |
||||
127 | } |
||||
128 | elseif ($action == 'USER_ENABLEDISABLE') |
||||
129 | { |
||||
130 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
131 | $langs->load("users"); |
||||
132 | // Initialisation donnees (date,duree,texte,desc) |
||||
133 | if ($object->statut == 0) |
||||
134 | { |
||||
135 | $text=$langs->transnoentities("UserEnabled",$object->login); |
||||
136 | $desc=$langs->transnoentities("UserEnabled",$object->login); |
||||
137 | } |
||||
138 | if ($object->statut == 1) |
||||
139 | { |
||||
140 | $text=$langs->transnoentities("UserDisabled",$object->login); |
||||
141 | $desc=$langs->transnoentities("UserDisabled",$object->login); |
||||
142 | } |
||||
143 | } |
||||
144 | elseif ($action == 'USER_DELETE') |
||||
145 | { |
||||
146 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
147 | $langs->load("users"); |
||||
148 | // Initialisation donnees (date,duree,texte,desc) |
||||
149 | $text=$langs->transnoentities("UserDeleted",$object->login); |
||||
150 | $desc=$langs->transnoentities("UserDeleted",$object->login); |
||||
151 | } |
||||
152 | |||||
153 | // Groupes |
||||
154 | elseif ($action == 'GROUP_CREATE') |
||||
155 | { |
||||
156 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
157 | $langs->load("users"); |
||||
158 | // Initialisation donnees (date,duree,texte,desc) |
||||
159 | $text=$langs->transnoentities("NewGroupCreated",$object->name); |
||||
160 | $desc=$langs->transnoentities("NewGroupCreated",$object->name); |
||||
161 | } |
||||
162 | elseif ($action == 'GROUP_MODIFY') |
||||
163 | { |
||||
164 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
165 | $langs->load("users"); |
||||
166 | // Initialisation donnees (date,duree,texte,desc) |
||||
167 | $text=$langs->transnoentities("GroupModified",$object->name); |
||||
168 | $desc=$langs->transnoentities("GroupModified",$object->name); |
||||
169 | } |
||||
170 | elseif ($action == 'GROUP_DELETE') |
||||
171 | { |
||||
172 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
||||
173 | $langs->load("users"); |
||||
174 | // Initialisation donnees (date,duree,texte,desc) |
||||
175 | $text=$langs->transnoentities("GroupDeleted",$object->name); |
||||
176 | $desc=$langs->transnoentities("GroupDeleted",$object->name); |
||||
177 | } |
||||
178 | |||||
179 | // If not found |
||||
180 | /* |
||||
181 | else |
||||
182 | { |
||||
183 | dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); |
||||
184 | return 0; |
||||
185 | } |
||||
186 | */ |
||||
187 | |||||
188 | // Add more information into desc from the context property |
||||
189 | if (! empty($desc) && ! empty($object->context['audit'])) $desc.=' - '.$object->context['audit']; |
||||
190 | |||||
191 | // Add entry in event table |
||||
192 | include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php'; |
||||
193 | |||||
194 | $event=new Events($this->db); |
||||
195 | $event->type=$action; |
||||
196 | $event->dateevent=$date; |
||||
197 | $event->label=$text; |
||||
198 | $event->description=$desc; |
||||
199 | $event->user_agent=$_SERVER["HTTP_USER_AGENT"]; |
||||
200 | |||||
201 | $result=$event->create($user); |
||||
202 | if ($result > 0) |
||||
203 | { |
||||
204 | return 1; |
||||
205 | } |
||||
206 | else |
||||
207 | { |
||||
208 | $error ="Failed to insert security event: ".$event->error; |
||||
209 | $this->error=$error; |
||||
0 ignored issues
–
show
|
|||||
210 | |||||
211 | dol_syslog(get_class($this).": ".$this->error, LOG_ERR); |
||||
0 ignored issues
–
show
The property
DolibarrTriggers::$error has been deprecated: Use $this->errors
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.
Loading history...
|
|||||
212 | return -1; |
||||
213 | } |
||||
214 | } |
||||
215 | } |
||||
216 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.