v1.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Tom Needham <tom@owncloud.com>
  9. * @author Vincent Petry <pvince81@owncloud.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. require_once '../lib/base.php';
  28. if (\OCP\Util::needUpgrade()
  29. || \OC::$server->getSystemConfig()->getValue('maintenance', false)
  30. || \OC::$server->getSystemConfig()->getValue('singleuser', false)) {
  31. // since the behavior of apps or remotes are unpredictable during
  32. // an upgrade, return a 503 directly
  33. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  34. $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable');
  35. OC_API::respond($response, OC_API::requestedFormat());
  36. exit;
  37. }
  38. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  39. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  40. try {
  41. // load all apps to get all api routes properly setup
  42. OC_App::loadApps();
  43. // force language as given in the http request
  44. \OC_L10N::setLanguageFromRequest();
  45. OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
  46. } catch (ResourceNotFoundException $e) {
  47. OC_API::setContentType();
  48. OC_OCS::notFound();
  49. } catch (MethodNotAllowedException $e) {
  50. OC_API::setContentType();
  51. OC_Response::setStatus(405);
  52. } catch (\OC\OCS\Exception $ex) {
  53. OC_API::respond($ex->getResult(), OC_API::requestedFormat());
  54. }