dolibarr  13.0.2
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 
26 require_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)) return 0; // Log events is disabled (hidden features)
65 
66  $key = 'MAIN_LOGEVENTS_'.$action;
67  //dol_syslog("xxxxxxxxxxx".$key);
68  if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
69 
70  if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form)
71 
72  $date = dol_now();
73 
74  // Actions
75  if ($action == 'USER_LOGIN') {
76  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
77 
78  $langs->load("users");
79  // Initialisation donnees (date,duree,texte,desc)
80  $text = "(UserLogged,".$object->login.")";
81  $text .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg);
82  $desc = "(UserLogged,".$object->login.")";
83  $desc .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg);
84  } elseif ($action == 'USER_LOGIN_FAILED') {
85  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
86 
87  // Initialisation donnees (date,duree,texte,desc)
88  $text = $object->trigger_mesg; // Message direct
89  $desc = $object->trigger_mesg; // Message direct
90  } elseif ($action == 'USER_LOGOUT') {
91  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
92 
93  $langs->load("users");
94  // Initialisation donnees (date,duree,texte,desc)
95  $text = "(UserLogoff,".$object->login.")";
96  $desc = "(UserLogoff,".$object->login.")";
97  } elseif ($action == 'USER_CREATE') {
98  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
99  $langs->load("users");
100 
101  // Initialisation donnees (date,duree,texte,desc)
102  $text = $langs->transnoentities("NewUserCreated", $object->login);
103  $desc = $langs->transnoentities("NewUserCreated", $object->login);
104  } elseif ($action == 'USER_MODIFY') {
105  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
106  $langs->load("users");
107 
108  // Initialisation donnees (date,duree,texte,desc)
109  $text = $langs->transnoentities("EventUserModified", $object->login);
110  $desc = $langs->transnoentities("EventUserModified", $object->login);
111  } elseif ($action == 'USER_NEW_PASSWORD') {
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("NewUserPassword", $object->login);
117  $desc = $langs->transnoentities("NewUserPassword", $object->login);
118  } elseif ($action == 'USER_ENABLEDISABLE') {
119  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
120  $langs->load("users");
121  // Initialisation donnees (date,duree,texte,desc)
122  if ($object->statut == 0) {
123  $text = $langs->transnoentities("UserEnabled", $object->login);
124  $desc = $langs->transnoentities("UserEnabled", $object->login);
125  }
126  if ($object->statut == 1) {
127  $text = $langs->transnoentities("UserDisabled", $object->login);
128  $desc = $langs->transnoentities("UserDisabled", $object->login);
129  }
130  } elseif ($action == 'USER_DELETE') {
131  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
132  $langs->load("users");
133  // Initialisation donnees (date,duree,texte,desc)
134  $text = $langs->transnoentities("UserDeleted", $object->login);
135  $desc = $langs->transnoentities("UserDeleted", $object->login);
136  } elseif ($action == 'USERGROUP_CREATE') {
137  // Groups
138  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
139  $langs->load("users");
140  // Initialisation donnees (date,duree,texte,desc)
141  $text = $langs->transnoentities("NewGroupCreated", $object->name);
142  $desc = $langs->transnoentities("NewGroupCreated", $object->name);
143  } elseif ($action == 'USERGROUP_MODIFY') {
144  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
145  $langs->load("users");
146  // Initialisation donnees (date,duree,texte,desc)
147  $text = $langs->transnoentities("GroupModified", $object->name);
148  $desc = $langs->transnoentities("GroupModified", $object->name);
149  } elseif ($action == 'USERGROUP_DELETE') {
150  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
151  $langs->load("users");
152  // Initialisation donnees (date,duree,texte,desc)
153  $text = $langs->transnoentities("GroupDeleted", $object->name);
154  $desc = $langs->transnoentities("GroupDeleted", $object->name);
155  }
156 
157  // If not found
158  /*
159  else
160  {
161  dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
162  return 0;
163  }
164  */
165 
166  // Add more information into desc from the context property
167  if (!empty($desc) && !empty($object->context['audit'])) $desc .= ' - '.$object->context['audit'];
168 
169  // Add entry in event table
170  include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
171 
172  $event = new Events($this->db);
173  $event->type = $action;
174  $event->dateevent = $date;
175  $event->label = $text;
176  $event->description = $desc;
177  $event->user_agent = (empty($_SERVER["HTTP_USER_AGENT"]) ? '' : $_SERVER["HTTP_USER_AGENT"]);
178 
179  $result = $event->create($user);
180  if ($result > 0) {
181  return 1;
182  } else {
183  $error = "Failed to insert security event: ".$event->error;
184  $this->errors[] = $error;
185  $this->error = $error;
186 
187  dol_syslog(get_class($this).": ".$error, LOG_ERR);
188  return -1;
189  }
190  }
191 }
Class to stock current configuration.
Definition: conf.class.php:33
transnoentities($key, $param1= '', $param2= '', $param3= '', $param4= '', $param5= '')
Return translated value of a text string If there is no match for this text, we look in alternative f...
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr security audit event is done.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class of triggers for security audit events.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage translations.
Class that all the triggers must extend.
print $_SERVER["PHP_SELF"]
Edit parameters.
load($domain, $alt=0, $stopafterdirection=0, $forcelangdir= '', $loadfromfileonly=0, $forceloadifalreadynotfound=0)
Load translation key-value for a particular file, into a memory array.
Events class.