44 public $signature =
'';
50 public $blockchain =
'';
83 $this->signature = $block_static->getSignature();
85 $blocks = $block_static->getLog(
'all', 0, 0,
'rowid',
'ASC');
87 $this->blockchain =
'';
89 if (is_array($blocks)) {
90 foreach ($blocks as &$b) {
91 $this->blockchain .= $b->signature;
95 return $this->blockchain;
105 return md5($this->signature.$this->blockchain);
127 $this->blockchain .= $block;
138 if (strlen($block) != 64) {
142 $blocks = str_split($this->blockchain, 64);
144 if (!in_array($block, $blocks)) {
159 public function fetch($id, $signature =
'')
163 dol_syslog(get_class($this).
"::fetch id=".((
int) $id), LOG_DEBUG);
165 if (empty($id) && empty($signature)) {
166 $this->error =
'BadParameter';
170 $langs->load(
"blockedlog");
172 $sql =
"SELECT b.rowid, b.signature, b.blockchain, b.tms";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog_authority as b";
176 $sql .=
" WHERE b.rowid = ".((int) $id);
177 } elseif ($signature) {
178 $sql .=
" WHERE b.signature = '".$this->db->escape($signature).
"'";
181 $resql = $this->db->query($sql);
183 if ($this->db->num_rows($resql)) {
184 $obj = $this->db->fetch_object($resql);
186 $this->
id = $obj->rowid;
187 $this->
ref = $obj->rowid;
189 $this->signature = $obj->signature;
190 $this->blockchain = $obj->blockchain;
192 $this->tms = $this->db->jdate($obj->tms);
196 $this->error = $langs->trans(
"RecordNotFound");
200 $this->error = $this->db->error();
213 global $conf, $langs, $hookmanager;
215 $langs->load(
'blockedlog');
219 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
223 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog_authority (";
224 $sql .=
" signature,";
225 $sql .=
" blockchain";
226 $sql .=
") VALUES (";
227 $sql .=
"'".$this->db->escape($this->signature).
"',";
228 $sql .=
"'".$this->db->escape($this->blockchain).
"'";
231 $res = $this->db->query($sql);
233 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog_authority");
242 $this->db->rollback();
246 $this->error = $this->db->error();
247 $this->db->rollback();
260 global $conf, $langs, $hookmanager;
262 $langs->load(
'blockedlog');
266 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
270 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog_authority SET ";
271 $sql .=
" blockchain='".$this->db->escape($this->blockchain).
"'";
272 $sql .=
" WHERE rowid=".((int) $this->
id);
274 $res = $this->db->query($sql);
280 $this->error = $this->db->error();
281 $this->db->rollback();
293 global $conf, $langs;
298 $this->error = $langs->trans(
'NoAuthorityURLDefined');
302 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
306 $blocks = $block_static->getLog(
'not_certified', 0, 0,
'rowid',
'ASC');
308 $signature = $block_static->getSignature();
310 if (is_array($blocks)) {
311 foreach ($blocks as &$block) {
312 $url =
getDolGlobalString(
'BLOCKEDLOG_AUTHORITY_URL') .
'/blockedlog/ajax/authority.php?s='.$signature.
'&b='.$block->signature;
315 echo $block->signature.
' '.$url.
' '.$res[
'content'].
'<br>';
316 if ($res[
'content'] ===
'blockalreadyadded' || $res[
'content'] ===
'blockadded') {
317 $block->setCertified();
319 $this->error = $langs->trans(
'ImpossibleToContactAuthority', $url);
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 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)
Function to get a content from an URL (use proxy if proxy defined).