index.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare(strict_types = 1);
  3. /*
  4. * This file is part of GNU social - https://www.gnu.org/software/social
  5. *
  6. * GNU social is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GNU social is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * GNU social's true web entry point, bootstraps Symfony's configuration and instantiates our Kernel
  21. *
  22. * @package GNUsocial
  23. * @category Framework
  24. *
  25. * @author Hugo Sales <hugo@hsal.es>
  26. * @author Diogo Peralta Cordeiro <mail@diogo.site>
  27. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  28. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  29. */
  30. use App\CacheKernel;
  31. use App\Kernel;
  32. use App\Core\Security;
  33. use Symfony\Component\ErrorHandler\Debug;
  34. use Symfony\Component\HttpFoundation\Request;
  35. require \dirname(__DIR__) . '/config/bootstrap.php';
  36. if ($_SERVER['APP_DEBUG']) {
  37. umask(0000);
  38. Debug::enable();
  39. }
  40. // When a request passes through a proxy, certain request information is sent using either
  41. // the standard Forwarded header or X-Forwarded-* headers.
  42. // Therefore, if the user configures trusted proxy IPs, we trust these headers.
  43. if ($trustedProxies = $_ENV['TRUSTED_PROXIES'] ?? $_SERVER['TRUSTED_PROXIES'] ?? false) {
  44. Request::setTrustedProxies(
  45. explode(',', $trustedProxies),
  46. Request::HEADER_FORWARDED | Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO,
  47. );
  48. }
  49. // For enhanced security while using Request, here we define the trusted hosts.
  50. // If the incoming request’s hostname doesn't match one of the regular expressions in
  51. // this list, the application won’t respond and the user will receive a 400 response.
  52. if ($trustedHosts = $_ENV['TRUSTED_HOSTS'] ?? $_SERVER['TRUSTED_HOSTS'] ?? false) {
  53. Request::setTrustedHosts([$trustedHosts]);
  54. }
  55. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  56. // Wrap the default Kernel with the CacheKernel one in 'prod' environment
  57. if ('prod' === $kernel->getEnvironment() || isset($_ENV['CONFIG_USE_CACHE_KERNEL'])) {
  58. $kernel = new CacheKernel($kernel);
  59. }
  60. $request = Request::createFromGlobals();
  61. Security::harden();
  62. $response = $kernel->handle($request);
  63. $response->send();
  64. $kernel->terminate($request, $response);