index.php 2.7 KB

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