v1.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 '../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. } catch (\OC\OCS\Exception $ex) {
  63. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  64. }
  65. /*
  66. * Try the appframework routes
  67. */
  68. try {
  69. if(!\OC::$server->getUserSession()->isLoggedIn()) {
  70. OC::handleLogin(\OC::$server->getRequest());
  71. }
  72. OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
  73. } catch (ResourceNotFoundException $e) {
  74. OC_API::setContentType();
  75. OC_OCS::notFound();
  76. } catch (MethodNotAllowedException $e) {
  77. OC_API::setContentType();
  78. OC_Response::setStatus(405);
  79. } catch (\OC\OCS\Exception $ex) {
  80. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  81. } catch (\OC\User\LoginException $e) {
  82. OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'));
  83. } catch (\Exception $e) {
  84. OC_API::setContentType();
  85. OC_OCS::notFound();
  86. }