Skip to content

Commit

Permalink
Add expiration date on IP bans
Browse files Browse the repository at this point in the history
  • Loading branch information
mchev committed Jan 7, 2024
1 parent ea97d96 commit fb8c30f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Banhammer, a Model and IP ban package for Laravel
# Banhammer, a Model, IP and Country ban package for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/mchev/banhammer.svg?style=flat-square)](https://packagist.org/packages/mchev/banhammer)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/mchev/banhammer/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mchev/banhammer/actions?query=workflow%3Arun-tests+branch%3Amain)
Expand Down Expand Up @@ -182,6 +182,19 @@ use Mchev\Banhammer\IP;
IP::ban("8.8.8.8");
IP::ban(["8.8.8.8", "4.4.4.4"]);
// Ban IP with expiration date
IP::ban("8.8.8.8", [], now()->addMinutes(10));
// Full
IP::ban(
"8.8.8.8",
[
"MetaKey1" => "MetaValue1",
"MetaKey2" => "MetaValue2",
],
now()->addMinutes(10)
);
```
Unban IPs
Expand Down
3 changes: 2 additions & 1 deletion src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class IP
{
public static function ban(string|array $ips, array $metas = []): void
public static function ban(string|array $ips, array $metas = [], string $date = null): void
{
$bannedIps = self::getBannedIPsFromCache();

Expand All @@ -17,6 +17,7 @@ public static function ban(string|array $ips, array $metas = []): void
Ban::create([
'ip' => $ip,
'metas' => count($metas) ? $metas : null,
'expired_at' => $date,
]);
}
}
Expand Down

0 comments on commit fb8c30f

Please sign in to comment.