pingresult.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* Copyright (C) 2019-2023 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/ajax/pingresult.php
  19. * \brief Page called after a ping was done in js to the official dolibarr ping service.
  20. * This ajax URL is called with parameter 'firstpingok' or 'firstpingko' depending on the result of the ping.
  21. * You can use &forceping=1 in parameters to force the ping if the ping was already sent.
  22. */
  23. if (!defined('NOTOKENRENEWAL')) {
  24. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  25. }
  26. if (!defined('NOREQUIREMENU')) {
  27. define('NOREQUIREMENU', '1');
  28. }
  29. if (!defined('NOREQUIREHTML')) {
  30. define('NOREQUIREHTML', '1');
  31. }
  32. if (!defined('NOREQUIREAJAX')) {
  33. define('NOREQUIREAJAX', '1');
  34. }
  35. if (!defined('NOREQUIRESOC')) {
  36. define('NOREQUIRESOC', '1');
  37. }
  38. if (!defined('NOREQUIRETRAN')) {
  39. define('NOREQUIRETRAN', '1');
  40. }
  41. // Load Dolibarr environment
  42. require '../../main.inc.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  44. $action = GETPOST('action', 'aZ09');
  45. $hash_unique_id = GETPOST('hash_unique_id', 'alpha');
  46. $hash_algo = GETPOST('hash_algo', 'alpha');
  47. // Security check
  48. // None. Beeing connected is enough.
  49. /*
  50. * View
  51. */
  52. $now = dol_now();
  53. top_httphead();
  54. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  55. // If ok
  56. if ($action == 'firstpingok') {
  57. // Note: pings are per installed instances / entity.
  58. // 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.
  59. dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity);
  60. dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', $hash_unique_id, 'chaine', 0, '', $conf->entity);
  61. print 'First ping OK saved for entity '.$conf->entity;
  62. } elseif ($action == 'firstpingko') {
  63. // If ko
  64. // Note: pings are by installation, done on entity 1.
  65. dolibarr_set_const($db, 'MAIN_LAST_PING_KO_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity); // erase last value
  66. print 'First ping KO saved for entity '.$conf->entity;
  67. } else {
  68. print 'Error action='.$action.' not supported';
  69. }