appconfig.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. OC_Util::checkAdminUser();
  26. OCP\JSON::callCheck();
  27. $action=isset($_POST['action'])?$_POST['action']:$_GET['action'];
  28. if(isset($_POST['app']) || isset($_GET['app'])) {
  29. $app=OC_App::cleanAppId(isset($_POST['app'])? (string)$_POST['app']: (string)$_GET['app']);
  30. }
  31. // An admin should not be able to add remote and public services
  32. // on its own. This should only be possible programmatically.
  33. // This change is due the fact that an admin may not be expected
  34. // to execute arbitrary code in every environment.
  35. if($app === 'core' && isset($_POST['key']) &&(substr((string)$_POST['key'],0,7) === 'remote_' || substr((string)$_POST['key'],0,7) === 'public_')) {
  36. OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
  37. return;
  38. }
  39. $result=false;
  40. $appConfig = \OC::$server->getAppConfig();
  41. switch($action) {
  42. case 'getValue':
  43. $result=$appConfig->getValue($app, (string)$_GET['key'], (string)$_GET['defaultValue']);
  44. break;
  45. case 'setValue':
  46. $result=$appConfig->setValue($app, (string)$_POST['key'], (string)$_POST['value']);
  47. break;
  48. case 'getApps':
  49. $result=$appConfig->getApps();
  50. break;
  51. case 'getKeys':
  52. $result=$appConfig->getKeys($app);
  53. break;
  54. case 'hasKey':
  55. $result=$appConfig->hasKey($app, (string)$_GET['key']);
  56. break;
  57. case 'deleteKey':
  58. $result=$appConfig->deleteKey($app, (string)$_POST['key']);
  59. break;
  60. case 'deleteApp':
  61. $result=$appConfig->deleteApp($app);
  62. break;
  63. }
  64. OC_JSON::success(array('data'=>$result));