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,45 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use IriksIT\Manager\Modules\Audit\IpBans;
|
||||
|
||||
/**
|
||||
* An address that is kept out of the manager (or, `whole_site`, off the site), until `expires_at`
|
||||
* or (null) until someone lifts it. Written by IpBans only.
|
||||
*
|
||||
* @property Carbon $created_at
|
||||
*/
|
||||
class IpBan extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['automatic' => 'boolean', 'whole_site' => 'boolean', 'hits' => 'integer', 'last_hit_at' => 'datetime', 'expires_at' => 'datetime', 'created_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/** The list of bans for the whole site is kept in the cache (IpBans::wholeSite): any change makes it stale. */
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(fn () => IpBans::forgetWholeSite());
|
||||
static::deleted(fn () => IpBans::forgetWholeSite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bans that still keep their address out.
|
||||
*
|
||||
* @param Builder<IpBan> $query
|
||||
*/
|
||||
public function scopeActive(Builder $query): void
|
||||
{
|
||||
$query->where(fn (Builder $q) => $q->whereNull('expires_at')->orWhere('expires_at', '>', now()));
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->expires_at === null || $this->expires_at->isFuture();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user