You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v1.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // since the behavior of apps or remotes are unpredictable during
  35. // an upgrade, return a 503 directly
  36. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  37. $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable');
  38. OC_API::respond($response, OC_API::requestedFormat());
  39. exit;
  40. }
  41. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  42. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  43. /*
  44. * Try old routes first
  45. * We first try the old routes since the appframework triggers more login stuff.
  46. */
  47. try {
  48. OC_App::loadApps(['session']);
  49. OC_App::loadApps(['authentication']);
  50. // load all apps to get all api routes properly setup
  51. OC_App::loadApps();
  52. // force language as given in the http request
  53. \OC::$server->getL10NFactory()->setLanguageFromRequest();
  54. OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
  55. return;
  56. } catch (ResourceNotFoundException $e) {
  57. // Fall through the not found
  58. } catch (MethodNotAllowedException $e) {
  59. OC_API::setContentType();
  60. OC_Response::setStatus(405);
  61. exit();
  62. } catch (Exception $ex) {
  63. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  64. exit();
  65. }
  66. /*
  67. * Try the appframework routes
  68. */
  69. try {
  70. if(!\OC::$server->getUserSession()->isLoggedIn()) {
  71. OC::handleLogin(\OC::$server->getRequest());
  72. }
  73. OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
  74. } catch (ResourceNotFoundException $e) {
  75. OC_API::setContentType();
  76. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  77. $txt='Invalid query, please check the syntax. API specifications are here:'
  78. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
  79. OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  80. } catch (MethodNotAllowedException $e) {
  81. OC_API::setContentType();
  82. OC_Response::setStatus(405);
  83. } catch (\OC\OCS\Exception $ex) {
  84. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  85. } catch (\OC\User\LoginException $e) {
  86. OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'));
  87. } catch (\Exception $e) {
  88. \OC::$server->getLogger()->logException($e);
  89. OC_API::setContentType();
  90. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  91. $txt='Invalid query, please check the syntax. API specifications are here:'
  92. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
  93. OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  94. }