nativegallery-weryskok/index.php

55 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-07-04 12:04:41 +03:00
<?php
// Prevent worker script termination when a client connection is interrupted
require __DIR__.'/vendor/autoload.php';
use App\Core\{Routes, Page};
use App\Services\DB;
use Symfony\Component\Yaml\Yaml;
use Tracy\Debugger;
class App
{
public static function start()
{
error_reporting(E_ALL & ~E_WARNING);
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/ngallery.yaml')) {
define("NGALLERY", Yaml::parse(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/ngallery.yaml'))['ngallery']);
if (NGALLERY['root']['debug'] === true) {
Debugger::enable();
}
try {
if (NGALLERY['root']['maintenance'] === false) {
2024-07-09 00:33:50 +03:00
$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'));
}
2024-07-04 12:04:41 +03:00
DB::connect();
Routes::init();
} else {
Page::set('Errors/ServerDown');
}
} catch (PDOException $ex) {
2024-07-08 21:31:59 +03:00
echo '<details><summary class="p20 s5" style="border:none; margin:0 -20px"><b>Произошла ошибка MySQL</b></summary>'.nl2br($ex).'</details>';
2024-07-04 12:04:41 +03:00
} catch (Exception $ex) {
2024-07-08 21:31:59 +03:00
echo '<details><summary class="p20 s5" style="border:none; margin:0 -20px"><b>Произошла скриптовая ошибка PHP</b></summary>'.nl2br($ex).'</details>';
2024-07-04 12:04:41 +03:00
}
} else {
Page::set('Errors/Problems');
}
}
}
App::start();