1
0

index.php 3.3 KB

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