You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

showconfig.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Laurens Post <Crote@users.noreply.github.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\user_ldap\Command;
  24. use Symfony\Component\Console\Command\Command;
  25. use Symfony\Component\Console\Input\InputArgument;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Input\InputOption;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. use \OCA\user_ldap\lib\Helper;
  30. use \OCA\user_ldap\lib\Configuration;
  31. class ShowConfig extends Command {
  32. /** @var \OCA\User_LDAP\lib\Helper */
  33. protected $helper;
  34. /**
  35. * @param Helper $helper
  36. */
  37. public function __construct(Helper $helper) {
  38. $this->helper = $helper;
  39. parent::__construct();
  40. }
  41. protected function configure() {
  42. $this
  43. ->setName('ldap:show-config')
  44. ->setDescription('shows the LDAP configuration')
  45. ->addArgument(
  46. 'configID',
  47. InputArgument::OPTIONAL,
  48. 'will show the configuration of the specified id'
  49. )
  50. ->addOption(
  51. 'show-password',
  52. null,
  53. InputOption::VALUE_NONE,
  54. 'show ldap bind password'
  55. )
  56. ;
  57. }
  58. protected function execute(InputInterface $input, OutputInterface $output) {
  59. $availableConfigs = $this->helper->getServerConfigurationPrefixes();
  60. $configID = $input->getArgument('configID');
  61. if(!is_null($configID)) {
  62. $configIDs[] = $configID;
  63. if(!in_array($configIDs[0], $availableConfigs)) {
  64. $output->writeln("Invalid configID");
  65. return;
  66. }
  67. } else {
  68. $configIDs = $availableConfigs;
  69. }
  70. $this->renderConfigs($configIDs, $output, $input->getOption('show-password'));
  71. }
  72. /**
  73. * prints the LDAP configuration(s)
  74. * @param string[] configID(s)
  75. * @param OutputInterface $output
  76. * @param bool $withPassword Set to TRUE to show plaintext passwords in output
  77. */
  78. protected function renderConfigs($configIDs, $output, $withPassword) {
  79. foreach($configIDs as $id) {
  80. $configHolder = new Configuration($id);
  81. $configuration = $configHolder->getConfiguration();
  82. ksort($configuration);
  83. $table = $this->getHelperSet()->get('table');
  84. $table->setHeaders(array('Configuration', $id));
  85. $rows = array();
  86. foreach($configuration as $key => $value) {
  87. if($key === 'ldapAgentPassword' && !$withPassword) {
  88. $value = '***';
  89. }
  90. if(is_array($value)) {
  91. $value = implode(';', $value);
  92. }
  93. $rows[] = array($key, $value);
  94. }
  95. $table->setRows($rows);
  96. $table->render($output);
  97. }
  98. }
  99. }