Add option to disable the anonymous ping

This commit is contained in:
Laurent Destailleur 2019-08-23 16:23:31 +02:00
parent bc269462a7
commit 1463302bdd
6 changed files with 78 additions and 59 deletions

View File

@ -32,7 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$action=GETPOST('action', 'alpha');
$hash_unique_id=GETPOST('hash_unique_id', 'alpha');
$hash_algo=GETPOST('hash', 'alpha');
$hash_algo=GETPOST('hash_algo', 'alpha');
// Security check
@ -53,7 +53,7 @@ print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"])
// If ok
if ($action == 'firstpingok')
{
// Note: pings are by entities
// Note: pings are by installation, done on entity 1.
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'));
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', $hash_unique_id);
@ -62,7 +62,7 @@ if ($action == 'firstpingok')
// If ko
elseif ($action == 'firstpingko')
{
// Note: pings are by entities
// Note: pings are by installation, done on entity 1.
dolibarr_set_const($db, 'MAIN_LAST_PING_KO_DATE', dol_print_date($now, 'dayhourlog'), 'gmt');
print 'First ping KO saved for entity '.$conf->entity;
}

View File

@ -412,7 +412,9 @@ function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl
}
print '</span>'."\n";
print '<form name="forminstall" style="width: 100%" action="'.$next.'.php'.($param?'?'.$param:'').'" method="POST">'."\n";
print '<form name="forminstall" style="width: 100%" action="'.$next.'.php'.($param?'?'.$param:'').'" method="POST"';
if ($next == 'step5') print ' autocomplete="off"';
print '>'."\n";
print '<input type="hidden" name="testpost" value="ok">'."\n";
print '<input type="hidden" name="action" value="'.$action.'">'."\n";

View File

@ -632,6 +632,25 @@ dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("- step2: end");
$out = '<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno" value="checked" checked="true"> ';
$out .= $langs->trans("MakeAnonymousPing");
$out .= '<!-- Add js script to manage the uncheck of option to not send the ping -->';
$out .= '<script type="text/javascript">';
$out .= 'jQuery(document).ready(function(){';
$out .= ' document.cookie = "DOLINSTALLNOPING_'.md5($dolibarr_main_instance_unique_id).'=0; path=/"'."\n";
$out .= ' jQuery("#dolibarrpingno").click(function() {';
$out .= ' if (! $(this).is(\':checked\')) {';
$out .= ' console.log("We uncheck anonymous ping");';
$out .= ' document.cookie = "DOLINSTALLNOPING_'.md5($dolibarr_main_instance_unique_id).'=1; path=/"'."\n";
$out .= ' }';
$out .= ' });';
$out .= '});';
$out .= '</script>';
print $out;
pFooter($ok?0:1, $setuplang);
if (isset($db) && is_object($db)) $db->close();

View File

