index.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. // Include the prepend file.
  3. require_once '../include/prepend.php';
  4. /**
  5. * Output a page not found message.
  6. *
  7. * @access public
  8. * @return void
  9. */
  10. function make404() {
  11. // Send the HTTP header.
  12. header('HTTP/1.0 404 Not Found');
  13. // Output a header for page not found.
  14. commonHeader('404 Not Found');
  15. // Output a message telling the user the page was not found.
  16. echo "<H1>Not Found</H1>\n";
  17. echo "<P>The page <B>" . htmlspecialchars($_SERVER['REQUEST_URI']) . "</B> could not be found.</P>\n";
  18. // Output the footer.
  19. commonFooter();
  20. }
  21. // Get the configuration file.
  22. if (file_exists("../configuration.inc")) {
  23. include_once "../configuration.inc";
  24. }
  25. // Clean up the request URI.
  26. $ri = htmlspecialchars($_SERVER['REQUEST_URI']);
  27. // Check to see if an GIF, JPEG or PDF was requested.
  28. if (preg_match('/\.(pdf|gif|jpg)$/', $_SERVER['REQUEST_URI'])) {
  29. // Spit out the 404 and exit.
  30. make404();
  31. exit;
  32. }
  33. // Set the default language to English.
  34. $lang = "en";
  35. if (!is_dir("{$_SERVER['DOCUMENT_ROOT']}/manual1/$lang")) {
  36. $lang = "en"; // fall back to English
  37. }
  38. # handle .php3 files that were renamed to .php
  39. // We don't really need this but I am leaving it in for now. Until I have a
  40. // better understanding of what needs to happen.
  41. if (preg_match("/(.*\.php)3$/", $ri, $array)) {
  42. if($_SERVER['SERVER_PORT']!=80) {
  43. $url = "http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$array[1];
  44. } else {
  45. $url = "http://".$_SERVER['SERVER_NAME'].$array[1];
  46. }
  47. $urle = htmlspecialchars($url);
  48. header("HTTP/1.0 302 Redirect");
  49. header("Location: $url");
  50. print "<html><title>Redirect to $urle</title><body>";
  51. print "<a href=\"".$url."\">Please click here</a></body></html>";
  52. exit;
  53. }
  54. # handle moving english manual down into its own directory
  55. // This changes .../manual1/html/page.html to .../manual1/en/html/page.html
  56. if (eregi("^(.*)/manual1/((html/)?[^/]+)$", $ri, $array)) {
  57. // Make sure the same port is used. Are any other ports open for this?
  58. if($_SERVER['SERVER_PORT']!=80) {
  59. $url = "http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."$array[1]/manual1/$lang/".$array[2];
  60. } else {
  61. $url = "http://".$_SERVER['SERVER_NAME']."$array[1]/manual1/$lang/".$array[2];
  62. }
  63. // URL Encode the new URL.
  64. $urle = htmlspecialchars($url);
  65. // Send the redirect header.
  66. header("HTTP/1.0 302 Redirect");
  67. // Send the redirect location.
  68. header("Location: $url");
  69. // Let the user know what is going on incase the redirect doesn't work.
  70. print "<html><title>Redirect to $urle</title><body>";
  71. print "<a href=\"".$url."\">Please click here</a></body></html>";
  72. exit;
  73. }
  74. // I have no idea what is going on here. I think this may strip out the host
  75. // name and protocol.
  76. $uri = substr($REDIRECT_REDIRECT_ERROR_NOTES,
  77. strpos($REDIRECT_REDIRECT_ERROR_NOTES,
  78. $_SERVER['DOCUMENT_ROOT']
  79. ) + strlen($_SERVER['DOCUMENT_ROOT']) + 1
  80. );
  81. # try to find the uri as a manual entry
  82. require "../include/manual1-lookup.inc";
  83. // Check to see if the URI has a '/' in it. If it does then a page like
  84. // .../en/show_all was requested.
  85. if(strchr($uri, '/')) {
  86. // Break the URI up into language and page.
  87. list($lang, $function) = explode('/', $uri, 2);
  88. $function = strtolower($function);
  89. $lang = strtolower($lang);
  90. } else {
  91. $function = strtolower($uri);
  92. }
  93. // Check to see if there is a manual page for the language and function.
  94. $try = find_manual_page($lang, $function);
  95. if($try) {
  96. // Send a redirect header.
  97. header("HTTP/1.0 302 Redirect");
  98. // Send the redirect location.
  99. header("Location: $try");
  100. exit;
  101. }
  102. # If all else fails ... redirect to the search page with the pattern set to $_SERVER['REQUEST_URI']
  103. #if ($_SERVER['REQUEST_URI']) {
  104. # header('HTTP/1.0 302 Redirect');
  105. # header('Location: /search.php?show=nosource&pattern='.urlencode($_SERVER['REQUEST_URI']) );
  106. # exit;
  107. #}
  108. make404();
  109. exit;
  110. ?>