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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
  53. return;
  54. } catch (ResourceNotFoundException $e) {
  55. // Fall through the not found
  56. } catch (MethodNotAllowedException $e) {
  57. OC_API::setContentType();
  58. OC_Response::setStatus(405);
  59. exit();
  60. } catch (Exception $ex) {
  61. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  62. exit();
  63. }
  64. /*
  65. * Try the appframework routes
  66. */
  67. try {
  68. if(!\OC::$server->getUserSession()->isLoggedIn()) {
  69. OC::handleLogin(\OC::$server->getRequest());
  70. }
  71. OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
  72. } catch (ResourceNotFoundException $e) {
  73. OC_API::setContentType();
  74. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  75. $txt='Invalid query, please check the syntax. API specifications are here:'
  76. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
  77. OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  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::$server->getLogger()->logException($e);
  87. OC_API::setContentType();
  88. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  89. $txt='Invalid query, please check the syntax. API specifications are here:'
  90. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
  91. OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  92. }