Ajout rapide de la detection des proxy

This commit is contained in:
Michael RICOIS 2015-04-08 08:57:49 +00:00
parent a6dd1294d0
commit a0981d0a66

View File

@ -6,22 +6,33 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
protected $_timeout = 1800;
protected $_checkIp = false;
protected $listProxyIp = array(
'62.210.222.34',
);
public function __construct($username, $password, $iponly = false)
{
$this->_username = $username;
$this->_password = $password;
if ($iponly){
$this->_password = 'iponly:'.$_SERVER['REMOTE_ADDR'];
$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 = $iponly;
}
public function authenticate()
{
$adressIp = $_SERVER['REMOTE_ADDR'];
$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($this->_username, $this->_password);
$InfosLogin = $ws->getInfosLogin($this->_username, $adressIp);
$InfosLogin = $ws->getInfosLogin($this->_username, $ip);
$identity = new stdClass();
$identity->username = $this->_username;
$identity->password = $this->_password;
@ -39,7 +50,7 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
$identity->dateDerniereConnexion = $InfosLogin->result->dateDerniereConnexion;
$identity->dateDebutCompte = $InfosLogin->result->dateDebutCompte;
$identity->dateFinCompte = $InfosLogin->result->dateFinCompte;
$identity->ip = $adressIp;
$identity->ip = $ip;
$identity->modeEdition = false;
$timeout = (!empty($InfosLogin->result->timeout)) ? $InfosLogin->result->timeout : $this->_timeout;
@ -68,7 +79,7 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
. ';' . '195.6.3.0-195.6.3.255' // ORT
. ';' . '217.144.112.0-217.144.116.63' // Coface
;
if ( $this->checkPlagesIp($ipInterdites, $adressIp) ) {
if ( $this->checkPlagesIp($ipInterdites, $ip) ) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, $identity);
}