dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
18  */
19 
26 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
27 
28 
33 {
34  public $picto = 'technic';
35  public $family = 'core';
36  public $description = "Triggers of this module allows to add security event records inside Dolibarr.";
37  public $version = self::VERSION_DOLIBARR;
38 
50  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
51  {
52  if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features)
53 
54  $key='MAIN_LOGEVENTS_'.$action;
55  //dol_syslog("xxxxxxxxxxx".$key);
56  if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
57 
58  if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form)
59 
60  $date = dol_now();
61 
62  // Actions
63  if ($action == 'USER_LOGIN')
64  {
65  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
66 
67  $langs->load("users");
68  // Initialisation donnees (date,duree,texte,desc)
69  $text="(UserLogged,".$object->login.")";
70  $text.=(empty($object->trigger_mesg)?'':' - '.$object->trigger_mesg);
71  $desc="(UserLogged,".$object->login.")";
72  $desc.=(empty($object->trigger_mesg)?'':' - '.$object->trigger_mesg);
73  }
74  if ($action == 'USER_LOGIN_FAILED')
75  {
76  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
77 
78  // Initialisation donnees (date,duree,texte,desc)
79  $text=$object->trigger_mesg; // Message direct
80  $desc=$object->trigger_mesg; // Message direct
81  }
82  if ($action == 'USER_LOGOUT')
83  {
84  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
85 
86  $langs->load("users");
87  // Initialisation donnees (date,duree,texte,desc)
88  $text="(UserLogoff,".$object->login.")";
89  $desc="(UserLogoff,".$object->login.")";
90  }
91  if ($action == 'USER_CREATE')
92  {
93  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
94  $langs->load("users");
95 
96  // Initialisation donnees (date,duree,texte,desc)
97  $text=$langs->transnoentities("NewUserCreated",$object->login);
98  $desc=$langs->transnoentities("NewUserCreated",$object->login);
99  }
100  elseif ($action == 'USER_MODIFY')
101  {
102  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
103  $langs->load("users");
104 
105  // Initialisation donnees (date,duree,texte,desc)
106  $text=$langs->transnoentities("EventUserModified",$object->login);
107  $desc=$langs->transnoentities("EventUserModified",$object->login);
108  }
109  elseif ($action == 'USER_NEW_PASSWORD')
110  {
111  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
112  $langs->load("users");
113 
114  // Initialisation donnees (date,duree,texte,desc)
115  $text=$langs->transnoentities("NewUserPassword",$object->login);
116  $desc=$langs->transnoentities("NewUserPassword",$object->login);
117  }
118  elseif ($action == 'USER_ENABLEDISABLE')
119  {
120  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
121  $langs->load("users");
122  // Initialisation donnees (date,duree,texte,desc)
123  if ($object->statut == 0)
124  {
125  $text=$langs->transnoentities("UserEnabled",$object->login);
126  $desc=$langs->transnoentities("UserEnabled",$object->login);
127  }
128  if ($object->statut == 1)
129  {
130  $text=$langs->transnoentities("UserDisabled",$object->login);
131  $desc=$langs->transnoentities("UserDisabled",$object->login);
132  }
133  }
134  elseif ($action == 'USER_DELETE')
135  {
136  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
137  $langs->load("users");
138  // Initialisation donnees (date,duree,texte,desc)
139  $text=$langs->transnoentities("UserDeleted",$object->login);
140  $desc=$langs->transnoentities("UserDeleted",$object->login);
141  }
142 
143  // Groupes
144  elseif ($action == 'GROUP_CREATE')
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("NewGroupCreated",$object->name);
150  $desc=$langs->transnoentities("NewGroupCreated",$object->name);
151  }
152  elseif ($action == 'GROUP_MODIFY')
153  {
154  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
155  $langs->load("users");
156  // Initialisation donnees (date,duree,texte,desc)
157  $text=$langs->transnoentities("GroupModified",$object->name);
158  $desc=$langs->transnoentities("GroupModified",$object->name);
159  }
160  elseif ($action == 'GROUP_DELETE')
161  {
162  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
163  $langs->load("users");
164  // Initialisation donnees (date,duree,texte,desc)
165  $text=$langs->transnoentities("GroupDeleted",$object->name);
166  $desc=$langs->transnoentities("GroupDeleted",$object->name);
167  }
168 
169  // If not found
170 /*
171  else
172  {
173  dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
174  return 0;
175  }
176 */
177 
178  // Add more information into desc from the context property
179  if (! empty($desc) && ! empty($object->context['audit'])) $desc.=' - '.$object->context['audit'];
180 
181  // Add entry in event table
182  include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
183 
184  $event=new Events($this->db);
185  $event->type=$action;
186  $event->dateevent=$date;
187  $event->label=$text;
188  $event->description=$desc;
189  $event->user_agent=$_SERVER["HTTP_USER_AGENT"];
190 
191  $result=$event->create($user);
192  if ($result > 0)
193  {
194  return 1;
195  }
196  else
197  {
198  $error ="Failed to insert security event: ".$event->error;
199  $this->error=$error;
200 
201  dol_syslog(get_class($this).": ".$this->error, LOG_ERR);
202  return -1;
203  }
204  }
205 
206 }
Class to stock current configuration.
Definition: conf.class.php:33
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Class to manage Dolibarr users.
Definition: user.class.php:39
Class of triggers for security events.
load($domain, $alt=0, $stopafterdirection=0, $forcelangdir='', $loadfromfileonly=0)
Load translation key-value for a particular file, into a memory array.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage translations.
dol_now($mode='gmt')
Return date for now.
Class that all the triggers must extend.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
transnoentities($key, $param1='', $param2='', $param3='', $param4='')
Return translated value of a text string Si il n'y a pas de correspondance pour ce texte...
Events class.