27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/events.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35 $action =
GETPOST(
'action',
'aZ09');
36 $confirm =
GETPOST(
'confirm',
'alpha');
39 if ($user->socid > 0) {
41 $socid = $user->socid;
45 $langs->loadLangs(array(
"companies",
"admin",
"users",
"other",
"withdrawals"));
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) {
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
59 $sortfield =
"dateevent";
65 $search_code =
GETPOST(
"search_code",
"alpha");
66 $search_ip =
GETPOST(
"search_ip",
"alpha");
67 $search_user =
GETPOST(
"search_user",
"alpha");
68 $search_desc =
GETPOST(
"search_desc",
"alpha");
69 $search_ua =
GETPOST(
"search_ua",
"restricthtml");
70 $search_prefix_session =
GETPOST(
"search_prefix_session",
"restricthtml");
71 $optioncss =
GETPOST(
"optioncss",
"aZ");
76 if (
GETPOST(
"date_startmonth",
'int') > 0) {
81 if (
GETPOST(
"date_endmonth",
'int') > 0) {
82 $date_end =
dol_get_last_hour(
dol_mktime(23, 59, 59,
GETPOST(
"date_endmonth",
'int'),
GETPOST(
"date_endday",
'int'),
GETPOST(
"date_endyear",
'int'),
'tzuserrel'),
'tzuserrel');
88 if ($date_start !==
'' && $date_end !==
'' && $date_start > $date_end) {
89 $date_end = $date_start + 86400;
94 $date_start =
dol_get_first_day($nowarray[
'year'], $nowarray[
'mon'],
'tzuserrel');
97 $date_end =
dol_get_last_day($nowarray[
'year'], $nowarray[
'mon'],
'tzuserrel');
102 $date_startmonth =
'';
103 $date_startyear =
'';
107 if ($date_start !==
'') {
109 $date_startday = $tmp[
'mday'];
110 $date_startmonth = $tmp[
'mon'];
111 $date_startyear = $tmp[
'year'];
113 if ($date_end !==
'') {
115 $date_endday = $tmp[
'mday'];
116 $date_endmonth = $tmp[
'mon'];
117 $date_endyear = $tmp[
'year'];
121 $arrayfields = array(
122 'e.prefix_session' => array(
123 'label'=>
'UserAgent',
124 'checked'=>(empty($conf->global->AUDIT_ENABLE_PREFIX_SESSION) ? 0 : 1),
125 'enabled'=>(empty($conf->global->AUDIT_ENABLE_PREFIX_SESSION) ? 0 : 1),
138 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
143 $date_startmonth =
'';
145 $date_startyear =
'';
152 $search_prefix_session =
'';
156 if ($action ==
'confirm_purge' && $confirm ==
'yes' && $user->admin) {
160 $securityevents =
new Events($db);
163 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"events";
164 $sql .=
" WHERE entity = ".$conf->entity;
167 $resql = $db->query($sql);
174 $text = $langs->trans(
"SecurityEventsPurged");
175 $securityevent =
new Events($db);
176 $securityevent->type =
'SECURITY_EVENTS_PURGE';
177 $securityevent->dateevent = $now;
178 $securityevent->description = $text;
180 $result = $securityevent->create($user);
196 $title = $langs->trans(
"Audit");
201 $userstatic =
new User($db);
204 $sql =
"SELECT e.rowid, e.type, e.ip, e.user_agent, e.dateevent,";
205 $sql .=
" e.fk_user, e.description, e.prefix_session,";
206 $sql .=
" u.login, u.admin, u.entity, u.firstname, u.lastname, u.statut as status";
207 $sql .=
" FROM ".MAIN_DB_PREFIX.
"events as e";
208 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = e.fk_user";
209 $sql .=
" WHERE e.entity IN (".getEntity(
'event').
")";
210 if ($date_start !==
'') {
211 $sql .=
" AND e.dateevent >= '".$db->idate($date_start).
"'";
213 if ($date_end !==
'' ) {
214 $sql .=
" AND e.dateevent <= '".$db->idate($date_end).
"'";
226 $usefilter++; $sql .=
natural_search(
"e.description", $search_desc, 0);
229 $usefilter++; $sql .=
natural_search(
"e.user_agent", $search_ua, 0);
231 if ($search_prefix_session) {
232 $usefilter++; $sql .=
natural_search(
"e.prefix_session", $search_prefix_session, 0);
234 $sql .= $db->order($sortfield, $sortorder);
237 $nbtotalofrecords =
'';
249 $sql .= $db->plimit($limit + 1, $offset);
251 $result = $db->query($sql);
253 $num = $db->num_rows($result);
257 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
258 $param .=
'&contextpage='.urlencode($contextpage);
260 if ($limit > 0 && $limit != $conf->liste_limit) {
261 $param .=
'&limit='.urlencode($limit);
263 if ($optioncss !=
'') {
264 $param .=
'&optioncss='.urlencode($optioncss);
267 $param .=
'&search_code='.urlencode($search_code);
270 $param .=
'&search_ip='.urlencode($search_ip);
273 $param .=
'&search_user='.urlencode($search_user);
276 $param .=
'&search_desc='.urlencode($search_desc);
279 $param .=
'&search_ua='.urlencode($search_ua);
281 if ($search_prefix_session) {
282 $param .=
'&search_prefix_session='.urlencode($search_prefix_session);
284 if ($date_startmonth) {
285 $param .=
"&date_startmonth=".urlencode($date_startmonth);
287 if ($date_startday) {
288 $param .=
"&date_startday=".urlencode($date_startday);
290 if ($date_startyear) {
291 $param .=
"&date_startyear=".urlencode($date_startyear);
293 if ($date_endmonth) {
294 $param .=
"&date_endmonth=".urlencode($date_endmonth);
297 $param .=
"&date_endday=".urlencode($date_endday);
300 $param .=
"&date_endyear=".urlencode($date_endyear);
305 $center =
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?action=purge">'.$langs->trans(
"Purge").
'</a>';
308 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
309 print
'<input type="hidden" name="token" value="'.newToken().
'">';
311 print_barre_liste($langs->trans(
"ListOfSecurityEvents"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $nbtotalofrecords,
'setup', 0,
'',
'', $limit);
313 if ($action ==
'purge') {
314 $formquestion = array();
315 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?noparam=noparam', $langs->trans(
'PurgeAuditEvents'), $langs->trans(
'ConfirmPurgeAuditEvents'),
'confirm_purge', $formquestion,
'no', 1);
332 print
'<div class="div-table-responsive">';
333 print
'<table class="liste centpercent">';
336 print
'<tr class="liste_titre">';
338 print
'<td class="liste_titre" width="15%">';
339 print
$form->selectDate($date_start ===
'' ? -1 : $date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzuserrel');
340 print
$form->selectDate($date_end ===
'' ? -1 : $date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzuserrel');
343 print
'<td class="liste_titre left">';
344 print
'<input class="flat maxwidth100" type="text" name="search_code" value="'.dol_escape_htmltag($search_code).
'">';
348 print
'<td class="liste_titre left">';
349 print
'<input class="flat maxwidth100" type="text" name="search_ip" value="'.dol_escape_htmltag($search_ip).
'">';
352 print
'<td class="liste_titre left">';
353 print
'<input class="flat maxwidth100" type="text" name="search_user" value="'.dol_escape_htmltag($search_user).
'">';
356 print
'<td class="liste_titre left">';
360 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
361 print
'<td class="liste_titre left">';
362 print
'<input class="flat maxwidth100" type="text" name="search_ua" value="'.dol_escape_htmltag($search_ua).
'">';
366 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
367 print
'<td class="liste_titre left">';
368 print
'<input class="flat maxwidth100" type="text" name="search_prefix_session" value="'.dol_escape_htmltag($search_prefix_session).
'">';
372 print
'<td class="liste_titre maxwidthsearch">';
373 $searchpicto =
$form->showFilterAndCheckAddButtons(0);
380 print
'<tr class="liste_titre">';
385 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"e.description",
"", $param,
'', $sortfield, $sortorder);
386 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
387 print_liste_field_titre(
"UserAgent", $_SERVER[
"PHP_SELF"],
"e.user_agent",
"", $param,
'', $sortfield, $sortorder);
389 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
390 print_liste_field_titre(
"SuffixSessionName", $_SERVER[
"PHP_SELF"],
"e.prefix_session",
"", $param,
'', $sortfield, $sortorder);
395 while ($i < min($num, $limit)) {
396 $obj = $db->fetch_object($result);
398 print
'<tr class="oddeven">';
401 print
'<td class="nowrap left">'.dol_print_date($db->jdate($obj->dateevent),
'%Y-%m-%d %H:%M:%S',
'tzuserrel').
'</td>';
404 print
'<td>'.$obj->type.
'</td>';
407 print
'<td class="nowrap">';
412 print
'<td class="nowrap">';
414 $userstatic->id = $obj->fk_user;
415 $userstatic->login = $obj->login;
416 $userstatic->admin = $obj->admin;
417 $userstatic->entity = $obj->entity;
418 $userstatic->status = $obj->status;
420 print $userstatic->getLoginUrl(1);
421 if (!empty($conf->multicompany->enabled) && $userstatic->admin && !$userstatic->entity) {
422 print
img_picto($langs->trans(
"SuperAdministrator"),
'redstar',
'class="valignmiddle paddingleft"');
423 } elseif ($userstatic->admin) {
424 print
img_picto($langs->trans(
"Administrator"),
'star',
'class="valignmiddle paddingleft"');
433 $text = $langs->trans($obj->description);
435 if (preg_match(
'/\((.*)\)(.*)/i', $obj->description, $reg)) {
436 $val = explode(
',', $reg[1]);
437 $text = $langs->trans($val[0], isset($val[1]) ? $val[1] :
'', isset($val[2]) ? $val[2] :
'', isset($val[3]) ? $val[3] :
'', isset($val[4]) ? $val[4] :
'');
438 if (!empty($reg[2])) {
445 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
448 print $obj->user_agent;
452 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
455 print $obj->prefix_session;
460 print
'<td class="right">';
461 $htmltext =
'<b>'.$langs->trans(
"UserAgent").
'</b>: '.($obj->user_agent ?
dol_string_nohtmltag($obj->user_agent) : $langs->trans(
"Unknown"));
462 $htmltext .=
'<br><b>'.$langs->trans(
"PrefixSession").
'</b>: '.($obj->prefix_session ?
dol_string_nohtmltag($obj->prefix_session) : $langs->trans(
"Unknown"));
463 print
$form->textwithpicto(
'', $htmltext);
472 print
'<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"NoEventFoundWithCriteria").
'</span></td></tr>';
474 print
'<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"NoEventOrNoAuditSetup").
'</span></td></tr>';