appconfig.php 2.3 KB

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