v1.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  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 Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Tom Needham <tom@owncloud.com>
  14. * @author Vincent Petry <pvince81@owncloud.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/base.php';
  32. if (\OCP\Util::needUpgrade()
  33. || \OC::$server->getSystemConfig()->getValue('maintenance', false)
  34. || \OC::$server->getSystemConfig()->getValue('singleuser', false)) {
  35. // since the behavior of apps or remotes are unpredictable during
  36. // an upgrade, return a 503 directly
  37. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  38. $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable');
  39. OC_API::respond($response, OC_API::requestedFormat());
  40. exit;
  41. }
  42. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  43. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  44. /*
  45. * Try old routes first
  46. * We first try the old routes since the appframework triggers more login stuff.
  47. */
  48. try {
  49. OC_App::loadApps(['session']);
  50. OC_App::loadApps(['authentication']);
  51. // load all apps to get all api routes properly setup
  52. OC_App::loadApps();
  53. // force language as given in the http request
  54. \OC::$server->getL10NFactory()->setLanguageFromRequest();
  55. OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
  56. return;
  57. } catch (ResourceNotFoundException $e) {
  58. // Fall through the not found
  59. } catch (MethodNotAllowedException $e) {
  60. OC_API::setContentType();
  61. OC_Response::setStatus(405);
  62. exit();
  63. } catch (Exception $ex) {
  64. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  65. exit();
  66. }
  67. /*
  68. * Try the appframework routes
  69. */
  70. try {
  71. if(!\OC::$server->getUserSession()->isLoggedIn()) {
  72. OC::handleLogin(\OC::$server->getRequest());
  73. }
  74. OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
  75. } catch (ResourceNotFoundException $e) {
  76. OC_API::setContentType();
  77. OC_OCS::notFound();
  78. } catch (MethodNotAllowedException $e) {
  79. OC_API::setContentType();
  80. OC_Response::setStatus(405);
  81. } catch (\OC\OCS\Exception $ex) {
  82. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  83. } catch (\OC\User\LoginException $e) {
  84. OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'));
  85. } catch (\Exception $e) {
  86. OC_API::setContentType();
  87. OC_OCS::notFound();
  88. }