Debug blockedlog module

This commit is contained in:
Laurent Destailleur 2017-11-30 15:13:23 +01:00
parent 8987e923f1
commit 25bccfde8b
5 changed files with 136 additions and 108 deletions

View File

@ -16,7 +16,7 @@
*/
/**
* \file htdocs/blockedlog/admin/fingerprints.php
* \file htdocs/blockedlog/admin/blockedlog_list.php
* \ingroup blockedlog
* \brief Page setup for blockedlog module
*/
@ -36,8 +36,22 @@ if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
$showonlyerrors = GETPOST('showonlyerrors','int');
// Load variable for pagination
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
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);
/*
* Actions
*/
@ -114,7 +128,7 @@ else if($action === 'downloadcsv') {
* View
*/
$blocks = $block_static->getLog('all', 0, GETPOST('all','alpha') ? 0 : 50);
$blocks = $block_static->getLog('all', 0, GETPOST('all','alpha') ? 0 : 50, $sortfield, $sortorder);
$form=new Form($db);
@ -143,11 +157,11 @@ print '<div class="div-table-responsive">'; // You can use div-table-responsive
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'minwidth50 ')."\n";
print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('#'), 0, $_SERVER["PHP_SELF"],'rowid','','','',$sortfield,$sortorder,'minwidth50 ')."\n";
print getTitleFieldOfList($langs->trans('Date'), 0, $_SERVER["PHP_SELF"],'date_creation','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Author'), 0, $_SERVER["PHP_SELF"],'user_fullname','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Action'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Ref'), 0, $_SERVER["PHP_SELF"],'ref_object','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Element'), 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('Amount'), 0, $_SERVER["PHP_SELF"],'','','','align="right"',$sortfield,$sortorder,'')."\n";
print getTitleFieldOfList($langs->trans('DataOfArchivedEvent'), 0, $_SERVER["PHP_SELF"],'','','','align="center"',$sortfield,$sortorder,'')."\n";
@ -155,18 +169,31 @@ print getTitleFieldOfList($langs->trans('Fingerprint'), 0, $_SERVER["PHP_SELF"],
print getTitleFieldOfList('<span id="blockchainstatus"></span>', 0, $_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder,'')."\n";
print '</tr>';
$atleastoneerror=0;
$loweridinerror=0;
$checkresult=array();
foreach($blocks as &$block) {
$checksignature = $block->checkSignature();
$checkresult[$block->id]=$checksignature; // false if error
if (! $checksignature)
{
if (empty($loweridinerror)) $loweridinerror=$block->id;
else $loweridinerror = min($loweridinerror, $block->id);
}
}
foreach($blocks as &$block) {
$object_link = $block->getObjectLink();
if (!$showonlyerrors || $block->error>0) {
if (empty($showonlyerrors) || ! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) {
print '<tr class="oddeven">';
print '<td>'.$block->id.'</td>';
print '<td>'.dol_print_date($block->tms,'dayhour').'</td>';
print '<td>'.$block->getUser().'</td>';
print '<td>';
//print $block->getUser()
print $block->user_fullname;
print '</td>';
print '<td>'.$langs->trans('log'.$block->action).'</td>';
print '<td>'.$block->ref_object.'</td>';
print '<td>'.$object_link.'</td>';
@ -178,15 +205,14 @@ foreach($blocks as &$block) {
print '</td>';
print '<td>';
if (empty($block->error))
if (! $checkresult[$block->id] || ($loweridinerror && $block->id >= $loweridinerror)) // If error
{
if (empty($atleastoneerror)) print img_picto($langs->trans('OkCheckFingerprintValidity'), 'statut4');
else print img_picto($langs->trans('OkCheckFingerprintValidityButChainIsKo'), 'statut1');
if (empty($checkresult[$block->id])) print img_picto($langs->trans('OkCheckFingerprintValidityButChainIsKo'), 'statut1');
else print img_picto($langs->trans('KoCheckFingerprintValidity'), 'statut8');
}
else
{
$atleastoneerror++;
print img_picto($langs->trans('KoCheckFingerprintValidity'), 'statut8');
print img_picto($langs->trans('OkCheckFingerprintValidity'), 'statut4');
}
if(!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) {

View File

@ -45,7 +45,7 @@ $auth->syncSignatureWithAuthority();
$block_static = new BlockedLog($db);
$blocks = $block_static->getLog('just_certified', 0, 0, 1) ;
$blocks = $block_static->getLog('just_certified', 0, 0, 'rowid', 'ASC');
$auth->signature = $block_static->getSignature();

View File

@ -67,7 +67,7 @@ class BlockedLogAuthority
$this->signature = $block_static->getSignature();
$blocks = $block_static->getLog('all', 0, 0, 1) ;
$blocks = $block_static->getLog('all', 0, 0, 'rowid', 'ASC') ;
$this->blockchain = '';
@ -303,7 +303,7 @@ class BlockedLogAuthority
$block_static = new BlockedLog($this->db);
$blocks = $block_static->getLog('not_certified', 0, 0, 1);
$blocks = $block_static->getLog('not_certified', 0, 0, 'rowid', 'ASC');
$signature=$block_static->getSignature();

View File

@ -495,7 +495,7 @@ class BlockedLog
/**
* Check if current signature still correct compare to the chain
*
* @return boolean
* @return boolean True if OK, False if KO
*/
public function checkSignature()
{
@ -512,8 +512,8 @@ class BlockedLog
$res = ($signature === $this->signature);
if(!$res) {
$this->error++;
if (!$res) {
$this->error = 'Signature KO';
}
return $res;
@ -578,10 +578,11 @@ class BlockedLog
* @param string $element element to search
* @param int $fk_object id of object to search
* @param int $limit max number of element, 0 for all
* @param string $order sort of query
* @param string $sortfield sort field
* @param string $sortorder sort order
* @return array array of object log
*/
public function getLog($element, $fk_object, $limit = 0, $order = -1)
public function getLog($element, $fk_object, $limit = 0, $sortfield = '', $sortorder = '')
{
global $conf, $cachedlogs;
@ -609,7 +610,8 @@ class BlockedLog
WHERE element='".$element."' AND fk_object=".(int) $fk_object;
}
$sql.=($order<0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC ');
$sql.=$this->db->order($sortfield, $sortorder);
//($order<0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC ');
if($limit > 0 )$sql.=' LIMIT '.$limit;

View File

@ -38,7 +38,7 @@ function blockedlogadmin_prepare_head()
$head[$h][2] = 'blockedlog';
$h++;
$head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/fingerprints.php";
$head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_list.php";
$head[$h][1] = $langs->trans("Fingerprints");
$head[$h][2] = 'fingerprints';
$h++;