2011-07-09 10:05:08 +02:00
|
|
|
<?php
|
2018-10-27 14:43:12 +02:00
|
|
|
/* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com>
|
2024-11-04 23:53:20 +01:00
|
|
|
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
2011-07-09 10:05:08 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2011-07-09 10:05:08 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2011-07-09 10:05:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-25 19:03:12 +02:00
|
|
|
* \file htdocs/core/ajax/security.php
|
2023-03-27 11:52:56 +02:00
|
|
|
* \brief This ajax component is used to generated hash keys for security purposes,
|
|
|
|
|
* like the key to use into URL to protect them.
|
2011-07-09 10:05:08 +02:00
|
|
|
*/
|
|
|
|
|
|
2021-02-23 22:03:23 +01:00
|
|
|
if (!defined('NOTOKENRENEWAL')) {
|
|
|
|
|
define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREMENU')) {
|
|
|
|
|
define('NOREQUIREMENU', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREHTML')) {
|
|
|
|
|
define('NOREQUIREHTML', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREAJAX')) {
|
|
|
|
|
define('NOREQUIREAJAX', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIRESOC')) {
|
|
|
|
|
define('NOREQUIRESOC', '1');
|
|
|
|
|
}
|
2023-03-13 15:57:36 +01:00
|
|
|
// We need langs because the getRandomPassword may use the user language to define some rules of pass generation
|
2023-01-17 11:47:16 +01:00
|
|
|
/*if (!defined('NOREQUIRETRAN')) {
|
2021-02-23 22:03:23 +01:00
|
|
|
define('NOREQUIRETRAN', '1');
|
2023-01-17 11:47:16 +01:00
|
|
|
}*/
|
2011-07-09 10:05:08 +02:00
|
|
|
|
2024-09-03 15:10:13 +02:00
|
|
|
// Load Dolibarr environment and check user is logged.
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../../main.inc.php';
|
2024-11-04 23:53:20 +01:00
|
|
|
/**
|
|
|
|
|
* @var Conf $conf
|
|
|
|
|
* @var DoliDB $db
|
|
|
|
|
* @var HookManager $hookmanager
|
|
|
|
|
* @var Translate $langs
|
|
|
|
|
* @var User $user
|
|
|
|
|
*/
|
2011-07-09 10:05:08 +02:00
|
|
|
|
2022-07-27 13:42:32 +02:00
|
|
|
$action = GETPOST('action');
|
|
|
|
|
|
2023-03-27 11:52:56 +02:00
|
|
|
// Security check
|
2023-04-24 13:20:23 +02:00
|
|
|
// None. This is public component with no access and effect on data.
|
2023-03-27 11:52:56 +02:00
|
|
|
|
2022-07-27 13:42:32 +02:00
|
|
|
|
2024-09-03 15:10:13 +02:00
|
|
|
/*
|
|
|
|
|
* Action
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// None
|
|
|
|
|
|
|
|
|
|
|
2011-07-09 10:05:08 +02:00
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
top_httphead();
|
|
|
|
|
|
2017-06-18 19:42:59 +02:00
|
|
|
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
|
2011-07-09 10:05:08 +02:00
|
|
|
|
2023-01-17 11:47:16 +01:00
|
|
|
// Return a new generated password
|
2022-07-27 13:42:32 +02:00
|
|
|
if ($action) {
|
2024-09-03 15:10:13 +02:00
|
|
|
if ($action == 'getrandompassword') { // Test on permission not required here. Endpoint can be called by anu logged user.
|
2020-03-23 15:54:02 +01:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
2022-07-27 13:42:32 +02:00
|
|
|
$generic = GETPOST('generic') ? true : false;
|
2011-07-09 10:05:08 +02:00
|
|
|
echo getRandomPassword($generic);
|
|
|
|
|
}
|
2023-04-24 13:20:23 +02:00
|
|
|
} else {
|
|
|
|
|
if (GETPOST('errorcode') == 'InvalidToken') {
|
|
|
|
|
http_response_code(401);
|
|
|
|
|
}
|
2011-07-09 10:05:08 +02:00
|
|
|
}
|