<?php
header('Access-Control-Allow-Origin: *');

if (!function_exists('isDebugClientIP')) {
    function isDebugClientIP($get_ip = False)
    {
        // return False;
        $client_ip = "";
        if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
            $client_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
            $client_ip = $_SERVER["REMOTE_ADDR"];
        } else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
            $client_ip = $_SERVER["HTTP_CLIENT_IP"];
        }
        if ($get_ip) {
            return $client_ip;
        }
        if (isset($_COOKIE["LU_ID"])) {
            if (in_array($_COOKIE["LU_ID"], array("1", "2", "19025", "25462"))) {
                return True;
            }
        }
        $debug_ips = array(
            "49.36.144.196",
            "103.46.202.111",
	           // This is the IP of biomax server - please do not comment 13.234.35.158
            "13.234.35.158",
            "49.42.72.210",
            "139.5.240.166",
            "139.5.240.25",
            "101.188.67.134",
            "106.215.89.85"
        );
        if (in_array($client_ip, $debug_ips)) {
            return True;
        }
        return true;
    }
}


// // TO Capture Entire RAW Requests
// $filePath = '/var/www/debug/request_log.log';

// $requestURL = sprintf("%s %s %s\n", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']);
// // Capture headers
// $headers = '';
// foreach ($_SERVER as $name => $value) {
//     if (substr($name, 0, 5) == 'HTTP_') {
//         $headers .= str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($name, 5))))) . ": $value\n";
//     }
// }
// // Capture request body
// $body = file_get_contents('php://input');
// // Combine everything with additional data
// $requestData = "Time: " . date("Y-m-d H:i:s") . "\n" .
//             "Raw Request:\n" . $requestURL . "\n" . $headers . "\n\n" . $body . "\n" .
//             "--------------------------------\n\n";
// // Append to file
// file_put_contents($filePath, $requestData, FILE_APPEND | LOCK_EX);

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package    Laravel
 * @author     Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__ . '/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__ . '/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);
