diff --git a/index.php b/index.php index d9f7cb5..1ca56f0 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,20 @@ class App } try { if (NGALLERY['root']['maintenance'] === false) { + $userIP = $_SERVER['REMOTE_ADDR']; + + function getCountryCodeByIP($ip) + { + $url = "http://ip-api.com/json/{$ip}?fields=countryCode"; + $response = file_get_contents($url); + $data = json_decode($response, true); + return $data['countryCode'] ?? null; + } + $countryCode = getCountryCodeByIP($userIP); + + if (in_array(strtolower($countryCode), explode(',', NGALLERY['root']['access']['countries']))) { + die(Page::set('Errors/ForbiddenCountry')); + } DB::connect(); Routes::init(); } else { diff --git a/static/img/403.jpg b/static/img/403.jpg new file mode 100644 index 0000000..9946e5b Binary files /dev/null and b/static/img/403.jpg differ diff --git a/views/pages/Errors/ForbiddenCountry.php b/views/pages/Errors/ForbiddenCountry.php new file mode 100644 index 0000000..c59b3f2 --- /dev/null +++ b/views/pages/Errors/ForbiddenCountry.php @@ -0,0 +1,28 @@ + + + + +
+ + + + + + + + +Вы можете связаться с администратором сервера, если считаете, что это ошибка.