Files
dbois/public/index.php
T

95 lines
2.7 KiB
PHP
Executable File

<?php
use CodeIgniter\Boot;
use Config\Paths;
/**
* CodeIgniter 4 Front Controller
*/
// Check PHP version.
$minPhpVersion = '8.1';
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
$message = sprintf(
'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
$minPhpVersion,
PHP_VERSION
);
header('HTTP/1.1 503 Service Unavailable.', true, 503);
echo $message;
exit(1);
}
/*
*---------------------------------------------------------------
* MAINTENANCE MODE CHECK
*---------------------------------------------------------------
*/
$maintenanceFile = __DIR__ . '/../writable/down';
if (file_exists($maintenanceFile)) {
$maintenanceData = json_decode(file_get_contents($maintenanceFile), true) ?: [];
$allowedIps = $maintenanceData['allowed'] ?? [];
// Get the visitor's IP address
$visitorIp = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? '';
// Handle comma-separated IPs in X-Forwarded-For
if (str_contains($visitorIp, ',')) {
$visitorIp = trim(explode(',', $visitorIp)[0]);
}
// Check if visitor IP is whitelisted
if (! in_array($visitorIp, $allowedIps, true)) {
http_response_code(503);
header('Retry-After: 3600');
header('Content-Type: text/html; charset=UTF-8');
$maintenancePage = __DIR__ . '/../app/Views/errors/html/maintenance.php';
if (file_exists($maintenancePage)) {
include $maintenancePage;
} else {
echo '<h1>Service Unavailable</h1><p>The site is currently under maintenance.</p>';
}
exit(1);
}
}
/*
*---------------------------------------------------------------
* SET THE CURRENT DIRECTORY
*---------------------------------------------------------------
*/
// Path to the front controller (this file)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);
// Ensure the current directory is pointing to the front controller's directory
if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
chdir(FCPATH);
}
/*
*---------------------------------------------------------------
* BOOTSTRAP THE APPLICATION
*---------------------------------------------------------------
*/
// LOAD COMPOSER AUTOLOADER
require_once __DIR__ . '/../vendor/autoload.php';
// LOAD ENVIRONMENT VARIABLES
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'ENVIRONMENT']);
// LOAD OUR PATHS CONFIG FILE
require FCPATH . '../app/Config/Paths.php';
$paths = new Paths();
// LOAD THE FRAMEWORK BOOTSTRAP FILE
require $paths->systemDirectory . '/Boot.php';
exit(Boot::bootWeb($paths));