Skip to content

Commit efe0f83

Browse files
Merge pull request #61682 from nextcloud/feat/improve-bruteforce-protection-command-output
feat(bruteforce): improve bruteforce protection command output
2 parents 68dd6ac + 738f237 commit efe0f83

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

core/Command/Security/BruteforceAttempts.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\Security\Bruteforce\IThrottler;
1313
use Symfony\Component\Console\Input\InputArgument;
1414
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputOption;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617

1718
class BruteforceAttempts extends Base {
@@ -37,12 +38,20 @@ protected function configure(): void {
3738
InputArgument::OPTIONAL,
3839
'Only count attempts for the given action',
3940
)
41+
->addOption(
42+
'interval',
43+
null,
44+
InputOption::VALUE_REQUIRED,
45+
'Interval in hours to count attempts for (max 48)',
46+
12,
47+
)
4048
;
4149
}
4250

4351
#[\Override]
4452
protected function execute(InputInterface $input, OutputInterface $output): int {
4553
$ip = $input->getArgument('ipaddress');
54+
$interval = (float)$input->getOption('interval');
4655

4756
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
4857
$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
@@ -54,12 +63,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5463
'attempts' => $this->throttler->getAttempts(
5564
$ip,
5665
(string)$input->getArgument('action'),
66+
$interval,
5767
),
5868
'delay' => $this->throttler->getDelay(
5969
$ip,
6070
(string)$input->getArgument('action'),
6171
),
6272
];
73+
if ($input->getOption('output') === 'plain') {
74+
$data['delay'] = $data['delay'] . ' ms';
75+
}
6376

6477
$this->writeArrayInOutputFormat($input, $output, $data);
6578

0 commit comments

Comments
 (0)