index.php

  1. 7.x index.php
  2. 6.x index.php
  3. 5.x index.php

The primary entry point for FlightPath.

This script will determine which page the user is trying to view, and display it for them.

File

index.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * The primary entry point for FlightPath.
  5. *
  6. * This script will determine which page the user is trying to view,
  7. * and display it for them.
  8. */
  9. // First, let's check to see if we are banning any IPs from our site...
  10. $remote_ip = $_SERVER['REMOTE_ADDR'];
  11. $blocklist_file = __DIR__ . '/custom/files/private/banned_ips.txt';
  12. $cache_key = 'banned_ips';
  13. // Load banned IPs
  14. if (function_exists('apcu_fetch')) {
  15. $blocked_ips_assoc = apcu_fetch($cache_key);
  16. if ($blocked_ips_assoc === FALSE) {
  17. // Not in cache, load from file, then store in cache
  18. $blocked_ips_assoc = array();
  19. if (file_exists($blocklist_file)) {
  20. $lines = file($blocklist_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  21. $lines = array_map('trim', $lines);
  22. $blocked_ips_assoc = array_flip($lines); // fast lookup
  23. apcu_store($cache_key, $blocked_ips_assoc, 60); // cache X seconds
  24. }
  25. }
  26. } // if apcu is installed
  27. else {
  28. // APCu not installed or we are instructed to look at the blocklist file directly
  29. // fallback to reading file every request
  30. $blocked_ips_assoc = array();
  31. if (file_exists($blocklist_file)) {
  32. $lines = file($blocklist_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  33. $lines = array_map('trim', $lines);
  34. $blocked_ips_assoc = array_flip($lines);
  35. }
  36. }
  37. /*
  38. // Check if IP is blocked
  39. if (isset($blocked_ips_assoc[$remote_ip])) {
  40. // TODO: If banned, give the user a chance to remove ban by visiting a page and answering
  41. // a CAPTCHA or some other challenge?
  42. error_log("Banned IP: $remote_ip tried to access " . $_SERVER['REQUEST_URI']); // optional
  43. header('HTTP/1.1 403 Forbidden');
  44. echo "403: Access denied";
  45. exit;
  46. }
  47. */
  48. //////////////////////
  49. // If we are here, we can now proceed with loading the FlightPath page.
  50. // Load all of the classes, as well as the custom classes.
  51. require_once("classes/all_classes.php");
  52. // Make sure our cookies are the most secure possible:
  53. ini_set('session.cookie_httponly', 'On');
  54. if( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443 ){
  55. //enable secure cookies, since we are on HTTPS.
  56. ini_set('session.cookie_secure', 'On');
  57. }
  58. // Should we init the session using a specific session_id?
  59. if (@$_GET['fp_session_str'] != '') {
  60. // For security, the fp_session_str is made of several pieces so we can be sure it is authentic
  61. // and not a hacker trying to imitate a known user's session_id.
  62. require_once("includes/misc.inc"); // Bring in the functions we need so we can validate the fp_session_str
  63. // We will validate now and retrieve the PHP session_id from it, or FALSE.
  64. $session_id = fp_get_session_id_from_str($_GET['fp_session_str']);
  65. if ($session_id) {
  66. session_id($session_id);
  67. }
  68. else {
  69. // The session did not validate. This might be a hacking attempt. Kill the script.
  70. die("Security Error: Session could not be validated by FlightPath (index.php). This is a security
  71. feature to protect data privacy.
  72. <br><br>
  73. This can happen for a number of reasons. For example, if you followed a link provided by another
  74. user that contained sensitive session information. Or, if you changed networks or turned a VPN
  75. off or on.
  76. <br><br>
  77. Visit the base URL for this site to log in securely. Ex: https://flightpath.example.com/
  78. <br><br>
  79. If this error continues, contact your IT administrator.");
  80. }
  81. }
  82. session_start();
  83. // Set headers for maximum security
  84. header("Cache-control: no-cache, no-store, must-revalidate"); // HTTP 1.1
  85. header("Pragma: no-cache"); // HTTP 1.0
  86. header("X-XSS-Protection: 1");
  87. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past, to ensure it expires when we close the browser.
  88. header('X-Frame-Options: SAMEORIGIN'); // No iframes except from the same website origins.
  89. // If the user is requesting a "clean URLs" check, display a simple success message.
  90. if (isset($_REQUEST["q"]) && $_REQUEST["q"] == "test-clean-urls/check") {
  91. print "CLEAN URLS CHECK SUCCESSFUL";
  92. die;
  93. }
  94. // If the settings.php file doesn't exist, then FlightPath must not be installed,
  95. // and we should redirect to install.php.
  96. if (!file_exists("custom/settings.php")) {
  97. header ("Location: install.php");
  98. die;
  99. }
  100. require_once("bootstrap.inc");
  101. // For development reasons only:
  102. // To rebuild the cache on every page load, un-comment the following line
  103. // menu_rebuild_cache();
  104. // FlightPath will now look at the request in the query to decide what page we are going to display.
  105. $page = menu_execute_page_request();
  106. if (!is_int($page)) {
  107. // Display the page!
  108. fp_display_page($page);
  109. }
  110. else {
  111. if ($page == MENU_NOT_FOUND) {
  112. display_not_found();
  113. }
  114. else if ($page == MENU_ACCESS_DENIED) {
  115. display_access_denied();
  116. }
  117. }
  118. // Call hook_exit as we leave the page.
  119. invoke_hook("exit");