* Copyright (C) 2017-2018 Laurent Destailleur * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/blockedlog/admin/blockedlog_list.php * \ingroup blockedlog * \brief Page to list and view unalterable logs */ // Load Dolibarr environment require '../../main.inc.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Societe $mysoc * @var Translate $langs * @var User $user * * @var string $dolibarr_main_db_name */ require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php'; require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'banks', 'bills', 'blockedlog', 'other')); // Get Parameters $action = GETPOST('action', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : getDolDefaultContextPage(__FILE__); // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $search_showonlyerrors = GETPOSTINT('search_showonlyerrors'); if ($search_showonlyerrors < 0) { $search_showonlyerrors = 0; } $search_startyear = GETPOSTINT('search_startyear'); $search_startmonth = GETPOSTINT('search_startmonth'); $search_startday = GETPOSTINT('search_startday'); $search_endyear = GETPOSTINT('search_endyear'); $search_endmonth = GETPOSTINT('search_endmonth'); $search_endday = GETPOSTINT('search_endday'); $search_id = GETPOST('search_id', 'alpha'); // Can be a USF search string $search_fk_user = GETPOST('search_fk_user', 'intcomma'); $search_start = -1; if (GETPOST('search_startyear') != '') { $search_start = dol_mktime(0, 0, 0, $search_startmonth, $search_startday, $search_startyear); } $search_end = -1; if (GETPOST('search_endyear') != '') { $search_end = dol_mktime(23, 59, 59, $search_endmonth, $search_endday, $search_endyear); } $search_code = GETPOST('search_code', 'array:alpha'); $search_module_source = GETPOST('search_module_source', 'array:alpha'); $search_ref = GETPOST('search_ref', 'alpha'); $search_amount = GETPOST('search_amount', 'alpha'); $search_signature = GETPOST('search_signature', 'alpha'); if (($search_start == -1 || empty($search_start)) && !GETPOSTISSET('search_startmonth') && !GETPOSTISSET('begin')) { $search_start = dol_time_plus_duree(dol_now(), -1, 'w'); $tmparray = dol_getdate($search_start); $search_startday = $tmparray['mday']; $search_startmonth = $tmparray['mon']; $search_startyear = $tmparray['year']; } // Load variable for pagination $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (empty($sortfield)) { $sortfield = 'rowid'; } if (empty($sortorder)) { $sortorder = 'DESC'; } $block_static = new BlockedLog($db); $block_static->loadTrackedEvents(); // Access Control if ((!$user->admin && !$user->hasRight('blockedlog', 'read')) || !isModEnabled('blockedlog')) { accessforbidden(); } $result = restrictedArea($user, 'blockedlog', 0, ''); // Execution Time $max_execution_time_for_importexport = getDolGlobalInt('EXPORT_MAX_EXECUTION_TIME', 300); // 5mn if not defined $max_time = @ini_get("max_execution_time"); if ($max_time && $max_time < $max_execution_time_for_importexport) { dol_syslog("max_execution_time=".$max_time." is lower than max_execution_time_for_importexport=".$max_execution_time_for_importexport.". We try to increase it dynamically."); @ini_set("max_execution_time", $max_execution_time_for_importexport); // This work only if safe mode is off. also web servers has timeout of 300 } $MAXLINES = getDolGlobalInt('BLOCKEDLOG_MAX_LINES', 10000); $MAXFORSHOWNLINKS = getDolGlobalInt('BLOCKEDLOG_MAX_FOR_SHOWN_LINKS', 100); /* * Actions */ // Purge search criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_id = ''; $search_fk_user = ''; $search_start = -1; $search_end = -1; $search_code = array(); $search_module_source = ''; $search_ref = ''; $search_amount = ''; $search_signature = ''; $search_showonlyerrors = 0; $search_startyear = ''; $search_startmonth = ''; $search_startday = ''; $search_endyear = ''; $search_endmonth = ''; $search_endday = ''; $toselect = array(); $search_array_options = array(); } /* * View */ $form = new Form($db); if (GETPOST('withtab', 'alpha')) { $title = $langs->trans("ModuleSetup").' '.$langs->trans('BlockedLog'); } else { $title = $langs->trans("BrowseBlockedLog"); } $help_url = "EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable"; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-blockedlog page-admin_blockedlog_list'); $blocks = $block_static->getLog('all', (string) $search_id, $MAXLINES, $sortfield, $sortorder, (int) $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code, $search_signature, $search_module_source); if (!is_array($blocks)) { if ($blocks == -2) { setEventMessages($langs->trans("TooManyRecordToScanRestrictFilters", $MAXLINES), null, 'errors'); } else { dol_print_error($block_static->db, $block_static->error, $block_static->errors); exit; } } $linkback = ''; if (GETPOST('withtab', 'alpha')) { $linkback = ''.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').''.$langs->trans("BackToModuleList").''; } $morehtmlcenter = ''; $registrationnumber = getHashUniqueIdOfRegistration(); $texttop = ''.$langs->trans("RegistrationNumber").': '.dol_trunc($registrationnumber, 10).''; print load_fiche_titre($title.'
'.$texttop, $linkback, 'blockedlog', 0, '', '', $morehtmlcenter); $head = blockedlogadmin_prepare_head(GETPOST('withtab', 'alpha')); print dol_get_fiche_head($head, 'fingerprints', '', -1); //print $texttop; //print '

