From 62c0e29b44044faf4fdc619d2f2af6895baff326 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 9 Oct 2020 08:37:34 +0200 Subject: [PATCH] modif Sylvain + gitignore png dans tmp --- .gitignore | 1 + core/module/user/user.php | 190 +++++++++++++++++++------------------- 2 files changed, 96 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index 7707a26e..218b1ed4 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Fichiers temporaires site/tmp/*.zip site/tmp/*.gz +site/tmp/*.png # Sauvegardes site/backup/* diff --git a/core/module/user/user.php b/core/module/user/user.php index dfa1bee9..44bee7e8 100644 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -371,114 +371,114 @@ class user extends common { AND password_verify($this->getInput('userLoginCaptcha', helper::FILTER_INT), $this->getInput('userLoginCaptchaResult') ) === false ) { self::$inputNotices['userLoginCaptcha'] = 'Incorrect'; - } + } else { + // Lire Id du compte + $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); - // Lire Id du compte - $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); - - /** - * Aucun compte existant - */ - if ( !$this->getData(['user', $userId])) { - //Stockage de l'IP - $this->setData([ - 'blacklist', - $userId, - [ - 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, - 'lastFail' => time(), - 'ip' => helper::getIp() - ] - ]); - // Verrouillage des IP - $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) ) { - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Trop de tentatives, compte verrouillé', - 'redirect' => helper::baseUrl(), - 'state' => false + /** + * Aucun compte existant + */ + if ( !$this->getData(['user', $userId])) { + //Stockage de l'IP + $this->setData([ + 'blacklist', + $userId, + [ + 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, + 'lastFail' => time(), + 'ip' => helper::getIp() + ] ]); - } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Identifiant ou mot de passe incorrect' - ]); - } - /** - * Le compte existe - */ - } else { - // Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser - if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() - AND $this->getData(['user',$userId,'connectFail']) === $this->getData(['config', 'connect', 'attempt']) ) { - $this->setData(['user',$userId,'connectFail',0 ]); - $this->setData(['user',$userId,'connectTimeout',0 ]); - } - // Check la présence des variables et contrôle du blocage du compte si valeurs dépassées - // Vérification du mot de passe et du groupe - if ( - ( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) ) < time() - 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 - ) { - // Expiration - $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; - $c = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? 'true' : 'false'; - setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false) , '', helper::isHttps(), true); - setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); - setcookie('ZWII_USER_LONGTIME', $c, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); - // Accès multiples avec le même compte - $this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); - // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur - if( - $this->getData(['config', 'maintenance']) - AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN - ) { + // Verrouillage des IP + $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) ) { + // Valeurs en sortie $this->addOutput([ - 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', + 'notification' => 'Trop de tentatives, compte verrouillé', 'redirect' => helper::baseUrl(), 'state' => false ]); } else { // Valeurs en sortie $this->addOutput([ - 'notification' => 'Connexion réussie', - 'redirect' => helper::baseUrl(), - 'state' => true + 'notification' => 'Identifiant ou mot de passe incorrect' ]); } - // Sinon notification d'échec - } else { - $notification = 'Identifiant ou mot de passe 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 ]); + /** + * Le compte existe + */ + } else { + // Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser + if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() + AND $this->getData(['user',$userId,'connectFail']) === $this->getData(['config', 'connect', 'attempt']) ) { + $this->setData(['user',$userId,'connectFail',0 ]); + $this->setData(['user',$userId,'connectTimeout',0 ]); } - // 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()]); + // Check la présence des variables et contrôle du blocage du compte si valeurs dépassées + // Vérification du mot de passe et du groupe + if ( + ( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) ) < time() + 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 + ) { + // Expiration + $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; + $c = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? 'true' : 'false'; + setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false) , '', helper::isHttps(), true); + setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); + setcookie('ZWII_USER_LONGTIME', $c, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); + // Accès multiples avec le même compte + $this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); + // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur + if( + $this->getData(['config', 'maintenance']) + AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN + ) { + $this->addOutput([ + 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', + 'redirect' => helper::baseUrl(), + 'state' => false + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Connexion réussie', + 'redirect' => helper::baseUrl(), + 'state' => true + ]); + } + // Sinon notification d'échec + } else { + $notification = 'Identifiant ou mot de passe 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 = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; + } + // Journalisation + $dataLog = strftime('%d/%m/%y',time()) . ';' . 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 + ]); } - // Cas 3 le délai de bloquage court - if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time() ) { - $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; - } - // Journalisation - $dataLog = strftime('%d/%m/%y',time()) . ';' . 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 - ]); } } }