@@ -36,73 +36,73 @@ |
||
36 | 36 | use Symfony\Component\Console\Output\OutputInterface; |
37 | 37 | |
38 | 38 | class ShowRemnants extends Command { |
39 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
40 | - protected $dui; |
|
39 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
40 | + protected $dui; |
|
41 | 41 | |
42 | - /** @var \OCP\IDateTimeFormatter */ |
|
43 | - protected $dateFormatter; |
|
42 | + /** @var \OCP\IDateTimeFormatter */ |
|
43 | + protected $dateFormatter; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param DeletedUsersIndex $dui |
|
47 | - * @param IDateTimeFormatter $dateFormatter |
|
48 | - */ |
|
49 | - public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
50 | - $this->dui = $dui; |
|
51 | - $this->dateFormatter = $dateFormatter; |
|
52 | - parent::__construct(); |
|
53 | - } |
|
45 | + /** |
|
46 | + * @param DeletedUsersIndex $dui |
|
47 | + * @param IDateTimeFormatter $dateFormatter |
|
48 | + */ |
|
49 | + public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
50 | + $this->dui = $dui; |
|
51 | + $this->dateFormatter = $dateFormatter; |
|
52 | + parent::__construct(); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function configure() { |
|
56 | - $this |
|
57 | - ->setName('ldap:show-remnants') |
|
58 | - ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.') |
|
59 | - ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.') |
|
60 | - ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format'); |
|
61 | - } |
|
55 | + protected function configure() { |
|
56 | + $this |
|
57 | + ->setName('ldap:show-remnants') |
|
58 | + ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.') |
|
59 | + ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.') |
|
60 | + ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format'); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function formatDate(int $timestamp, string $default, bool $showShortDate) { |
|
64 | - if (!($timestamp > 0)) { |
|
65 | - return $default; |
|
66 | - } |
|
67 | - if ($showShortDate) { |
|
68 | - return date('Y-m-d', $timestamp); |
|
69 | - } |
|
70 | - return $this->dateFormatter->formatDate($timestamp); |
|
71 | - } |
|
63 | + protected function formatDate(int $timestamp, string $default, bool $showShortDate) { |
|
64 | + if (!($timestamp > 0)) { |
|
65 | + return $default; |
|
66 | + } |
|
67 | + if ($showShortDate) { |
|
68 | + return date('Y-m-d', $timestamp); |
|
69 | + } |
|
70 | + return $this->dateFormatter->formatDate($timestamp); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted |
|
75 | - * |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
79 | - /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
80 | - $table = new Table($output); |
|
81 | - $table->setHeaders([ |
|
82 | - 'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
83 | - 'Detected on', 'Dir', 'Sharer' |
|
84 | - ]); |
|
85 | - $rows = []; |
|
86 | - $resultSet = $this->dui->getUsers(); |
|
87 | - foreach ($resultSet as $user) { |
|
88 | - $rows[] = [ |
|
89 | - 'ocName' => $user->getOCName(), |
|
90 | - 'displayName' => $user->getDisplayName(), |
|
91 | - 'uid' => $user->getUID(), |
|
92 | - 'dn' => $user->getDN(), |
|
93 | - 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
94 | - 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
95 | - 'homePath' => $user->getHomePath(), |
|
96 | - 'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
|
97 | - ]; |
|
98 | - } |
|
73 | + /** |
|
74 | + * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted |
|
75 | + * |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
79 | + /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
80 | + $table = new Table($output); |
|
81 | + $table->setHeaders([ |
|
82 | + 'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
83 | + 'Detected on', 'Dir', 'Sharer' |
|
84 | + ]); |
|
85 | + $rows = []; |
|
86 | + $resultSet = $this->dui->getUsers(); |
|
87 | + foreach ($resultSet as $user) { |
|
88 | + $rows[] = [ |
|
89 | + 'ocName' => $user->getOCName(), |
|
90 | + 'displayName' => $user->getDisplayName(), |
|
91 | + 'uid' => $user->getUID(), |
|
92 | + 'dn' => $user->getDN(), |
|
93 | + 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
94 | + 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
95 | + 'homePath' => $user->getHomePath(), |
|
96 | + 'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
|
97 | + ]; |
|
98 | + } |
|
99 | 99 | |
100 | - if ($input->getOption('json')) { |
|
101 | - $output->writeln(json_encode($rows)); |
|
102 | - } else { |
|
103 | - $table->setRows($rows); |
|
104 | - $table->render(); |
|
105 | - } |
|
106 | - return 0; |
|
107 | - } |
|
100 | + if ($input->getOption('json')) { |
|
101 | + $output->writeln(json_encode($rows)); |
|
102 | + } else { |
|
103 | + $table->setRows($rows); |
|
104 | + $table->render(); |
|
105 | + } |
|
106 | + return 0; |
|
107 | + } |
|
108 | 108 | } |
@@ -37,78 +37,78 @@ |
||
37 | 37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | 38 | |
39 | 39 | class ShowConfig extends Command { |
40 | - /** @var \OCA\User_LDAP\Helper */ |
|
41 | - protected $helper; |
|
40 | + /** @var \OCA\User_LDAP\Helper */ |
|
41 | + protected $helper; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param Helper $helper |
|
45 | - */ |
|
46 | - public function __construct(Helper $helper) { |
|
47 | - $this->helper = $helper; |
|
48 | - parent::__construct(); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param Helper $helper |
|
45 | + */ |
|
46 | + public function __construct(Helper $helper) { |
|
47 | + $this->helper = $helper; |
|
48 | + parent::__construct(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function configure() { |
|
52 | - $this |
|
53 | - ->setName('ldap:show-config') |
|
54 | - ->setDescription('shows the LDAP configuration') |
|
55 | - ->addArgument( |
|
56 | - 'configID', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'will show the configuration of the specified id' |
|
59 | - ) |
|
60 | - ->addOption( |
|
61 | - 'show-password', |
|
62 | - null, |
|
63 | - InputOption::VALUE_NONE, |
|
64 | - 'show ldap bind password' |
|
65 | - ) |
|
66 | - ; |
|
67 | - } |
|
51 | + protected function configure() { |
|
52 | + $this |
|
53 | + ->setName('ldap:show-config') |
|
54 | + ->setDescription('shows the LDAP configuration') |
|
55 | + ->addArgument( |
|
56 | + 'configID', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'will show the configuration of the specified id' |
|
59 | + ) |
|
60 | + ->addOption( |
|
61 | + 'show-password', |
|
62 | + null, |
|
63 | + InputOption::VALUE_NONE, |
|
64 | + 'show ldap bind password' |
|
65 | + ) |
|
66 | + ; |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
70 | - $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
71 | - $configID = $input->getArgument('configID'); |
|
72 | - if (!is_null($configID)) { |
|
73 | - $configIDs[] = $configID; |
|
74 | - if (!in_array($configIDs[0], $availableConfigs)) { |
|
75 | - $output->writeln("Invalid configID"); |
|
76 | - return 1; |
|
77 | - } |
|
78 | - } else { |
|
79 | - $configIDs = $availableConfigs; |
|
80 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
70 | + $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
71 | + $configID = $input->getArgument('configID'); |
|
72 | + if (!is_null($configID)) { |
|
73 | + $configIDs[] = $configID; |
|
74 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
75 | + $output->writeln("Invalid configID"); |
|
76 | + return 1; |
|
77 | + } |
|
78 | + } else { |
|
79 | + $configIDs = $availableConfigs; |
|
80 | + } |
|
81 | 81 | |
82 | - $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
83 | - return 0; |
|
84 | - } |
|
82 | + $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
83 | + return 0; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * prints the LDAP configuration(s) |
|
88 | - * @param string[] configID(s) |
|
89 | - * @param OutputInterface $output |
|
90 | - * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
91 | - */ |
|
92 | - protected function renderConfigs($configIDs, $output, $withPassword) { |
|
93 | - foreach ($configIDs as $id) { |
|
94 | - $configHolder = new Configuration($id); |
|
95 | - $configuration = $configHolder->getConfiguration(); |
|
96 | - ksort($configuration); |
|
86 | + /** |
|
87 | + * prints the LDAP configuration(s) |
|
88 | + * @param string[] configID(s) |
|
89 | + * @param OutputInterface $output |
|
90 | + * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
91 | + */ |
|
92 | + protected function renderConfigs($configIDs, $output, $withPassword) { |
|
93 | + foreach ($configIDs as $id) { |
|
94 | + $configHolder = new Configuration($id); |
|
95 | + $configuration = $configHolder->getConfiguration(); |
|
96 | + ksort($configuration); |
|
97 | 97 | |
98 | - $table = new Table($output); |
|
99 | - $table->setHeaders(['Configuration', $id]); |
|
100 | - $rows = []; |
|
101 | - foreach ($configuration as $key => $value) { |
|
102 | - if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
103 | - $value = '***'; |
|
104 | - } |
|
105 | - if (is_array($value)) { |
|
106 | - $value = implode(';', $value); |
|
107 | - } |
|
108 | - $rows[] = [$key, $value]; |
|
109 | - } |
|
110 | - $table->setRows($rows); |
|
111 | - $table->render(); |
|
112 | - } |
|
113 | - } |
|
98 | + $table = new Table($output); |
|
99 | + $table->setHeaders(['Configuration', $id]); |
|
100 | + $rows = []; |
|
101 | + foreach ($configuration as $key => $value) { |
|
102 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
103 | + $value = '***'; |
|
104 | + } |
|
105 | + if (is_array($value)) { |
|
106 | + $value = implode(';', $value); |
|
107 | + } |
|
108 | + $rows[] = [$key, $value]; |
|
109 | + } |
|
110 | + $table->setRows($rows); |
|
111 | + $table->render(); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | } |