dolibarr 25.0.0-alpha
pingresult.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1'); // Disables token renewal
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38if (!defined('NOREQUIRESOC')) {
39 define('NOREQUIRESOC', '1');
40}
41if (!defined('NOREQUIRETRAN')) {
42 define('NOREQUIRETRAN', '1');
43}
44if (!defined('CSRFCHECK_WITH_TOKEN')) {
45 define('CSRFCHECK_WITH_TOKEN', '1'); // This page saves constants: the token is required even in GET mode (the js callers send it)
46}
47
48// Load Dolibarr environment
49require '../../main.inc.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
60$action = GETPOST('action', 'aZ09');
61
62// The hash of the instance unique id is computed here from the configuration, it is not taken from the request: the value saved
63// into MAIN_FIRST_PING_OK_ID / MAIN_FIRST_REGISTRATION_OK_ID is the identifier of this instance and must not be forgeable.
64$hash_unique_id = getHashUniqueIdOfRegistration('sha256');
65
66
67// Security check
68// Being connected is enough (the ping is sent by any user from the home page), the token is required (CSRFCHECK_WITH_TOKEN).
69
70
71/*
72 * Actions
73 */
74
75// None
76
77
78/*
79 * View
80 */
81
82$now = dol_now();
83
85
86print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
87
88// If ok
89if ($action == 'MAIN_FIRST_PING_OK_DATE') {
90 // Note: pings are per installed instances / entity.
91 // Once this constants are set, no more ping will be tried (except if we add parameter &forceping=1 on URL). So we can say this are 'first' ping.
92 dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity);
93 dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', $hash_unique_id.' - '.DOL_VERSION, 'chaine', 0, '', $conf->entity);
94
95 print 'First ping OK saved for entity '.$conf->entity;
96} elseif ($action == 'MAIN_LAST_PING_KO_DATE') {
97 // If ko
98 // Note: pings are by installation, done on entity 1.
99 dolibarr_set_const($db, 'MAIN_LAST_PING_KO_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity); // erase last value
100 print 'First ping KO saved for entity '.$conf->entity;
101} elseif ($action == 'MAIN_FIRST_REGISTRATION_OK_DATE') {
102 // Note: pings are per installed instances / entity.
103 // Once this constants are set, no more ping will be tried (except if we add parameter &forceping=1 on URL). So we can say this are 'first' ping.
104 dolibarr_set_const($db, 'MAIN_FIRST_REGISTRATION_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity);
105 dolibarr_set_const($db, 'MAIN_FIRST_REGISTRATION_OK_ID', $hash_unique_id.' - '.DOL_VERSION, 'chaine', 0, '', $conf->entity);
106
107 print 'First ping OK saved for entity '.$conf->entity;
108} elseif ($action == 'MAIN_LAST_REGISTRATION_KO_DATE') {
109 // If ko
110 // Note: pings are by installation, done on entity 1.
111 dolibarr_set_const($db, 'MAIN_LAST_REGISTRATION_KO_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity); // erase last value
112 print 'First ping KO saved for entity '.$conf->entity;
113} else {
114 print 'Error action='.$action.' not supported';
115}
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
getHashUniqueIdOfRegistration($algo='sha256')
Return a hash unique identifier of the registration (used to identify the registration of instance wi...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.