Prepare obfuscation key
This commit is contained in:
parent
626c3cfe79
commit
40f571ebca
4 changed files with 121 additions and 31 deletions
|
|
@ -217,41 +217,43 @@ if (getDolGlobalString('BLOCKEDLOG_USE_REMOTE_AUTHORITY')) {
|
|||
|
||||
|
||||
// Show the input of countries not allowed for disabling
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>';
|
||||
print $form->textwithpicto($langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry"), $langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry2"));
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
if ($mysoc->country_code != 'FR' || !isALNERunningVersion()) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>';
|
||||
print $form->textwithpicto($langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry"), $langs->transnoentitiesnoconv("BlockedLogDisableNotAllowedForCountry2"));
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="set_BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY">';
|
||||
print '<input type="hidden" name="withtab" value="'.$withtab.'">';
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="set_BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY">';
|
||||
print '<input type="hidden" name="withtab" value="'.$withtab.'">';
|
||||
|
||||
$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 '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"'.($canbedisabled ? '' : ' disabled').'>';
|
||||
print '</form>';
|
||||
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
$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 '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"'.($canbedisabled ? '' : ' disabled').'>';
|
||||
print '</form>';
|
||||
|
||||
print '</td>';
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="">';
|
||||
print $langs->trans("ListOfTrackedEvents").'</td><td>';
|
||||
|
|
@ -290,11 +292,26 @@ print ajax_autoselect('forceregistration');
|
|||
|
||||
print '<br>';
|
||||
|
||||
/*
|
||||
$urlforcepushcounter = DOL_MAIN_URL_ROOT.'/index.php?forcepushcounter=1';
|
||||
print $langs->trans("URLToForcePushOfBlockedLogCounter").'<br>';
|
||||
print '<div class="urllink"><input type="text" id="forcepushcounter" spellcheck="false" class="quatrevingtpercentminusx" value="'.$urlforcepushcounter.'"><a class="" href="'.$urlforcepushcounter.'" target="_blank" rel="noopener noreferrer"><span class="fas fa-external-link-alt paddingleft" style=""></span></a></div>';
|
||||
print ajax_autoselect('forcepushcounter');
|
||||
*/
|
||||
|
||||
$urltogetkeyobfuscation = DOL_MAIN_URL_ROOT.'/blockedlog/admin/blockedlog.php?forcegetkeyobfuscation=1&token='.newToken();
|
||||
print $langs->trans("URLToGetObfuscationkey").'<br>';
|
||||
print '<div class="urllink"><input type="text" id="forcegetkeyobfuscation" spellcheck="false" class="quatrevingtpercentminusx" value="'.$urltogetkeyobfuscation.'"><a class="" href="'.$urltogetkeyobfuscation.'" target="_blank" rel="noopener noreferrer"><span class="fas fa-external-link-alt paddingleft" style=""></span></a></div>';
|
||||
print ajax_autoselect('forcegetkeyobfuscation');
|
||||
|
||||
if (GETPOST('forcegetkeyobfuscation')) {
|
||||
$resultcall = callApiToGetObfuscationKey($mysoc->idprof1, $registrationnumber, true);
|
||||
if (preg_match('/^ERROR/', $resultcall)) {
|
||||
print '<div class="error">'.$resultcall.'</div>';
|
||||
} else {
|
||||
print "\n<!-- API TO GET OBFUSCATION KEY RETURNED result: ".$resultcall." -->\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($withtab) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue