security.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 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 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. /*
  45. * View
  46. */
  47. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  48. top_httphead();
  49. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  50. // Return a new generated password
  51. if ($action) {
  52. if ($action == 'getrandompassword') {
  53. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  54. $generic = GETPOST('generic') ? true : false;
  55. echo getRandomPassword($generic);
  56. }
  57. }