2015-03-25 14:44:59 +00:00
|
|
|
<?php
|
|
|
|
class Scores_Auth_Adapter_Ws implements Zend_Auth_Adapter_Interface
|
|
|
|
{
|
|
|
|
/**
|
2016-04-08 11:51:04 +02:00
|
|
|
* Identifiant de l'utilisateur
|
2015-03-25 14:44:59 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_username;
|
|
|
|
|
|
|
|
/**
|
2016-04-08 11:51:04 +02:00
|
|
|
* Password
|
2015-03-25 14:44:59 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_password;
|
|
|
|
|
|
|
|
/**
|
2016-04-08 11:51:04 +02:00
|
|
|
* Timeout
|
|
|
|
* @var int
|
2015-03-25 14:44:59 +00:00
|
|
|
*/
|
|
|
|
protected $_timeout = 1800;
|
|
|
|
|
|
|
|
/**
|
2016-04-08 11:51:04 +02:00
|
|
|
* Marqueur de vérification IP (en iponly)
|
|
|
|
* @var boolean
|
2015-03-25 14:44:59 +00:00
|
|
|
*/
|
|
|
|
protected $_checkIp = false;
|
|
|
|
|
2016-04-08 11:51:04 +02:00
|
|
|
/**
|
|
|
|
* Marqueur de vérification de hach
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $_checkHach = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Liste des IPs des frontends (proxy)
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $listProxyIp = array(
|
|
|
|
'62.210.222.34',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentification par WS
|
|
|
|
* @param string $username
|
|
|
|
* @param string $password
|
|
|
|
* @param string $mode
|
|
|
|
*/
|
|
|
|
public function __construct($username, $password, $mode = null)
|
2015-03-25 14:44:59 +00:00
|
|
|
{
|
|
|
|
$this->_username = $username;
|
|
|
|
$this->_password = $password;
|
2016-04-08 11:51:04 +02:00
|
|
|
|
|
|
|
if ($mode == 'hach') {
|
|
|
|
$this->_checkHach = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($mode == 'iponly'){
|
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && in_array($ip, $this->listProxyIp)) {
|
|
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
}
|
|
|
|
$this->_password = 'iponly:'.$ip;
|
|
|
|
$this->_checkIp = true;
|
2015-03-25 14:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (non-PHPdoc)
|
|
|
|
* @see Zend_Auth_Adapter_Interface::authenticate()
|
|
|
|
*/
|
|
|
|
public function authenticate()
|
|
|
|
{
|
2016-04-08 11:51:04 +02:00
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && in_array($ip, $this->listProxyIp)) {
|
|
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.3');
|
|
|
|
$ws->setHttpLogin($this->_username);
|
|
|
|
$ws->setHttpPassword($this->_password);
|
2015-03-25 14:44:59 +00:00
|
|
|
$adressIp = $_SERVER['REMOTE_ADDR'];
|
2016-04-08 11:51:04 +02:00
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->login = $this->_username;
|
|
|
|
$parameters->ipUtilisateur = $ip;
|
|
|
|
$parameters->from = 'auth';
|
|
|
|
$InfosLogin = $ws->getInfosLogin($parameters);
|
2015-03-25 14:44:59 +00:00
|
|
|
|
2016-04-08 11:51:04 +02:00
|
|
|
// --- Renvoi
|
|
|
|
if ( is_string($InfosLogin) || $InfosLogin->error->errnum != 0 ) {
|
|
|
|
$message = $InfosLogin;
|
|
|
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity, array($message));
|
2015-03-25 14:44:59 +00:00
|
|
|
}
|
2016-04-08 11:51:04 +02:00
|
|
|
// --- Assignation identity
|
|
|
|
elseif ( $InfosLogin !== false && !empty($InfosLogin->result->login)) {
|
|
|
|
$identity = new stdClass();
|
|
|
|
if ($this->_checkIp || $this->_checkHach) {
|
|
|
|
Zend_Registry::get('firebug')->info("IN");
|
|
|
|
$identity->password = $this->_password;
|
|
|
|
} else {
|
|
|
|
$identity->password = md5($InfosLogin->result->login.'|'.$this->_password);
|
|
|
|
}
|
|
|
|
Zend_Registry::get('firebug')->info($identity->password);
|
|
|
|
$identity->username = $InfosLogin->result->login;
|
|
|
|
$identity->email = $InfosLogin->result->email;
|
|
|
|
$identity->profil = $InfosLogin->result->profil;
|
|
|
|
$identity->pref = $InfosLogin->result->pref;
|
|
|
|
$identity->droits = $InfosLogin->result->droits;
|
|
|
|
$identity->droitsClients = $InfosLogin->result->droitsClients;
|
|
|
|
$identity->nom = $InfosLogin->result->nom;
|
|
|
|
$identity->prenom = $InfosLogin->result->prenom;
|
|
|
|
$identity->tel = $InfosLogin->result->tel;
|
|
|
|
$identity->fax = $InfosLogin->result->fax;
|
|
|
|
$identity->mobile = $InfosLogin->result->mobile;
|
|
|
|
$identity->id = $InfosLogin->result->id;
|
|
|
|
$identity->idClient = $InfosLogin->result->idClient;
|
|
|
|
$identity->reference = $InfosLogin->result->reference;
|
|
|
|
$identity->nbReponses = $InfosLogin->result->nbReponses;
|
|
|
|
$identity->typeScore = $InfosLogin->result->typeScore;
|
|
|
|
$identity->dateValidation = $InfosLogin->result->dateValidation;
|
|
|
|
$identity->nombreConnexions = $InfosLogin->result->nombreConnexions;
|
|
|
|
$identity->dateDerniereConnexion = $InfosLogin->result->dateDerniereConnexion;
|
|
|
|
$identity->dateDebutCompte = $InfosLogin->result->dateDebutCompte;
|
|
|
|
$identity->dateFinCompte = $InfosLogin->result->dateFinCompte;
|
|
|
|
$identity->acceptationCGU = $InfosLogin->result->acceptationCGU;
|
|
|
|
$identity->ip = $ip;
|
|
|
|
$identity->version = $InfosLogin->result->version;
|
|
|
|
$identity->modeEdition = false;
|
|
|
|
|
|
|
|
$timeout = (!empty($InfosLogin->result->timeout)) ? $InfosLogin->result->timeout : $this->_timeout;
|
|
|
|
$identity->timeout = $timeout;
|
|
|
|
$identity->time = time() + $timeout;
|
|
|
|
$lang = in_array($InfosLogin->result->lang, array('fr','en')) ? $InfosLogin->result->lang : 'fr';
|
|
|
|
$identity->lang = $lang;
|
|
|
|
$identity->langtmp = $lang;
|
|
|
|
|
|
|
|
// --- Adresse Ip interdites
|
2016-07-19 10:37:46 +02:00
|
|
|
$ipInterdites = array(
|
|
|
|
'81.252.88.0-81.252.88.7', // CTE D AGGLOMERATION DE SOPHIA
|
|
|
|
'195.200.187.163', // PacWan
|
|
|
|
'213.11.81.41', // Verizon France SAS
|
|
|
|
'83.206.171.252', // FR-BASE-D-INFORMATIONS-LEGALES-BI
|
|
|
|
'81.255.32.139',
|
|
|
|
'212.155.191.100-212.155.191.199', // Satair A/S
|
|
|
|
'212.37.196.156', // GENERALE-MULTIMEDIA-SUD
|
|
|
|
'80.245.60.121', // Planete Marseille - Mailclub
|
|
|
|
'213.246.57.101', // IKOULA
|
|
|
|
'193.104.158.0-193.104.158.255', // Altares.fr
|
|
|
|
'195.6.3.0-195.6.3.255', // ORT
|
|
|
|
'217.144.112.0-217.144.116.63', // Coface
|
|
|
|
);
|
|
|
|
|
|
|
|
// --- Validation IP
|
|
|
|
$overallIpValidate = false;
|
|
|
|
foreach ( $ipInterdites as $filtre ) {
|
|
|
|
if ( strpos($filtre, '*') ) {
|
|
|
|
$filtre = str_replace('*', '0', $filtre) . '-' . str_replace('*', '255', $filtre);
|
|
|
|
}
|
|
|
|
// Is it a range ?
|
|
|
|
if ( strpos($filtre, '-') ) {
|
|
|
|
$validateIp = new Scores_Validate_IpInNetwork();
|
|
|
|
$validateIp->setNetworkNotation($filtre);
|
|
|
|
$overallIpValidate = $validateIp->isValid($ipToValidate);
|
|
|
|
}
|
|
|
|
// Ip only
|
|
|
|
else {
|
|
|
|
if ( $filtre === $ipToValidate ) {
|
|
|
|
$overallIpValidate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Break foreach
|
|
|
|
if ( $overallIpValidate === true ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit with error
|
|
|
|
if ( $overallIpValidate === false ) {
|
|
|
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, $identity);
|
|
|
|
}
|
2016-04-08 11:51:04 +02:00
|
|
|
|
|
|
|
// --- OK connecté
|
|
|
|
$this->_username = $identity->username;
|
|
|
|
$this->_password = $identity->password;
|
|
|
|
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
2015-03-25 14:44:59 +00:00
|
|
|
|
|
|
|
} else {
|
2016-04-08 11:51:04 +02:00
|
|
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, $identity, array("Identification impossible"));
|
2015-03-25 14:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|