security.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com>
  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/security.php
  19. * \brief This ajax component is used to generated hash keys for security purposes,
  20. * like the key to use into URL to protect them.
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. }
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1');
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1');
  30. }
  31. if (!defined('NOREQUIREAJAX')) {
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. if (!defined('NOREQUIRESOC')) {
  35. define('NOREQUIRESOC', '1');
  36. }
  37. // We need langs because the getRandomPassword may use the user language to define some rules of pass generation
  38. /*if (!defined('NOREQUIRETRAN')) {
  39. define('NOREQUIRETRAN', '1');
  40. }*/
  41. // Load Dolibarr environment
  42. require '../../main.inc.php';
  43. $action = GETPOST('action');
  44. // Security check
  45. // None. This is public component with no access and effect on data.
  46. /*
  47. * View
  48. */
  49. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  50. top_httphead();
  51. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  52. // Return a new generated password
  53. if ($action) {
  54. if ($action == 'getrandompassword') {
  55. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  56. $generic = GETPOST('generic') ? true : false;
  57. echo getRandomPassword($generic);
  58. }
  59. } else {
  60. if (GETPOST('errorcode') == 'InvalidToken') {
  61. http_response_code(401);
  62. }
  63. }