enableapp.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Kamil Domanski <kdomanski@kdemail.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. OC_JSON::checkAdminUser();
  29. OCP\JSON::callCheck();
  30. $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
  31. if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
  32. $l = \OC::$server->getL10N('core');
  33. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
  34. exit();
  35. }
  36. $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null;
  37. try {
  38. $app = new OC_App();
  39. $appId = (string)$_POST['appid'];
  40. $appId = OC_App::cleanAppId($appId);
  41. $app->enable($appId, $groups);
  42. OC_JSON::success(['data' => ['update_required' => \OC_App::shouldUpgrade($appId)]]);
  43. } catch (Exception $e) {
  44. \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR);
  45. OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
  46. }