File: //home/shaping-sar.ru/public_html/web.php
<?php
// Редирект с HTTP на HTTPS
if (
!isset($_SERVER['HTTPS']) ||
$_SERVER['HTTPS'] !== 'on'
) {
$httpsUrl = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
header("Location: $httpsUrl");
exit();
}
define('WEB_REQUEST_LOG', '/request_log_27312343154fadslkfjlhffsdh623sdkfjsdifoj4637.txt');
include_once ('web_utils.php');
// Блокировка доступа по IP (REMOTE_HOST)
$allowedHosts = [
// '185.39.118.75',
// '88.147.173.12',
// '188.235.151.189'
];
$remoteHost = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$allowed = false;
if (empty($allowedHosts)) {
$allowed = true;
} else {
foreach ($allowedHosts as $host) {
if (strpos($remoteHost, $host) === 0) {
$allowed = true;
break;
}
}
}
if (!$allowed) {
header("HTTP/1.1 403 Forbidden");
echo "Access denied";
exit();
}
$requestUri = $_SERVER['REQUEST_URI'];
$path = parse_url(urldecode($requestUri), PHP_URL_PATH);
$fullPath = $_SERVER['DOCUMENT_ROOT'] . $path;
if (file_exists($fullPath) || is_link($fullPath) || file_exists($fullPath . '/index.php')) {
if(is_dir($fullPath)) {
$fullPath .= 'index.php';
}
if (isPhpFile($fullPath)) {
$_SERVER['PHP_SELF'] = $path;
log_request($_SERVER['DOCUMENT_ROOT'] . WEB_REQUEST_LOG);
include($fullPath);
} else {
serveFileDirectly($fullPath);
}
exit();
}
if ($path === '/index.php') {
include $_SERVER['DOCUMENT_ROOT'] . '/index.php';
exit();
}
log_request($_SERVER['DOCUMENT_ROOT'] . WEB_REQUEST_LOG);
$_SERVER['PHP_SELF'] = '/index.php';
include $_SERVER['DOCUMENT_ROOT'] . '/index.php';
exit();