'; print '
'; print $langs->trans("FingerprintsDesc")."
"; $s = $langs->trans("FilesIntegrityDesc", '{s}'); $s = str_replace('{s}', DOL_URL_ROOT.'/blockedlog/admin/filecheck.php', $s); print $s; print "
\n"; print "
\n"; $htmltext = ''; $htmltext .= $langs->trans("UnalterableLogTool2", $langs->transnoentitiesnoconv("Archives"))."
"; $htmltext .= $langs->trans("UnalterableLogTool3")."
"; print info_admin($htmltext, 0, 0, 'warning'); print '
'; $param = ''; if ($contextpage != getDolDefaultContextPage(__FILE__)) { $param .= '&contextpage='.urlencode($contextpage); } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.((int) $limit); } if ($search_id != '') { $param .= '&search_id='.urlencode($search_id); } if ($search_ref != '') { $param .= '&search_ref='.urlencode($search_ref); } if ($search_fk_user > 0) { $param .= '&search_fk_user='.urlencode($search_fk_user); } if ($search_startyear > 0) { $param .= '&search_startyear='.((int) $search_startyear); } if ($search_startmonth > 0) { $param .= '&search_startmonth='.((int) $search_startmonth); } if ($search_startday > 0) { $param .= '&search_startday='.((int) $search_startday); } if ($search_endyear > 0) { $param .= '&search_endyear='.((int) $search_endyear); } if ($search_endmonth > 0) { $param .= '&search_endmonth='.((int) $search_endmonth); } if ($search_endday > 0) { $param .= '&search_endday='.((int) $search_endday); } if ($search_amount) { $param .= '&search_amount='.urlencode($search_amount); } if ($search_signature) { $param .= '&search_signature='.urlencode($search_signature); } if ($search_showonlyerrors > 0) { $param .= '&search_showonlyerrors='.((int) $search_showonlyerrors); } if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } if (GETPOST('withtab', 'alpha')) { $param .= '&withtab='.urlencode(GETPOST('withtab', 'alpha')); } print '
'; if ($optioncss != '') { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; // You can use div-table-responsive-no-min if you don't need reserved height for your table print ''; // Line of filters print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } print ''; print ''; // User print ''; // Module source print ''; // Actions code print ''; // Ref print ''; // Amount print ''; // Full data print ''; // Fingerprint print ''; // Status print ''; // Link to debug information object if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { // If in experimental or develop mode, we add some debug information. It may help developers to find origin of bugs. print ''; } // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } print ''; print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, 'class="center"', $sortfield, $sortorder, '')."\n"; } print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"], 'rowid', '', $param, '', $sortfield, $sortorder, 'minwidth50 ')."\n"; print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"], 'date_creation', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"], 'user_fullname', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($langs->trans('POS'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($langs->trans('Action'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"], 'ref_object', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($langs->trans('Amount'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ', 0, $langs->trans("TotalTTCIfInvoiceSeeCompleteDataForDetail").'
'.$langs->trans("AmountInCurrency", getDolCurrency()))."\n"; print getTitleFieldOfList($langs->trans('DataOfArchivedEvent'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ', 0, $langs->trans('DataOfArchivedEventHelp'), 1)."\n"; print getTitleFieldOfList($langs->trans('Fingerprint'), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n"; print getTitleFieldOfList($form->textwithpicto($langs->trans('Status'), $langs->trans('DataOfArchivedEventHelp2')), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { // If in experimental or develop mode, we add some debug information. It may help developers to find origin of bugs. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '')."\n"; } // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, 'class="center"', $sortfield, $sortorder, '')."\n"; } print ''; $checkresult = array(); $checkdetail = array(); $loweridinerror = 0; if (getDolGlobalString('BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR')) { // This is version that is faster but require more memory and report errors that are outside the filter range // TODO Make a full scan of table in reverse order of id of $block, so we can use the parameter $previoushash into checkSignature to save requests // to find the $loweridinerror. } else { // This is version that optimize the memory (note: it will not report errors that are outside the filter range, but we don't need them) if (is_array($blocks)) { foreach ($blocks as &$block) { //var_dump($block->id.' '.$block->signature, $block->object_data); $tmpcheckresult = $block->checkSignature('', 1); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various $checksignature = $tmpcheckresult['checkresult']; $checkresult[$block->id] = $checksignature; // false if error $checkdetail[$block->id] = $tmpcheckresult; if (!$checksignature) { if (empty($loweridinerror)) { $loweridinerror = $block->id; } else { $loweridinerror = min($loweridinerror, $block->id); } } } } } $refinvoicefound = array(); $totalhtamount = array(); $totalvatamount = array(); $totalamount = array(); if (is_array($blocks)) { $nbshown = 0; $object_link = ''; $object_link_title = ''; foreach ($blocks as &$block) { //if (empty($search_showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) if (empty($search_showonlyerrors) || !$checkresult[$block->id]) { $nbshown++; if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { if ($nbshown < $MAXFORSHOWNLINKS) { // For performance and memory purpose, we get/show the debug info link of objects only for the 100 first output $object_link = $block->getObjectLink(); $object_link_title = ''; } else { $object_link = $block->element.'/'.$block->fk_object; $object_link_title = $langs->trans('LinkHasBeenDisabledForPerformancePurpose'); } } print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } // ID print ''; // Date print ''; // User print ''; // ModulePOS $labelofmodulesource = $block->module_source; print ''; // Action $labelofaction = $langs->transnoentitiesnoconv('log'.$block->action); print ''; // Ref print ''; //$tmpobj = json_decode($block->object_data); // Define $totalhtamount, $totalvatamount, $totalamount for $block action code and module $total_ht = $total_vat = $total_ttc = 0; sumAmountsForUnalterableEvent($block, $refinvoicefound, $totalhtamount, $totalvatamount, $totalamount, $total_ht, $total_vat, $total_ttc); // Amount print ''; // Details link print ''; // Fingerprint print ''; // Status print ''; // Link to debug information object if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { // If in experimental or develop mode, we add some debug information. It may help developers to find origin of bugs. print ''; } print ''; } } // Show total line if ($nbshown == 0) { $colspan = 11; if (getDolGlobalString('MAIN_FEATURES_LEVEL') > 0) { // If in experimental or develop mode, we add some debug information. It may help developers to find origin of bugs. $colspan++; } print ''; } else { foreach ($totalamount as $key => $totalamountperref) { if ($key == 'BILL_VALIDATE') { // Total print ''; // Action column if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } // ID print ''; // Date //print ''; // User print ''; // Module source print ''; // Action print ''; // Ref print ''; // Amount (HT) print ''; // Details link print ''; // Fingerprint print ''; // Status print ''; // Link to debug information object if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { // If in experimental or develop mode, we add some debug information. It may help developers to find origin of bugs. print ''; } // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; } print ''; } } } } print '
'; $searchpicto = $form->showFilterButtons(); print $searchpicto; print ''; //print $langs->trans("from").': '; print $form->selectDate($search_start, 'search_start'); //print '
'; //print $langs->trans("to").': '; print $form->selectDate($search_end, 'search_end'); print '
'; print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth100'); print ''; print $form->multiselectarray('search_module_source', $block_static->trackedmodules, $search_module_source, 0, 0, 'maxwidth150', 1); print ''; print $form->multiselectarray('search_code', $block_static->trackedevents, $search_code, 0, 0, 'maxwidth150', 1); print ''; $array = array("1" => "OnlyNonValid"); print $form->selectarray('search_showonlyerrors', $array, $search_showonlyerrors, 1, 0, 0, '', 1, 0, 0, 'ASC', 'search_status width100 onrightofpage', 1); print ''; $searchpicto = $form->showFilterButtons(); print $searchpicto; print '
'; print ''.dolPrintHTML((string) $block->id).''.dol_print_date($block->date_creation, 'dayhour').''; //print $block->getUser() print dolPrintHTML($block->user_fullname); print ''.dolPrintHTML($labelofmodulesource).''.dolPrintHTML($labelofaction).'
'; if (!empty($block->ref_object)) { print dol_escape_htmltag($block->ref_object); if ($block->linktype && $block->linktoref) { if ($block->linktype == 'payment') { print '
'.$langs->trans("PaymentOf").' '.$block->linktoref.''; } if ($block->linktype == 'replacedby') { print '
'.$langs->trans("ReplacedBy").' '.$block->linktoref.''; } } } else { // Ref not stored } print '
'; if (empty($total_ttc)) { print ''; } print price($total_ttc); if (empty($total_ttc)) { print ''; } print ''.img_picto($langs->trans('ShowDetails'), 'note', 'class="size15x"').''; // Note: the previous line id is not necessarily id-1, so in texttoshow we say "on previous line" without giving id to avoid a search/fetch to get previous id. $texttoshow = $langs->trans("Fingerprint").' - '.$langs->trans("SavedOnLine").' =
'.$block->signature; $texttoshow .= '

