2
0
stany.ferer 1 жил өмнө
parent
commit
d01f6c99cd

+ 1 - 56
access.inc.php

@@ -17,59 +17,4 @@
         "authenticator",
         "login",
         "cron",
-    ));
-
-    // Filtre les IP authorisés à accéder au site
-
-    function getUserIP() {
-        $ip = 'Inconnu';
-    
-        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
-            // IP partagée par un proxy
-            $ip = $_SERVER['HTTP_CLIENT_IP'];
-        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
-            // IP du client derrière un proxy
-            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
-        } else {
-            // IP du client directement connectée au serveur
-            $ip = $_SERVER['REMOTE_ADDR'];
-        }
-    
-        // Nettoyage des IPs multiples dans le cas de 'HTTP_X_FORWARDED_FOR'
-        if (strpos($ip, ',') !== false) {
-            $ip = explode(',', $ip)[0];
-        }
-    
-        return $ip;
-    }
-
-    if(!is_null(WHITE_IP)){
-        if(!in_array(htmlspecialchars(getUserIP()), WHITE_IP)){
-            header('HTTP/1.0 401 Unauthorized');
-            header('Content-Type: text/html; charset=utf-8');
-            echo '  <!DOCTYPE html>
-                    <html lang="fr">
-                    <head>
-                        <meta charset="UTF-8">
-                        <meta name="viewport" content="width=device-width, initial-scale=1.0">
-                        <title>403 Accès Interdit</title>
-                        <style>
-                            body {
-                                font-family: Arial, sans-serif;
-                                background-color: #f8d7da;
-                                color: #721c24;
-                                text-align: center;
-                                padding: 50px;
-                            }
-                            h1 {
-                                font-size: 2em;
-                            }
-                        </style>
-                    </head>
-                    <body>
-                        <h1>403 Accès Interdit</h1>
-                    </body>
-                    </html>';
-            exit();
-        }
-    }
+    ));

+ 22 - 0
core/class/core.class.php

@@ -447,4 +447,26 @@ class core
         echo '</ul>';
         echo '</div>';
     }
+
+    static public function getUserIP() {
+        $ip = 'Inconnue';
+    
+        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
+            // IP partagée par un proxy
+            $ip = $_SERVER['HTTP_CLIENT_IP'];
+        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+            // IP du client derrière un proxy
+            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+        } else {
+            // IP du client directement connectée au serveur
+            $ip = $_SERVER['REMOTE_ADDR'];
+        }
+    
+        // Nettoyage des IPs multiples dans le cas de 'HTTP_X_FORWARDED_FOR'
+        if (strpos($ip, ',') !== false) {
+            $ip = explode(',', $ip)[0];
+        }
+    
+        return $ip;
+    }
 }

+ 8 - 0
core/controllers/header.php

@@ -15,6 +15,14 @@ spl_autoload_register(function ($class_name) {
     require_once DIR_PHP_CLASS.'/'.$class_name.'.class.php' : '';
 });
 
+// Filtre les IP authorisés à accéder au site
+if(!is_null(WHITE_IP)){
+    if(!in_array(htmlspecialchars(core::getUserIP()), WHITE_IP)){
+        header("Location: /noAccess.php");
+        exit();
+    }
+}
+
 if(debug::isFile("debug")){
     error_reporting(E_ALL);
     ini_set("display_errors", 1);

+ 31 - 0
public-cms/noAccess.php

@@ -0,0 +1,31 @@
+<?php
+header('HTTP/1.0 401 Unauthorized');
+header('Content-Type: text/html; charset=utf-8');
+?>
+<!DOCTYPE html>
+<html lang="fr">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>401 Accès Interdit</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            background-color: #f8d7da;
+            color: #721c24;
+            text-align: center;
+            padding: 50px;
+        }
+
+        h1 {
+            font-size: 2em;
+        }
+    </style>
+</head>
+
+<body>
+    <h1>Accès Non Autorisé</h1>
+</body>
+
+</html>

+ 31 - 0
public-events/noAccess.php

@@ -0,0 +1,31 @@
+<?php
+header('HTTP/1.0 401 Unauthorized');
+header('Content-Type: text/html; charset=utf-8');
+?>
+<!DOCTYPE html>
+<html lang="fr">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>401 Accès Interdit</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            background-color: #f8d7da;
+            color: #721c24;
+            text-align: center;
+            padding: 50px;
+        }
+
+        h1 {
+            font-size: 2em;
+        }
+    </style>
+</head>
+
+<body>
+    <h1>Accès Non Autorisé</h1>
+</body>
+
+</html>