2008-09-30 01:18:52 +02:00
|
|
|
<?php
|
2011-08-08 17:45:04 +02:00
|
|
|
/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
|
|
|
|
|
* Copyright (C) 2008-2011 Laurent Destailleur <eldy@uers.sourceforge.net>
|
2009-05-22 00:55:53 +02:00
|
|
|
*
|
2008-09-30 01:18:52 +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
|
2008-09-30 01:18:52 +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/>.
|
2008-09-30 01:18:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2011-08-08 17:45:04 +02:00
|
|
|
/**
|
|
|
|
|
* Class ot manage authentication for pos module (cashdesk)
|
|
|
|
|
*/
|
2011-09-20 17:51:28 +02:00
|
|
|
class Auth
|
|
|
|
|
{
|
2017-02-09 00:24:20 +01:00
|
|
|
protected $db;
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2017-02-08 21:36:04 +01:00
|
|
|
private $login;
|
|
|
|
|
private $passwd;
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2017-02-08 21:36:04 +01:00
|
|
|
private $reponse;
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2017-02-08 21:36:04 +01:00
|
|
|
public $sqlQuery;
|
2011-09-23 13:46:16 +02:00
|
|
|
|
2011-09-20 17:51:28 +02:00
|
|
|
/**
|
|
|
|
|
* Enter description here ...
|
2011-09-23 13:46:16 +02:00
|
|
|
*
|
2012-07-30 17:17:33 +02:00
|
|
|
* @param DoliDB $db Database handler
|
2011-10-13 20:32:03 +02:00
|
|
|
* @return void
|
2011-09-20 17:51:28 +02:00
|
|
|
*/
|
2017-02-08 21:36:04 +01:00
|
|
|
public function __construct($db)
|
2011-09-20 17:51:28 +02:00
|
|
|
{
|
2012-07-30 17:17:33 +02:00
|
|
|
$this->db = $db;
|
2011-09-20 11:40:27 +02:00
|
|
|
$this->reponse(null);
|
2010-07-21 13:21:37 +02:00
|
|
|
}
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2011-09-20 17:51:28 +02:00
|
|
|
/**
|
|
|
|
|
* Enter description here ...
|
2011-09-23 13:46:16 +02:00
|
|
|
*
|
2011-10-13 20:32:03 +02:00
|
|
|
* @param string $aLogin Login
|
|
|
|
|
* @return void
|
2011-09-20 17:51:28 +02:00
|
|
|
*/
|
2017-02-08 21:36:04 +01:00
|
|
|
public function login($aLogin)
|
2011-09-20 17:51:28 +02:00
|
|
|
{
|
2010-07-21 13:21:37 +02:00
|
|
|
$this->login = $aLogin;
|
|
|
|
|
}
|
2011-09-23 13:46:16 +02:00
|
|
|
|
2011-09-20 17:51:28 +02:00
|
|
|
/**
|
|
|
|
|
* Enter description here ...
|
2011-09-23 13:46:16 +02:00
|
|
|
*
|
2011-10-13 20:32:03 +02:00
|
|
|
* @param string $aPasswd Password
|
|
|
|
|
* @return void
|
2011-09-20 17:51:28 +02:00
|
|
|
*/
|
2019-03-02 00:14:22 +01:00
|
|
|
public function passwd($aPasswd)
|
2011-09-20 17:51:28 +02:00
|
|
|
{
|
2010-07-21 13:21:37 +02:00
|
|
|
$this->passwd = $aPasswd;
|
|
|
|
|
}
|
2011-09-23 13:46:16 +02:00
|
|
|
|
2011-09-20 17:51:28 +02:00
|
|
|
/**
|
|
|
|
|
* Enter description here ...
|
2011-09-23 13:46:16 +02:00
|
|
|
*
|
2011-10-13 20:32:03 +02:00
|
|
|
* @param string $aReponse Response
|
|
|
|
|
* @return void
|
2011-09-20 17:51:28 +02:00
|
|
|
*/
|
2017-02-08 21:36:04 +01:00
|
|
|
public function reponse($aReponse)
|
2011-09-20 17:51:28 +02:00
|
|
|
{
|
2010-07-21 13:21:37 +02:00
|
|
|
$this->reponse = $aReponse;
|
|
|
|
|
}
|
2009-05-22 00:55:53 +02:00
|
|
|
|
2011-09-20 17:51:28 +02:00
|
|
|
/**
|
2011-09-23 13:46:16 +02:00
|
|
|
* Validate login/pass
|
|
|
|
|
*
|
|
|
|
|
* @param string $aLogin Login
|
|
|
|
|
* @param string $aPasswd Password
|
2011-10-13 20:32:03 +02:00
|
|
|
* @return int 0 or 1
|
2011-09-20 17:51:28 +02:00
|
|
|
*/
|
2017-02-08 21:36:04 +01:00
|
|
|
public function verif($aLogin, $aPasswd)
|
2011-05-30 15:45:51 +02:00
|
|
|
{
|
2020-04-10 10:59:32 +02:00
|
|
|
global $conf, $langs;
|
|
|
|
|
global $dolibarr_main_authentication, $dolibarr_auto_user;
|
2011-05-30 15:45:51 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$ret = -1;
|
2011-05-30 15:45:51 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$login = '';
|
2011-05-30 15:45:51 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$test = true;
|
2011-09-23 13:46:16 +02:00
|
|
|
|
2011-05-30 15:45:51 +02:00
|
|
|
// Authentication mode
|
2020-04-10 10:59:32 +02:00
|
|
|
if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication = 'http,dolibarr';
|
2011-05-30 15:45:51 +02:00
|
|
|
// Authentication mode: forceuser
|
2020-04-10 10:59:32 +02:00
|
|
|
if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user = 'auto';
|
2011-05-30 15:45:51 +02:00
|
|
|
// Set authmode
|
2020-04-10 10:59:32 +02:00
|
|
|
$authmode = explode(',', $dolibarr_main_authentication);
|
2011-05-30 15:45:51 +02:00
|
|
|
|
|
|
|
|
// No authentication mode
|
2020-04-10 10:59:32 +02:00
|
|
|
if (!count($authmode))
|
2011-05-30 15:45:51 +02:00
|
|
|
{
|
|
|
|
|
$langs->load('main');
|
2019-01-27 11:55:16 +01:00
|
|
|
dol_print_error('', $langs->trans("ErrorConfigParameterNotDefined", 'dolibarr_main_authentication'));
|
2011-05-30 15:45:51 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$usertotest = $aLogin;
|
|
|
|
|
$passwordtotest = $aPasswd;
|
|
|
|
|
$entitytotest = $conf->entity;
|
2011-05-30 15:45:51 +02:00
|
|
|
|
|
|
|
|
// Validation tests user / password
|
|
|
|
|
// If ok, the variable will be initialized login
|
|
|
|
|
// If error, we will put error message in session under the name dol_loginmesg
|
2020-04-10 10:59:32 +02:00
|
|
|
$goontestloop = false;
|
|
|
|
|
if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) $goontestloop = true;
|
|
|
|
|
if (isset($aLogin) || GETPOST('openid_mode', 'alpha', 1)) $goontestloop = true;
|
2011-05-30 15:45:51 +02:00
|
|
|
|
|
|
|
|
if ($test && $goontestloop)
|
|
|
|
|
{
|
2012-08-23 02:04:35 +02:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
2019-01-27 11:55:16 +01:00
|
|
|
$login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode);
|
2011-09-23 13:46:16 +02:00
|
|
|
if ($login)
|
|
|
|
|
{
|
|
|
|
|
$this->login($aLogin);
|
|
|
|
|
$this->passwd($aPasswd);
|
2020-04-10 10:59:32 +02:00
|
|
|
$ret = 0;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$ret = -1;
|
2011-05-30 15:45:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2010-07-21 13:21:37 +02:00
|
|
|
return $ret;
|
2008-09-30 01:18:52 +02:00
|
|
|
}
|
2010-07-21 13:21:37 +02:00
|
|
|
}
|