security.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. if (!defined('NOREQUIRETRAN')) {
  38. define('NOREQUIRETRAN', '1');
  39. }
  40. require '../../main.inc.php';
  41. /*
  42. * View
  43. */
  44. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  45. top_httphead();
  46. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  47. // Registering the location of boxes
  48. if (isset($_GET['action']) && !empty($_GET['action'])) {
  49. if ($_GET['action'] == 'getrandompassword' && ($user->admin || $user->rights->api->apikey->generate)) {
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  51. $generic = $_GET['generic'] ? true : false;
  52. echo getRandomPassword($generic);
  53. }
  54. }