index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Symfony\Component\ErrorHandler\Debug;
  33. use Symfony\Component\HttpFoundation\Request;
  34. require \dirname(__DIR__) . '/config/bootstrap.php';
  35. if ($_SERVER['APP_DEBUG']) {
  36. umask(0000);
  37. Debug::enable();
  38. }
  39. // When a request passes through a proxy, certain request information is sent using either
  40. // the standard Forwarded header or X-Forwarded-* headers.
  41. // Therefore, if the user configures trusted proxy IPs, we trust these headers.
  42. if ($trustedProxies = $_ENV['TRUSTED_PROXIES'] ?? $_SERVER['TRUSTED_PROXIES'] ?? false) {
  43. Request::setTrustedProxies(
  44. explode(',', $trustedProxies),
  45. Request::HEADER_FORWARDED | Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO,
  46. );
  47. }
  48. // For enhanced security while using Request, here we define the trusted hosts.
  49. // If the incoming request’s hostname doesn't match one of the regular expressions in
  50. // this list, the application won’t respond and the user will receive a 400 response.
  51. if ($trustedHosts = $_ENV['TRUSTED_HOSTS'] ?? $_SERVER['TRUSTED_HOSTS'] ?? false) {
  52. Request::setTrustedHosts([$trustedHosts]);
  53. }
  54. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  55. // Wrap the default Kernel with the CacheKernel one in 'prod' environment
  56. if ('prod' === $kernel->getEnvironment() || isset($_ENV['SOCIAL_USE_CACHE_KERNEL'])) {
  57. $kernel = new CacheKernel($kernel);
  58. }
  59. $request = Request::createFromGlobals();
  60. $response = $kernel->handle($request);
  61. $response->send();
  62. $kernel->terminate($request, $response);