|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
6
|
|
|
* @author Joas Schilling <[email protected]> |
|
7
|
|
|
* @author Morris Jobke <[email protected]> |
|
8
|
|
|
* @author scolebrook <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @license AGPL-3.0 |
|
11
|
|
|
* |
|
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
14
|
|
|
* as published by the Free Software Foundation. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\User_LDAP\Command; |
|
27
|
|
|
|
|
28
|
|
|
use Symfony\Component\Console\Command\Command; |
|
29
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
31
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
32
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
33
|
|
|
|
|
34
|
|
|
use OCA\User_LDAP\User\DeletedUsersIndex; |
|
35
|
|
|
use OCP\IDateTimeFormatter; |
|
36
|
|
|
|
|
37
|
|
|
class ShowRemnants extends Command { |
|
38
|
|
|
/** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
39
|
|
|
protected $dui; |
|
40
|
|
|
|
|
41
|
|
|
/** @var \OCP\IDateTimeFormatter */ |
|
42
|
|
|
protected $dateFormatter; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param DeletedUsersIndex $dui |
|
46
|
|
|
* @param IDateTimeFormatter $dateFormatter |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
49
|
|
|
$this->dui = $dui; |
|
50
|
|
|
$this->dateFormatter = $dateFormatter; |
|
51
|
|
|
parent::__construct(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function configure() { |
|
55
|
|
|
$this |
|
56
|
|
|
->setName('ldap:show-remnants') |
|
57
|
|
|
->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.') |
|
58
|
|
|
->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.') |
|
59
|
|
|
->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function formatDate(int $timestamp, string $default, bool $showShortDate) { |
|
63
|
|
|
if (!($timestamp > 0)) { |
|
64
|
|
|
return $default; |
|
65
|
|
|
} |
|
66
|
|
|
if ($showShortDate) { |
|
67
|
|
|
return date('Y-m-d', $timestamp); |
|
68
|
|
|
} |
|
69
|
|
|
return $this->dateFormatter->formatDate($timestamp); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* executes the command, i.e. creates and outputs a table of LDAP users marked as deleted |
|
74
|
|
|
* |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
78
|
|
|
/** @var \Symfony\Component\Console\Helper\Table $table */ |
|
79
|
|
|
$table = new Table($output); |
|
80
|
|
|
$table->setHeaders([ |
|
81
|
|
|
'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
82
|
|
|
'Detected on', 'Dir', 'Sharer' |
|
83
|
|
|
]); |
|
84
|
|
|
$rows = []; |
|
85
|
|
|
$resultSet = $this->dui->getUsers(); |
|
86
|
|
|
foreach ($resultSet as $user) { |
|
87
|
|
|
$rows[] = [ |
|
88
|
|
|
'ocName' => $user->getOCName(), |
|
89
|
|
|
'displayName' => $user->getDisplayName(), |
|
90
|
|
|
'uid' => $user->getUID(), |
|
91
|
|
|
'dn' => $user->getDN(), |
|
92
|
|
|
'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
93
|
|
|
'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
94
|
|
|
'homePath' => $user->getHomePath(), |
|
95
|
|
|
'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if ($input->getOption('json')) { |
|
100
|
|
|
$output->writeln(json_encode($rows)); |
|
101
|
|
|
} else { |
|
102
|
|
|
$table->setRows($rows); |
|
103
|
|
|
$table->render($output); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.