dolibarr 25.0.0-alpha
blockedlog.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3 * Copyright (C) 2018 Destailleur Laurent <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/blockedlog/versionmod.inc.php';
28
29
36{
37 $versionbadge = constant('DOLCERT_VERSION');
38
39 if (constant('DOLCERT_NAME') != 'BlockedLog') { // Can add a prefix name before version text for clarity.
40 $versionbadge = constant('DOLCERT_NAME').'-'.$versionbadge;
41 }
42
43 return $versionbadge;
44}
45
46
53function blockedlogadmin_prepare_head($withtabsetup)
54{
55 global $db, $langs, $conf, $mysoc;
56
57 $langs->load("blockedlog");
58
59 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
60
61 $param = '';
62 $param .= ($withtabsetup? "?withtab=".$withtabsetup : "");
63 $param .= (GETPOST('origin') ? ($param ? '&' : '?').'origin='.GETPOST('origin') : '');
64
65 $h = 0;
66 $head = array();
67
68 if (!userIsTaxAuditor()) {
69 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/registration.php".$param;
70 $head[$h][1] = $langs->trans("UserRegistration");
71 $head[$h][2] = 'registration';
72 $h++;
73 }
74
75 if (!userIsTaxAuditor()) {
76 $b = new BlockedLog($db);
77 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_list.php".$param;
78 $head[$h][1] = $langs->trans("BrowseBlockedLog");
79 if ($b->alreadyUsed()) {
80 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">...</span>' : '');
81 }
82 $head[$h][2] = 'fingerprints';
83 $h++;
84 }
85
86 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_archives.php".$param;
87 $head[$h][1] = $langs->trans("Archives");
88 // Add badge on nb of files
89 $block_static = new BlockedLog($db);
90 $upload_dir = getMultidirOutput($block_static, 'blockedlog').'/archives';
91 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
92 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
93 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
94 $nbLinks = 0;
95 if (($nbFiles + $nbLinks) > 0) {
96 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
97 }
98 $head[$h][2] = 'archives';
99 $h++;
100
101 if (userIsTaxAuditor()) {
102 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog_control.php".$param;
103 $head[$h][1] = $langs->trans("OtherControl");
104 $head[$h][2] = 'control';
105 $h++;
106 }
107
108 if ($mysoc->country_code == 'FR') {
109 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/documentation.php".$param;
110 $head[$h][1] = $langs->trans("Documentation");
111 $head[$h][2] = 'documentation';
112 $h++;
113 }
114
115 if ($withtabsetup && !userIsTaxAuditor()) {
116 $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog.php".$param;
117 $head[$h][1] = $langs->trans("TechnicalInformation");
118 $head[$h][2] = 'technicalinfo';
119 $h++;
120 }
121
122
123 $object = new stdClass();
124
125 // Show more tabs from modules
126 // Entries must be declared in modules descriptor with line
127 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
128 // $this->tabs = array('entity:-tabname); to remove a tab
129 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog');
130
131 complete_head_from_modules($conf, $langs, $object, $head, $h, 'blockedlog', 'remove');
132
133 return $head;
134}
135
136
144{
145 global $mysoc;
146
147 $companyname = getDolGlobalString('BLOCKEDLOG_REGISTRATION_NAME', $mysoc->name);
148 $companyemail = getDolGlobalString('BLOCKEDLOG_REGISTRATION_EMAIL', $mysoc->email);
149 $companycountrycode = $mysoc->country_code;
150 $companyidprof1 = getDolGlobalString('MAIN_INFO_SIREN', $mysoc->idprof1);
151 $companyidprof2 = getDolGlobalString('MAIN_INFO_SIRET', $mysoc->idprof2);
152 //$companytel = getDolGlobalString('BLOCKEDLOG_REGISTRATION_TEL', $mysoc->phone);
153
154 if (empty($companyname) || empty($companycountrycode) || empty($companyidprof1) || empty($companyidprof2) || empty($companyemail)) {
155 return false;
156 }
157 /*
158 $providerset = getDolGlobalString('MAIN_INFO_ITPROVIDER_NAME'); // Can be 'myself'
159
160 if (empty($providerset)) {
161 return false;
162 }
163 */
164
165 return true;
166}
167
168
175{
176 return isRegistrationDataSaved() && (bool) getDolGlobalString('MAIN_FIRST_REGISTRATION_OK_DATE');
177}
178
179
186function getHashUniqueIdOfRegistration($algo = 'sha256')
187{
188 global $conf;
189
190 return dol_hash('dolibarr'.$conf->file->instance_unique_id.($conf->entity > 1 ? $conf->entity : ''), $algo, 1);
191}
192
193
204function isALNEQualifiedVersion($ignoredev = 0, $ignoremodule = 0)
205{
206 global $mysoc;
207
208 // For Dev/Debug purpose: Constant set by developer to force all LNE restrictions even if country is not France so we can test them on any dev instance.
209 // Note that you can force, with this option, the enabling of the LNE restrictions, but there is no way to force the disabling of the LNE restriction.
210 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2) {
211 return 'CERTIF_LNE_IS_2';
212 }
213
214 if (!$ignoredev && preg_match('/\-/', DOL_VERSION)) { // This is not a stable version (dev version), it can't be the certified versions.
215 return '';
216 }
217 if (empty($mysoc) || $mysoc->country_code != 'FR') {
218 return '';
219 }
220 if (!defined('CERTIF_LNE') || (int) constant('CERTIF_LNE') === 0) {
221 return '';
222 }
223 if (!$ignoremodule && !isModEnabled('blockedlog')) {
224 return '';
225 }
226
227 // All conditions are ok to become a LNE certified version
228 return ($ignoredev ? '' : 'NOT_BETA+').'FR+CERTIF_LNE_IS_1'.($ignoremodule ? '' : '+MODENABLED');
229}
230
231
240function isALNERunningVersion($blockedlogusagealreadychecked = 0, $blockedlogmoduleonalreadychecked = 0)
241{
242 // For Debug help: Constant CERTIF_LNE can be set 2 by developers get mode 1 compliant with dev env.
243 // Note that you can force, with this constant, the enabling of the restrictions,
244 // but there is no way to force the disabling of a restriction.
245 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 2 // Value is 2 for debug purpose to enable restriction except https for dev env.
246 && ($blockedlogmoduleonalreadychecked || isModEnabled('blockedlog'))
247 && ($blockedlogusagealreadychecked || isBlockedLogUsed())) {
248 return true;
249 }
250 if (defined('CERTIF_LNE') && (int) constant('CERTIF_LNE') === 1 // Value is 1 when version is certified
251 && ($blockedlogmoduleonalreadychecked || isModEnabled('blockedlog'))
252 && ($blockedlogusagealreadychecked || isBlockedLogUsed())) {
253 return true;
254 }
255
256 return false;
257}
258
265function isBlockedLogUsed($ignoresystem = 0)
266{
267 global $conf, $db;
268
269 $result = true; // by default restrictions are on, so we can't disable them
270
271 // Note: if module on, we suppose it is used, if not, we check in case of it was disabled.
272 if (!isModEnabled('blockedlog')) {
273 // Test the cache key
274 if (array_key_exists('isblockedlogused', $conf->cache)) {
275 return $conf->cache['isblockedlogused'.$ignoresystem];
276 }
277
278 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog";
279 $sql .= " WHERE entity = ".((int) $conf->entity); // Sharing entity in blocked log will never be allowed
280 if ($ignoresystem) {
281 $sql .= " AND action NOT IN ('MODULE_SET', 'MODULE_RESET')";
282 }
283 $sql .= $db->plimit(1);
284
285 $resql = $db->query($sql);
286 if ($resql !== false) {
287 $obj = $db->fetch_object($resql);
288 if (!$obj) {
289 $result = false;
290 }
291 } else {
292 dol_print_error($db);
293 }
294
295 $conf->cache['isblockedlogused'.$ignoresystem] = $result;
296 }
297
298 dol_syslog("isBlockedLogUsed: ignoresystem=".$ignoresystem." returns ".(string) $result);
299
300 return $result;
301}
302
303
315function pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
316{
317 $result = 0;
318
319 if (in_array($seller->country_code, array('FR'))) {
320 $outputlangs->load("blockedlog");
321 $blockedlog_mention = '';
322
323 $isalne = isALNEQualifiedVersion(); // If necessary, we could replace with "if isALNERunningVersion()"
324 if ($isalne == 'CERTIF_LNE_IS_2') {
325 $blockedlog_mention = $outputlangs->transnoentitiesnoconv("InvoiceGeneratedWithLNECandidatePOSSystem");
326 } elseif ($isalne) {
327 $blockedlog_mention = $outputlangs->transnoentitiesnoconv("InvoiceGeneratedWithLNECertifiedPOSSystem");
328 }
329
330 if ($blockedlog_mention) {
331 $pdf->SetFont('', '', $default_font_size - 2);
332 $pdf->SetXY($pdftemplate->marge_gauche, $posy);
333 $pdf->MultiCell(100, 3, $blockedlog_mention, 0, 'L', false);
334 $posy = $pdf->GetY();
335 $result = 1;
336 }
337 }
338
339 return $result;
340}
341
355function sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
356{
357 if ($block->action == 'BILL_VALIDATE') {
358 $total_ht = $block->object_data->total_ht;
359 $total_vat = $block->object_data->total_tva;
360 $total_ttc = $block->object_data->total_ttc;
361
362 // Init to avoid warnings if not initialized yet
363 if (!isset($totalamount[$block->action][$block->module_source])) {
364 $totalhtamount[$block->action][$block->module_source] = 0;
365 $totalvatamount[$block->action][$block->module_source] = 0;
366 $totalamount[$block->action][$block->module_source] = 0;
367 }
368
369 // We add total for the invoice if "invoice validate event" not yet met.
370 // If we already met the event for this object, we keep only first one but this should not happen because edition of validated invoice is not allowed on secured versions.
371 if (empty($refinvoicefound[$block->ref_object])) {
372 $totalhtamount[$block->action][$block->module_source] += $total_ht;
373 $totalvatamount[$block->action][$block->module_source] += $total_vat;
374 $totalamount[$block->action][$block->module_source] += $total_ttc;
375 }
376 $refinvoicefound[$block->ref_object] = 1;
377 } elseif ($block->action == 'PAYMENT_CUSTOMER_CREATE' || $block->action == 'PAYMENT_CUSTOMER_DELETE') {
378 $total_ht = $block->object_data->amount;
379 $total_vat = 0;
380 $total_ttc = $block->object_data->amount;
381
382 //$actionkey = $block->action;
383 $actionkey = 'PAYMENT_CUSTOMER';
384
385 // Init to avoid warnings if not initialized yet
386 if (!isset($totalamount[$actionkey][$block->module_source])) {
387 $totalhtamount[$actionkey][$block->module_source] = 0;
388 $totalvatamount[$actionkey][$block->module_source] = 0;
389 $totalamount[$actionkey][$block->module_source] = 0;
390 }
391
392 $totalhtamount[$actionkey][$block->module_source] += $total_ht;
393 $totalvatamount[$actionkey][$block->module_source] += $total_vat;
394 $totalamount[$actionkey][$block->module_source] += $total_ttc;
395 } else {
396 $total_ttc = $block->amounts;
397 }
398
399 return 1;
400}
401
402
412function callApiToGetObfuscationKey($idprof1, $registrationnumber, $force = false)
413{
414 global $mysoc, $conf;
415
416 $obfuscationkey = 'ERROR';
417
418 if (empty($idprof1)) {
419 dol_syslog("callApiToGetObfuscationKey was called with empty idprof1", LOG_DEBUG);
420 return 'ERROR callApiToGetObfuscationKey was called with empty idprof1';
421 }
422
423 //if ((isALNERunningVersion(1) || $force) && $mysoc->country_code == 'FR') {
424 $url_for_ping = getDolGlobalString('MAIN_URL_FOR_PING', "https://ping.dolibarr.org/");
425
426 $algo = 'sha256';
427 $hash_unique_id = getHashUniqueIdOfRegistration($algo); // The hash of the unique IDof instance
428
429 $t = microtime(true);
430 $micro = sprintf("%06d", (int) (($t - floor($t)) * 1000000));
431
432 $data = '';
433 $data .= 'hash_algo=dol_hash-'.urlencode($algo);
434 $data .= '&hash_unique_id='.urlencode($hash_unique_id);
435 $data .= '&action=dolibarrgetkeyobfuscation';
436 $data .= '&datesys='.urlencode(dol_print_date(dol_now('gmt'), 'standard', 'gmt').'.'.$micro);
437 $data .= '&version='.(float) DOL_VERSION;
438 $data .= '&version_full='.urlencode(DOL_VERSION);
439 $data .= '&versionblockedlog='.(float) getBlockedLogVersionToShow();
440 $data .= '&versionblockedlog_full='.urlencode(getBlockedLogVersionToShow());
441
442 $data .= '&entity='.(int) $conf->entity;
443
444 $data .= '&company_idprof1='.urlencode(dol_sanitizeKeyCode($idprof1));
445 $data .= '&registrationnumber='.urlencode(dol_sanitizeKeyCode($registrationnumber));
446
447 $addheaders = array();
448 $timeoutconnect = 3;
449 $timeoutresponse = 3;
450
451 dol_syslog("callApiToGetObfuscationKey call remote URL idprod1=".dol_sanitizeKeyCode($idprof1), LOG_DEBUG);
452 dol_syslog("callApiToGetObfuscationKey call remote URL idprod1=".dol_sanitizeKeyCode($idprof1), LOG_DEBUG, 0, '_dolibarrgetkeyobfuscation');
453
454 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
455
456 $maxretry = getDolGlobalInt('BLOCKEDLOG_MAX_TRY_FOR_REMOTE_OBFUSCATION_KEY', 2);
457 $retrydelay = 300000; // 300ms, in microseconds
458
459 for ($tryid = 1; $tryid <= $maxretry; $tryid++) {
460 $retryable = false;
461
462 try {
463 $tmpresult = getURLContent($url_for_ping, 'POST', $data, 1, $addheaders, array('https'), 0, -1, $timeoutconnect, $timeoutresponse, array());
464 usleep(10000);
465
466 // Add a warning in log in case of error
467 if ($tmpresult['http_code'] == 0 && !empty($tmpresult['curl_error_msg'])) {
468 $logerrormessage = 'Error: '.$tmpresult['curl_error_msg'];
469 $obfuscationkey = 'ERROR '.$tmpresult['curl_error_msg'];
470 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING);
471 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
472 $retryable = true; // No connection / timeout, worth retrying
473 } elseif ($tmpresult['http_code'] >= 500) {
474 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
475 $obfuscationkey = 'ERROR '.$tmpresult['http_code'].' '.$tmpresult['content'];
476 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING);
477 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
478 $retryable = true; // Remote server error, may be transient
479 } elseif ($tmpresult['http_code'] == 403) {
480 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
481 $obfuscationkey = 'ERROR '.$tmpresult['http_code'].' '.$tmpresult['content'];
482 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING);
483 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key (try ".$tryid."/".$maxretry."): ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
484 $retryable = true; // ping.dolibarr.org is Cloudflare-fronted; a 403 from a
485 // shared/CI IP is far more likely bot-mitigation on that
486 // specific request than a permanent application-level
487 // rejection, so it is worth a retry too
488 } elseif ($tmpresult['http_code'] != 200) {
489 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
490 $obfuscationkey = 'ERROR '.$tmpresult['http_code'].' '.$tmpresult['content'];
491 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING);
492 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
493 } else {
494 $reg = array();
495 if (preg_match('/(DOLOBFUSCKEY.*)/', $tmpresult['content'], $reg)) { // gitleaks:allow $tmpresult['content'] may contains text comments before the line 'DOLOBFUSCKEY1...,DOLOBFUSCKEY2...'
496 $obfuscationkey = $reg[1];
497 dol_syslog("callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG);
498 dol_syslog("callApiToGetObfuscationKey we got the remote obfuscation key", LOG_DEBUG, 0, '_dolibarrgetkeyobfuscation');
499 } else {
500 $obfuscationkey = 'ERROR '.$tmpresult['content'];
501 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult['content'], LOG_WARNING);
502 dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$tmpresult['content'], LOG_WARNING, 0, '_dolibarrgetkeyobfuscation');
503 }
504 }
505 } catch (Exception $e) {
506 $obfuscationkey = 'ERROR '.$e->getMessage();
507 dol_syslog("callApiToGetObfuscationKey result error (try ".$tryid."/".$maxretry."): ".$e->getMessage(), LOG_ERR);
508 dol_syslog("callApiToGetObfuscationKey result error (try ".$tryid."/".$maxretry."): ".$e->getMessage(), LOG_ERR, 0, '_dolibarrgetkeyobfuscation');
509 $retryable = true; // Network exception, worth retrying
510 }
511
512 if (!$retryable || $tryid == $maxretry) {
513 break;
514 }
515
516 usleep($retrydelay);
517 }
518
519 return $obfuscationkey;
520}
521
522
535/*
536function callApiToPushCounter($id, $signature, $datecreation, $test, $previousid, $previoussignature, $previousdatecreation)
537{
538 global $mysoc, $conf;
539
540 if (isALNERunningVersion(1) && $mysoc->country_code == 'FR') {
541 // Push last rowid + signature to remote dolibarr server
542 // Do it only for selected events: BILL_VALIDATE ?
543
544 // Code here is similar to the one into printCodeForPing(), except that message code/properties/fields may differ.
545 $url_for_ping = getDolGlobalString('MAIN_URL_FOR_PING', "https://ping.dolibarr.org/");
546
547 $algo = 'sha256';
548 $hash_unique_id = getHashUniqueIdOfRegistration($algo); // The hash of the unique IDof instance
549
550 $t = microtime(true);
551 $micro = sprintf("%06d", (int) (($t - floor($t)) * 1000000));
552
553 $data = '';
554 $data .= 'hash_algo=dol_hash-'.urlencode($algo);
555 $data .= '&hash_unique_id='.urlencode($hash_unique_id);
556 $data .= '&action=dolibarrpushcounter';
557 $data .= '&datesys='.urlencode(dol_print_date(dol_now('gmt'), 'standard', 'gmt').'.'.$micro);
558 $data .= '&version='.(float) DOL_VERSION;
559 $data .= '&version_full='.urlencode(DOL_VERSION);
560 $data .= '&versionblockedlog='.(float) getBlockedLogVersionToShow();
561 $data .= '&versionblockedlog_full='.urlencode(getBlockedLogVersionToShow());
562
563 $data .= '&entity='.(int) $conf->entity;
564
565 $data .= '&lastrowid='.(int) $id;
566 $data .= '&lastsignature='.urlencode($signature);
567 $data .= '&lastdatecreation='.urlencode(dol_print_date($datecreation, 'standard', 'gmt'));
568 $data .= '&previousrowid='.(int) $previousid;
569 $data .= '&previoussignature='.urlencode($previoussignature);
570 $data .= '&previousdatecreation='.urlencode(dol_print_date($previousdatecreation, 'standard', 'gmt'));
571 if ($test) {
572 $data .= '&test=1';
573 }
574
575 $addheaders = array();
576 $timeoutconnect = 1;
577 $timeoutresponse = 1;
578
579 $conf->global->BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = 1; // Force probability to 1
580
581 // Probability will be between 1/10 by default and 1/1 if const BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING is set to 1. Can't be lower than 1/10.
582 $BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = min(10, getDolGlobalInt('BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING', 10));
583 $random = 1;
584 //$BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING = 1; // To force track at every call
585 if ($BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING > 1) {
586 $random = random_int(1, (int) $BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING);
587 }
588
589 if ($random == 1) { // 1 chance on BLOCKEDLOG_RANDOMRANGE_FOR_TRACKING
590 dol_syslog("callApiToPushCounter create Record is selected to be remotely pushed for tracking", LOG_DEBUG);
591
592 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
593 try {
594 $tmpresult = getURLContent($url_for_ping, 'POST', $data, 1, $addheaders, array('https'), 0, -1, $timeoutconnect, $timeoutresponse, array(), '_dolibarrpushcounter');
595 usleep(1000);
596
597 // Add a warning in log in case of error
598 if ($tmpresult['http_code'] != 200) {
599 $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content'];
600 dol_syslog("callApiToPushCounter create Error when pushing track info: ".$logerrormessage, LOG_WARNING);
601 }
602 } catch (Exception $e) {
603 dol_syslog("callApiToPushCounter create Error ".$e->getMessage(), LOG_ERR);
604 }
605 } else {
606 dol_syslog("callApiToPushCounter create Record is NOT selected to be remotely pushed for tracking", LOG_DEBUG);
607 }
608
609 return 1;
610 }
611
612 return 0;
613}
614*/
615
616
625{
626 global $user;
627
628 return (((getDolGlobalString('BLOCKEDLOG_FOR_TAX_AUDITOR') && $user->socid) || getDolGlobalString('BLOCKEDLOG_FOR_TAX_AUDITOR') == '2') ? 1 : 0);
629}
630
631
632
645function pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
646{
647 global $db;
648
649 // Transaction ID
650 if (isALNERunningVersion() && isModEnabled('blockedlog')) {
651 if ($object->status > $object::STATUS_DRAFT) {
652 $unalterablelogid = 'UNDEFINED'; // By default
653
654 $sql = "SELECT signature FROM ".MAIN_DB_PREFIX."blockedlog";
655 $sql .= " WHERE action = 'BILL_VALIDATE' AND element = 'facture' AND ref_object = '".$db->escape($object->ref)."'";
656 $sql .= $db->order('rowid', 'DESC');
657 $sql .= $db->plimit(1);
658
659 $resql = $db->query($sql);
660 if ($resql) {
661 $obj = $db->fetch_object($resql);
662 if ($obj) {
663 $unalterablelogid = $obj->signature;
664 }
665 }
666
667 if ($unalterablelogid != 'UNDEFINED') {
668 $pdf->SetXY($posx, $posy);
669 $pdf->SetTextColor(0, 0, 60);
670 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SignatureID")." : ".dol_trunc(strtoupper($unalterablelogid), 10), '', 'R');
671 $posy += 3;
672 }
673
674 $isADuplicata = ($object->pos_print_counter >= 2);
675 if ($isADuplicata) {
676 $pdf->SetXY($posx, $posy);
677 $pdf->SetTextColor(0, 0, 60);
678 $pdf->MultiCell($w, 3, '*** '.$outputlangs->trans("DUPLICATA").(getDolGlobalString('TAKEPOS_SHOW_PRINT_COUNTER_ON_RECEIPT') ? ' (no '.($object->pos_print_counter - 1).')' : '').' ***', '', 'R');
679 $posy += 3;
680 }
681 }
682
683 if ($object->status == $object::STATUS_DRAFT) {
684 $pdf->SetXY($posx, $posy);
685 $pdf->SetTextColor(0, 0, 60);
686 $pdf->MultiCell($w, 3, '*** '.strtoupper($outputlangs->trans("TemporaryReceipt")).' ***', '', 'R');
687 $posy += 3;
688 }
689 }
690}
691
692
693
700{
701 global $conf, $db, $langs, $mysoc;
702
703 include_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
704
705 $blocklog_static = new BlockedLog($db);
706
707 // Loop on all entities found in llx_blockedlog
708 $listofentities = array();
709 $sql = "SELECT DISTINCT entity FROM ".MAIN_DB_PREFIX."blockedlog";
710 $resql = $db->query($sql);
711 if ($resql) {
712 while ($obj = $db->fetch_object($resql)) {
713 $listofentities[] = $obj->entity;
714 }
715 } else {
716 print '<tr class="trforrunsql"><td colspan="4">';
717 print '<b>'.$langs->trans('InitEndFlagFile')."</b>:\n";
718 print 'Error: Failed to get list of entities in blockedlog table';
719 print '</td></tr>';
720 return -1;
721 }
722
723 foreach ($listofentities as $entity) {
724 print '<tr class="trforrunsql"><td colspan="4">';
725 print '<b>'.$langs->trans('InitEndFlagFile')." (entity = ".$entity.")</b>:\n";
726
727 // Load the data of company (country, ...). Erase current one so this function can be used by migration script only.
728 $conf->setEntityValues($db, $entity);
729 $mysoc = new Societe($db);
730 $mysoc->setMysoc($conf);
731
732 $maxid = 0;
733 $sql = "SELECT MAX(rowid) as maxid FROM ".MAIN_DB_PREFIX."blockedlog WHERE entity = ".((int) $entity);
734 $resql = $db->query($sql);
735 if ($resql) {
736 $obj = $db->fetch_object($resql);
737 if ($obj) {
738 $maxid = $obj->maxid;
739 }
740 } else {
741 print 'Error: Failed to get max id of blockedlog table';
742 print '</td></tr>';
743 return -1;
744 }
745
746 $blocklog_static->fetch($maxid);
747
748 $lockfile = $blocklog_static->getEndOfChainFlagFile();
749
750 // Lock acquired, we can now write the new .end file
751 $stringtowrite = 'BLOCKEDLOGHEAD '.$blocklog_static->id." ".dol_print_date($blocklog_static->date_creation, 'dayhourrfc', 'gmt')." ".(string) $blocklog_static->signature;
752
753 if (isALNERunningVersion(1) && $mysoc->country_code == 'FR') {
754 $remoteobfuscationkey = $blocklog_static->getObfuscationKey();
755 if (empty($remoteobfuscationkey)) {
756 print "Error: Failed to get the remote obfuscation key. We can't record the end of chain flag file so we abort the transaction.";
757 print '</td></tr>';
758 return -1;
759 }
760
761 $stringtowriteencoded = dolEncrypt($stringtowrite, $remoteobfuscationkey, '', '', 'dolobfuscationv1-'.$mysoc->idprof1.'-'.$blocklog_static->id);
762 } else {
763 $stringtowriteencoded = dolEncrypt($stringtowrite, '', '', '', 'dolcrypt-'.$mysoc->idprof1.'-'.$blocklog_static->id);
764 }
765
766 // Update or create the .end flag file.
767 if (defined('BLOCKEDLOG_END_FLAG_IN_A_FILE')) { // If we want to store the .end flag into a files instead of database (not used, may be for a future need)
768 $lockhandle = fopen($lockfile, 'w+');
769 if ($lockhandle) {
770 if (fwrite($lockhandle, $stringtowriteencoded."\n") === false) {
771 print "Cannot write to the blockedlog .end file ".$lockfile;
772 print '</td></tr>';
773 return -1;
774 }
775
776 fclose($lockhandle); // Remove the lock
777 dolChmod($lockfile);
778 } else {
779 print "Cannot open for writing the blockedlog .end file ".$lockfile;
780 print '</td></tr>';
781 return -1;
782 }
783 } else {
784 $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
785 $sql .= " WHERE name = '".$db->escape(basename($lockfile))."' AND entity = ".((int) $conf->entity);
786 $resql = $db->query($sql);
787
788 $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity)";
789 $sql .= " VALUES('".$db->escape(basename($lockfile))."', '".$db->escape($stringtowriteencoded)."', 'chaine', 0, 'Blockedlog end of chain flag', ".((int) $conf->entity).")";
790 $resql = $db->query($sql);
791 if (!$resql) {
792 print "Cannot open for writing the blockedlog .end file ".basename($lockfile);
793 print '</td></tr>';
794 return -1;
795 }
796 }
797
798 print $langs->trans("Done");
799 print '</td></tr>';
800 }
801
802 return 1;
803}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
migrate_blockedlog_add_end_file()
Migrate an old database to add the .end flag.
sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamount, &$totalvatamount, &$totalamount, &$total_ht, &$total_vat, &$total_ttc)
sumAmountsForUnalterableEvent
getBlockedLogVersionToShow()
Define head array for tabs of blockedlog tools setup pages.
pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
isALNEQualifiedVersion($ignoredev=0, $ignoremodule=0)
Return if the version is a candidate version to get the LNE certification and if the prerequisites ar...
isRegistrationDataSaved()
Return if the KYC mandatory parameters are set Must be the same fields than the one defined as mandat...
userIsTaxAuditor()
Call remote API service to push the last counter and signature.
pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal mention.
isBlockedLogUsed($ignoresystem=0)
Return if the blocked log was already used to block some events.
blockedlogadmin_prepare_head($withtabsetup)
Define head array for tabs of blockedlog tools setup pages.
isRegistrationDataSavedAndPushed()
Return if the KYC mandatory parameters are set AND pushed/registered centralized server.
getHashUniqueIdOfRegistration($algo='sha256')
Return a hash unique identifier of the registration (used to identify the registration of instance wi...
isALNERunningVersion($blockedlogusagealreadychecked=0, $blockedlogmoduleonalreadychecked=0)
Return if the application is executed with the LNE requirements on.
callApiToGetObfuscationKey($idprof1, $registrationnumber, $force=false)
Call remote API service to get the obfuscation key.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage Blocked Log.
Class to manage third parties objects (customers, suppliers, prospects...)
global $mysoc
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
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, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.