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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/versioncheck.php';
  32. require_once __DIR__ . '/../lib/base.php';
  33. if (\OCP\Util::needUpgrade()
  34. || \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
  35. // since the behavior of apps or remotes are unpredictable during
  36. // an upgrade, return a 503 directly
  37. http_response_code(503);
  38. $response = new \OC\OCS\Result(null, 503, '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. OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
  54. sleep(1);
  55. OC::$server->getLogger()->info('This uses an old OCP\API::register construct. This will be removed in a future version of Nextcloud. Please migrate to the OCSController');
  56. return;
  57. } catch (ResourceNotFoundException $e) {
  58. // Fall through the not found
  59. } catch (MethodNotAllowedException $e) {
  60. OC_API::setContentType();
  61. http_response_code(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. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  78. $txt='Invalid query, please check the syntax. API specifications are here:'
  79. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
  80. OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  81. } catch (MethodNotAllowedException $e) {
  82. OC_API::setContentType();
  83. http_response_code(405);
  84. } catch (\OC\OCS\Exception $ex) {
  85. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  86. } catch (\OC\User\LoginException $e) {
  87. OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'));
  88. } catch (\Exception $e) {
  89. \OC::$server->getLogger()->logException($e);
  90. OC_API::setContentType();
  91. $format = \OC::$server->getRequest()->getParam('format', 'xml');
  92. $txt='Invalid query, please check the syntax. API specifications are here:'
  93. .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.'."\n";
  94. OC_API::respond(new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format);
  95. }