PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/triggers/interface_all_Logevents.class.php

https://github.com/asterix14/dolibarr
PHP | 255 lines | 151 code | 29 blank | 75 comment | 39 complexity | f1c923d8c0e63a66caab8febe5c25d74 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/triggers/interface_all_Logevents.class.php
  20. * \ingroup core
  21. * \brief Trigger file for
  22. */
  23. /**
  24. * \class InterfaceLogevents
  25. * \brief Class of triggers for security events
  26. */
  27. class InterfaceLogevents
  28. {
  29. var $db;
  30. var $error;
  31. var $date;
  32. var $duree;
  33. var $texte;
  34. var $desc;
  35. /**
  36. * Constructor.
  37. * @param DB Database handler
  38. */
  39. function InterfaceLogevents($DB)
  40. {
  41. $this->db = $DB ;
  42. $this->name = preg_replace('/^Interface/i','',get_class($this));
  43. $this->family = "core";
  44. $this->description = "Triggers of this module allows to add security event records inside Dolibarr.";
  45. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  46. $this->picto = 'technic';
  47. }
  48. /**
  49. * Return name of trigger file
  50. * @return string Name of trigger file
  51. */
  52. function getName()
  53. {
  54. return $this->name;
  55. }
  56. /**
  57. * Return description of trigger file
  58. * @return string Description of trigger file
  59. */
  60. function getDesc()
  61. {
  62. return $this->description;
  63. }
  64. /**
  65. * Return version of trigger file
  66. * @return string Version of trigger file
  67. */
  68. function getVersion()
  69. {
  70. global $langs;
  71. $langs->load("admin");
  72. if ($this->version == 'experimental') return $langs->trans("Experimental");
  73. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  74. elseif ($this->version) return $this->version;
  75. else return $langs->trans("Unknown");
  76. }
  77. /**
  78. * Function called when a Dolibarrr business event is done.
  79. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  80. * @param action Code de l'evenement
  81. * @param object Objet concerne
  82. * @param user Objet user
  83. * @param langs Objet langs
  84. * @param conf Objet conf
  85. * @param entity Value for instance of data (Always 1 except if module MultiCompany is installed)
  86. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  87. */
  88. function run_trigger($action,$object,$user,$langs,$conf,$entity=1)
  89. {
  90. if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features)
  91. $key='MAIN_LOGEVENTS_'.$action;
  92. //dol_syslog("xxxxxxxxxxx".$key);
  93. if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
  94. if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form)
  95. $this->date=gmmktime();
  96. $this->duree=0;
  97. // Actions
  98. if ($action == 'USER_LOGIN')
  99. {
  100. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  101. // Initialisation donnees (date,duree,texte,desc)
  102. $this->texte="(UserLogged,".$object->login.")";
  103. $this->desc="(UserLogged,".$object->login.")";
  104. }
  105. if ($action == 'USER_LOGIN_FAILED')
  106. {
  107. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  108. // Initialisation donnees (date,duree,texte,desc)
  109. $this->texte=$object->trigger_mesg; // Message direct
  110. $this->desc=$object->trigger_mesg; // Message direct
  111. }
  112. if ($action == 'USER_LOGOUT')
  113. {
  114. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  115. // Initialisation donnees (date,duree,texte,desc)
  116. $this->texte="(UserLogoff,".$object->login.")";
  117. $this->desc="(UserLogoff,".$object->login.")";
  118. }
  119. if ($action == 'USER_CREATE')
  120. {
  121. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  122. $langs->load("users");
  123. // Initialisation donnees (date,duree,texte,desc)
  124. $this->texte=$langs->transnoentities("NewUserCreated",$object->login);
  125. $this->desc=$langs->transnoentities("NewUserCreated",$object->login);
  126. }
  127. elseif ($action == 'USER_MODIFY')
  128. {
  129. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  130. $langs->load("users");
  131. // Initialisation donnees (date,duree,texte,desc)
  132. $this->texte=$langs->transnoentities("EventUserModified",$object->login);
  133. $this->desc=$langs->transnoentities("EventUserModified",$object->login);
  134. }
  135. elseif ($action == 'USER_NEW_PASSWORD')
  136. {
  137. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  138. $langs->load("users");
  139. // Initialisation donnees (date,duree,texte,desc)
  140. $this->texte=$langs->transnoentities("NewUserPassword",$object->login);
  141. $this->desc=$langs->transnoentities("NewUserPassword",$object->login);
  142. }
  143. elseif ($action == 'USER_ENABLEDISABLE')
  144. {
  145. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  146. $langs->load("users");
  147. // Initialisation donnees (date,duree,texte,desc)
  148. if ($object->statut == 0)
  149. {
  150. $this->texte=$langs->transnoentities("UserEnabled",$object->login);
  151. $this->desc=$langs->transnoentities("UserEnabled",$object->login);
  152. }
  153. if ($object->statut == 1)
  154. {
  155. $this->texte=$langs->transnoentities("UserDisabled",$object->login);
  156. $this->desc=$langs->transnoentities("UserDisabled",$object->login);
  157. }
  158. }
  159. elseif ($action == 'USER_DELETE')
  160. {
  161. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  162. $langs->load("users");
  163. // Initialisation donnees (date,duree,texte,desc)
  164. $this->texte=$langs->transnoentities("UserDeleted",$object->login);
  165. $this->desc=$langs->transnoentities("UserDeleted",$object->login);
  166. }
  167. // Groupes
  168. elseif ($action == 'GROUP_CREATE')
  169. {
  170. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  171. $langs->load("users");
  172. // Initialisation donnees (date,duree,texte,desc)
  173. $this->texte=$langs->transnoentities("NewGroupCreated",$object->nom);
  174. $this->desc=$langs->transnoentities("NewGroupCreated",$object->nom);
  175. }
  176. elseif ($action == 'GROUP_MODIFY')
  177. {
  178. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  179. $langs->load("users");
  180. // Initialisation donnees (date,duree,texte,desc)
  181. $this->texte=$langs->transnoentities("GroupModified",$object->nom);
  182. $this->desc=$langs->transnoentities("GroupModified",$object->nom);
  183. }
  184. elseif ($action == 'GROUP_DELETE')
  185. {
  186. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  187. $langs->load("users");
  188. // Initialisation donnees (date,duree,texte,desc)
  189. $this->texte=$langs->transnoentities("GroupDeleted",$object->nom);
  190. $this->desc=$langs->transnoentities("GroupDeleted",$object->nom);
  191. }
  192. // If not found
  193. /*
  194. else
  195. {
  196. dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
  197. return 0;
  198. }
  199. */
  200. // Add entry in event table
  201. if ($this->date)
  202. {
  203. include_once(DOL_DOCUMENT_ROOT.'/core/class/events.class.php');
  204. $event=new Events($this->db);
  205. $event->type=$action;
  206. $event->dateevent=$this->date;
  207. $event->label=$this->texte;
  208. $event->description=$this->desc;
  209. $event->user_agent=$_SERVER["HTTP_USER_AGENT"];
  210. $result=$event->create($user);
  211. if ($result > 0)
  212. {
  213. return 1;
  214. }
  215. else
  216. {
  217. $error ="Failed to insert security event: ".$event->error;
  218. $this->error=$error;
  219. dol_syslog("interface_all_Logevents.class.php: ".$this->error, LOG_ERR);
  220. return -1;
  221. }
  222. }
  223. return 0;
  224. }
  225. }
  226. ?>