index.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. *
  4. * Your webserver seems to be not configured to use PHP or PHP is not installed.
  5. * Please contact your administrator or follow our documentation:
  6. * https://docs.nextcloud.com/server/13/admin_manual/installation/source_installation.html
  7. *
  8. * @copyright Copyright (c) 2016, ownCloud, Inc.
  9. *
  10. * @author Georg Ehrke <oc.list@georgehrke.com>
  11. * @author Joas Schilling <coding@schilljs.com>
  12. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  13. * @author Lukas Reschke <lukas@statuscode.ch>
  14. * @author Morris Jobke <hey@morrisjobke.de>
  15. * @author Robin Appelman <robin@icewind.nl>
  16. * @author Sergio Bertolín <sbertolin@solidgear.es>
  17. * @author Thomas Müller <thomas.mueller@tmit.eu>
  18. * @author Vincent Petry <pvince81@owncloud.com>
  19. *
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. require_once __DIR__ . '/lib/versioncheck.php';
  36. try {
  37. require_once __DIR__ . '/lib/base.php';
  38. OC::handleRequest();
  39. } catch(\OC\ServiceUnavailableException $ex) {
  40. \OC::$server->getLogger()->logException($ex, array('app' => 'index'));
  41. //show the user a detailed error page
  42. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  43. OC_Template::printExceptionErrorPage($ex);
  44. } catch (\OC\HintException $ex) {
  45. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  46. try {
  47. OC_Template::printErrorPage($ex->getMessage(), $ex->getHint());
  48. } catch (Exception $ex2) {
  49. \OC::$server->getLogger()->logException($ex, array('app' => 'index'));
  50. \OC::$server->getLogger()->logException($ex2, array('app' => 'index'));
  51. //show the user a detailed error page
  52. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  53. OC_Template::printExceptionErrorPage($ex);
  54. }
  55. } catch (\OC\User\LoginException $ex) {
  56. OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN);
  57. OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage());
  58. } catch (Exception $ex) {
  59. \OC::$server->getLogger()->logException($ex, array('app' => 'index'));
  60. //show the user a detailed error page
  61. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  62. OC_Template::printExceptionErrorPage($ex);
  63. } catch (Error $ex) {
  64. try {
  65. \OC::$server->getLogger()->logException($ex, array('app' => 'index'));
  66. } catch (Error $e) {
  67. $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
  68. $validProtocols = [
  69. 'HTTP/1.0',
  70. 'HTTP/1.1',
  71. 'HTTP/2',
  72. ];
  73. $protocol = 'HTTP/1.1';
  74. if(in_array($claimedProtocol, $validProtocols, true)) {
  75. $protocol = $claimedProtocol;
  76. }
  77. header($protocol . ' 500 Internal Server Error');
  78. header('Content-Type: text/plain; charset=utf-8');
  79. print("Internal Server Error\n\n");
  80. print("The server encountered an internal error and was unable to complete your request.\n");
  81. print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
  82. print("More details can be found in the webserver log.\n");
  83. throw $e;
  84. }
  85. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  86. OC_Template::printExceptionErrorPage($ex);
  87. }