One Hat Cyber Team
Your IP :
216.73.216.55
Server IP :
5.189.175.239
Server :
Linux panel.gemx-ai.com 5.14.0-570.19.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 4 04:00:24 EDT 2025 x86_64
Server Software :
LiteSpeed
PHP Version :
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
farmersapp
/
loans.farmersapp.store
/
Edit File:
index.php
<?php /** * Farmers Loan Management System * Main Entry Point * Version: 1.0.0 */ // ============================================= // BOOTSTRAP AND CONFIGURATION // ============================================= // Define application paths define('APP_ROOT', dirname(__FILE__)); define('APP_NAME', 'Farmers Loan Management System'); define('APP_VERSION', '1.0.0'); // Set default timezone date_default_timezone_set('Africa/Blantyre'); // Start session if (session_status() === PHP_SESSION_NONE) { session_start(); } // ============================================= // ERROR HANDLING // ============================================= // Development vs Production error reporting if (file_exists(APP_ROOT . '/config/environment.php')) { require_once APP_ROOT . '/config/environment.php'; } else { // Default to development define('ENVIRONMENT', 'development'); } if (ENVIRONMENT === 'development') { error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); ini_set('display_startup_errors', 0); } // Custom error handler set_error_handler(function($errno, $errstr, $errfile, $errline) { if (ENVIRONMENT === 'development') { echo "<div style='background: #f8d7da; color: #721c24; padding: 15px; margin: 10px; border: 1px solid #f5c6cb; border-radius: 5px;'>"; echo "<h3>Error [$errno]</h3>"; echo "<p><strong>Message:</strong> $errstr</p>"; echo "<p><strong>File:</strong> $errfile (Line: $errline)</p>"; echo "</div>"; } else { error_log("Error [$errno]: $errstr in $errfile on line $errline"); } return true; }); // ============================================= // CHECK INSTALLATION // ============================================= // Check if installation is needed $installFile = APP_ROOT . '/config/installed.php'; if (!file_exists($installFile)) { // Redirect to installation wizard if (file_exists(APP_ROOT . '/install.php')) { header('Location: install.php'); exit; } else { die("System not installed. Please run the installation wizard."); } } // Load installation status require_once $installFile; if (!defined('INSTALLED') || INSTALLED !== true) { die("System installation incomplete. Please run the installation wizard."); } // ============================================= // LOAD CONFIGURATIONS // ============================================= // Load database configuration require_once APP_ROOT . '/config/database.php'; // Load constants require_once APP_ROOT . '/config/constants.php'; // Load security functions require_once APP_ROOT . '/includes/security.php'; // Load authentication functions require_once APP_ROOT . '/includes/auth.php'; // Load common functions require_once APP_ROOT . '/includes/functions.php'; // ============================================= // ROUTING SYSTEM // ============================================= // Get requested URL $request = $_SERVER['REQUEST_URI']; $basePath = str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']); $request = str_replace($basePath, '', $request); // Remove query string $request = strtok($request, '?'); // Default route if ($request === '/' || $request === '') { $request = '/login'; } // Route mapping $routes = [ // Authentication '/login' => 'modules/auth/login.php', '/logout' => 'modules/auth/logout.php', '/forgot-password' => 'modules/auth/forgot_password.php', '/reset-password' => 'modules/auth/reset_password.php', // Admin Dashboard '/dashboard' => 'modules/admin/dashboard.php', // Borrower Management '/borrowers' => 'modules/admin/borrowers.php', '/borrowers/add' => 'modules/admin/borrowers.php?action=add', '/borrowers/edit' => 'modules/admin/borrowers.php?action=edit', '/borrowers/view' => 'modules/admin/borrowers.php?action=view', // Loan Management '/loans' => 'modules/admin/loans.php', '/loans/apply' => 'modules/admin/loans.php?action=apply', '/loans/view' => 'modules/admin/loans.php?action=view', '/loans/approve' => 'modules/admin/loans.php?action=approve', '/loans/disburse' => 'modules/admin/loans.php?action=disburse', // Repayment Management '/repayments' => 'modules/admin/repayments.php', '/repayments/receive' => 'modules/admin/repayments.php?action=receive', // Reports '/reports' => 'modules/admin/reports.php', // Settings '/settings' => 'modules/admin/settings.php', // Borrower Portal '/borrower/dashboard' => 'modules/borrower/dashboard.php', '/borrower/loans' => 'modules/borrower/loans.php', '/borrower/repayments' => 'modules/borrower/repayments.php', // API Endpoints '/api/' => 'api/index.php', ]; // Find matching route $matchedRoute = null; foreach ($routes as $route => $file) { if (strpos($request, $route) === 0) { $matchedRoute = $file; break; } } // If no route matched, check for direct file access if (!$matchedRoute) { // Check if it's a direct PHP file request $requestedFile = APP_ROOT . $request; if (file_exists($requestedFile) && is_file($requestedFile)) { $matchedRoute = $request; } else { // 404 Not Found http_response_code(404); require_once APP_ROOT . '/modules/errors/404.php'; exit; } } // ============================================= // SECURITY CHECKS // ============================================= // Initialize security $security = new Security(); // Generate CSRF token for forms $csrf_token = $security->generateCsrfToken(); // Check for maintenance mode $maintenanceFile = APP_ROOT . '/config/maintenance.php'; if (file_exists($maintenanceFile)) { require_once $maintenanceFile; if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE === true) { require_once APP_ROOT . '/modules/errors/maintenance.php'; exit; } } // ============================================= // LOAD THE REQUESTED MODULE // ============================================= // Check if user is authenticated (except for public pages) $publicPages = ['/login', '/forgot-password', '/reset-password', '/install.php']; if (!in_array($request, $publicPages)) { // Check if user is logged in if (!isset($_SESSION['user_id'])) { header('Location: /login'); exit; } // Check if user is active if (!isUserActive($_SESSION['user_id'])) { session_destroy(); header('Location: /login?error=inactive'); exit; } } // Load the requested file $filePath = APP_ROOT . '/' . $matchedRoute; if (file_exists($filePath)) { // Set global variables for the module $current_user_id = $_SESSION['user_id'] ?? null; $current_role = $_SESSION['role'] ?? null; $current_branch_id = $_SESSION['branch_id'] ?? null; // Include the module require_once $filePath; } else { // File not found http_response_code(404); require_once APP_ROOT . '/modules/errors/404.php'; exit; } // ============================================= // CLEANUP // ============================================= // Close database connection if needed if (isset($GLOBALS['db']) && method_exists($GLOBALS['db'], 'close')) { // Don't close persistent connections // $GLOBALS['db']->close(); } // ============================================= // END OF FILE // ============================================= ?>
Simpan