61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Fail2banIpList extends Model
|
|
{
|
|
protected $table = 'fail2ban_ip_lists';
|
|
|
|
protected $fillable = [
|
|
'ip',
|
|
'type',
|
|
];
|
|
|
|
protected $casts = [
|
|
'ip' => 'string',
|
|
'type' => 'string',
|
|
];
|
|
|
|
const TYPE_WHITELIST = 'whitelist';
|
|
const TYPE_BLACKLIST = 'blacklist';
|
|
|
|
/**
|
|
* Scopes
|
|
*/
|
|
public function scopeWhitelist($query)
|
|
{
|
|
return $query->where('type', self::TYPE_WHITELIST);
|
|
}
|
|
|
|
public function scopeBlacklist($query)
|
|
{
|
|
return $query->where('type', self::TYPE_BLACKLIST);
|
|
}
|
|
|
|
/**
|
|
* Validiert grob die IP.
|
|
*/
|
|
public function isValidIp(): bool
|
|
{
|
|
return filter_var($this->ip, FILTER_VALIDATE_IP) !== false;
|
|
}
|
|
|
|
/**
|
|
* Gibt Liste aller Whitelist-IPs als Array zurück.
|
|
*/
|
|
public static function whitelistArray(): array
|
|
{
|
|
return static::where('type', self::TYPE_WHITELIST)->pluck('ip')->all();
|
|
}
|
|
|
|
/**
|
|
* Gibt Liste aller Blacklist-IPs als Array zurück.
|
|
*/
|
|
public static function blacklistArray(): array
|
|
{
|
|
return static::where('type', self::TYPE_BLACKLIST)->pluck('ip')->all();
|
|
}
|
|
}
|