26include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
27include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
28include_once DOL_DOCUMENT_ROOT.
'/blockedlog/versionmod.inc.php';
48 $this->rights_class =
'blockedlog';
52 $this->family =
"base";
54 $this->module_position =
'76';
56 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
57 $this->
description =
"Enable a log on some business events into an unalterable log. This module may be mandatory for some countries.";
60 $this->version = constant(
'DOLCERT_VERSION');
61 $this->version_if_core = 1;
63 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
65 $this->picto =
'blockedlog';
68 $this->dirs = array();
72 $this->config_page_url = array(
'registration.php?origin=setupmodule&withtab=1@blockedlog');
76 $this->hidden =
false;
77 $this->depends = array(
'always' =>
'modFacture');
78 $this->requiredby = array();
79 $this->conflictwith = array();
80 $this->langfiles = array(
'blockedlog');
82 $this->warnings_activation = array();
83 $this->warnings_activation_ext = array();
84 $this->warnings_unactivation = array(
'FR' =>
'BlockedLogAreRequiredByYourCountryLegislation');
100 && in_array((empty(
$mysoc->country_code) ?
'' :
$mysoc->country_code), explode(
',',
getDolGlobalString(
'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')))
105 $this->
const = array(
106 1 => array(
'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY',
'chaine',
'FR',
'This is list of country code where the module may be mandatory', 0,
'current', 0)
111 $this->tabs = array();
115 $this->boxes = array();
119 $this->rights = array();
122 $this->rights[$r][0] = $this->numero + $r;
123 $this->rights[$r][1] =
'Read archived events and fingerprints';
124 $this->rights[$r][3] = 0;
125 $this->rights[$r][4] =
'read';
126 $this->rights[$r][5] =
'';
131 $this->menu[$r] = array(
132 'fk_menu' =>
'fk_mainmenu=tools',
133 'mainmenu' =>
'tools',
134 'leftmenu' =>
'blockedlogbrowser',
136 'titre' =>
'BrowseBlockedLog',
137 'prefix' =>
img_picto(
'', $this->picto,
'class="paddingright pictofixedwidth"'),
138 'url' =>
'/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser',
139 'langs' =>
'blockedlog',
141 'enabled' =>
'isModEnabled("blockedlog")',
142 'perms' =>
'$user->hasRight("blockedlog", "read")',
157 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
171 public function init($options =
'')
178 if (version_compare(PHP_VERSION,
'7.0.0') < 0) {
179 $errmsg =
'Error: You are using a too low version of PHP';
181 $this->error = $errmsg;
186 unset($_SESSION[
'obfuscationkey_'.((
int)
$conf->entity)]);
187 unset(
$conf->cache[
'obfuscationkey_'.((int)
$conf->entity)]);
189 require_once DOL_DOCUMENT_ROOT .
'/blockedlog/class/blockedlog.class.php';
195 header(
"Location: ".DOL_URL_ROOT.
'/blockedlog/admin/registration.php?origin=initmodule&withtab=0');
200 if (empty(
$mysoc->country_code)) {
201 $errmsg =
'Error: The context of the running company is not defined';
203 $this->error = $errmsg;
208 $s = $b->canBeEnabled();
221 $hmac_encoded_secret_key = $b->getEncodedHMACSecretKey();
223 if (empty($hmac_encoded_secret_key)) {
225 $randomsecret = bin2hex(random_bytes(32));
227 $hmac_secret_key =
'BLOCKEDLOGHMAC'.$randomsecret;
230 $obfuscationkey =
'';
233 $obfuscationkey = $b->getObfuscationKey();
238 $obfuscationkey =
'';
241 if (empty($obfuscationkey)) {
243 $url_for_ping =
getDolGlobalString(
'MAIN_URL_FOR_PING',
"https://ping.dolibarr.org/");
244 setEventMessages($langs->trans(
'FailedToGetRemoteObfuscationKeyReTryLater', $url_for_ping),
null,
'errors');
250 $result = $b->saveHMACSecretKey($hmac_secret_key,
'dolobfuscationv1-'.
$mysoc->idprof1, $obfuscationkey);
257 $result = $b->saveHMACSecretKey($hmac_secret_key,
'dolcrypt');
269 $hmac_secret_key =
'';
271 $hmac_secret_key = $b->getClearHMACSecretKey($hmac_encoded_secret_key);
273 $firsterrormessage = $e->getMessage();
276 $hmac_encoded_secret_key_alt = $b->getEncodedHMACSecretKey(1, 1);
277 if (!empty($hmac_encoded_secret_key_alt)) {
279 $hmac_secret_key_alt = $b->getClearHMACSecretKey($hmac_encoded_secret_key_alt);
281 if (preg_match(
'/^BLOCKEDLOGHMAC/', (
string) $hmac_secret_key_alt)) {
282 $hmac_secret_key = $hmac_secret_key_alt;
283 $firsterrormessage =
'';
286 if (empty($firsterrormessage)) {
287 $firsterrormessage = $e->getMessage();
291 if (empty($firsterrormessage)) {
292 $firsterrormessage = $e->getMessage();
296 if ($firsterrormessage) {
298 $this->error =
'modBlockLog init Error: '.$firsterrormessage.
'. ';
301 if (! preg_match(
'/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
303 $this->error .=
'modBlockedLog init Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY '.$hmac_encoded_secret_key.
' using the remote obfuscation key. The value was found in llx_const table but decoding with obfuscation key failed. May be the remote server to get the obfuscation key to decode it was offline.';
304 $this->error .=
' If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.';
349 $this->db->rollback();
364 $object->label =
'Module enabled';
367 $action =
'MODULE_SET';
368 $result = $b->setObjectData(
$object, $action, 0, $user, 0);
371 $this->error = $b->error;
372 $this->errors = $b->errors;
378 $res = $b->create($user);
380 $this->db->rollback();
382 $this->error = $b->error;
383 $this->errors = $b->errors;
387 $resinit = $this->
_init($sql, $options);
389 $this->db->rollback();
407 public function remove($options =
'')
414 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
417 dol_syslog(
"modBlockedLog::remove option=".$options, LOG_DEBUG);
425 $object->label =
'Module disabled';
428 $action =
'MODULE_RESET';
429 $result = $b->setObjectData(
$object, $action, 0, $user, 0);
431 $this->error = $b->error;
432 $this->errors = $b->errors;
436 if ($b->alreadyUsed(1)) {
438 if ($options !=
'forcedisable' && !$b->canBeDisabled()) {
441 $this->error = $langs->trans(
'DisablingBlockedLogIsNotallowedOnceUsedExceptOnFullreset', $langs->transnoentitiesnoconv(
'BlockedLog'));
445 $res = $b->create($user,
'0000000000');
448 $res = $b->create($user);
451 $this->error = $b->error;
452 $this->errors = $b->errors;
456 return $this->
_remove($sql, $options);
466 public function getDesc($foruseinpopupdesc = 0)
469 $langs->load(
"admin");
472 $s = $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
474 if ($foruseinpopupdesc) {
475 $langs->load(
"blockedlog");
479 if (
$mysoc->country_code ==
'FR') {
482 $versionbadge =
'<span class="badge-text badge-secondary">'.getBlockedLogVersionToShow();
489 $versionbadge .=
'</span>';
491 if (preg_match(
'/\-/', DOL_VERSION)) {
493 $s .=
info_admin($langs->trans(
"LNECandidateVersionForCertificationFR", $versionbadge), 0, 0,
'info');
495 $s .=
info_admin($langs->trans(
"LNECertifiedVersionFR", $versionbadge), 0, 0,
'info');
498 $s .=
info_admin($langs->trans(
"NotCertifiedVersionFR", $versionbadge), 0, 0,
'warning');
503 if (in_array(
$mysoc->country_code, array(
'FR'))) {
504 $s .=
info_admin($langs->trans(
"UnalterableLogTool1FR"), 0, 0,
'warning');
if(! $sortfield) if(! $sortorder) $object
isALNEQualifiedVersion($ignoredev=0, $ignoremodule=0)
Return if the version is a candidate version to get the LNE certification and if the prerequisites ar...
isBlockedLogUsed($ignoresystem=0)
Return if the blocked log was already used to block some events.
isALNERunningVersion($blockedlogtestalreadydone=0, $blockedlogmodulealreadydone=0)
Return if the application is executed with the LNE requirements on.
Class to manage Blocked Log.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Class to describe a BlockedLog module.
init($options='')
Function called when module is enabled.
alreadyUsed()
Check if module was already used before unactivation linked to warnings_unactivation property.
getDesc($foruseinpopupdesc=0)
Overwrite the common getDesc() method.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.