router.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. define("CONF", parse_ini_file(__DIR__ . "/config.ini", true, INI_SCANNER_TYPED));
  3. foreach (array_diff(scandir(CONF['common']['root_path'] . "/fn"), array('..', '.')) as $file)
  4. require CONF['common']['root_path'] . '/fn/' . $file;
  5. define("DB_PATH", CONF['common']['root_path'] . "/db/niver.db");
  6. define("PLACEHOLDER_DOMAIN", "example"); // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples
  7. define("PLACEHOLDER_IPV6", "2001:db8::3"); // From RFC3849: IPv6 Address Prefix Reserved for Documentation
  8. define("PLACEHOLDER_IPV4", "203.0.113.42"); // From RFC5737: IPv4 Address Blocks Reserved for Documentation
  9. if ($_SERVER['REQUEST_URI'] === '/sftpgo-auth.php')
  10. return;
  11. $pageAddress = substr($_SERVER['REQUEST_URI'], strlen(CONF['common']['prefix']) + 1);
  12. if (strpos($pageAddress, "?") !== false) {
  13. parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET);
  14. $pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?"));
  15. }
  16. define("PAGE_URL", $pageAddress);
  17. define("PAGE_ADDRESS", $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : ''));
  18. define("PAGE_LINEAGE", explode('/', PAGE_ADDRESS));
  19. define("SERVICE", dirname(PAGE_ADDRESS));
  20. define("PAGE", basename(PAGE_ADDRESS, '.php'));
  21. require "pages.php";
  22. if (PAGE !== 'index') {
  23. if (!isset(TITLES[SERVICE][PAGE])) {
  24. http_response_code(404);
  25. exit('Page not found.');
  26. }
  27. if (SERVICE !== '.') {
  28. if (!isset(TITLES[SERVICE]['index'])) {
  29. http_response_code(404);
  30. exit('Page not found.');
  31. }
  32. }
  33. }
  34. for (
  35. $path_i = PAGE_LINEAGE , $results = [] , $firstIteration = true ;
  36. $title = TITLES , $path_i !== [] ;
  37. array_pop($path_i) , $results[] = $title
  38. ) {
  39. foreach ($path_i as $el) {
  40. if (end($path_i) !== $el)
  41. $title = $title[$el];
  42. else {
  43. if ($firstIteration AND end($path_i) !== 'index')
  44. $results[] = $title[$el];
  45. $firstIteration = false;
  46. $title = $title['index'];
  47. }
  48. }
  49. }
  50. define('TITLES_LINEAGE', array_reverse($results));
  51. require "html.php";
  52. function executePage() {
  53. require "pages/" . PAGE_ADDRESS . ".php";
  54. closeHtml();
  55. }
  56. executePage();