From aa2bfa5ddba112c2af6e758f8ec9a2d4312e13f0 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Sun, 3 Jan 2021 18:41:25 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Am=C3=A9lioration=20journalisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/module/user/user.php | 222 ++++++++++++++++++-------------------- 1 file changed, 107 insertions(+), 115 deletions(-) diff --git a/core/module/user/user.php b/core/module/user/user.php index 5d465942..930fdfc4 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -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,137 +342,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, 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']; } From 18bfadec1fecdd5e5c7545b1e646364bb1cf67ae Mon Sep 17 00:00:00 2001 From: fredtempez Date: Sun, 3 Jan 2021 18:52:36 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Pr=C3=A9fixe=20=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 4 +++- core/class/helper.class.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1cc36c74..bce9fdfd 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,8 +6,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: From b9864fbfb841b061fefcf9960b9ea172ebf6e190 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Mon, 4 Jan 2021 17:33:38 +0100 Subject: [PATCH 3/4] =?UTF-8?q?login=20message=20erron=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/module/user/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/module/user/user.php b/core/module/user/user.php index 930fdfc4..00ce6831 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -456,7 +456,7 @@ class user extends common { ? 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->getInput('userLoginId', helper::FILTER_ID) . ';' ; $dataLog .= $this->getUrl() .';' ; $dataLog .= $logStatus ; $dataLog .= PHP_EOL; From bb782a7e8ff2dbc2c22f6c2d68a83ce8316d0f23 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Mon, 4 Jan 2021 17:54:47 +0100 Subject: [PATCH 4/4] Nom des fichiers de backup + htaccess --- CHANGES.md | 1 - core/class/jsondb/JsonDb.class.php | 2 +- site/data/.htaccess | 13 ++----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bce9fdfd..f7791f23 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,6 @@ Modifications : - 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. 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/jsondb/JsonDb.class.php b/core/class/jsondb/JsonDb.class.php index 23b8e5ac..2cb9d394 100755 --- a/core/class/jsondb/JsonDb.class.php +++ b/core/class/jsondb/JsonDb.class.php @@ -133,7 +133,7 @@ class JsonDb extends \Prowebcraft\Dot } // Backup file if ($this->config['backup']) { - copy ($this->db, $this->db . '.back'); + copy ($this->db, str_replace('json' , 'back.json', $this->db)); } if ( is_writable($this->db) ) { // 3 essais diff --git a/site/data/.htaccess b/site/data/.htaccess index 2d900f16..ff0d5418 100755 --- a/site/data/.htaccess +++ b/site/data/.htaccess @@ -1,14 +1,5 @@ # Bloque l'accès aux données - + Order deny,allow Deny from all - - - Order deny,allow - Deny from all - -# Bloque l'accès htaccess - - Order deny,allow - Deny from all - \ No newline at end of file + \ No newline at end of file