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 in days (default one month)') |
22
|
|
|
->addOption('dryrun', null, InputOption::VALUE_NONE, 'Dry run mode') |
23
|
|
|
->setDescription( |
24
|
|
|
<<<HELP |
25
|
|
|
Lock every admin user account for the optionally specified lifetime (in days). If not provided, defaults to one month. |
26
|
|
|
HELP |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param InputInterface $input |
32
|
|
|
* @param OutputInterface $output |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$this->detectMagento($output, true); |
39
|
|
|
if (!$this->initMagento()) { |
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($dryrun = $input->getOption('dryrun')) { |
44
|
|
|
$output->writeln('<info>Dry run mode enabled.</info>'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$lifetime = $input->getArgument('lifetime') ?: $this->daysToSeconds(self::LIFETIME_DEFAULT); |
48
|
|
|
|
49
|
|
|
$userIds = \Mage::getModel('admin/user')->getCollection()->getAllIds(); |
50
|
|
|
|
51
|
|
|
if (empty($userIds)) { |
52
|
|
|
$output->writeln('<error>No admin users were found!</error>'); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ |
57
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
58
|
|
|
$confirm = $dialog->ask( |
59
|
|
|
$output, |
60
|
|
|
'<info><comment>Are you sure? This will lock all admin accounts! Type "yes" to continue...</comment></info>' |
61
|
|
|
. PHP_EOL |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
if ('yes' !== $confirm) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (!$dryrun) { |
69
|
|
|
\Mage::getResourceModel('enterprise_pci/admin_user')->lock($userIds, 0, $lifetime); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$lifetimeMessage = ''; |
73
|
|
|
if ($input->getArgument('lifetime')) { |
74
|
|
|
$lifetimeMessage = sprintf(' for %d days.', $input->getArgument('lifetime')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$output->writeln( |
78
|
|
|
sprintf('<info><comment>All %d admins</comment> locked%s</info>', count($userIds), $lifetimeMessage) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|