Browse Source

Maj bann IP

stany.ferer 3 months ago
parent
commit
fa7575e19f
3 changed files with 14 additions and 13 deletions
  1. 1 0
      .gitignore
  2. 6 6
      core/class/blacklist.class.php
  3. 7 7
      public-cms/404.php

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ env.inc.php
 
 .codegpt
 blacklist/ip_attempts.log
+blacklist/ip.txt

+ 6 - 6
core/class/blacklist.class.php

@@ -71,22 +71,22 @@ class blacklist {
             }
 
             if ($blacklisted == TRUE) {
-                return "Votre IP a été blacklistée pour trop de tentatives.";
+                header("Location: /noAccess.php");
                 exit();
             } else {
-                return "Nombre de tentatives récentes pour votre IP<br /><h2>" . (count($recent_attempts) + 1)."</h2>";
+                return ["error" => 404, "text" => "La page que vous cherchez n'existe pas."];
             }
         } else {
-            return  "La page que vous cherchez n'existe pas.";
+            return ["error" => 404, "text" => "La page que vous cherchez n'existe pas."];
         }
     }
 
     public static function itIs(){ // Est-il blacklisté
-        $ip = $_SERVER['REMOTE_ADDR'];
-        if(self::checkBlacklist($ip)){
-            echo "Votre IP (" . $ip . ") a été blacklistée pour trop de tentatives.";
+        if(self::checkBlacklist($_SERVER['REMOTE_ADDR'])){
+            header("Location: /noAccess.php");
             exit();
         }
+        return NULL;
     }
 
 }

+ 7 - 7
public-cms/404.php

@@ -7,20 +7,20 @@ require_once "../core/class/blacklist.class.php";
 new blacklist;
 
 
-if(blacklist::isValidIPv4()){
-    $text = blacklist::execute();
+if(!blacklist::isValidIPv4()){
+    $result = blacklist::execute();
 } else {
-    $text = "La page que vous cherchez n'existe pas.";
+    $result = "La page que vous cherchez n'existe pas.";
 }
 
-http_response_code(404);
+http_response_code($result["error"]);
 ?>
 
 <!DOCTYPE html>
 <html lang="fr">
 <head>
     <meta charset="UTF-8">
-    <title>Page non trouvée - Erreur 404</title>
+    <title>CSE Invent :. Erreur <?= $result["error"] ?></title>
     <style>
         body {
             font-family: Arial, sans-serif;
@@ -56,7 +56,7 @@ http_response_code(404);
 <body>
     <div class="container">
         <img src="img/logo.png" id="icon" alt="CSE Invent" width="300px">
-        <h1>404</h1>
-        <p><?= $text ?></p>
+        <h1><?= $result["error"] ?></h1>
+        <p><?= $result["text"] ?></p>
 </body>
 </html>