Advertisement
Guest User

Untitled

a guest
Jan 29th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  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 Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Sergio Bertolín <sbertolin@solidgear.es>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Petry <vincent@nextcloud.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. require_once __DIR__ . '/lib/versioncheck.php';
  32.  
  33. try {
  34. require_once __DIR__ . '/lib/base.php';
  35.  
  36. OC::handleRequest();
  37. } catch (\OC\ServiceUnavailableException $ex) {
  38. \OC::$server->getLogger()->logException($ex, ['app' => 'index']);
  39.  
  40. //show the user a detailed error page
  41. OC_Template::printExceptionErrorPage($ex, 503);
  42. } catch (\OC\HintException $ex) {
  43. try {
  44. OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
  45. } catch (Exception $ex2) {
  46. try {
  47. \OC::$server->getLogger()->logException($ex, ['app' => 'index']);
  48. \OC::$server->getLogger()->logException($ex2, ['app' => 'index']);
  49. } catch (Throwable $e) {
  50. // no way to log it properly - but to avoid a white page of death we try harder and ignore this one here
  51. }
  52.  
  53. //show the user a detailed error page
  54. OC_Template::printExceptionErrorPage($ex, 500);
  55. }
  56. } catch (\OC\User\LoginException $ex) {
  57. $request = \OC::$server->getRequest();
  58. /**
  59. * Routes with the @CORS annotation and other API endpoints should
  60. * not return a webpage, so we only print the error page when html is accepted,
  61. * otherwise we reply with a JSON array like the SecurityMiddleware would do.
  62. */
  63. if (stripos($request->getHeader('Accept'),'html') === false) {
  64. http_response_code(401);
  65. header('Content-Type: application/json; charset=utf-8');
  66. echo json_encode(['message' => $ex->getMessage()]);
  67. exit();
  68. }
  69. OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
  70. } catch (Exception $ex) {
  71. \OC::$server->getLogger()->logException($ex, ['app' => 'index']);
  72.  
  73. //show the user a detailed error page
  74. OC_Template::printExceptionErrorPage($ex, 500);
  75. } catch (Error $ex) {
  76. try {
  77. \OC::$server->getLogger()->logException($ex, ['app' => 'index']);
  78. } catch (Error $e) {
  79. http_response_code(500);
  80. header('Content-Type: text/plain; charset=utf-8');
  81. print("Internal Server Error\n\n");
  82. print("The server encountered an internal error and was unable to complete your request.\n");
  83. print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
  84. print("More details can be found in the webserver log.\n");
  85.  
  86. throw $ex;
  87. }
  88. OC_Template::printExceptionErrorPage($ex, 500);
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement