diff --git a/core/core.php b/core/core.php index 8653a62d..889798b5 100755 --- a/core/core.php +++ b/core/core.php @@ -39,7 +39,7 @@ class common { const ACCESS_TIMER = 1800; // Numéro de version - const ZWII_VERSION = '10.2.00.dev18'; + const ZWII_VERSION = '10.2.00.dev19'; const ZWII_UPDATE_CHANNEL = "v10"; public static $actions = []; @@ -1589,7 +1589,7 @@ class core extends common { // Journalisation $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; $dataLog .= $_SERVER['REMOTE_ADDR'] . ';' ; - $dataLog .= $this->getUser('id') . ';' ; + $dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'visiteur' . ';'; $dataLog .= $this->getUrl(); $dataLog .= PHP_EOL; if ($this->getData(['config','connect','log'])) { diff --git a/core/module/config/config.php b/core/module/config/config.php index f5ab9fc1..d7bc9440 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -26,7 +26,10 @@ class config extends common { 'updateBaseUrl' => self::GROUP_ADMIN, 'script' => self::GROUP_ADMIN, 'logReset' => self::GROUP_ADMIN, - 'logDownload'=> self::GROUP_ADMIN + 'logDownload'=> self::GROUP_ADMIN, + 'blacklistReset' => self::GROUP_ADMIN, + 'blacklistDownload' => self::GROUP_ADMIN + ]; public static $timezones = [ @@ -603,14 +606,25 @@ class config extends common { */ public function logReset() { - unlink(self::DATA_DIR . 'journal.log'); - // Valeurs en sortie + if ( file_exists(self::DATA_DIR . 'journal.log') ) { + unlink(self::DATA_DIR . 'journal.log'); + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Configuration', + 'view' => 'index', + 'notification' => 'Journal réinitialisé avec succès', + 'state' => true + ]); + } else { + // Valeurs en sortie $this->addOutput([ - 'title' => 'Configuration', - 'view' => 'index', - 'notification' => 'Journal réinitialisé avec succès', - 'state' => true - ]); + 'title' => 'Configuration', + 'view' => 'index', + 'notification' => 'Pas de journal à effacer', + 'state' => false + ]); + } + } @@ -619,10 +633,7 @@ class config extends common { * Télécharger le fichier de log */ public function logDownload() { - // Creation du ZIP $fileName = self::DATA_DIR . 'journal.log'; - - // Téléchargement du ZIP header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Length: ' . filesize($fileName)); @@ -638,6 +649,58 @@ class config extends common { ]); } + /** + * Tableau des IP blacklistés + */ + public function blacklistDownload () { + $d = $this->getData(['blacklist']); + $data = ''; + foreach ($d as $key => $item) { + $data .= $key . ';' . $item['ip'] . PHP_EOL; + } + $fileName = self::TEMP_DIR . 'blacklist.log'; + file_put_contents($fileName,$data); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="' . $fileName . '"'); + header('Content-Length: ' . filesize($fileName)); + readfile( $fileName); + // Valeurs en sortie + $this->addOutput([ + 'display' => self::DISPLAY_RAW + ]); + unlink(self::TEMP_DIR . 'blacklist.tmp'); + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Configuration', + 'view' => 'index' + ]); + } + + /** + * Réinitialiser les ip blacklistées + */ + + public function blacklistReset() { + if ( file_exists(self::DATA_DIR . 'blacklist.json') ) { + unlink(self::DATA_DIR . 'blacklist.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Configuration', + 'view' => 'index', + 'notification' => 'Liste noire réinitialisée avec succès', + 'state' => true + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Configuration', + 'view' => 'index', + 'notification' => 'Pas de liste à effacer', + 'state' => false + ]); + } + } + /** * Fonction de parcours des données de module diff --git a/core/module/config/view/index/index.php b/core/module/config/view/index/index.php index 0debcd7d..71b4b69f 100755 --- a/core/module/config/view/index/index.php +++ b/core/module/config/view/index/index.php @@ -350,7 +350,7 @@
-

Options avancées

+

Sécurité

$this->getData(['config', 'connect', 'timeout']) ]); ?>
+
+ helper::baseUrl() . 'config/blacklistDownload', + 'value' => 'IP liste noire', + 'ico' => 'download' + ]); ?> +
+
+ 'buttonRed', + 'href' => helper::baseUrl() . 'config/blacklistReset', + 'value' => 'Réinitialisation liste', + 'ico' => 'cancel' + ]); ?> +
+
+
+ $this->getData(['config', 'connect', 'log']) + ]); ?> +
+
+ helper::baseUrl() . 'config/logDownload', + 'value' => 'Téléchargement du journal', + 'ico' => 'download' + ]); ?> +
+
+ 'buttonRed', + 'href' => helper::baseUrl() . 'config/logReset', + 'value' => 'Réinitialisation du journal', + 'ico' => 'cancel' + ]); ?> +
+
+
+
+
+
+
+
+

Options de script

-
-
- $this->getData(['config', 'connect', 'log']) - ]); ?> -
-
- helper::baseUrl() . 'config/logDownload', - 'value' => 'Téléchargement du journal', - 'ico' => 'download' - ]); ?> -
-
- 'buttonRed', - 'href' => helper::baseUrl() . 'config/logReset', - 'value' => 'Réinitialisation du journal', - 'ico' => 'cancel' - ]); ?> -
-
diff --git a/core/module/user/user.php b/core/module/user/user.php index 2fbb9420..1efaf287 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -332,7 +332,7 @@ class user extends common { // Soumission du formulaire if($this->isPost()) { $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); - // le userId n'existe pas + // le userId n'existe pas, créer une entré dans la liste noire if( !$this->getData(['user', $userId])) { //Stockage de l'IP $this->setData([ @@ -343,15 +343,6 @@ class user extends common { 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) ? $this->getData(['blacklist',$userId,'connectFail']) + 1 : 1 ] ]); - // Après les tentatives autorisées, bloquer l'IP. - if ( $this->getData(['blacklist',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt']) || - array_search($_SERVER['REMOTE_ADDR'],helper::arrayCollumn($this->getData(['blacklist']), 'ip')) ) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl(), - 'state' => false - ]); - } } // Contrôle du timeout pas de vérification du mot de passe si le temps est dépassé. // Connexion si les informations sont correctes @@ -389,20 +380,28 @@ class user extends common { } // Sinon notification d'échec else { - // Incrémenter le compteur d'échec de connexion si l'utilisateur existe + // L'utilisateur existe : incrémenter le compteur d'échec de connexion if ( is_array($this->getdata(['user',$userId])) ) { $this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); - } - // Mettre à jour le timer et notifier - if ( $this->getdata(['user',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt'])) { - $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; - // Ne pas incrémenter le timer si actif - if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() ) { - $this->setData(['user',$userId,'connectTimeout', time()]); + // Mettre à jour le timer et notifier + if ( $this->getdata(['user',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt'])) { + $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; + // Ne pas incrémenter le timer si actif + if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() ) { + $this->setData(['user',$userId,'connectTimeout', time()]); + } + } else { + $notification = 'Identifiant ou mot de passe incorrect'; } - } else { - $notification = 'Identifiant ou mot de passe incorrect'; + // L'utilisateur n'existe pas + // Bloquer l'IP après les tentatives autorisées, + } elseif ( + $this->getData(['blacklist',$userId,'connectFail']) > $this->getData(['config', 'connect', 'attempt']) || + array_search($_SERVER['REMOTE_ADDR'],helper::arrayCollumn($this->getData(['blacklist']), 'ip')) + ) { + $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 .= $_SERVER['REMOTE_ADDR'] . ';' ;