'.$langs->trans("Fingerprint").' - Recalculated hash_hmac(\'sha256\', '.strtolower($langs->trans("PreviousHash").' on previous line').' + data, secret key) =
'.$checkdetail[$block->id]['calculatedsignature']; $texttoshow .= '
'.$langs->trans("PreviousHash").'='.$checkdetail[$block->id]['previoushash'].''; $texttoshow .= '
'.$langs->trans("SecretKey").'=Not available from interface'; //$texttoshow .= '
keyforsignature='.$checkdetail[$block->id]['keyforsignature']; print $form->textwithpicto(dol_trunc($block->signature, 8), $texttoshow, 1, 'help', '', 0, 2, 'fingerprint'.$block->id); print '
'; if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error if ($checkresult[$block->id]) { print 'OK'; } else { print 'KO'; } } else { print 'OK'; } // Note if (!$checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) { // If error if ($checkresult[$block->id]) { if (getDolGlobalString("BLOCKEDLOG_DEBUG")) { print $form->textwithpicto('', $langs->trans('OkCheckFingerprintValidityButChainIsKo')); } } } /* if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY') && getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL')) { print ' '.($block->certified ? img_picto($langs->trans('AddedByAuthority'), 'info') : img_picto($langs->trans('NotAddedByAuthorityYet'), 'info_black')); } */ print ''; print ''; // $object_link can be a ''; } // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; print '
'.$langs->trans("NoRecordFound").'
'; print ''.dolPrintHTML($langs->trans("TotalForAction").' '.$langs->trans('log'.$key)).''; print ''; print ''; $totalhttoshow = 0; foreach ($totalhtamount[$key] as $value) { // Loop on each module $totalhttoshow += $value; } print $langs->trans("HT").': '; print price($totalhttoshow); print '
'; $totalvattoshow = 0; foreach ($totalvatamount[$key] as $value) { $totalvattoshow += $value; } print $langs->trans("VAT").': '; print price($totalvattoshow); print '
'; $totaltoshow = 0; foreach ($totalamountperref as $value) { $totaltoshow += $value; } print $langs->trans("TTC").': '; print price($totaltoshow); print '
'; print ''; print ''; print ''; print '
'; print '
'; print '
'; // Javascript to manage the showinfo popup print ''."\n"; /* if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY') && getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL')) { ?>
'; // End of page llxFooter(); $db->close();