2
0
forked from Wavyzz/dolibarr

Clean code

This commit is contained in:
Laurent Destailleur
2025-10-22 14:14:58 +02:00
parent 8d50b69bce
commit 2c1ab9b40a
8 changed files with 63 additions and 650 deletions

View File

@@ -272,137 +272,72 @@ $checksumconcat = array();
fputs($fp, '<dolibarr_unalterable_files version="'.$release.'">'."\n");
// TODO Use this array to make the scan
// Array of dir/files to include in the section
$arrayofunalterablefiles = array(
array('dir' => dirname(__FILE__).'/../../htdocs/blockedlog', 'files' => 'all', 'regextoinclude' => '(\.php|\.sql)$', 'regextoexclude' => ''),
array('dir' => dirname(__FILE__).'/../../htdocs/install/mysql/tables', 'files' => 'all', 'regextoinclude' => 'llx_blockedlog.*(\.php|\.sql)$'),
array('dir' => dirname(__FILE__).'/../../htdocs/core/triggers', 'files' => 'interface_50_modBlockedlog_ActionsBlockedLog.class.php'),
array('dir' => dirname(__FILE__).'/../../htdocs/core/class', 'files' => 'interfaces.class.php'),
array('dir' => dirname(__FILE__).'/../../htdocs/core/class', 'files' => 'commontrigger.class.php'),
array('dir' => dirname(__FILE__).'/../../htdocs/takepos', 'files' => 'receipt.php')
array('dir' => dirname(__FILE__).'/../../htdocs/', 'file' => 'version.inc.php'),
array('dir' => dirname(__FILE__).'/../../htdocs/blockedlog', 'file' => 'all', 'regextoinclude' => '(\.php|\.sql)$', 'regextoexclude' => ''),
array('dir' => dirname(__FILE__).'/../../htdocs/install/mysql/tables', 'file' => 'all', 'regextoinclude' => 'llx_blockedlog.*(\.php|\.sql)$', 'regextoexclude' => ''),
array('dir' => dirname(__FILE__).'/../../htdocs/core/triggers', 'file' => 'interface_50_modBlockedlog_ActionsBlockedLog.class.php'),
array('dir' => dirname(__FILE__).'/../../htdocs/core/class', 'file' => 'all', 'regextoinclude' => '(interfaces.class.php|commontrigger.class.php)$', 'regextoexclude' => ''),
array('dir' => dirname(__FILE__).'/../../htdocs/takepos', 'file' => 'receipt.php')
);
$regextoinclude = '(\.php|\.sql)$';
$regextoexclude = ''; // Exclude dirs
$files = dol_dir_list(dirname(__FILE__).'/../../htdocs/blockedlog', 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir = '';
foreach ($files as $filetmp) {
$file = $filetmp['fullname'];
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
foreach ($arrayofunalterablefiles as $entry) {
if ($entry['file'] == 'all') {
$regextoinclude = $entry['regextoinclude'];
$regextoexclude = $entry['regextoexclude'];
$files = dol_dir_list($entry['dir'], 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir = '';
foreach ($files as $filetmp) {
$file = $filetmp['fullname'];
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
// Add the SQL file
$regextoinclude = 'llx_blockedlog.*(\.php|\.sql)$';
$regextoexclude = ''; // Exclude dirs
$files = dol_dir_list(dirname(__FILE__).'/../../htdocs/install/mysql/tables', 'files', 0, $regextoinclude, $regextoexclude, 'fullname');
foreach ($files as $filetmp) {
$file = $filetmp['fullname'];
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
} else {
$file = $entry['dir'].'/'.$entry['file'];
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if (!file_exists($file)) {
print "Error file ".$file." does not exists.";
exit(1);
}
if ($newdir != $dir) {
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
// Add the trigger file
$file = dirname(__FILE__).'/../../htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php';
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
// Add the interfaces.class.php file
$file = dirname(__FILE__).'/../../htdocs/core/class/interfaces.class.php';
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
//$needtoclose = 1; // close will be done in next filethat is in same dir
}
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
// Add the commontrigger.class.php file
$file = dirname(__FILE__).'/../../htdocs/core/class/commontrigger.class.php';
$newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
$newdir = str_replace(dirname(__FILE__).'/../../htdocs', '', dirname($file));
if ($newdir != $dir) {
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}
fputs($fp, ' <dir name="'.$newdir.'">'."\n");
$dir = $newdir;
$needtoclose = 1;
}
$needtoclose = 1; // This is the last file
if (filetype($file) == "file") {
$md5 = md5_file($file);
$checksumconcat[] = $md5;
fputs($fp, ' <md5file name="'.basename($file).'" size="'.filesize($file).'">'.$md5.'</md5file>'."\n");
}
if ($needtoclose) {
fputs($fp, ' </dir>'."\n");
$needtoclose = 0;
}

View File

@@ -126,6 +126,7 @@ print $langs->trans("CompanyInitialKey").'</td><td>';
print $block_static->getSignature();
print '</td></tr>';
/*
if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
// Example with a yes / no select
print '<tr class="oddeven">';
@@ -142,6 +143,7 @@ if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
print '</td></tr>';
}
*/
print '<tr class="oddeven">';
print '<td>'.$langs->trans("BlockedLogDisableNotAllowedForCountry").'</td>';

View File

@@ -29,7 +29,6 @@
require '../../main.inc.php';
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.'/blockedlog/class/authority.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/class/html.formother.class.php';
@@ -153,19 +152,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$search_array_options = array();
}
if ($action === 'downloadblockchain') {
$auth = new BlockedLogAuthority($db);
$bc = $auth->getLocalBlockChain();
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$auth->signature.".certif\"");
echo $bc;
exit;
} elseif (GETPOST('downloadcsv', 'alpha')) {
if (GETPOST('downloadcsv', 'alpha')) {
$error = 0;
$previoushash = '';
@@ -495,9 +482,9 @@ print $formother->select_month((string) GETPOSTINT('monthtoexport'), 'monthtoexp
print '<input type="text" name="yeartoexport" class="valignmiddle maxwidth75imp" value="'.GETPOST('yeartoexport').'" placeholder="'.$langs->trans("Year").'">';
print '<input type="hidden" name="withtab" value="'.GETPOST('withtab', 'alpha').'">';
print '<input type="submit" name="downloadcsv" class="button" value="'.$langs->trans('DownloadLogCSV').'">';
if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
/*if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
print ' | <a href="?action=downloadblockchain'.(GETPOST('withtab', 'alpha') ? '&withtab='.GETPOST('withtab', 'alpha') : '').'">'.$langs->trans('DownloadBlockChain').'</a>';
}
}*/
print ' </div><br>';
print '</form>';
@@ -730,9 +717,11 @@ if (is_array($blocks)) {
//print $form->textwithpicto('', $langs->trans('DataOfArchivedEventHelp2'));
}
/*
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 '</td>';
// Link to source object
@@ -799,6 +788,7 @@ jQuery(document).ready(function () {
</script>'."\n";
/*
if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY') && getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL')) {
?>
<script type="text/javascript">
@@ -821,6 +811,7 @@ if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY') && getDolGlobalString(
</script>
<?php
}
*/
if (GETPOST('withtab', 'alpha')) {
print dol_get_fiche_end();

View File

@@ -1,87 +0,0 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* 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 <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/blockedlog/ajax/authority.php
* \ingroup blockedlog
* \brief authority
*/
// This script is called with a POST method.
// Directory to scan (full path) is inside POST['dir'].
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
require '../../master.inc.php';
require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
$user = new User($db);
$user->fetch(1); //TODO conf user authority
/*
* View
*/
top_httphead();
$auth = new BlockedLogAuthority($db);
$signature = GETPOST('s');
$newblock = GETPOST('b');
$hash = GETPOST('h');
if ($auth->fetch(0, $signature) <= 0) {
$auth->signature = $signature;
$auth->create($user);
}
if (!empty($hash)) {
echo $auth->checkBlockchain($hash) ? 'hashisok' : 'hashisjunk';
} elseif (!empty($newblock)) {
if ($auth->checkBlock($newblock)) {
$auth->addBlock($newblock);
$auth->update($user);
echo 'blockadded';
} else {
echo 'blockalreadyadded';
}
} else {
echo 'idontunderstandwhatihavetodo';
}

View File

@@ -1,91 +0,0 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* 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 <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/blockedlog/ajax/check_signature.php
* \ingroup blockedlog
* \brief This page is not used yet.
*/
// This script is called with a POST method.
// Directory to scan (full path) is inside POST['dir'].
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
if (!getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL')) {
exit('BLOCKEDLOG_AUTHORITY_URL not set');
}
/*
* View
*/
top_httphead();
$auth = new BlockedLogAuthority($db);
$auth->syncSignatureWithAuthority();
$block_static = new BlockedLog($db);
$blocks = $block_static->getLog('just_certified', 0, 0, 'rowid', 'ASC');
$auth->signature = $block_static->getSignature();
if (is_array($blocks)) {
foreach ($blocks as &$b) {
$auth->blockchain .= $b->signature;
}
}
$hash = $auth->getBlockchainHash();
// Call external authority
$url = getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL') . '/blockedlog/ajax/authority.php?s='.urlencode($auth->signature).'&h='.urlencode($hash);
$resarray = getURLContent($url, 'GET', '', 1, array(), array(), 2);
$res = $resarray['content'];
//echo $url;
echo dol_escape_htmltag($res);

View File

@@ -1,329 +0,0 @@
<?php
/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
*
* 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 <https://www.gnu.org/licenses/>.
*/
/**
* Class to manage certif authority
*/
class BlockedLogAuthority
{
/**
* DoliDB
* @var DoliDB
*/
public $db;
/**
* Id of the authority
* @var int
*/
public $id;
/**
* @var string Ref of the authority
*/
public $ref;
/**
* Unique fingerprint of the blockchain to store
* @var string
*/
public $signature = '';
/**
* Entire fingerprints blockchain
* @var string
*/
public $blockchain = '';
/**
* timestamp
* @var int
*/
public $tms = 0;
/**
* Error message
* @var string
*/
public $error;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Get the blockchain
*
* @return string blockchain
*/
public function getLocalBlockChain()
{
$block_static = new BlockedLog($this->db);
$this->signature = $block_static->getSignature();
$blocks = $block_static->getLog('all', 0, 0, 'rowid', 'ASC');
$this->blockchain = '';
if (is_array($blocks)) {
foreach ($blocks as &$b) {
$this->blockchain .= $b->signature;
}
}
return $this->blockchain;
}
/**
* Get hash of the block chain to check
*
* @return string hash md5 of blockchain
*/
public function getBlockchainHash()
{
return md5($this->signature.$this->blockchain);
}
/**
* Get hash of the block chain to check
*
* @param string $hash hash md5 of blockchain to test
* @return boolean
*/
public function checkBlockchain($hash)
{
return ($hash === $this->getBlockchainHash());
}
/**
* Add a new block to the chain
*
* @param string $block new block to chain
* @return void
*/
public function addBlock($block)
{
$this->blockchain .= $block;
}
/**
* hash already exist into chain ?
*
* @param string $block new block to chain
* @return boolean
*/
public function checkBlock($block)
{
if (strlen($block) != 64) {
return false;
}
$blocks = str_split($this->blockchain, 64);
if (!in_array($block, $blocks)) {
return true;
} else {
return false;
}
}
/**
* Get object from database
*
* @param int $id Id of object to load
* @param string $signature Signature of object to load
* @return int >0 if OK, <0 if KO, 0 if not found
*/
public function fetch($id, $signature = '')
{
global $langs;
dol_syslog(get_class($this)."::fetch id=".((int) $id), LOG_DEBUG);
if (empty($id) && empty($signature)) {
$this->error = 'BadParameter';
return -1;
}
$langs->load("blockedlog");
$sql = "SELECT b.rowid, b.signature, b.blockchain, b.tms";
$sql .= " FROM ".MAIN_DB_PREFIX."blockedlog_authority as b";
if ($id) {
$sql .= " WHERE b.rowid = ".((int) $id);
} elseif ($signature) {
$sql .= " WHERE b.signature = '".$this->db->escape($signature)."'";
}
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->signature = $obj->signature;
$this->blockchain = $obj->blockchain;
$this->tms = $this->db->jdate($obj->tms);
return 1;
} else {
$langs->load("errors");
$this->error = $langs->trans("ErrorRecordNotFound");
return 0;
}
} else {
$this->error = $this->db->error();
return -1;
}
}
/**
* Create authority in database.
*
* @param User $user Object user that create
* @return int Return integer <0 if KO, >0 if OK
*/
public function create($user)
{
global $conf, $langs, $hookmanager;
$langs->load('blockedlog');
$error = 0;
dol_syslog(get_class($this).'::create', LOG_DEBUG);
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."blockedlog_authority (";
$sql .= " signature,";
$sql .= " blockchain";
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($this->signature)."',";
$sql .= "'".$this->db->escape($this->blockchain)."'";
$sql .= ")";
$res = $this->db->query($sql);
if ($res) {
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."blockedlog_authority");
if ($id > 0) {
$this->id = $id;
$this->db->commit();
return $this->id;
} else {
$this->db->rollback();
return -2;
}
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Create authority in database.
*
* @param User $user Object user that create
* @return int Return integer <0 if KO, >0 if OK
*/
public function update($user)
{
global $conf, $langs, $hookmanager;
$langs->load('blockedlog');
$error = 0;
dol_syslog(get_class($this).'::create', LOG_DEBUG);
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."blockedlog_authority SET ";
$sql .= " blockchain='".$this->db->escape($this->blockchain)."'";
$sql .= " WHERE rowid=".((int) $this->id);
$res = $this->db->query($sql);
if ($res) {
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* For cron to sync to authority.
*
* @return int Return integer <0 if KO, >0 if OK
*/
public function syncSignatureWithAuthority()
{
global $conf, $langs;
//TODO create cron task on activation
if (!getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL') || !getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
$this->error = $langs->trans('NoAuthorityURLDefined');
return -2;
}
require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
$block_static = new BlockedLog($this->db);
$blocks = $block_static->getLog('not_certified', 0, 0, 'rowid', 'ASC');
$signature = $block_static->getSignature();
if (is_array($blocks)) {
foreach ($blocks as &$block) {
$url = getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL') . '/blockedlog/ajax/authority.php?s='.$signature.'&b='.$block->signature;
$res = getURLContent($url);
echo $block->signature.' '.$url.' '.$res['content'].'<br>';
if ($res['content'] === 'blockalreadyadded' || $res['content'] === 'blockadded') {
$block->setCertified();
} else {
$this->error = $langs->trans('ImpossibleToContactAuthority', $url);
return -1;
}
}
}
return 1;
}
}

View File

@@ -1 +0,0 @@
ALTER TABLE llx_blockedlog_authority ADD INDEX signature (signature);

View File

@@ -1,7 +0,0 @@
CREATE TABLE llx_blockedlog_authority
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
blockchain longtext NOT NULL,
signature varchar(100) NOT NULL,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=innodb;