Kaynağa Gözat

Maj Bann IP

stany.ferer 3 ay önce
ebeveyn
işleme
e50e81a779
2 değiştirilmiş dosya ile 55 ekleme ve 62 silme
  1. 5 8
      core/class/blacklist.class.php
  2. 50 54
      public-cms/404.php

+ 5 - 8
core/class/blacklist.class.php

@@ -7,8 +7,8 @@ class blacklist {
     private static $max_attempts = 5;
     private static $time_window = 10 * 60; // 10 minutes en secondes
 
-    public static function execute(?string $_from = NULL) {
-        self::check($_from);
+    public static function execute() {
+        return self::check();
     }
 
     public static function isValidIPv4() {
@@ -71,16 +71,13 @@ class blacklist {
             }
 
             if ($blacklisted == TRUE) {
-                header('HTTP/1.0 401 Unauthorized');
-                echo "Votre IP (" . $ip . ") a été blacklistée pour trop de tentatives.";
+                return "Votre IP a été blacklistée pour trop de tentatives.";
                 exit();
             } else {
-                echo "Votre IP est : " . $ip . ". Nombre de tentatives récentes : " . (count($recent_attempts) + 1);
-                exit();
+                return "Nombre de tentatives récentes pour votre IP<br /><h2>" . (count($recent_attempts) + 1)."</h2>";
             }
         } else {
-            echo json_encode(["Error 404"]);
-            exit();
+            return  "La page que vous cherchez n'existe pas.";
         }
     }
 

+ 50 - 54
public-cms/404.php

@@ -1,66 +1,62 @@
 <?php
 /*
-$visitor_ip = $_SERVER['REMOTE_ADDR'];
-
-if(!blacklistisValidIPv4($visitor_ip)){
-    $log_file = '../blacklist/ip_attempts.log';
-    $blacklist_file = '../blacklist/ip.txt';
-    $max_attempts = 5;
-    $time_window = 10 * 60; // 10 minutes en secondes
-
-    // Charger les tentatives existantes
-    $attempts = [];
-    if (file_exists($log_file)) {
-        $lines = file($log_file, FILE_IGNORE_NEW_LINES);
-        foreach ($lines as $line) {
-            list($ip, $timestamp) = explode(',', $line);
-            $attempts[] = ['ip' => $ip, 'timestamp' => strtotime($timestamp)];
-        }
-    }
-
-    // Vérifier si l'IP est déjà blacklistée
-    $blacklisted = false;
-    if (file_exists($blacklist_file)) {
-        $blacklisted_ips = file($blacklist_file, FILE_IGNORE_NEW_LINES);
-        $blacklisted = in_array($visitor_ip, $blacklisted_ips);
-    }
-
-    // Ajouter une nouvelle tentative
-    file_put_contents($log_file, "$visitor_ip," . date('Y-m-d H:i:s') . ", " . $_SERVER["REQUEST_METHOD"] . "," . getFullUrl() . "\n", FILE_APPEND);
-
-    // Compter les tentatives récentes
-    $now = time();
-    $recent_attempts = array_filter($attempts, function ($attempt) use ($visitor_ip, $now, $time_window) {
-        return $attempt['ip'] === $visitor_ip && ($now - $attempt['timestamp']) <= $time_window;
-    });
-
-    if (count($recent_attempts) + 1 > $max_attempts && !$blacklisted) {
-        file_put_contents($blacklist_file, "$visitor_ip\n", FILE_APPEND);
-        $blacklisted = true;
-    }
-
-    if ($blacklisted) {
-        header('HTTP/1.0 401 Unauthorized');
-        echo "Votre IP ($visitor_ip) a été blacklistée pour trop de tentatives.";
-        exit();
-    } else {
-        echo "Votre IP est : $visitor_ip. Nombre de tentatives récentes : " . (count($recent_attempts) + 1);
-    }
-} else {
-    echo json_encode([["error" => "404"]]);
-}
-*/
-
 error_reporting(E_ALL);
 ini_set('display_errors', 'On');
-
+*/
 require_once "../core/class/blacklist.class.php";
 new blacklist;
 
+
 if(blacklist::isValidIPv4()){
-    blacklist::execute("404");
+    $text = blacklist::execute();
 } else {
-    echo json_encode([["error" => "404"]]);
+    $text = "La page que vous cherchez n'existe pas.";
 }
 
+http_response_code(404);
 ?>
+
+<!DOCTYPE html>
+<html lang="fr">
+<head>
+    <meta charset="UTF-8">
+    <title>Page non trouvée - Erreur 404</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            background-color: #f2f2f2;
+            text-align: center;
+            padding: 50px;
+        }
+        .container {
+            background-color: #fff;
+            padding: 40px;
+            border-radius: 10px;
+            display: inline-block;
+            box-shadow: 0 0 10px rgba(0,0,0,0.1);
+        }
+        h1 {
+            font-size: 48px;
+            color: #e74c3c;
+        }
+        p {
+            font-size: 18px;
+            color: #333;
+        }
+        a {
+            color: #3498db;
+            text-decoration: none;
+            font-weight: bold;
+        }
+        a:hover {
+            text-decoration: underline;
+        }
+    </style>
+</head>
+<body>
+    <div class="container">
+        <img src="img/logo.png" id="icon" alt="CSE Invent" width="300px">
+        <h1>404</h1>
+        <p><?= $text ?></p>
+</body>
+</html>