diff --git a/CHANGES.md b/CHANGES.md index 8a880738..33b66594 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,8 +24,10 @@ Modifications : - Verrouillage des fichiers de données ouverts en écriture. - Message d'erreur littéral. - Sauvegarde des fichiers de données après un effacement et une écriture. + - Identifiant des noms de ressources (id de page , d'utilisateur, etc..) composés de nombres , remplacement du caractère de préfixe "i" par "_". - Google Analytics, option d'anonymisation. - - Procédure de connexion : les erreurs de captcha sont comptabilisées comme des échecs, allégement des messages d'information. + - Procédure de connexion : les erreurs de captcha sont comptabilisées comme des échecs, allégement des messages d'information. Echecs de connexion, informations plus précises dans le journal de connexion. + - TinyMCE : ajout des scripts possibles. Correction : - Notification de commentaire, remplacement du nom de la page par le titre de l'article. diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 58613dc0..396208ec 100755 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -273,7 +273,7 @@ class helper { } // Un ID ne peut pas être un entier, pour éviter les conflits avec le système de pagination if(intval($text) !== 0) { - $text = 'i' . $text; + $text = '_' . $text; } break; case self::FILTER_INT: diff --git a/core/module/user/user.php b/core/module/user/user.php index 8f01c904..69c3580e 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -365,6 +365,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); @@ -373,137 +374,128 @@ 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 { - /** - * 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() - ] + $captcha = true; + } + /** + * Aucun compte existant + */ + if ( !$this->getData(['user', $userId])) { + $logStatus = 'Compte inconnu'; + //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) ) { + $logStatus = 'Compte inconnu verrouillé'; + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Compte verrouillé', + 'redirect' => helper::baseUrl(), + 'state' => false ]); - // 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 + } else { + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Captcha, identifiant ou mot de passe incorrects' + ]); + } + /** + * 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 + AND $captcha === true + ) { + // RAZ + $this->setData(['user',$userId,'connectFail',0 ]); + $this->setData(['user',$userId,'connectTimeout',0 ]); + // 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' => 'Compte verrouillé', + 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', 'redirect' => helper::baseUrl(), 'state' => false ]); } else { + $logStatus = 'Connexion réussie'; // Valeurs en sortie $this->addOutput([ - 'notification' => 'Identifiant ou mot de passe incorrects' + 'notification' => 'Bienvenue ' . $this->getData(['user',$userId,'firstname']) . ' ' . $this->getData(['user',$userId,'lastname']) , + 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), + 'state' => true ]); } - /** - * 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 ]); + // Sinon notification d'échec + } else { + $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 ]); } - // 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 - ) { - // RAZ - $this->setData(['user',$userId,'connectFail',0 ]); - $this->setData(['user',$userId,'connectTimeout',0 ]); - // 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' => 'Bienvenue ' . $this->getData(['user',$userId,'firstname']) . ' ' . $this->getData(['user',$userId,'lastname']) , - 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), - 'state' => true - ]); - } - // Sinon notification d'échec - } else { - $notification = 'Identifiant ou mot de passe incorrects'; - // 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.'; - } - // 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 - ]); + // 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 + ]); } } } + // 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) . ';' ; + $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']; }