1
0

getNewServerConfigPrefix.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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. // Check user and app status
  26. \OC_JSON::checkAdminUser();
  27. \OC_JSON::checkAppEnabled('user_ldap');
  28. \OC_JSON::callCheck();
  29. $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
  30. $serverConnections = $helper->getServerConfigurationPrefixes();
  31. sort($serverConnections);
  32. $lk = array_pop($serverConnections);
  33. $ln = (int)str_replace('s', '', $lk);
  34. $nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT);
  35. $resultData = array('configPrefix' => $nk);
  36. $newConfig = new \OCA\User_LDAP\Configuration($nk, false);
  37. if(isset($_POST['copyConfig'])) {
  38. $originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']);
  39. $newConfig->setConfiguration($originalConfig->getConfiguration());
  40. } else {
  41. $configuration = new \OCA\User_LDAP\Configuration($nk, false);
  42. $newConfig->setConfiguration($configuration->getDefaults());
  43. $resultData['defaults'] = $configuration->getDefaults();
  44. }
  45. $newConfig->saveConfiguration();
  46. \OC_JSON::success($resultData);