2014-06-03 06:35:18 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 10:49:16 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 05:57:22 -04:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
2014-06-03 06:35:18 -04:00
|
|
|
*/
|
2016-05-12 03:59:29 -04:00
|
|
|
namespace OCA\User_LDAP\Command;
|
2014-06-03 06:35:18 -04:00
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\User_LDAP\Configuration;
|
2018-12-16 18:31:27 -05:00
|
|
|
use OCA\User_LDAP\ConnectionFactory;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\User_LDAP\Helper;
|
2018-12-16 18:31:27 -05:00
|
|
|
use OCA\User_LDAP\LDAP;
|
2014-06-03 06:35:18 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class SetConfig extends Command {
|
|
|
|
|
protected function configure() {
|
|
|
|
|
$this
|
|
|
|
|
->setName('ldap:set-config')
|
2014-06-03 06:36:42 -04:00
|
|
|
->setDescription('modifies an LDAP configuration')
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
|
|
|
|
'configID',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the configuration ID'
|
2020-04-09 03:22:29 -04:00
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
|
|
|
|
'configKey',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the configuration key'
|
2020-04-09 03:22:29 -04:00
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
|
|
|
|
'configValue',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the new configuration value'
|
2020-04-09 03:22:29 -04:00
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 09:12:11 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2020-11-06 05:25:28 -05:00
|
|
|
$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
|
2014-08-21 11:59:13 -04:00
|
|
|
$availableConfigs = $helper->getServerConfigurationPrefixes();
|
2014-06-03 06:35:18 -04:00
|
|
|
$configID = $input->getArgument('configID');
|
2020-04-10 08:19:56 -04:00
|
|
|
if (!in_array($configID, $availableConfigs)) {
|
2014-06-03 06:35:18 -04:00
|
|
|
$output->writeln("Invalid configID");
|
2020-06-26 09:12:11 -04:00
|
|
|
return 1;
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setValue(
|
|
|
|
|
$configID,
|
|
|
|
|
$input->getArgument('configKey'),
|
|
|
|
|
$input->getArgument('configValue')
|
|
|
|
|
);
|
2020-06-26 09:12:11 -04:00
|
|
|
return 0;
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* save the configuration value as provided
|
2014-06-03 13:10:18 -04:00
|
|
|
* @param string $configID
|
|
|
|
|
* @param string $configKey
|
|
|
|
|
* @param string $configValue
|
2014-06-03 06:35:18 -04:00
|
|
|
*/
|
|
|
|
|
protected function setValue($configID, $key, $value) {
|
|
|
|
|
$configHolder = new Configuration($configID);
|
|
|
|
|
$configHolder->$key = $value;
|
|
|
|
|
$configHolder->saveConfiguration();
|
2018-12-16 18:31:27 -05:00
|
|
|
|
|
|
|
|
$connectionFactory = new ConnectionFactory(new LDAP());
|
|
|
|
|
$connectionFactory->get($configID)->clearCache();
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
}
|