|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Admin\User; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
|
|
10
|
|
|
class LockdownCommand extends LockCommand |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Setup |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setName('admin:user:lockdown') |
|
21
|
|
|
->addArgument('lifetime', InputArgument::OPTIONAL, 'Optional - lock lifetime (default one month)') |
|
22
|
|
|
->setDescription( |
|
23
|
|
|
<<<HELP |
|
24
|
|
|
Lock every admin user account for the optionally specified lifetime (in days). If not provided, defaults to one month. |
|
25
|
|
|
HELP |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param InputInterface $input |
|
31
|
|
|
* @param OutputInterface $output |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->detectMagento($output, true); |
|
38
|
|
|
if (!$this->initMagento()) { |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$lifetime = $input->getArgument('lifetime') ?: $this->daysToSeconds(self::LIFETIME_DEFAULT); |
|
43
|
|
|
|
|
44
|
|
|
$userIds = \Mage::getModel('admin/user')->getCollection()->getAllIds(); |
|
45
|
|
|
|
|
46
|
|
|
if (empty($userIds)) { |
|
47
|
|
|
$output->writeln('<error>No admin users were found!</error>'); |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ |
|
52
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
|
53
|
|
|
$confirm = $dialog->ask( |
|
54
|
|
|
$output, |
|
55
|
|
|
'<info><comment>Are you sure? This will lock all admin accounts! Type "yes" to continue...</comment></info>' |
|
56
|
|
|
. PHP_EOL |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
if ('yes' !== $confirm) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
\Mage::getResourceModel('enterprise_pci/admin_user')->lock($userIds, 0, $lifetime); |
|
64
|
|
|
|
|
65
|
|
|
$lifetimeMessage = ''; |
|
66
|
|
|
if ($input->getArgument('lifetime')) { |
|
67
|
|
|
$lifetimeMessage = sprintf(' for %d days.', $input->getArgument('lifetime')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$output->writeln( |
|
71
|
|
|
sprintf('<info><comment>All %d admins</comment> locked%s</info>', count($userIds), $lifetimeMessage) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|