27include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
28include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
29include_once DOL_DOCUMENT_ROOT.
'/blockedlog/versionmod.inc.php';
49 $this->rights_class =
'blockedlog';
53 $this->family =
"base";
55 $this->module_position =
'76';
57 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
58 $this->
description =
"Enable a log on some business events into an unalterable log. This module may be mandatory for some countries.";
61 $this->version = constant(
'DOLCERT_VERSION');
62 $this->version_if_core = 1;
64 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
66 $this->picto =
'blockedlog';
69 $this->dirs = array();
73 $this->config_page_url = array(
'registration.php?origin=setupmodule&withtab=1@blockedlog');
77 $this->hidden =
false;
78 $this->depends = array(
'always' =>
'modFacture');
79 $this->requiredby = array();
80 $this->conflictwith = array();
81 $this->langfiles = array(
'blockedlog');
83 $this->warnings_activation = array();
84 $this->warnings_activation_ext = array();
85 $this->warnings_unactivation = array(
'FR' =>
'BlockedLogAreRequiredByYourCountryLegislation');
101 && in_array((empty(
$mysoc->country_code) ?
'' :
$mysoc->country_code), explode(
',',
getDolGlobalString(
'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')))
106 $this->
const = array(
107 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)
112 $this->tabs = array();
116 $this->boxes = array();
120 $this->rights = array();
123 $this->rights[$r][0] = $this->numero + $r;
124 $this->rights[$r][1] =
'Read archived events and fingerprints';
125 $this->rights[$r][3] = 0;
126 $this->rights[$r][4] =
'read';
127 $this->rights[$r][5] =
'';
132 $this->menu[$r] = array(
133 'fk_menu' =>
'fk_mainmenu=tools',
134 'mainmenu' =>
'tools',
135 'leftmenu' =>
'blockedlogbrowser',
137 'titre' =>
'BrowseBlockedLog',
138 'prefix' =>
img_picto(
'', $this->picto,
'class="paddingright pictofixedwidth"'),
139 'url' =>
'/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser',
140 'langs' =>
'blockedlog',
142 'enabled' =>
'isModEnabled("blockedlog")',
143 'perms' =>
'$user->hasRight("blockedlog", "read")',
158 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
172 public function init($options =
'')
179 if (version_compare(PHP_VERSION,
'7.0.0') < 0) {
180 $errmsg =
'Error: You are using a too low version of PHP';
182 $this->error = $errmsg;
187 unset($_SESSION[
'obfuscationkey_'.((
int)
$conf->entity)]);
188 unset(
$conf->cache[
'obfuscationkey_'.((int)
$conf->entity)]);
190 require_once DOL_DOCUMENT_ROOT .
'/blockedlog/class/blockedlog.class.php';
196 header(
"Location: ".DOL_URL_ROOT.
'/blockedlog/admin/registration.php?origin=initmodule&withtab=0');
201 if (empty(
$mysoc->country_code)) {
202 $errmsg =
'Error: The context of the running company is not defined';
204 $this->error = $errmsg;
209 $s = $b->canBeEnabled();
222 $hmac_encoded_secret_key = $b->getEncodedHMACSecretKey();
224 if (empty($hmac_encoded_secret_key)) {
226 $randomsecret = bin2hex(random_bytes(32));
228 $hmac_secret_key =
'BLOCKEDLOGHMAC'.$randomsecret;
231 $obfuscationkey =
'';
234 $obfuscationkey = $b->getObfuscationKey();
239 $obfuscationkey =
'';
242 if (empty($obfuscationkey)) {
244 $url_for_ping =
getDolGlobalString(
'MAIN_URL_FOR_PING',
"https://ping.dolibarr.org/");
245 setEventMessages($langs->trans(
'FailedToGetRemoteObfuscationKeyReTryLater', $url_for_ping),
null,
'errors');
251 $result = $b->saveHMACSecretKey($hmac_secret_key,
'dolobfuscationv1-'.
$mysoc->idprof1, $obfuscationkey);
258 $result = $b->saveHMACSecretKey($hmac_secret_key,
'dolcrypt');
270 $hmac_secret_key =
'';
272 $hmac_secret_key = $b->getClearHMACSecretKey($hmac_encoded_secret_key);
274 $firsterrormessage = $e->getMessage();
277 $hmac_encoded_secret_key_alt = $b->getEncodedHMACSecretKey(1, 1);
278 if (!empty($hmac_encoded_secret_key_alt)) {
280 $hmac_secret_key_alt = $b->getClearHMACSecretKey($hmac_encoded_secret_key_alt);
282 if (preg_match(
'/^BLOCKEDLOGHMAC/', (
string) $hmac_secret_key_alt)) {
283 $hmac_secret_key = $hmac_secret_key_alt;
284 $firsterrormessage =
'';
287 if (empty($firsterrormessage)) {
288 $firsterrormessage = $e->getMessage();
292 if (empty($firsterrormessage)) {
293 $firsterrormessage = $e->getMessage();
297 if ($firsterrormessage) {
299 $this->error =
'modBlockLog init Error: '.$firsterrormessage.
'. ';
302 if (! preg_match(
'/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
304 $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.';
305 $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.';
350 $this->db->rollback();
365 $object->label =
'Module enabled';
368 $action =
'MODULE_SET';
369 $result = $b->setObjectData(
$object, $action, 0, $user, 0);
372 $this->error = $b->error;
373 $this->errors = $b->errors;
379 $res = $b->create($user);
381 $this->db->rollback();
383 $this->error = $b->error;
384 $this->errors = $b->errors;
388 $resinit = $this->
_init($sql, $options);
390 $this->db->rollback();
408 public function remove($options =
'')
415 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
418 dol_syslog(
"modBlockedLog::remove option=".$options, LOG_DEBUG);
426 $object->label =
'Module disabled';
429 $action =
'MODULE_RESET';
430 $result = $b->setObjectData(
$object, $action, 0, $user, 0);
432 $this->error = $b->error;
433 $this->errors = $b->errors;
437 if ($b->alreadyUsed(1)) {
439 if ($options !=
'forcedisable' && !$b->canBeDisabled()) {
442 $this->error = $langs->trans(
'DisablingBlockedLogIsNotallowedOnceUsedExceptOnFullreset', $langs->transnoentitiesnoconv(
'BlockedLog'));
446 $res = $b->create($user,
'0000000000');
449 $res = $b->create($user);
452 $this->error = $b->error;
453 $this->errors = $b->errors;
457 return $this->
_remove($sql, $options);
467 public function getDesc($foruseinpopupdesc = 0)
470 $langs->load(
"admin");
473 $s = $langs->transnoentitiesnoconv(
"Module".$this->numero.
"Desc");
475 if ($foruseinpopupdesc) {
476 $langs->load(
"blockedlog");
480 if (
$mysoc->country_code ==
'FR') {
483 $versionbadge =
'<span class="badge-text badge-secondary">'.getBlockedLogVersionToShow();
490 $versionbadge .=
'</span>';
492 if (preg_match(
'/\-/', DOL_VERSION)) {
494 $s .=
info_admin($langs->trans(
"LNECandidateVersionForCertificationFR", $versionbadge), 0, 0,
'info');
496 $s .=
info_admin($langs->trans(
"LNECertifiedVersionFR", $versionbadge), 0, 0,
'info');
499 $s .=
info_admin($langs->trans(
"NotCertifiedVersionFR", $versionbadge), 0, 0,
'warning');
504 if (in_array(
$mysoc->country_code, array(
'FR'))) {
505 $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)
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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.