@ -80,7 +80,7 @@ $db=getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->
if ($db->ok)
{
print '<tr><td><label for="login">'.$langs->trans("Login").' :</label></td><td>';
print '<input id="login" name="login" type="text" value="' . (!empty($_GET["login"]) ? GETPOST("login") : (isset($force_install_dolibarrlogin) ? $force_install_dolibarrlogin : '')) . '"' . (@$force_install_noedit == 2 && $force_install_dolibarrlogin !== null ? ' disabled' : '') . '></td></tr>';
print '<input id="login" name="login" type="text" value="' . (!empty($_GET["login"]) ? GETPOST("login", 'alpha') : (isset($force_install_dolibarrlogin) ? $force_install_dolibarrlogin : '')) . '"' . (@$force_install_noedit == 2 && $force_install_dolibarrlogin !== null ? ' disabled' : '') . '></td></tr>';
print '<tr><td><label for="pass">'.$langs->trans("Password").' :</label></td><td>';
print '<input type="password" id="pass" name="pass" autocomplete="new-password"></td></tr>';
print '<tr><td><label for="pass_verif">'.$langs->trans("PasswordAgain").' :</label></td><td>';

View File

@ -1935,4 +1935,5 @@ AtLeastOneDefaultBankAccountMandatory=At least 1 default bank account must be de
RESTRICT_API_ON_IP=Allow available APIs to some host IP only (wildcard not allowed, use space between values). Empty means every hosts can use the available APIs.
RESTRICT_ON_IP=Allow access to some host IP only (wildcard not allowed, use space between values). Empty means every hosts can access.
BaseOnSabeDavVersion=Based on the library SabreDAV version
NotAPublicIp=Not a public IP
NotAPublicIp=Not a public IP
MakeAnonymousPing=Make an anonymous Ping '+1' to the Dolibarr foundation server (done 1 time only after installation) to allow the foundation to count the number of Dolibarr installation.

View File

@ -2205,7 +2205,7 @@ if (! function_exists("llxFooter"))
*/
function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
{
global $conf, $langs, $user, $object;
global $conf, $db, $langs, $user, $object;
global $delayedhtmlcontent;
global $contextpage, $page, $limit;
@ -2334,65 +2334,62 @@ if (! function_exists("llxFooter"))
// Add code for the asynchronous anonymous first ping (for telemetry)
if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || GETPOST('forceping', 'alpha'))
{
//print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->';
if (empty($conf->global->MAIN_FIRST_PING_OK_DATE)
|| (! empty($conf->file->instance_unique_id) && (md5($conf->file->instance_unique_id) != $conf->global->MAIN_FIRST_PING_OK_ID))
|| (! empty($conf->file->instance_unique_id) && (md5($conf->file->instance_unique_id) != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled'))
|| GETPOST('forceping', 'alpha'))
{
print "\n".'<!-- Includes JS for Ping of Dolibarr MAIN_FIRST_PING_OK_DATE = '.$conf->global->MAIN_FIRST_PING_OK_DATE.' MAIN_FIRST_PING_OK_ID = '.$conf->global->MAIN_FIRST_PING_OK_ID.' -->'."\n";
print "\n<!-- JS CODE TO ENABLE the anonymous Ontime Ping -->\n";
?>
<script>
jQuery(document).ready(function (tmp) {
$.ajax({
method: "POST",
url: "https://ping.dolibarr.org/",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo md5('dolibarr'.$conf->file->instance_unique_id); ?>", action: "dolibarrping", version: "<?php echo (float) DOL_VERSION; ?>", entity: <?php echo (int) $conf->entity; ?> },
success: function (data, status, xhr) { // success callback function (data contains body of response)
console.log("Ping ok");
$.ajax({
method: "GET",
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo md5($conf->file->instance_unique_id); ?>", action: "firstpingok" },
});
},
error: function (data,status,xhr) { // success callback function
console.log("Ping ko: " + data);
$.ajax({
method: "GET",
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo md5($conf->file->instance_unique_id); ?>", action: "firstpingko", version: "<?php echo (float) DOL_VERSION; ?>" },
});
}
});
});
</script>
<?php
if (empty($_COOKIE['DOLINSTALLNOPING_'.md5($conf->file->instance_unique_id)]))
{
print "\n".'<!-- Includes JS for Ping of Dolibarr MAIN_FIRST_PING_OK_DATE = '.$conf->global->MAIN_FIRST_PING_OK_DATE.' MAIN_FIRST_PING_OK_ID = '.$conf->global->MAIN_FIRST_PING_OK_ID.' -->'."\n";
print "\n<!-- JS CODE TO ENABLE the anonymous Ontime Ping -->\n";
$hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id);
?>
<script>
jQuery(document).ready(function (tmp) {
$.ajax({
method: "POST",
url: "https://ping.dolibarr.org/",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo $hash_unique_id; ?>", action: "dolibarrping", version: "<?php echo (float) DOL_VERSION; ?>", entity: <?php echo (int) $conf->entity; ?> },
success: function (data, status, xhr) { // success callback function (data contains body of response)
console.log("Ping ok");
$.ajax({
method: "GET",
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo $hash_unique_id; ?>", action: "firstpingok" },
});
},
error: function (data,status,xhr) { // success callback function
console.log("Ping ko: " + data);
$.ajax({
method: "GET",
url: "<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>",
timeout: 500, // timeout milliseconds
cache: false,
data: { hash_algo: "md5", hash_unique_id: "<?php echo $hash_unique_id; ?>", action: "firstpingko", version: "<?php echo (float) DOL_VERSION; ?>" },
});
}
});
});
</script>
<?php
}
else
{
$now = dol_now();
print "\n<!-- NO JS CODE TO ENABLE the anonymous One time Ping. It was disabled -->\n";
include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'));
dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', 'disabled');
}
}
}
print "</body>\n";
print "</html>\n";
?>
<!-- Disabled. This creates a lot of regression. A better solution is to add a protection on submitted page to avoid action to be done twice.
<script type="text/javascript">
//Prevent from multiple form sending
$(function() {
$('input[type=submit]').click(function(e) {
e.preventDefault();
$(this).prop('disabled', true);
$(this).closest('form').submit();
});
});
</script>
-->
<?php
}
}