From 8902d8ce924a2ce43dc53420c502adfbd53730ed Mon Sep 17 00:00:00 2001 From: tofulm Date: Thu, 19 Dec 2019 16:57:40 +0100 Subject: [PATCH] ajout sur la page sha256sum d'une verification id_objet objet --- blocklog_fonctions.php | 49 +++++++++++++++++++------- sha256sum.html | 80 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 106 insertions(+), 23 deletions(-) diff --git a/blocklog_fonctions.php b/blocklog_fonctions.php index 777edd9..0a515be 100755 --- a/blocklog_fonctions.php +++ b/blocklog_fonctions.php @@ -13,17 +13,42 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } -function trouver_blocklog($id_objet, $objet){ - $from = array( - 'spip_blocklogs as B', - 'spip_blocklogs_liens as L' - ); - $where = array( - 'L.id_objet='.intval($id_objet), - 'L.objet='.sql_quote($objet), - 'L.id_blocklog=B.id_blocklog' - ); - $blockchaine = sql_getfetsel('blockchaine', $from, $where, '', 'B.id_blocklog DESC', 1); +function trouver_blocklog($id_objet, $objet, $id = false){ + static $r; - return $blockchaine; + if ($r == null) { + $from = array( + 'spip_blocklogs as B', + 'spip_blocklogs_liens as L' + ); + $where = array( + 'L.id_objet='.intval($id_objet), + 'L.objet='.sql_quote($objet), + 'L.id_blocklog=B.id_blocklog' + ); + $r = sql_fetsel('B.id_blocklog, B.blockchaine, B.chaine', $from, $where, '', 'B.id_blocklog DESC', 1); + } + + if ($id) { + return $r; + } + + return $r['blockchaine']; +} + + +function blocklog_verifier_blockchaine($id_objet, $objet){ + if (intval($id_objet) and $objet) { + $r = trouver_blocklog($id_objet, $objet, true); + $id_blocklog_pre = intval($r['id_blocklog']) - 1; + $blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', 'id_blocklog='.intval($id_blocklog_pre)); + + if (! defined("_BLOCKLOG_ALGO")) { + define("_BLOCKLOG_ALGO", 'sha256'); + } + $blockchaine .= "|" . $r['chaine']; + $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); + + return $blockchaine === $r['blockchaine']; + } } diff --git a/sha256sum.html b/sha256sum.html index 47327ad..2f10620 100755 --- a/sha256sum.html +++ b/sha256sum.html @@ -5,19 +5,45 @@ sha256sum @@ -26,13 +52,13 @@ body {

sha256sum

- +
- +
- +


@@ -43,12 +69,45 @@ body {

Resultat

- + +
+
+
+
+

Tester la blockchaine d'un id_objet

+
+ +
+
+ +
+
+
+
+ + [(#ENV{id_objet}|oui) + [(#ENV{id_objet}|blocklog_verifier_blockchaine{#ENV{objet}}|oui) + Blockchaine Valide + ] + [(#ENV{id_objet}|blocklog_verifier_blockchaine{#ENV{objet}}|non) + Blockchaine Valide + ] + ] +
+