Audit module: audit log and address bans
This commit is contained in:
1 parent
b75403e5ea
commit
d2ea1bacac
41 files changed
+2137
-5
No files matched your search
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Models;
|
||||
|
||||
/**
|
||||
* The rules of the audit log (one row, id 1): when an address is banned by itself and how long
|
||||
* the log is kept. Set in the manager.
|
||||
*/
|
||||
class AuditSetting extends Model
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
protected $attributes = [
|
||||
'auto_ban' => true,
|
||||
// This many failed logins from one address ...
|
||||
'max_failures' => 10,
|
||||
// ... within this many minutes ...
|
||||
'window_minutes' => 30,
|
||||
// ... keep it out this long. 0: until someone lifts the ban.
|
||||
'ban_minutes' => 1440,
|
||||
'keep_days' => 90,
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'auto_ban' => 'boolean',
|
||||
'max_failures' => 'integer',
|
||||
'window_minutes' => 'integer',
|
||||
'ban_minutes' => 'integer',
|
||||
'keep_days' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/** The longest the log may be kept (config `manager.audit.max_keep_days`): what a privacy policy promises. */
|
||||
public static function maxKeepDays(): int
|
||||
{
|
||||
return max(7, (int) config('manager.audit.max_keep_days', 90));
|
||||
}
|
||||
|
||||
/** The rules as they are now: the saved row, or the defaults while nothing was saved. */
|
||||
public static function current(): self
|
||||
{
|
||||
return static::query()->find(1) ?? new self;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{auto_ban: bool, max_failures: int, window_minutes: int, ban_minutes: int, keep_days: int}
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'auto_ban' => (bool) $this->auto_ban,
|
||||
'max_failures' => (int) $this->max_failures,
|
||||
'window_minutes' => (int) $this->window_minutes,
|
||||
'ban_minutes' => (int) $this->ban_minutes,
|
||||
// Also for a row that was saved when more was allowed.
|
||||
'keep_days' => min(self::maxKeepDays(), (int) $this->keep_days),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user