28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/events.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36$action =
GETPOST(
'action',
'aZ09');
37$confirm =
GETPOST(
'confirm',
'alpha');
40if ($user->socid > 0) {
42 $socid = $user->socid;
46$langs->loadLangs(array(
"companies",
"admin",
"users",
"other",
"withdrawals"));
49$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
50$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
53if (empty($page) || $page == -1) {
56$offset = $limit * $page;
60 $sortfield =
"e.rowid";
66$search_rowid =
GETPOST(
"search_rowid",
"int");
67$search_code =
GETPOST(
"search_code",
"alpha");
68$search_ip =
GETPOST(
"search_ip",
"alpha");
69$search_user =
GETPOST(
"search_user",
"alpha");
70$search_desc =
GETPOST(
"search_desc",
"alpha");
71$search_ua =
GETPOST(
"search_ua",
"restricthtml");
72$search_prefix_session =
GETPOST(
"search_prefix_session",
"restricthtml");
73$optioncss =
GETPOST(
"optioncss",
"aZ");
78if (
GETPOST(
"date_startmonth",
'int') > 0) {
83if (
GETPOST(
"date_endmonth",
'int') > 0) {
84 $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');
90if ($date_start !==
'' && $date_end !==
'' && $date_start > $date_end) {
91 $date_end = $date_start + 86400;
95if (!GETPOSTISSET(
'pageplusoneold') && !GETPOSTISSET(
'page') && $date_start ===
'') {
96 $date_start =
dol_get_first_day($nowarray[
'year'], $nowarray[
'mon'],
'tzuserrel');
98if (!GETPOSTISSET(
'pageplusoneold') && !GETPOSTISSET(
'page') && $date_end ===
'') {
99 $date_end =
dol_get_last_day($nowarray[
'year'], $nowarray[
'mon'],
'tzuserrel');
104$date_startmonth =
'';
109if ($date_start !==
'') {
111 $date_startday = $tmp[
'mday'];
112 $date_startmonth = $tmp[
'mon'];
113 $date_startyear = $tmp[
'year'];
115if ($date_end !==
'') {
117 $date_endday = $tmp[
'mday'];
118 $date_endmonth = $tmp[
'mon'];
119 $date_endyear = $tmp[
'year'];
124 'e.prefix_session' => array(
125 'label'=>
'UserAgent',
126 'checked'=>(empty($conf->global->AUDIT_ENABLE_PREFIX_SESSION) ? 0 : 1),
127 'enabled'=>(empty($conf->global->AUDIT_ENABLE_PREFIX_SESSION) ? 0 : 1),
140if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
145 $date_startmonth =
'';
147 $date_startyear =
'';
155 $search_prefix_session =
'';
159if ($action ==
'confirm_purge' && $confirm ==
'yes' && $user->admin) {
163 $securityevents =
new Events($db);
166 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"events";
167 $sql .=
" WHERE entity = ".$conf->entity;
170 $resql = $db->query($sql);
177 $text = $langs->trans(
"SecurityEventsPurged");
178 $securityevent =
new Events($db);
179 $securityevent->type =
'SECURITY_EVENTS_PURGE';
180 $securityevent->dateevent = $now;
181 $securityevent->description = $text;
183 $result = $securityevent->create($user);
199$title = $langs->trans(
"Audit");
202$form =
new Form($db);
204$userstatic =
new User($db);
207$sql =
"SELECT e.rowid, e.type, e.ip, e.user_agent, e.dateevent,";
208$sql .=
" e.fk_user, e.description, e.prefix_session,";
209$sql .=
" u.login, u.admin, u.entity, u.firstname, u.lastname, u.statut as status";
210$sql .=
" FROM ".MAIN_DB_PREFIX.
"events as e";
211$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = e.fk_user";
212$sql .=
" WHERE e.entity IN (".getEntity(
'event').
")";
213if ($date_start !==
'') {
214 $sql .=
" AND e.dateevent >= '".$db->idate($date_start).
"'";
216if ($date_end !==
'' ) {
217 $sql .=
" AND e.dateevent <= '".$db->idate($date_end).
"'";
220 $usefilter++; $sql .=
natural_search(
"e.rowid", $search_rowid, 1);
232 $usefilter++; $sql .=
natural_search(
"e.description", $search_desc, 0);
235 $usefilter++; $sql .=
natural_search(
"e.user_agent", $search_ua, 0);
237if ($search_prefix_session) {
238 $usefilter++; $sql .=
natural_search(
"e.prefix_session", $search_prefix_session, 0);
240$sql .= $db->order($sortfield, $sortorder);
243$nbtotalofrecords =
'';
255$sql .= $db->plimit($limit + 1, $offset);
257$result = $db->query($sql);
259 $num = $db->num_rows($result);
263 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
264 $param .=
'&contextpage='.urlencode($contextpage);
266 if ($limit > 0 && $limit != $conf->liste_limit) {
267 $param .=
'&limit='.((int) $limit);
269 if ($optioncss !=
'') {
270 $param .=
'&optioncss='.urlencode($optioncss);
273 $param .=
'&search_rowid='.urlencode($search_rowid);
276 $param .=
'&search_code='.urlencode($search_code);
279 $param .=
'&search_ip='.urlencode($search_ip);
282 $param .=
'&search_user='.urlencode($search_user);
285 $param .=
'&search_desc='.urlencode($search_desc);
288 $param .=
'&search_ua='.urlencode($search_ua);
290 if ($search_prefix_session) {
291 $param .=
'&search_prefix_session='.urlencode($search_prefix_session);
293 if ($date_startmonth) {
294 $param .=
"&date_startmonth=".urlencode($date_startmonth);
296 if ($date_startday) {
297 $param .=
"&date_startday=".urlencode($date_startday);
299 if ($date_startyear) {
300 $param .=
"&date_startyear=".urlencode($date_startyear);
302 if ($date_endmonth) {
303 $param .=
"&date_endmonth=".urlencode($date_endmonth);
306 $param .=
"&date_endday=".urlencode($date_endday);
309 $param .=
"&date_endyear=".urlencode($date_endyear);
314 $center =
'<a class="butActionDelete small" href="'.$_SERVER[
"PHP_SELF"].
'?action=purge">'.$langs->trans(
"Purge").
'</a>';
317 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
318 print
'<input type="hidden" name="token" value="'.newToken().
'">';
320 print_barre_liste($langs->trans(
"ListOfSecurityEvents"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $nbtotalofrecords,
'setup', 0,
'',
'', $limit);
322 if ($action ==
'purge') {
323 $formquestion = array();
324 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?noparam=noparam', $langs->trans(
'PurgeAuditEvents'), $langs->trans(
'ConfirmPurgeAuditEvents'),
'confirm_purge', $formquestion,
'no', 1);
341 print
'<div class="div-table-responsive">';
342 print
'<table class="liste centpercent">';
345 print
'<tr class="liste_titre">';
349 print
'<td class="liste_titre maxwidthsearch center">';
350 $searchpicto = $form->showFilterAndCheckAddButtons(0);
356 print
'<td class="liste_titre">';
357 print
'<input class="flat maxwidth50" type="text" name="search_rowid" value="'.dol_escape_htmltag($search_rowid).
'">';
361 print
'<td class="liste_titre" width="15%">';
362 print $form->selectDate($date_start ===
'' ? -1 : $date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzuserrel');
363 print $form->selectDate($date_end ===
'' ? -1 : $date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzuserrel');
366 print
'<td class="liste_titre">';
367 print
'<input class="flat maxwidth75" type="text" name="search_code" value="'.dol_escape_htmltag($search_code).
'">';
371 print
'<td class="liste_titre">';
372 print
'<input class="flat maxwidth75" type="text" name="search_ip" value="'.dol_escape_htmltag($search_ip).
'">';
375 print
'<td class="liste_titre">';
376 print
'<input class="flat maxwidth100" type="text" name="search_user" value="'.dol_escape_htmltag($search_user).
'">';
379 print
'<td class="liste_titre">';
383 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
384 print
'<td class="liste_titre left">';
385 print
'<input class="flat maxwidth100" type="text" name="search_ua" value="'.dol_escape_htmltag($search_ua).
'">';
389 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
390 print
'<td class="liste_titre left">';
391 print
'<input class="flat maxwidth100" type="text" name="search_prefix_session" value="'.dol_escape_htmltag($search_prefix_session).
'">';
397 print
'<td class="liste_titre maxwidthsearch">';
398 $searchpicto = $form->showFilterAndCheckAddButtons(0);
406 print
'<tr class="liste_titre">';
416 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"e.description",
"", $param,
'', $sortfield, $sortorder);
417 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
418 print_liste_field_titre(
"UserAgent", $_SERVER[
"PHP_SELF"],
"e.user_agent",
"", $param,
'', $sortfield, $sortorder);
420 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
421 print_liste_field_titre(
"SuffixSessionName", $_SERVER[
"PHP_SELF"],
"e.prefix_session",
"", $param,
'', $sortfield, $sortorder);
429 while ($i < min($num, $limit)) {
430 $obj = $db->fetch_object($result);
432 print
'<tr class="oddeven">';
436 print
'<td class="center">';
437 $htmltext =
'<b>'.$langs->trans(
"UserAgent").
'</b>: '.($obj->user_agent ?
dol_string_nohtmltag($obj->user_agent) : $langs->trans(
"Unknown"));
438 $htmltext .=
'<br><b>'.$langs->trans(
"SuffixSessionName").
' (DOLSESSID_...)</b>: '.($obj->prefix_session ?
dol_string_nohtmltag($obj->prefix_session) : $langs->trans(
"Unknown"));
439 print $form->textwithpicto(
'', $htmltext);
444 print
'<td class="nowrap left">'.dol_escape_htmltag($obj->rowid).
'</td>';
447 print
'<td class="nowrap left">'.dol_print_date($db->jdate($obj->dateevent),
'%Y-%m-%d %H:%M:%S',
'tzuserrel').
'</td>';
450 print
'<td>'.dol_escape_htmltag($obj->type).
'</td>';
453 print
'<td class="nowraponall">';
458 print
'<td class="tdoverflowmax125">';
459 if ($obj->fk_user > 0) {
460 $userstatic->id = $obj->fk_user;
461 $userstatic->login = $obj->login;
462 $userstatic->admin = $obj->admin;
463 $userstatic->entity = $obj->entity;
464 $userstatic->status = $obj->status;
466 print $userstatic->getLoginUrl(1);
467 if (isModEnabled(
'multicompany') && $userstatic->admin && !$userstatic->entity) {
468 print
img_picto($langs->trans(
"SuperAdministrator"),
'redstar',
'class="valignmiddle paddingleft"');
469 } elseif ($userstatic->admin) {
470 print
img_picto($langs->trans(
"Administrator"),
'star',
'class="valignmiddle paddingleft"');
478 $text = $langs->trans($obj->description);
480 if (preg_match(
'/\((.*)\)(.*)/i', $obj->description, $reg)) {
481 $val = explode(
',', $reg[1]);
482 $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] :
'');
483 if (!empty($reg[2])) {
487 print
'<td class="tdoverflowmax400" title="'.dol_escape_htmltag($text).
'">';
491 if (!empty($arrayfields[
'e.user_agent'][
'checked'])) {
493 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->user_agent).
'">';
498 if (!empty($arrayfields[
'e.prefix_session'][
'checked'])) {
500 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->prefix_session).
'">';
507 print
'<td class="right">';
508 $htmltext =
'<b>'.$langs->trans(
"UserAgent").
'</b>: '.($obj->user_agent ?
dol_string_nohtmltag($obj->user_agent) : $langs->trans(
"Unknown"));
509 $htmltext .=
'<br><b>'.$langs->trans(
"SuffixSessionName").
' (DOLSESSID_...)</b>: '.($obj->prefix_session ?
dol_string_nohtmltag($obj->prefix_session) : $langs->trans(
"Unknown"));
510 print $form->textwithpicto(
'', $htmltext);
521 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoEventFoundWithCriteria").
'</span></td></tr>';
523 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoEventOrNoAuditSetup").
'</span></td></tr>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage Dolibarr users.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.