IPFilter
in package
Prevents brute force attacks through a list of IP addresses and their counters failed attempts.
Table of Contents
Constants
- BAN_SECONDS = 600
- The number of seconds the system blocks access.
- MAX_ATTEMPTS = 5
- Maximum number of access attempts.
Properties
- $filePath : string
- Path of the file with the list.
- $ipList : array<string|int, mixed>
- Contains IP addresses.
Methods
- __construct() : mixed
- IPFilter constructor.
- clear() : void
- Clean the list of IP addresses and save the data.
- isBanned() : bool
- Returns true if attempts to access from the IP address exceed the MAX_ATTEMPTS limit.
- setAttempt() : void
- Add or increase the attempt counter of the provided IP address.
- readFile() : void
- Reads file and load IP addresses.
- readIp() : void
- Load the IP addresses in the ipList array
- save() : void
- Stores the list of IP addresses in the file.
Constants
BAN_SECONDS
The number of seconds the system blocks access.
public
mixed
BAN_SECONDS
= 600
MAX_ATTEMPTS
Maximum number of access attempts.
public
mixed
MAX_ATTEMPTS
= 5
Properties
$filePath
Path of the file with the list.
private
string
$filePath
$ipList
Contains IP addresses.
private
array<string|int, mixed>
$ipList
Methods
__construct()
IPFilter constructor.
public
__construct() : mixed
clear()
Clean the list of IP addresses and save the data.
public
clear() : void
isBanned()
Returns true if attempts to access from the IP address exceed the MAX_ATTEMPTS limit.
public
isBanned(string $ip) : bool
Parameters
- $ip : string
Return values
boolsetAttempt()
Add or increase the attempt counter of the provided IP address.
public
setAttempt(string $ip) : void
Parameters
- $ip : string
readFile()
Reads file and load IP addresses.
private
readFile() : void
readIp()
Load the IP addresses in the ipList array
private
readIp(array<string|int, mixed> $line) : void
Parameters
- $line : array<string|int, mixed>
save()
Stores the list of IP addresses in the file.
private
save() : void