getNewServerConfigPrefix.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. // Check user and app status
  27. \OC_JSON::checkAdminUser();
  28. \OC_JSON::checkAppEnabled('user_ldap');
  29. \OC_JSON::callCheck();
  30. $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
  31. $serverConnections = $helper->getServerConfigurationPrefixes();
  32. sort($serverConnections);
  33. $lk = array_pop($serverConnections);
  34. $ln = (int)str_replace('s', '', $lk);
  35. $nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT);
  36. $resultData = ['configPrefix' => $nk];
  37. $newConfig = new \OCA\User_LDAP\Configuration($nk, false);
  38. if(isset($_POST['copyConfig'])) {
  39. $originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']);
  40. $newConfig->setConfiguration($originalConfig->getConfiguration());
  41. } else {
  42. $configuration = new \OCA\User_LDAP\Configuration($nk, false);
  43. $newConfig->setConfiguration($configuration->getDefaults());
  44. $resultData['defaults'] = $configuration->getDefaults();
  45. }
  46. $newConfig->saveConfiguration();
  47. \OC_JSON::success($resultData);