diff --git a/htdocs/blockedlog/admin/blockedlog.php b/htdocs/blockedlog/admin/blockedlog.php index 8f381560e98..c0dd86fda70 100644 --- a/htdocs/blockedlog/admin/blockedlog.php +++ b/htdocs/blockedlog/admin/blockedlog.php @@ -217,41 +217,43 @@ if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) { // Show the input of countries not allowed for disabling -print ''; -print ''; -print $form->textwithpicto($langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry"), $langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry2")); -print ''; -print ''; +if ($mysoc->country_code != 'FR' || !isALNERunningVersion()) { + print ''; + print ''; + print $form->textwithpicto($langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry"), $langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry2")); + print ''; + print ''; -print '
'; -print ''; -print ''; -print ''; + print ''; + print ''; + print ''; + print ''; -$sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; -$sql .= " FROM ".MAIN_DB_PREFIX."c_country"; -$sql .= " WHERE active > 0"; + $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; + $sql .= " WHERE active > 0"; -$countryArray = array(); -$resql = $db->query($sql); -if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $countryArray[$obj->code_iso] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); + $countryArray = array(); + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $countryArray[$obj->code_iso] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); + } } + + $selected = !getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY') ? array() : explode(',', getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')); + + // Can module be disabled + $canbedisabled = $block_static->canBeDisabled(); + + print $form->multiselectarray('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', $countryArray, $selected, 0, 0, '', 0, 0, $canbedisabled ? '' : 'disabled'); + print ''; + print '
'; + + print ''; + print ''; } -$selected = !getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY') ? array() : explode(',', getDolGlobalString('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY')); - -// Can module be disabled -$canbedisabled = $block_static->canBeDisabled(); - -print $form->multiselectarray('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', $countryArray, $selected, 0, 0, '', 0, 0, $canbedisabled ? '' : 'disabled'); -print ''; -print ''; - -print ''; - - print ''; print ''; print $langs->trans("ListOfTrackedEvents").''; @@ -290,11 +292,26 @@ print ajax_autoselect('forceregistration'); print '
'; +/* $urlforcepushcounter = DOL_MAIN_URL_ROOT.'/index.php?forcepushcounter=1'; print $langs->trans("URLToForcePushOfBlockedLogCounter").'
'; print ''; print ajax_autoselect('forcepushcounter'); +*/ +$urltogetkeyobfuscation = DOL_MAIN_URL_ROOT.'/blockedlog/admin/blockedlog.php?forcegetkeyobfuscation=1&token='.newToken(); +print $langs->trans("URLToGetObfuscationkey").'
'; +print ''; +print ajax_autoselect('forcegetkeyobfuscation'); + +if (GETPOST('forcegetkeyobfuscation')) { + $resultcall = callApiToGetObfuscationKey($mysoc->idprof1, $registrationnumber, true); + if (preg_match('/^ERROR/', $resultcall)) { + print '
'.$resultcall.'
'; + } else { + print "\n\n"; + } +} if ($withtab) { diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index a5bb9e76f3e..a86e2a5cbf4 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -1419,11 +1419,12 @@ class BlockedLog // The new ID $this->id = $id; - $error = 0; - $this->db->commit(); // Call remote API service to record the last counter + /* + $error = 0; + include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php'; try { $resultcall = callApiToPushCounter((int) $this->id, $this->signature, $this->date_creation, 0, (int) $previousid, $previoushash, $previousdatecreation); @@ -1437,6 +1438,8 @@ class BlockedLog } else { return -3; } + */ + return $this->id; } else { $this->db->rollback(); return -2; diff --git a/htdocs/blockedlog/lib/blockedlog.lib.php b/htdocs/blockedlog/lib/blockedlog.lib.php index dc87384543f..0d6ef209e02 100644 --- a/htdocs/blockedlog/lib/blockedlog.lib.php +++ b/htdocs/blockedlog/lib/blockedlog.lib.php @@ -391,6 +391,73 @@ function sumAmountsForUnalterableEvent($block, &$refinvoicefound, &$totalhtamoun } +/** + * Call remote API service to push the last counter and signature + * + * @param string $idprof1 Counter ID/value of ne record + * @param string $registrationnumber Registration number + * @param string $force False. Use true for tests. + * @return string Obfuscationkey + */ +function callApiToGetObfuscationKey($idprof1, $registrationnumber, $force = false) +{ + global $mysoc, $conf; + + $obfuscationkey = 'ERROR'; + + if ((isALNERunningVersion(1) || $force) && $mysoc->country_code == 'FR') { + $url_for_ping = getDolGlobalString('MAIN_URL_FOR_PING', "https://ping.dolibarr.org/"); + + $algo = 'sha256'; + $hash_unique_id = getHashUniqueIdOfRegistration($algo); // The hash of the unique IDof instance + + $t = microtime(true); + $micro = sprintf("%06d", (int) (($t - floor($t)) * 1000000)); + + $data = ''; + $data .= 'hash_algo=dol_hash-'.urlencode($algo); + $data .= '&hash_unique_id='.urlencode($hash_unique_id); + $data .= '&action=dolibarrgetkeyobfuscation'; + $data .= '&datesys='.urlencode(dol_print_date(dol_now('gmt'), 'standard', 'gmt').'.'.$micro); + $data .= '&version='.(float) DOL_VERSION; + $data .= '&version_full='.urlencode(DOL_VERSION); + $data .= '&versionblockedlog='.(float) getBlockedLogVersionToShow(); + $data .= '&versionblockedlog_full='.urlencode(getBlockedLogVersionToShow()); + + $data .= '&entity='.(int) $conf->entity; + + $data .= '&profid1='.(int) $idprof1; + $data .= '®istrationnumber='.urlencode($registrationnumber); + + $addheaders = array(); + $timeoutconnect = 1; + $timeoutresponse = 1; + + dol_syslog("callApiToGetObfuscationKey call remote URL", LOG_DEBUG); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + try { + $tmpresult = getURLContent($url_for_ping, 'POST', $data, 1, $addheaders, array('https'), 0, -1, $timeoutconnect, $timeoutresponse, array(), '_dolibarrgetkeyobfuscation'); + usleep(1000); + + // Add a warning in log in case of error + if ($tmpresult['http_code'] != 200) { + $logerrormessage = 'Error: '.$tmpresult['http_code'].' '.$tmpresult['content']; + $obfuscationkey .= ' '.$tmpresult['http_code'].' '.$tmpresult['content']; + dol_syslog("callApiToGetObfuscationKey result error when getting obfuscation key: ".$logerrormessage, LOG_WARNING); + } else { + $obfuscationkey = $tmpresult['content']; + } + } catch (Exception $e) { + $obfuscationkey .= ' '.$e->getMessage(); + dol_syslog("callApiToGetObfuscationKey result error ".$e->getMessage(), LOG_ERR); + } + } + + return $obfuscationkey; +} + + /** * Call remote API service to push the last counter and signature * diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index d30076b75e4..681a6812b23 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -4079,6 +4079,7 @@ if (!function_exists("llxFooter")) { // Add code for the asynchronous emulation of pushing a tracking counter of the use of the BlockedLog module trigger(for test purposes) // You can use &forceregistration=1 in parameters to force also the recall if the call was already sent. + /* $forcepushcounter = GETPOSTINT('forcepushcounter'); if (isModEnabled('blockedlog') && ($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') && $forcepushcounter) { @@ -4111,6 +4112,8 @@ if (!function_exists("llxFooter")) { } } } + */ + $parameters = array();