From 9579315407802629ee0efabe5b691176acde4c2f Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sat, 27 Jun 2020 16:21:22 +0200 Subject: [PATCH] 10.2 Optimisation script protection login + journalisation IP --- core/class/helper.class.php | 21 +++++++++++++++++++++ core/core.js.php | 2 +- core/core.php | 20 ++++++++++---------- core/module/config/config.php | 2 +- core/module/user/user.php | 24 ++++++++++++++++-------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index ad094b0f..c337becc 100755 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -17,6 +17,27 @@ class helper { const FILTER_TIMESTAMP = 10; const FILTER_URL = 11; + + + /** + * Récupérer l'adresse IP sans tenit compte du proxy + * @return string IP adress + * Cette focntion est utilisé par user + */ + + public static function getIp() { + if(!empty($_SERVER['HTTP_CLIENT_IP'])){ + $ip=$_SERVER['HTTP_CLIENT_IP']; + } + elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ + $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; + } + else{ + $ip=$_SERVER['REMOTE_ADDR']; + } + return $ip; + } + /** * Fonction pour récupérer le numéro de version en ligne * @param string $url à récupérer diff --git a/core/core.js.php b/core/core.js.php index 0ab52f46..2342eb13 100755 --- a/core/core.js.php +++ b/core/core.js.php @@ -225,7 +225,7 @@ core.start = function() { if(document.cookie.indexOf("ZWII_COOKIE_CONSENT") === -1) { $("body").append( $("
").attr("id", "cookieConsent").append( - $("").text("En poursuivant votre navigation sur ce site, vous acceptez l'utilisation de cookies."), + $("").text("En poursuivant votre navigation sur ce site, vous acceptez l'utilisation de cookies et de vos données de visite."), $("") .attr("id", "cookieConsentConfirm") .text("OK") diff --git a/core/core.php b/core/core.php index e072ce55..69d59eb6 100755 --- a/core/core.php +++ b/core/core.php @@ -1320,7 +1320,7 @@ class common { $this->setData(['user', $this->getUser('id'), 'accessTimer',0]); $this->setData(['user', $this->getUser('id'), 'accessUrl','']); $this->setData(['user', $this->getUser('id'), 'accessCsrf',$_SESSION['csrf']]); - // Paramètres de sécurité + // Paramètres de sécurité $this->setData(['config', 'connect', 'attempt',999]); $this->setData(['config', 'connect', 'timeout',0]); $this->setData(['config', 'connect', 'log',false]); @@ -1331,12 +1331,12 @@ class common { unlink(self::DATA_DIR . 'theme.css'); } // Créer les en-têtes du journal - $d = 'Date;Heure;Id;Action' . PHP_EOL; + $d = 'Date;Heure;IP;Id;Action' . PHP_EOL; file_put_contents(self::DATA_DIR . 'journal.log',$d); // Init préservation htaccess $this->setData(['config','autoUpdateHtaccess',false]); // Options de barre de membre simple - $this->setData(['theme','menu','memberBar',true]); + $this->setData(['theme','menu','memberBar',true]); // Thème Menu : couleur de page active non définie if (!$this->getData(['theme','menu','activeTextColor']) ) { @@ -1352,7 +1352,6 @@ class common { $this->setData(['theme','menu','memberBar',true]); $this->deleteData(['theme','footer','displayMemberAccount']); $this->deleteData(['theme','footer','displayMemberLogout']); - $this->setData(['core', 'dataVersion', 10201]); } } @@ -1535,31 +1534,31 @@ class core extends common { $css .= '#toggle span,#menu a{padding:' . $this->getData(['theme', 'menu', 'height']) .';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'menu', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'menu', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'menu', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'menu', 'textTransform']) . '}'; // Pied de page - + $colors = helper::colorVariants($this->getData(['theme', 'footer', 'backgroundColor'])); if($this->getData(['theme', 'footer', 'margin'])) { $css .= 'footer{padding:0 20px;}'; } else { $css .= 'footer{padding:0}'; } - + $css .= 'footer span, #footerText > p {color:' . $this->getData(['theme', 'footer', 'textColor']) . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'footer', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'footer', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'footer', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'footer', 'textTransform']) . '}'; $css .= 'footer{background-color:' . $colors['normal'] . ';color:' . $this->getData(['theme', 'footer', 'textColor']) . '}'; $css .= 'footer a{color:' . $this->getData(['theme', 'footer', 'textColor']) . '}'; $css .= 'footer #footersite > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}'; - + $css .= 'footer #footerbody > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}'; $css .= '#footerSocials{text-align:' . $this->getData(['theme', 'footer', 'socialsAlign']) . '}'; $css .= '#footerText > p {text-align:' . $this->getData(['theme', 'footer', 'textAlign']) . '}'; $css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}'; - + // Marge supplémentaire lorsque le pied de page est fixe if ( $this->getData(['theme', 'footer', 'fixed']) === true && $this->getData(['theme', 'footer', 'position']) === 'body') { $css .= "@media (min-width: 769px) { #site {margin-bottom: 100px;} }"; $css .= "@media (max-width: 768px) { #site {margin-bottom: 150px;} }"; } - + // Enregistre la personnalisation file_put_contents(self::DATA_DIR.'theme.css', $css); // Effacer le cache pour tenir compte de la couleur de fond TinyMCE @@ -1634,6 +1633,7 @@ class core extends common { } // Journalisation $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; + $dataLog .= helper::getIp() . ';'; $dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'anonyme' . ';'; $dataLog .= $this->getUrl(); $dataLog .= PHP_EOL; @@ -2635,7 +2635,7 @@ class layout extends common { helper::checkNewVersion(common::ZWII_UPDATE_CHANNEL)) { $this->setData(['core','updateAvailable', true]); $this->setData(['core','lastAutoUpdate',$lastAutoUpdate]); - } + } // Afficher le bouton : Mise à jour détectée + activée if ( $this->getData(['core','updateAvailable']) === true && $this->getData(['config','autoUpdate']) === true ) { diff --git a/core/module/config/config.php b/core/module/config/config.php index 59cbc098..157118ff 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -612,7 +612,7 @@ class config extends common { if ( file_exists(self::DATA_DIR . 'journal.log') ) { unlink(self::DATA_DIR . 'journal.log'); // Créer les en-têtes des journaux - $d = 'Date;Heure;Id;Action' . PHP_EOL; + $d = 'Date;Heure;IP;Id;Action' . PHP_EOL; file_put_contents(self::DATA_DIR . 'journal.log',$d); // Valeurs en sortie $this->addOutput([ diff --git a/core/module/user/user.php b/core/module/user/user.php index 1af92239..0b6678d7 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -349,18 +349,25 @@ class user extends common { [ 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, 'lastFail' => time(), - 'ip' => $_SERVER['REMOTE_ADDR'] + 'ip' => helper::getIp() ] ]); - if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) ) { - $notification = 'Trop de tentatives, compte verrouillé'; + // Verrouillage des IP + $ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip'); + if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) + OR in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) { + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Trop de tentatives, compte verrouillé', + 'redirect' => helper::baseUrl(), + 'state' => false + ]); } else { - $notification = 'Identifiant ou mot de passe incorrect'; + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Identifiant ou mot de passe incorrect' + ]); } - // Valeurs en sortie - $this->addOutput([ - 'notification' => $notification - ]); /** * Le compte existe */ @@ -419,6 +426,7 @@ class user extends common { } // Journalisation $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; + $dataLog .= helper::getIp() . ';'; $dataLog .= $userId . ';' ; $dataLog .= $this->getUrl() .';' ; $dataLog .= 'échec de connexion' ;