@@ -34,44 +34,44 @@ |
||
34 | 34 | |
35 | 35 | class CreateAddressBook extends Command { |
36 | 36 | |
37 | - /** @var IUserManager */ |
|
38 | - private $userManager; |
|
37 | + /** @var IUserManager */ |
|
38 | + private $userManager; |
|
39 | 39 | |
40 | - /** @var CardDavBackend */ |
|
41 | - private $cardDavBackend; |
|
40 | + /** @var CardDavBackend */ |
|
41 | + private $cardDavBackend; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param IUserManager $userManager |
|
45 | - * @param CardDavBackend $cardDavBackend |
|
46 | - */ |
|
47 | - public function __construct(IUserManager $userManager, |
|
48 | - CardDavBackend $cardDavBackend |
|
49 | - ) { |
|
50 | - parent::__construct(); |
|
51 | - $this->userManager = $userManager; |
|
52 | - $this->cardDavBackend = $cardDavBackend; |
|
53 | - } |
|
43 | + /** |
|
44 | + * @param IUserManager $userManager |
|
45 | + * @param CardDavBackend $cardDavBackend |
|
46 | + */ |
|
47 | + public function __construct(IUserManager $userManager, |
|
48 | + CardDavBackend $cardDavBackend |
|
49 | + ) { |
|
50 | + parent::__construct(); |
|
51 | + $this->userManager = $userManager; |
|
52 | + $this->cardDavBackend = $cardDavBackend; |
|
53 | + } |
|
54 | 54 | |
55 | - protected function configure() { |
|
56 | - $this |
|
57 | - ->setName('dav:create-addressbook') |
|
58 | - ->setDescription('Create a dav addressbook') |
|
59 | - ->addArgument('user', |
|
60 | - InputArgument::REQUIRED, |
|
61 | - 'User for whom the addressbook will be created') |
|
62 | - ->addArgument('name', |
|
63 | - InputArgument::REQUIRED, |
|
64 | - 'Name of the addressbook'); |
|
65 | - } |
|
55 | + protected function configure() { |
|
56 | + $this |
|
57 | + ->setName('dav:create-addressbook') |
|
58 | + ->setDescription('Create a dav addressbook') |
|
59 | + ->addArgument('user', |
|
60 | + InputArgument::REQUIRED, |
|
61 | + 'User for whom the addressbook will be created') |
|
62 | + ->addArgument('name', |
|
63 | + InputArgument::REQUIRED, |
|
64 | + 'Name of the addressbook'); |
|
65 | + } |
|
66 | 66 | |
67 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
68 | - $user = $input->getArgument('user'); |
|
69 | - if (!$this->userManager->userExists($user)) { |
|
70 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
71 | - } |
|
67 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
68 | + $user = $input->getArgument('user'); |
|
69 | + if (!$this->userManager->userExists($user)) { |
|
70 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
71 | + } |
|
72 | 72 | |
73 | - $name = $input->getArgument('name'); |
|
74 | - $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
75 | - return 0; |
|
76 | - } |
|
73 | + $name = $input->getArgument('name'); |
|
74 | + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
75 | + return 0; |
|
76 | + } |
|
77 | 77 | } |
@@ -38,87 +38,87 @@ |
||
38 | 38 | |
39 | 39 | class SyncBirthdayCalendar extends Command { |
40 | 40 | |
41 | - /** @var BirthdayService */ |
|
42 | - private $birthdayService; |
|
43 | - |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - |
|
47 | - /** @var IUserManager */ |
|
48 | - private $userManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param IUserManager $userManager |
|
52 | - * @param IConfig $config |
|
53 | - * @param BirthdayService $birthdayService |
|
54 | - */ |
|
55 | - public function __construct(IUserManager $userManager, IConfig $config, |
|
56 | - BirthdayService $birthdayService) { |
|
57 | - parent::__construct(); |
|
58 | - $this->birthdayService = $birthdayService; |
|
59 | - $this->config = $config; |
|
60 | - $this->userManager = $userManager; |
|
61 | - } |
|
62 | - |
|
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('dav:sync-birthday-calendar') |
|
66 | - ->setDescription('Synchronizes the birthday calendar') |
|
67 | - ->addArgument('user', |
|
68 | - InputArgument::OPTIONAL, |
|
69 | - 'User for whom the birthday calendar will be synchronized'); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param InputInterface $input |
|
74 | - * @param OutputInterface $output |
|
75 | - */ |
|
76 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
77 | - $this->verifyEnabled(); |
|
78 | - |
|
79 | - $user = $input->getArgument('user'); |
|
80 | - if (!is_null($user)) { |
|
81 | - if (!$this->userManager->userExists($user)) { |
|
82 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
83 | - } |
|
84 | - |
|
85 | - // re-enable the birthday calendar in case it's called directly with a user name |
|
86 | - $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
87 | - if ($isEnabled !== 'yes') { |
|
88 | - $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
89 | - $output->writeln("Re-enabling birthday calendar for $user"); |
|
90 | - } |
|
91 | - |
|
92 | - $output->writeln("Start birthday calendar sync for $user"); |
|
93 | - $this->birthdayService->syncUser($user); |
|
94 | - return 0; |
|
95 | - } |
|
96 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
97 | - $p = new ProgressBar($output); |
|
98 | - $p->start(); |
|
99 | - $this->userManager->callForSeenUsers(function ($user) use ($p) { |
|
100 | - $p->advance(); |
|
101 | - |
|
102 | - $userId = $user->getUID(); |
|
103 | - $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
104 | - if ($isEnabled !== 'yes') { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - /** @var IUser $user */ |
|
109 | - $this->birthdayService->syncUser($user->getUID()); |
|
110 | - }); |
|
111 | - |
|
112 | - $p->finish(); |
|
113 | - $output->writeln(''); |
|
114 | - return 0; |
|
115 | - } |
|
116 | - |
|
117 | - protected function verifyEnabled() { |
|
118 | - $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
119 | - |
|
120 | - if ($isEnabled !== 'yes') { |
|
121 | - throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
122 | - } |
|
123 | - } |
|
41 | + /** @var BirthdayService */ |
|
42 | + private $birthdayService; |
|
43 | + |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + |
|
47 | + /** @var IUserManager */ |
|
48 | + private $userManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param IUserManager $userManager |
|
52 | + * @param IConfig $config |
|
53 | + * @param BirthdayService $birthdayService |
|
54 | + */ |
|
55 | + public function __construct(IUserManager $userManager, IConfig $config, |
|
56 | + BirthdayService $birthdayService) { |
|
57 | + parent::__construct(); |
|
58 | + $this->birthdayService = $birthdayService; |
|
59 | + $this->config = $config; |
|
60 | + $this->userManager = $userManager; |
|
61 | + } |
|
62 | + |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('dav:sync-birthday-calendar') |
|
66 | + ->setDescription('Synchronizes the birthday calendar') |
|
67 | + ->addArgument('user', |
|
68 | + InputArgument::OPTIONAL, |
|
69 | + 'User for whom the birthday calendar will be synchronized'); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param InputInterface $input |
|
74 | + * @param OutputInterface $output |
|
75 | + */ |
|
76 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
77 | + $this->verifyEnabled(); |
|
78 | + |
|
79 | + $user = $input->getArgument('user'); |
|
80 | + if (!is_null($user)) { |
|
81 | + if (!$this->userManager->userExists($user)) { |
|
82 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
83 | + } |
|
84 | + |
|
85 | + // re-enable the birthday calendar in case it's called directly with a user name |
|
86 | + $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
87 | + if ($isEnabled !== 'yes') { |
|
88 | + $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
89 | + $output->writeln("Re-enabling birthday calendar for $user"); |
|
90 | + } |
|
91 | + |
|
92 | + $output->writeln("Start birthday calendar sync for $user"); |
|
93 | + $this->birthdayService->syncUser($user); |
|
94 | + return 0; |
|
95 | + } |
|
96 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
97 | + $p = new ProgressBar($output); |
|
98 | + $p->start(); |
|
99 | + $this->userManager->callForSeenUsers(function ($user) use ($p) { |
|
100 | + $p->advance(); |
|
101 | + |
|
102 | + $userId = $user->getUID(); |
|
103 | + $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
104 | + if ($isEnabled !== 'yes') { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + /** @var IUser $user */ |
|
109 | + $this->birthdayService->syncUser($user->getUID()); |
|
110 | + }); |
|
111 | + |
|
112 | + $p->finish(); |
|
113 | + $output->writeln(''); |
|
114 | + return 0; |
|
115 | + } |
|
116 | + |
|
117 | + protected function verifyEnabled() { |
|
118 | + $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
119 | + |
|
120 | + if ($isEnabled !== 'yes') { |
|
121 | + throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
122 | + } |
|
123 | + } |
|
124 | 124 | } |
@@ -37,133 +37,133 @@ |
||
37 | 37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | 38 | |
39 | 39 | class CheckUser extends Command { |
40 | - /** @var User_Proxy */ |
|
41 | - protected $backend; |
|
42 | - |
|
43 | - /** @var Helper */ |
|
44 | - protected $helper; |
|
45 | - |
|
46 | - /** @var DeletedUsersIndex */ |
|
47 | - protected $dui; |
|
48 | - |
|
49 | - /** @var UserMapping */ |
|
50 | - protected $mapping; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param User_Proxy $uBackend |
|
54 | - * @param Helper $helper |
|
55 | - * @param DeletedUsersIndex $dui |
|
56 | - * @param UserMapping $mapping |
|
57 | - */ |
|
58 | - public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
59 | - $this->backend = $uBackend; |
|
60 | - $this->helper = $helper; |
|
61 | - $this->dui = $dui; |
|
62 | - $this->mapping = $mapping; |
|
63 | - parent::__construct(); |
|
64 | - } |
|
65 | - |
|
66 | - protected function configure() { |
|
67 | - $this |
|
68 | - ->setName('ldap:check-user') |
|
69 | - ->setDescription('checks whether a user exists on LDAP.') |
|
70 | - ->addArgument( |
|
71 | - 'ocName', |
|
72 | - InputArgument::REQUIRED, |
|
73 | - 'the user name as used in Nextcloud' |
|
74 | - ) |
|
75 | - ->addOption( |
|
76 | - 'force', |
|
77 | - null, |
|
78 | - InputOption::VALUE_NONE, |
|
79 | - 'ignores disabled LDAP configuration' |
|
80 | - ) |
|
81 | - ->addOption( |
|
82 | - 'update', |
|
83 | - null, |
|
84 | - InputOption::VALUE_NONE, |
|
85 | - 'syncs values from LDAP' |
|
86 | - ) |
|
87 | - ; |
|
88 | - } |
|
89 | - |
|
90 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
91 | - try { |
|
92 | - $uid = $input->getArgument('ocName'); |
|
93 | - $this->isAllowed($input->getOption('force')); |
|
94 | - $this->confirmUserIsMapped($uid); |
|
95 | - $exists = $this->backend->userExistsOnLDAP($uid); |
|
96 | - if ($exists === true) { |
|
97 | - $output->writeln('The user is still available on LDAP.'); |
|
98 | - if ($input->getOption('update')) { |
|
99 | - $this->updateUser($uid, $output); |
|
100 | - } |
|
101 | - return 0; |
|
102 | - } |
|
103 | - |
|
104 | - $this->dui->markUser($uid); |
|
105 | - $output->writeln('The user does not exists on LDAP anymore.'); |
|
106 | - $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
107 | - . $uid . '"'); |
|
108 | - return 0; |
|
109 | - } catch (\Exception $e) { |
|
110 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
111 | - return 1; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * checks whether a user is actually mapped |
|
117 | - * @param string $ocName the username as used in Nextcloud |
|
118 | - * @throws \Exception |
|
119 | - * @return true |
|
120 | - */ |
|
121 | - protected function confirmUserIsMapped($ocName) { |
|
122 | - $dn = $this->mapping->getDNByName($ocName); |
|
123 | - if ($dn === false) { |
|
124 | - throw new \Exception('The given user is not a recognized LDAP user.'); |
|
125 | - } |
|
126 | - |
|
127 | - return true; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * checks whether the setup allows reliable checking of LDAP user existence |
|
132 | - * @throws \Exception |
|
133 | - * @return true |
|
134 | - */ |
|
135 | - protected function isAllowed($force) { |
|
136 | - if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
137 | - throw new \Exception('Cannot check user existence, because ' |
|
138 | - . 'disabled LDAP configurations are present.'); |
|
139 | - } |
|
140 | - |
|
141 | - // we don't check ldapUserCleanupInterval from config.php because this |
|
142 | - // action is triggered manually, while the setting only controls the |
|
143 | - // background job. |
|
144 | - |
|
145 | - return true; |
|
146 | - } |
|
147 | - |
|
148 | - private function updateUser(string $uid, OutputInterface $output): void { |
|
149 | - try { |
|
150 | - $access = $this->backend->getLDAPAccess($uid); |
|
151 | - $attrs = $access->userManager->getAttributes(); |
|
152 | - $user = $access->userManager->get($uid); |
|
153 | - $avatarAttributes = $access->getConnection()->resolveRule('avatar'); |
|
154 | - $result = $access->search('objectclass=*', $user->getDN(), $attrs, 1, 0); |
|
155 | - foreach ($result[0] as $attribute => $valueSet) { |
|
156 | - $output->writeln(' ' . $attribute . ': '); |
|
157 | - foreach ($valueSet as $value) { |
|
158 | - if (in_array($attribute, $avatarAttributes)) { |
|
159 | - $value = '{ImageData}'; |
|
160 | - } |
|
161 | - $output->writeln(' ' . $value); |
|
162 | - } |
|
163 | - } |
|
164 | - $access->batchApplyUserAttributes($result); |
|
165 | - } catch (\Exception $e) { |
|
166 | - $output->writeln('<error>Error while trying to lookup and update attributes from LDAP</error>'); |
|
167 | - } |
|
168 | - } |
|
40 | + /** @var User_Proxy */ |
|
41 | + protected $backend; |
|
42 | + |
|
43 | + /** @var Helper */ |
|
44 | + protected $helper; |
|
45 | + |
|
46 | + /** @var DeletedUsersIndex */ |
|
47 | + protected $dui; |
|
48 | + |
|
49 | + /** @var UserMapping */ |
|
50 | + protected $mapping; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param User_Proxy $uBackend |
|
54 | + * @param Helper $helper |
|
55 | + * @param DeletedUsersIndex $dui |
|
56 | + * @param UserMapping $mapping |
|
57 | + */ |
|
58 | + public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
59 | + $this->backend = $uBackend; |
|
60 | + $this->helper = $helper; |
|
61 | + $this->dui = $dui; |
|
62 | + $this->mapping = $mapping; |
|
63 | + parent::__construct(); |
|
64 | + } |
|
65 | + |
|
66 | + protected function configure() { |
|
67 | + $this |
|
68 | + ->setName('ldap:check-user') |
|
69 | + ->setDescription('checks whether a user exists on LDAP.') |
|
70 | + ->addArgument( |
|
71 | + 'ocName', |
|
72 | + InputArgument::REQUIRED, |
|
73 | + 'the user name as used in Nextcloud' |
|
74 | + ) |
|
75 | + ->addOption( |
|
76 | + 'force', |
|
77 | + null, |
|
78 | + InputOption::VALUE_NONE, |
|
79 | + 'ignores disabled LDAP configuration' |
|
80 | + ) |
|
81 | + ->addOption( |
|
82 | + 'update', |
|
83 | + null, |
|
84 | + InputOption::VALUE_NONE, |
|
85 | + 'syncs values from LDAP' |
|
86 | + ) |
|
87 | + ; |
|
88 | + } |
|
89 | + |
|
90 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
91 | + try { |
|
92 | + $uid = $input->getArgument('ocName'); |
|
93 | + $this->isAllowed($input->getOption('force')); |
|
94 | + $this->confirmUserIsMapped($uid); |
|
95 | + $exists = $this->backend->userExistsOnLDAP($uid); |
|
96 | + if ($exists === true) { |
|
97 | + $output->writeln('The user is still available on LDAP.'); |
|
98 | + if ($input->getOption('update')) { |
|
99 | + $this->updateUser($uid, $output); |
|
100 | + } |
|
101 | + return 0; |
|
102 | + } |
|
103 | + |
|
104 | + $this->dui->markUser($uid); |
|
105 | + $output->writeln('The user does not exists on LDAP anymore.'); |
|
106 | + $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
107 | + . $uid . '"'); |
|
108 | + return 0; |
|
109 | + } catch (\Exception $e) { |
|
110 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
111 | + return 1; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * checks whether a user is actually mapped |
|
117 | + * @param string $ocName the username as used in Nextcloud |
|
118 | + * @throws \Exception |
|
119 | + * @return true |
|
120 | + */ |
|
121 | + protected function confirmUserIsMapped($ocName) { |
|
122 | + $dn = $this->mapping->getDNByName($ocName); |
|
123 | + if ($dn === false) { |
|
124 | + throw new \Exception('The given user is not a recognized LDAP user.'); |
|
125 | + } |
|
126 | + |
|
127 | + return true; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * checks whether the setup allows reliable checking of LDAP user existence |
|
132 | + * @throws \Exception |
|
133 | + * @return true |
|
134 | + */ |
|
135 | + protected function isAllowed($force) { |
|
136 | + if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
137 | + throw new \Exception('Cannot check user existence, because ' |
|
138 | + . 'disabled LDAP configurations are present.'); |
|
139 | + } |
|
140 | + |
|
141 | + // we don't check ldapUserCleanupInterval from config.php because this |
|
142 | + // action is triggered manually, while the setting only controls the |
|
143 | + // background job. |
|
144 | + |
|
145 | + return true; |
|
146 | + } |
|
147 | + |
|
148 | + private function updateUser(string $uid, OutputInterface $output): void { |
|
149 | + try { |
|
150 | + $access = $this->backend->getLDAPAccess($uid); |
|
151 | + $attrs = $access->userManager->getAttributes(); |
|
152 | + $user = $access->userManager->get($uid); |
|
153 | + $avatarAttributes = $access->getConnection()->resolveRule('avatar'); |
|
154 | + $result = $access->search('objectclass=*', $user->getDN(), $attrs, 1, 0); |
|
155 | + foreach ($result[0] as $attribute => $valueSet) { |
|
156 | + $output->writeln(' ' . $attribute . ': '); |
|
157 | + foreach ($valueSet as $value) { |
|
158 | + if (in_array($attribute, $avatarAttributes)) { |
|
159 | + $value = '{ImageData}'; |
|
160 | + } |
|
161 | + $output->writeln(' ' . $value); |
|
162 | + } |
|
163 | + } |
|
164 | + $access->batchApplyUserAttributes($result); |
|
165 | + } catch (\Exception $e) { |
|
166 | + $output->writeln('<error>Error while trying to lookup and update attributes from LDAP</error>'); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | } |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | $this->dui->markUser($uid); |
105 | 105 | $output->writeln('The user does not exists on LDAP anymore.'); |
106 | 106 | $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
107 | - . $uid . '"'); |
|
107 | + . $uid.'"'); |
|
108 | 108 | return 0; |
109 | 109 | } catch (\Exception $e) { |
110 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
110 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
111 | 111 | return 1; |
112 | 112 | } |
113 | 113 | } |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | $avatarAttributes = $access->getConnection()->resolveRule('avatar'); |
154 | 154 | $result = $access->search('objectclass=*', $user->getDN(), $attrs, 1, 0); |
155 | 155 | foreach ($result[0] as $attribute => $valueSet) { |
156 | - $output->writeln(' ' . $attribute . ': '); |
|
156 | + $output->writeln(' '.$attribute.': '); |
|
157 | 157 | foreach ($valueSet as $value) { |
158 | 158 | if (in_array($attribute, $avatarAttributes)) { |
159 | 159 | $value = '{ImageData}'; |
160 | 160 | } |
161 | - $output->writeln(' ' . $value); |
|
161 | + $output->writeln(' '.$value); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | $access->batchApplyUserAttributes($result); |
@@ -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($output); |
|
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($output); |
|
105 | + } |
|
106 | + return 0; |
|
107 | + } |
|
108 | 108 | } |
@@ -41,106 +41,106 @@ |
||
41 | 41 | use Symfony\Component\Console\Output\OutputInterface; |
42 | 42 | |
43 | 43 | class Search extends Command { |
44 | - /** @var \OCP\IConfig */ |
|
45 | - protected $ocConfig; |
|
44 | + /** @var \OCP\IConfig */ |
|
45 | + protected $ocConfig; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param \OCP\IConfig $ocConfig |
|
49 | - */ |
|
50 | - public function __construct(IConfig $ocConfig) { |
|
51 | - $this->ocConfig = $ocConfig; |
|
52 | - parent::__construct(); |
|
53 | - } |
|
47 | + /** |
|
48 | + * @param \OCP\IConfig $ocConfig |
|
49 | + */ |
|
50 | + public function __construct(IConfig $ocConfig) { |
|
51 | + $this->ocConfig = $ocConfig; |
|
52 | + parent::__construct(); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function configure() { |
|
56 | - $this |
|
57 | - ->setName('ldap:search') |
|
58 | - ->setDescription('executes a user or group search') |
|
59 | - ->addArgument( |
|
60 | - 'search', |
|
61 | - InputArgument::REQUIRED, |
|
62 | - 'the search string (can be empty)' |
|
63 | - ) |
|
64 | - ->addOption( |
|
65 | - 'group', |
|
66 | - null, |
|
67 | - InputOption::VALUE_NONE, |
|
68 | - 'searches groups instead of users' |
|
69 | - ) |
|
70 | - ->addOption( |
|
71 | - 'offset', |
|
72 | - null, |
|
73 | - InputOption::VALUE_REQUIRED, |
|
74 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
75 | - 0 |
|
76 | - ) |
|
77 | - ->addOption( |
|
78 | - 'limit', |
|
79 | - null, |
|
80 | - InputOption::VALUE_REQUIRED, |
|
81 | - 'limit the results. 0 means no limit, defaults to 15', |
|
82 | - 15 |
|
83 | - ) |
|
84 | - ; |
|
85 | - } |
|
55 | + protected function configure() { |
|
56 | + $this |
|
57 | + ->setName('ldap:search') |
|
58 | + ->setDescription('executes a user or group search') |
|
59 | + ->addArgument( |
|
60 | + 'search', |
|
61 | + InputArgument::REQUIRED, |
|
62 | + 'the search string (can be empty)' |
|
63 | + ) |
|
64 | + ->addOption( |
|
65 | + 'group', |
|
66 | + null, |
|
67 | + InputOption::VALUE_NONE, |
|
68 | + 'searches groups instead of users' |
|
69 | + ) |
|
70 | + ->addOption( |
|
71 | + 'offset', |
|
72 | + null, |
|
73 | + InputOption::VALUE_REQUIRED, |
|
74 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
75 | + 0 |
|
76 | + ) |
|
77 | + ->addOption( |
|
78 | + 'limit', |
|
79 | + null, |
|
80 | + InputOption::VALUE_REQUIRED, |
|
81 | + 'limit the results. 0 means no limit, defaults to 15', |
|
82 | + 15 |
|
83 | + ) |
|
84 | + ; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Tests whether the offset and limit options are valid |
|
89 | - * @param int $offset |
|
90 | - * @param int $limit |
|
91 | - * @throws \InvalidArgumentException |
|
92 | - */ |
|
93 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
94 | - if ($limit < 0) { |
|
95 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
96 | - } |
|
97 | - if ($offset < 0) { |
|
98 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
99 | - } |
|
100 | - if ($limit === 0 && $offset !== 0) { |
|
101 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
102 | - } |
|
103 | - if ($offset > 0 && ($offset % $limit !== 0)) { |
|
104 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
105 | - } |
|
106 | - } |
|
87 | + /** |
|
88 | + * Tests whether the offset and limit options are valid |
|
89 | + * @param int $offset |
|
90 | + * @param int $limit |
|
91 | + * @throws \InvalidArgumentException |
|
92 | + */ |
|
93 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
94 | + if ($limit < 0) { |
|
95 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
96 | + } |
|
97 | + if ($offset < 0) { |
|
98 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
99 | + } |
|
100 | + if ($limit === 0 && $offset !== 0) { |
|
101 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
102 | + } |
|
103 | + if ($offset > 0 && ($offset % $limit !== 0)) { |
|
104 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
109 | - $helper = new Helper($this->ocConfig); |
|
110 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
111 | - $ldapWrapper = new LDAP(); |
|
108 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
109 | + $helper = new Helper($this->ocConfig); |
|
110 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
111 | + $ldapWrapper = new LDAP(); |
|
112 | 112 | |
113 | - $offset = (int)$input->getOption('offset'); |
|
114 | - $limit = (int)$input->getOption('limit'); |
|
115 | - $this->validateOffsetAndLimit($offset, $limit); |
|
113 | + $offset = (int)$input->getOption('offset'); |
|
114 | + $limit = (int)$input->getOption('limit'); |
|
115 | + $this->validateOffsetAndLimit($offset, $limit); |
|
116 | 116 | |
117 | - if ($input->getOption('group')) { |
|
118 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query('LDAPGroupPluginManager')); |
|
119 | - $getMethod = 'getGroups'; |
|
120 | - $printID = false; |
|
121 | - // convert the limit of groups to null. This will show all the groups available instead of |
|
122 | - // nothing, and will match the same behaviour the search for users has. |
|
123 | - if ($limit === 0) { |
|
124 | - $limit = null; |
|
125 | - } |
|
126 | - } else { |
|
127 | - $proxy = new User_Proxy( |
|
128 | - $configPrefixes, |
|
129 | - $ldapWrapper, |
|
130 | - $this->ocConfig, |
|
131 | - \OC::$server->getNotificationManager(), |
|
132 | - \OC::$server->getUserSession(), |
|
133 | - \OC::$server->query('LDAPUserPluginManager') |
|
134 | - ); |
|
135 | - $getMethod = 'getDisplayNames'; |
|
136 | - $printID = true; |
|
137 | - } |
|
117 | + if ($input->getOption('group')) { |
|
118 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query('LDAPGroupPluginManager')); |
|
119 | + $getMethod = 'getGroups'; |
|
120 | + $printID = false; |
|
121 | + // convert the limit of groups to null. This will show all the groups available instead of |
|
122 | + // nothing, and will match the same behaviour the search for users has. |
|
123 | + if ($limit === 0) { |
|
124 | + $limit = null; |
|
125 | + } |
|
126 | + } else { |
|
127 | + $proxy = new User_Proxy( |
|
128 | + $configPrefixes, |
|
129 | + $ldapWrapper, |
|
130 | + $this->ocConfig, |
|
131 | + \OC::$server->getNotificationManager(), |
|
132 | + \OC::$server->getUserSession(), |
|
133 | + \OC::$server->query('LDAPUserPluginManager') |
|
134 | + ); |
|
135 | + $getMethod = 'getDisplayNames'; |
|
136 | + $printID = true; |
|
137 | + } |
|
138 | 138 | |
139 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
140 | - foreach ($result as $id => $name) { |
|
141 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
142 | - $output->writeln($line); |
|
143 | - } |
|
144 | - return 0; |
|
145 | - } |
|
139 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
140 | + foreach ($result as $id => $name) { |
|
141 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
142 | + $output->writeln($line); |
|
143 | + } |
|
144 | + return 0; |
|
145 | + } |
|
146 | 146 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | if ($limit < 0) { |
95 | 95 | throw new \InvalidArgumentException('limit must be 0 or greater'); |
96 | 96 | } |
97 | - if ($offset < 0) { |
|
97 | + if ($offset < 0) { |
|
98 | 98 | throw new \InvalidArgumentException('offset must be 0 or greater'); |
99 | 99 | } |
100 | 100 | if ($limit === 0 && $offset !== 0) { |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
111 | 111 | $ldapWrapper = new LDAP(); |
112 | 112 | |
113 | - $offset = (int)$input->getOption('offset'); |
|
114 | - $limit = (int)$input->getOption('limit'); |
|
113 | + $offset = (int) $input->getOption('offset'); |
|
114 | + $limit = (int) $input->getOption('limit'); |
|
115 | 115 | $this->validateOffsetAndLimit($offset, $limit); |
116 | 116 | |
117 | 117 | if ($input->getOption('group')) { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
140 | 140 | foreach ($result as $id => $name) { |
141 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
141 | + $line = $name.($printID ? ' ('.$id.')' : ''); |
|
142 | 142 | $output->writeln($line); |
143 | 143 | } |
144 | 144 | return 0; |
@@ -35,61 +35,61 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class TestConfig extends Command { |
38 | - protected function configure() { |
|
39 | - $this |
|
40 | - ->setName('ldap:test-config') |
|
41 | - ->setDescription('tests an LDAP configuration') |
|
42 | - ->addArgument( |
|
43 | - 'configID', |
|
44 | - InputArgument::REQUIRED, |
|
45 | - 'the configuration ID' |
|
46 | - ) |
|
47 | - ; |
|
48 | - } |
|
38 | + protected function configure() { |
|
39 | + $this |
|
40 | + ->setName('ldap:test-config') |
|
41 | + ->setDescription('tests an LDAP configuration') |
|
42 | + ->addArgument( |
|
43 | + 'configID', |
|
44 | + InputArgument::REQUIRED, |
|
45 | + 'the configuration ID' |
|
46 | + ) |
|
47 | + ; |
|
48 | + } |
|
49 | 49 | |
50 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
51 | - $helper = new Helper(\OC::$server->getConfig()); |
|
52 | - $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
53 | - $configID = $input->getArgument('configID'); |
|
54 | - if (!in_array($configID, $availableConfigs)) { |
|
55 | - $output->writeln("Invalid configID"); |
|
56 | - return 1; |
|
57 | - } |
|
50 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
51 | + $helper = new Helper(\OC::$server->getConfig()); |
|
52 | + $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
53 | + $configID = $input->getArgument('configID'); |
|
54 | + if (!in_array($configID, $availableConfigs)) { |
|
55 | + $output->writeln("Invalid configID"); |
|
56 | + return 1; |
|
57 | + } |
|
58 | 58 | |
59 | - $result = $this->testConfig($configID); |
|
60 | - if ($result === 0) { |
|
61 | - $output->writeln('The configuration is valid and the connection could be established!'); |
|
62 | - } elseif ($result === 1) { |
|
63 | - $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
64 | - return 1; |
|
65 | - } elseif ($result === 2) { |
|
66 | - $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
67 | - } else { |
|
68 | - $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
69 | - } |
|
70 | - return 0; |
|
71 | - } |
|
59 | + $result = $this->testConfig($configID); |
|
60 | + if ($result === 0) { |
|
61 | + $output->writeln('The configuration is valid and the connection could be established!'); |
|
62 | + } elseif ($result === 1) { |
|
63 | + $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
64 | + return 1; |
|
65 | + } elseif ($result === 2) { |
|
66 | + $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
67 | + } else { |
|
68 | + $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
69 | + } |
|
70 | + return 0; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * tests the specified connection |
|
75 | - * @param string $configID |
|
76 | - * @return int |
|
77 | - */ |
|
78 | - protected function testConfig($configID) { |
|
79 | - $lw = new \OCA\User_LDAP\LDAP(); |
|
80 | - $connection = new Connection($lw, $configID); |
|
73 | + /** |
|
74 | + * tests the specified connection |
|
75 | + * @param string $configID |
|
76 | + * @return int |
|
77 | + */ |
|
78 | + protected function testConfig($configID) { |
|
79 | + $lw = new \OCA\User_LDAP\LDAP(); |
|
80 | + $connection = new Connection($lw, $configID); |
|
81 | 81 | |
82 | - //ensure validation is run before we attempt the bind |
|
83 | - $connection->getConfiguration(); |
|
82 | + //ensure validation is run before we attempt the bind |
|
83 | + $connection->getConfiguration(); |
|
84 | 84 | |
85 | - if (!$connection->setConfiguration([ |
|
86 | - 'ldap_configuration_active' => 1, |
|
87 | - ])) { |
|
88 | - return 1; |
|
89 | - } |
|
90 | - if ($connection->bind()) { |
|
91 | - return 0; |
|
92 | - } |
|
93 | - return 2; |
|
94 | - } |
|
85 | + if (!$connection->setConfiguration([ |
|
86 | + 'ldap_configuration_active' => 1, |
|
87 | + ])) { |
|
88 | + return 1; |
|
89 | + } |
|
90 | + if ($connection->bind()) { |
|
91 | + return 0; |
|
92 | + } |
|
93 | + return 2; |
|
94 | + } |
|
95 | 95 | } |
@@ -37,57 +37,57 @@ |
||
37 | 37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | 38 | |
39 | 39 | class SetConfig extends Command { |
40 | - protected function configure() { |
|
41 | - $this |
|
42 | - ->setName('ldap:set-config') |
|
43 | - ->setDescription('modifies an LDAP configuration') |
|
44 | - ->addArgument( |
|
45 | - 'configID', |
|
46 | - InputArgument::REQUIRED, |
|
47 | - 'the configuration ID' |
|
48 | - ) |
|
49 | - ->addArgument( |
|
50 | - 'configKey', |
|
51 | - InputArgument::REQUIRED, |
|
52 | - 'the configuration key' |
|
53 | - ) |
|
54 | - ->addArgument( |
|
55 | - 'configValue', |
|
56 | - InputArgument::REQUIRED, |
|
57 | - 'the new configuration value' |
|
58 | - ) |
|
59 | - ; |
|
60 | - } |
|
40 | + protected function configure() { |
|
41 | + $this |
|
42 | + ->setName('ldap:set-config') |
|
43 | + ->setDescription('modifies an LDAP configuration') |
|
44 | + ->addArgument( |
|
45 | + 'configID', |
|
46 | + InputArgument::REQUIRED, |
|
47 | + 'the configuration ID' |
|
48 | + ) |
|
49 | + ->addArgument( |
|
50 | + 'configKey', |
|
51 | + InputArgument::REQUIRED, |
|
52 | + 'the configuration key' |
|
53 | + ) |
|
54 | + ->addArgument( |
|
55 | + 'configValue', |
|
56 | + InputArgument::REQUIRED, |
|
57 | + 'the new configuration value' |
|
58 | + ) |
|
59 | + ; |
|
60 | + } |
|
61 | 61 | |
62 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | - $helper = new Helper(\OC::$server->getConfig()); |
|
64 | - $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
65 | - $configID = $input->getArgument('configID'); |
|
66 | - if (!in_array($configID, $availableConfigs)) { |
|
67 | - $output->writeln("Invalid configID"); |
|
68 | - return 1; |
|
69 | - } |
|
62 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | + $helper = new Helper(\OC::$server->getConfig()); |
|
64 | + $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
65 | + $configID = $input->getArgument('configID'); |
|
66 | + if (!in_array($configID, $availableConfigs)) { |
|
67 | + $output->writeln("Invalid configID"); |
|
68 | + return 1; |
|
69 | + } |
|
70 | 70 | |
71 | - $this->setValue( |
|
72 | - $configID, |
|
73 | - $input->getArgument('configKey'), |
|
74 | - $input->getArgument('configValue') |
|
75 | - ); |
|
76 | - return 0; |
|
77 | - } |
|
71 | + $this->setValue( |
|
72 | + $configID, |
|
73 | + $input->getArgument('configKey'), |
|
74 | + $input->getArgument('configValue') |
|
75 | + ); |
|
76 | + return 0; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * save the configuration value as provided |
|
81 | - * @param string $configID |
|
82 | - * @param string $configKey |
|
83 | - * @param string $configValue |
|
84 | - */ |
|
85 | - protected function setValue($configID, $key, $value) { |
|
86 | - $configHolder = new Configuration($configID); |
|
87 | - $configHolder->$key = $value; |
|
88 | - $configHolder->saveConfiguration(); |
|
79 | + /** |
|
80 | + * save the configuration value as provided |
|
81 | + * @param string $configID |
|
82 | + * @param string $configKey |
|
83 | + * @param string $configValue |
|
84 | + */ |
|
85 | + protected function setValue($configID, $key, $value) { |
|
86 | + $configHolder = new Configuration($configID); |
|
87 | + $configHolder->$key = $value; |
|
88 | + $configHolder->saveConfiguration(); |
|
89 | 89 | |
90 | - $connectionFactory = new ConnectionFactory(new LDAP()); |
|
91 | - $connectionFactory->get($configID)->clearCache(); |
|
92 | - } |
|
90 | + $connectionFactory = new ConnectionFactory(new LDAP()); |
|
91 | + $connectionFactory->get($configID)->clearCache(); |
|
92 | + } |
|
93 | 93 | } |
@@ -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($output); |
|
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($output); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | } |
@@ -34,40 +34,40 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class CreateEmptyConfig extends Command { |
37 | - /** @var \OCA\User_LDAP\Helper */ |
|
38 | - protected $helper; |
|
37 | + /** @var \OCA\User_LDAP\Helper */ |
|
38 | + protected $helper; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param Helper $helper |
|
42 | - */ |
|
43 | - public function __construct(Helper $helper) { |
|
44 | - $this->helper = $helper; |
|
45 | - parent::__construct(); |
|
46 | - } |
|
40 | + /** |
|
41 | + * @param Helper $helper |
|
42 | + */ |
|
43 | + public function __construct(Helper $helper) { |
|
44 | + $this->helper = $helper; |
|
45 | + parent::__construct(); |
|
46 | + } |
|
47 | 47 | |
48 | - protected function configure() { |
|
49 | - $this |
|
50 | - ->setName('ldap:create-empty-config') |
|
51 | - ->setDescription('creates an empty LDAP configuration') |
|
52 | - ->addOption( |
|
53 | - 'only-print-prefix', |
|
54 | - 'p', |
|
55 | - InputOption::VALUE_NONE, |
|
56 | - 'outputs only the prefix' |
|
57 | - ) |
|
58 | - ; |
|
59 | - } |
|
48 | + protected function configure() { |
|
49 | + $this |
|
50 | + ->setName('ldap:create-empty-config') |
|
51 | + ->setDescription('creates an empty LDAP configuration') |
|
52 | + ->addOption( |
|
53 | + 'only-print-prefix', |
|
54 | + 'p', |
|
55 | + InputOption::VALUE_NONE, |
|
56 | + 'outputs only the prefix' |
|
57 | + ) |
|
58 | + ; |
|
59 | + } |
|
60 | 60 | |
61 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
62 | - $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
63 | - $configHolder = new Configuration($configPrefix); |
|
64 | - $configHolder->saveConfiguration(); |
|
61 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
62 | + $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
63 | + $configHolder = new Configuration($configPrefix); |
|
64 | + $configHolder->saveConfiguration(); |
|
65 | 65 | |
66 | - $prose = ''; |
|
67 | - if (!$input->getOption('only-print-prefix')) { |
|
68 | - $prose = 'Created new configuration with configID '; |
|
69 | - } |
|
70 | - $output->writeln($prose . "{$configPrefix}"); |
|
71 | - return 0; |
|
72 | - } |
|
66 | + $prose = ''; |
|
67 | + if (!$input->getOption('only-print-prefix')) { |
|
68 | + $prose = 'Created new configuration with configID '; |
|
69 | + } |
|
70 | + $output->writeln($prose . "{$configPrefix}"); |
|
71 | + return 0; |
|
72 | + } |
|
73 | 73 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | if (!$input->getOption('only-print-prefix')) { |
68 | 68 | $prose = 'Created new configuration with configID '; |
69 | 69 | } |
70 | - $output->writeln($prose . "{$configPrefix}"); |
|
70 | + $output->writeln($prose."{$configPrefix}"); |
|
71 | 71 | return 0; |
72 | 72 | } |
73 | 73 | } |