Amélioration journalisation

This commit is contained in:
fredtempez 2021-01-03 18:41:25 +01:00
parent 03b9ee2094
commit aa2bfa5ddb
1 changed files with 107 additions and 115 deletions

View File

@ -333,6 +333,7 @@ class user extends common {
*/
public function login() {
// Soumission du formulaire
$logStatus = '';
if($this->isPost()) {
// Lire Id du compte
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
@ -341,29 +342,15 @@ class user extends common {
$this->getData(['config','connect','captcha'])
AND password_verify($this->getInput('userLoginCaptcha', helper::FILTER_INT), $this->getInput('userLoginCaptchaResult') ) === false )
{
//self::$inputNotices['userLoginCaptcha'] = 'Incorrect';
$notification = 'Captcha incorrect !';
// Cas 1 le nombre de connexions est inférieur aux tentatives autorisées : incrément compteur d'échec
if ($this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) {
$this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]);
}
// Cas 2 la limite du nombre de connexion est atteinte : placer le timer
if ( $this->getdata(['user',$userId,'connectFail']) == $this->getData(['config', 'connect', 'attempt']) ) {
$this->setData(['user',$userId,'connectTimeout', time()]);
}
// Cas 3 le délai de bloquage court
if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time() ) {
$notification = 'Accès bloqué ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
}
// Valeurs en sortie
$this->addOutput([
'notification' => $notification
]);
$captcha = false;
} else {
$captcha = true;
}
/**
* Aucun compte existant
*/
if ( !$this->getData(['user', $userId])) {
$logStatus = 'Compte inconnu';
//Stockage de l'IP
$this->setData([
'blacklist',
@ -378,6 +365,7 @@ class user extends common {
$ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip');
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
AND in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) {
$logStatus = 'Compte inconnu verrouillé';
// Valeurs en sortie
$this->addOutput([
'notification' => 'Compte verrouillé',
@ -387,7 +375,7 @@ class user extends common {
} else {
// Valeurs en sortie
$this->addOutput([
'notification' => 'Identifiant ou mot de passe incorrects'
'notification' => 'Captcha, identifiant ou mot de passe incorrects'
]);
}
/**
@ -407,6 +395,7 @@ class user extends common {
AND $this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt'])
AND password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password']))
AND $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER
AND $captcha === true
) {
// RAZ
$this->setData(['user',$userId,'connectFail',0 ]);
@ -430,6 +419,7 @@ class user extends common {
'state' => false
]);
} else {
$logStatus = 'Connexion réussie';
// Valeurs en sortie
$this->addOutput([
'notification' => 'Bienvenue ' . $this->getData(['user',$userId,'firstname']) . ' ' . $this->getData(['user',$userId,'lastname']) ,
@ -439,7 +429,8 @@ class user extends common {
}
// Sinon notification d'échec
} else {
$notification = 'Identifiant ou mot de passe incorrects';
$notification = 'Captcha, identifiant ou mot de passe incorrects';
$logStatus = $captcha === true ? 'Erreur de mot de passe' : 'Erreur de captcha';
// Cas 1 le nombre de connexions est inférieur aux tentatives autorisées : incrément compteur d'échec
if ($this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) {
$this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]);
@ -452,18 +443,7 @@ class user extends common {
if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time() ) {
$notification = 'Accès bloqué ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
}
// Journalisation
$dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true)
? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';'
: utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(strftime('%R',time())) . ';' ;
$dataLog .= helper::getIp() . ';';
$dataLog .= $userId . ';' ;
$dataLog .= $this->getUrl() .';' ;
$dataLog .= 'échec de connexion' ;
$dataLog .= PHP_EOL;
if ($this->getData(['config','connect','log'])) {
file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND);
}
// Valeurs en sortie
$this->addOutput([
'notification' => $notification
@ -471,7 +451,19 @@ class user extends common {
}
}
}
// Journalisation
$dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true)
? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';'
: utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(strftime('%R',time())) . ';' ;
$dataLog .= helper::getIp() . ';';
$dataLog .= $this->getInput('userLoginId', helper::FILTER_ID, true) . ';' ;
$dataLog .= $this->getUrl() .';' ;
$dataLog .= $logStatus ;
$dataLog .= PHP_EOL;
if ($this->getData(['config','connect','log'])) {
file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND);
}
// Stockage des cookies
if (!empty($_COOKIE['ZWII_USER_ID'])) {
self::$userId = $_COOKIE['ZWII_USER_ID'];
}