From 332662aeaa6ec3682043a19ed11f146b881f8b3e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Dec 2025 20:56:05 +0100 Subject: [PATCH 1/2] WIP LNE --- .../blockedlog/admin/blockedlog_archives.php | 24 ++++++++------ htdocs/blockedlog/admin/blockedlog_list.php | 4 +-- htdocs/blockedlog/class/blockedlog.class.php | 32 +++++++++---------- htdocs/langs/en_US/blockedlog.lang | 1 + 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/htdocs/blockedlog/admin/blockedlog_archives.php b/htdocs/blockedlog/admin/blockedlog_archives.php index 3c37541cd4b..752605831d5 100644 --- a/htdocs/blockedlog/admin/blockedlog_archives.php +++ b/htdocs/blockedlog/admin/blockedlog_archives.php @@ -186,8 +186,8 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / } */ - $dates = dol_get_first_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') ? GETPOSTINT('monthtoexport') : 1); - $datee = dol_get_last_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') ? GETPOSTINT('monthtoexport') : 12); + $dates = dol_get_first_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') > 0 ? GETPOSTINT('monthtoexport') : 1); + $datee = dol_get_last_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') > 0 ? GETPOSTINT('monthtoexport') : 12); if ($datee >= dol_now()) { setEventMessages($langs->trans("ErrorPeriodMustBePastToAllowExport"), null, "errors"); @@ -280,7 +280,7 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / $fh = fopen($tmpfile, 'w'); // Print line with title - fwrite($fh, "BEGIN - date=".$yearmonthdateofexport." - period=".$yearmonthtoexport + fwrite($fh, "BEGIN - date=".$yearmonthdateofexport." - period=".$yearmonthtoexport." - format=V1" .';'.$langs->transnoentities('Id') .';'.$langs->transnoentities('DateCreation') .';'.$langs->transnoentities('Action') @@ -295,6 +295,7 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / .';'.$langs->transnoentities('Fingerprint') .';'.$langs->transnoentities('Status') .';'.$langs->transnoentities('FingerprintExport') + .';'.$langs->transnoentities('FingerprintFormat') //.';'.$langs->transnoentities('FingerprintExportHMAC') ."\n"); @@ -307,14 +308,13 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / $block_static->id = $obj->rowid; $block_static->entity = $obj->entity; - - $block_static->date_creation = $db->jdate($obj->date_creation); // TODO Use gmt + $block_static->date_creation = $db->jdate($obj->date_creation); // jdate(date_creation) is UTC $block_static->amounts = (float) $obj->amounts; // Database store value with 8 digits, we cut ending 0 them with (flow) $block_static->vat = $obj->vat; $block_static->action = $obj->action; - $block_static->date_object = $db->jdate($obj->date_object); // TODO Use gmt ? + $block_static->date_object = $db->jdate($obj->date_object); // jdate(date_object) is UTC $block_static->ref_object = $obj->ref_object; $block_static->user_fullname = $obj->user_fullname; @@ -341,7 +341,7 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / $block_static->debuginfo = $obj->debuginfo; //var_dump($block->id.' '.$block->signature, $block->object_data); - $checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it + $checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it if ($checksignature) { $statusofrecord = 'Valid'; @@ -360,8 +360,11 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / $statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : ''); } - $signatureexport = 'TODO'; - $signatureexporthmac = 'TODO'; + $concatenateddata = $block_static->buildKeyForSignature(); + + // Version archive V1=sha256 + $signatureexport = dol_hash($previoushash.$concatenateddata, 'sha256'); // SHA256 + //$signatureexporthmac = 'TODO'; fwrite($fh, ';'.$block_static->id @@ -377,7 +380,8 @@ if (GETPOST('action') == 'export' && $user->hasRight('blockedlog', 'read')) { / .';"'.str_replace('"', '""', $block_static->object_version).'";"' .str_replace('"', '""', $block_static->signature).'";"' .str_replace('"', '""', $statusofrecord).'";"' - .str_replace('"', '""', $signatureexport).'";' + .str_replace('"', '""', $signatureexport).'";"' + .str_replace('"', '""', $block_static->object_format).'";' //.str_replace('"', '""', $signatureexporthmac).'"' //.';'.$statusofrecordnote ."\n"); diff --git a/htdocs/blockedlog/admin/blockedlog_list.php b/htdocs/blockedlog/admin/blockedlog_list.php index 2a44e0b631c..9a40628312a 100644 --- a/htdocs/blockedlog/admin/blockedlog_list.php +++ b/htdocs/blockedlog/admin/blockedlog_list.php @@ -64,7 +64,7 @@ $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'); +$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') != '') { @@ -384,7 +384,7 @@ $help_url = "EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Ina llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-blockedlog page-admin_blockedlog_list'); -$blocks = $block_static->getLog('all', (int) $search_id, $MAXLINES, $sortfield, $sortorder, (int) $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code, $search_signature); +$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); if (!is_array($blocks)) { if ($blocks == -2) { setEventMessages($langs->trans("TooManyRecordToScanRestrictFilters", $MAXLINES), null, 'errors'); diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index 3981bca7afa..71a19dfa656 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -980,15 +980,15 @@ class BlockedLog $this->id = $obj->rowid; $this->entity = $obj->entity; - $this->date_creation = $this->db->jdate($obj->date_creation); // TODO Use gmt ? - $this->date_modification = $this->db->jdate($obj->tms); // TODO Use gmt ? + $this->date_creation = $this->db->jdate($obj->date_creation); // jdate(date_creation)is UTC + $this->date_modification = $this->db->jdate($obj->tms); // jdate(tms) is UTC $this->amounts = (float) $obj->amounts; $this->action = $obj->action; $this->element = $obj->element; $this->fk_object = $obj->fk_object; - $this->date_object = $this->db->jdate($obj->date_object); // TODO Use gmt ? + $this->date_object = $this->db->jdate($obj->date_object); // jdate(date_object) is UTC $this->ref_object = $obj->ref_object; $this->fk_user = $obj->fk_user; @@ -1132,9 +1132,9 @@ class BlockedLog try { $previoushash = $this->getPreviousHash(1, 0); // This get last record and lock database until insert is done and transaction closed - $concatenatedata = $this->buildKeyForSignature(); // All the information for the hash (meta data + data saved) + $concatenateddata = $this->buildKeyForSignature(); // All the information for the hash (meta data + data saved) - $this->signature = $this->buildFinalSignatureHash($previoushash.$concatenatedata); // Build the hmac signature + $this->signature = $this->buildFinalSignatureHash($previoushash.$concatenateddata); // Build the hmac signature // For debug: $this->debuginfo = $this->buildFirstPartOfKeyForSignature(); // Not used @@ -1150,7 +1150,7 @@ class BlockedLog if ($forcesignature) { $this->signature = $forcesignature; } - //var_dump($concatenatedata);var_dump($previoushash);var_dump($this->signature); + //var_dump($concatenateddata);var_dump($previoushash);var_dump($this->signature); $sql = "INSERT INTO ".MAIN_DB_PREFIX."blockedlog ("; $sql .= " date_creation,"; @@ -1232,15 +1232,15 @@ class BlockedLog $previoushash = $this->getPreviousHash(0, $this->id); } - $concatenatedata = ''; + $concatenateddata = ''; $signature = ''; // Recalculate the signature try { // Build the string for the signature - $concatenatedata = $this->buildKeyForSignature(); + $concatenateddata = $this->buildKeyForSignature(); - $signature = $this->buildFinalSignatureHash($previoushash.$concatenatedata); + $signature = $this->buildFinalSignatureHash($previoushash.$concatenateddata); } catch (Exception $e) { $res = ($signature === $this->signature); $this->error = $e->getMessage(); @@ -1262,13 +1262,13 @@ class BlockedLog if ($returnarray) { if ($returnarray == 1) { - unset($concatenatedata); + unset($concatenateddata); return array('checkresult' => $res, 'calculatedsignature' => $signature, 'previoushash' => $previoushash); - } else { // Consume much memory ($concatenatedata is a large var) - return array('checkresult' => $res, 'calculatedsignature' => $signature, 'previoushash' => $previoushash, 'keyforsignature' => $concatenatedata); + } else { // Consume much memory ($concatenateddata is a large var) + return array('checkresult' => $res, 'calculatedsignature' => $signature, 'previoushash' => $previoushash, 'keyforsignature' => $concatenateddata); } } else { - unset($concatenatedata); + unset($concatenateddata); return $res; } } @@ -1299,12 +1299,10 @@ class BlockedLog /** * Return the string for signature (clear data). - * Note: rowid of line not included as it is not a business data and this allow to make backup of a year - * and restore it into another database with different ids without comprimising checksums * * @return string Key for signature */ - private function buildKeyForSignature() + public function buildKeyForSignature() { //print_r($this->object_data); if ($this->object_format == '') { @@ -1415,7 +1413,7 @@ class BlockedLog * Return array of log objects (with criteria) * * @param string $element Element to search - * @param int $fk_object Id of object to search + * @param string|int $fk_object Id of object to search. Can be a UFS search criteria. * @param int<0,max> $limit Max number of element, 0 for all * @param string $sortfield Sort field * @param string $sortorder Sort order diff --git a/htdocs/langs/en_US/blockedlog.lang b/htdocs/langs/en_US/blockedlog.lang index f419e83f0f6..6889b96acf7 100644 --- a/htdocs/langs/en_US/blockedlog.lang +++ b/htdocs/langs/en_US/blockedlog.lang @@ -25,6 +25,7 @@ ListOfTrackedEvents=List of tracked events Fingerprint=Fingerprint FingerprintExport=Fingerprint export FingerprintExportHMAC=Fingerprint export HMAC +FingerprintFormat=Fingerprint format DownloadLogCSV=Export unalterable logs (CSV) DataOfArchivedEvent=Complete data of archived event DataOfArchivedEventHelp=This field contains the complementary data that was archived on real time. Even if some parent business event could have been canceled or modified, the data stored here is the original data, and it can't be modified. From 64f966eddffda2287854f9947f70f66d3c35c925 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Dec 2025 21:14:03 +0100 Subject: [PATCH 2/2] Debug v23 --- htdocs/commande/list_det.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/commande/list_det.php b/htdocs/commande/list_det.php index 8cd8008bee6..037a23c4cd6 100644 --- a/htdocs/commande/list_det.php +++ b/htdocs/commande/list_det.php @@ -36,6 +36,13 @@ */ require '../main.inc.php'; +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * @var Translate $langs + * @var User $user + */ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; @@ -55,14 +62,6 @@ if (isModEnabled('category')) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; } -/** - * @var Conf $conf - * @var DoliDB $db - * @var HookManager $hookmanager - * @var Translate $langs - * @var User $user - */ - // Load translation files required by the page $langs->loadLangs(array("categories", "orders", 'sendings', 'companies', 'compta', 'bills', 'stocks', 'products')); @@ -156,10 +155,10 @@ $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortfield) { - $sortfield = 'pr.ref'; + $sortfield = 'c.ref'; } if (!$sortorder) { - $sortorder = 'ASC'; + $sortorder = 'DESC'; } $show_shippable_command = GETPOST('show_shippable_command', 'aZ09');