2020-10-08 09:02:51 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-12-16 08:54:15 -05:00
|
|
|
|
2020-10-08 09:02:51 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-10-08 09:02:51 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Security\Bruteforce;
|
|
|
|
|
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\TimedJob;
|
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
|
|
class CleanupJob extends TimedJob {
|
2023-06-26 05:58:09 -04:00
|
|
|
public function __construct(
|
|
|
|
|
ITimeFactory $time,
|
|
|
|
|
private IDBConnection $connection,
|
|
|
|
|
) {
|
2020-10-08 09:02:51 -04:00
|
|
|
parent::__construct($time);
|
|
|
|
|
|
|
|
|
|
// Run once a day
|
2024-10-07 11:36:55 -04:00
|
|
|
$this->setInterval(60 * 60 * 24);
|
|
|
|
|
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
2020-10-08 09:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-26 05:58:09 -04:00
|
|
|
protected function run($argument): void {
|
2020-10-08 09:02:51 -04:00
|
|
|
// Delete all entries more than 48 hours old
|
|
|
|
|
$time = $this->time->getTime() - (48 * 3600);
|
|
|
|
|
|
|
|
|
|
$qb = $this->connection->getQueryBuilder();
|
|
|
|
|
$qb->delete('bruteforce_attempts')
|
|
|
|
|
->where($qb->expr()->lt('occurred', $qb->createNamedParameter($time), IQueryBuilder::PARAM_INT));
|
2024-10-16 04:41:21 -04:00
|
|
|
$qb->executeStatement();
|
2020-10-08 09:02:51 -04:00
|
|
|
}
|
|
|
|
|
}
|