45 public $signature =
'';
51 public $blockchain =
'';
84 $this->signature = $block_static->getSignature();
86 $blocks = $block_static->getLog(
'all', 0, 0,
'rowid',
'ASC');
88 $this->blockchain =
'';
90 if (is_array($blocks)) {
91 foreach ($blocks as &$b) {
92 $this->blockchain .= $b->signature;
96 return $this->blockchain;
106 return md5($this->signature.$this->blockchain);
128 $this->blockchain .= $block;
139 if (strlen($block) != 64) {
143 $blocks = str_split($this->blockchain, 64);
145 if (!in_array($block, $blocks)) {
160 public function fetch($id, $signature =
'')
164 dol_syslog(get_class($this).
"::fetch id=".((
int) $id), LOG_DEBUG);
166 if (empty(
$id) && empty($signature)) {
167 $this->error =
'BadParameter';
171 $langs->load(
"blockedlog");
173 $sql =
"SELECT b.rowid, b.signature, b.blockchain, b.tms";
174 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog_authority as b";
177 $sql .=
" WHERE b.rowid = ".((int)
$id);
178 } elseif ($signature) {
179 $sql .=
" WHERE b.signature = '".$this->db->escape($signature).
"'";
182 $resql = $this->db->query($sql);
184 if ($this->db->num_rows($resql)) {
185 $obj = $this->db->fetch_object($resql);
187 $this->
id = $obj->rowid;
188 $this->
ref = $obj->rowid;
190 $this->signature = $obj->signature;
191 $this->blockchain = $obj->blockchain;
193 $this->tms = $this->db->jdate($obj->tms);
197 $langs->load(
"errors");
198 $this->error = $langs->trans(
"ErrorRecordNotFound");
202 $this->error = $this->db->error();
215 global
$conf, $langs, $hookmanager;
217 $langs->load(
'blockedlog');
221 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
225 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog_authority (";
226 $sql .=
" signature,";
227 $sql .=
" blockchain";
228 $sql .=
") VALUES (";
229 $sql .=
"'".$this->db->escape($this->signature).
"',";
230 $sql .=
"'".$this->db->escape($this->blockchain).
"'";
233 $res = $this->db->query($sql);
235 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog_authority");
244 $this->db->rollback();
248 $this->error = $this->db->error();
249 $this->db->rollback();
262 global
$conf, $langs, $hookmanager;
264 $langs->load(
'blockedlog');
268 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
272 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog_authority SET ";
273 $sql .=
" blockchain='".$this->db->escape($this->blockchain).
"'";
274 $sql .=
" WHERE rowid=".((int) $this->
id);
276 $res = $this->db->query($sql);
282 $this->error = $this->db->error();
283 $this->db->rollback();
295 global
$conf, $langs;
300 $this->error = $langs->trans(
'NoAuthorityURLDefined');
304 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
308 $blocks = $block_static->getLog(
'not_certified', 0, 0,
'rowid',
'ASC');
310 $signature = $block_static->getSignature();
312 if (is_array($blocks)) {
313 foreach ($blocks as &$block) {
314 $url =
getDolGlobalString(
'BLOCKEDLOG_AUTHORITY_URL') .
'/blockedlog/ajax/authority.php?s='.$signature.
'&b='.$block->signature;
317 echo $block->signature.
' '.$url.
' '.$res[
'content'].
'<br>';
318 if ($res[
'content'] ===
'blockalreadyadded' || $res[
'content'] ===
'blockadded') {
319 $block->setCertified();
321 $this->error = $langs->trans(
'ImpossibleToContactAuthority', $url);
$id
Support class for third parties, contacts, members, users or resources.
Class to manage certif authority.
fetch($id, $signature='')
Get object from database.
checkBlock($block)
hash already exist into chain ?
create($user)
Create authority in database.
__construct($db)
Constructor.
getLocalBlockChain()
Get the blockchain.
syncSignatureWithAuthority()
For cron to sync to authority.
update($user)
Create authority in database.
checkBlockchain($hash)
Get hash of the block chain to check.
addBlock($block)
Add a new block to the chain.
getBlockchainHash()
Get hash of the block chain to check.
Class to manage Blocked Log.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0)
Function to get a content from an URL (use proxy if proxy defined).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...