Blacklist extends AppModel
Blacklist management
Table of Contents
Methods
| __construct() | Initialize Blacklist |
| add() | Adds a rule to the blacklist |
| get() | Fetches a specific rule |
| getList() | Returns a list of the rules |
| getListCount() | Returns the total number of rules |
| getTypes() | Retrieves a list of the rule types and their language |
| remove() | Removes a rule |
| removeByPlugin() | Deletes all the rules created by a specific plugin |
| validateEmail() | Validates a rule of "email" type |
| validateIp() | Validates a rule of "ip" type |
| verify() | Verify an incoming request against the blacklist |
| validateCidr() | Validates a rule of "ip" type, in CIDR format |
Methods
__construct()
Initialize Blacklist
public
__construct() : mixed
add()
Adds a rule to the blacklist
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of client info including:
- rule The IP address, CIDR block, email address or wildcard email to block
- type The rule type, it could be "ip" or "email"
- plugin_dir The directory of the plugin that created the rule (optional)
- note A note about the rule (optional)
Return values
int —The ID of the blacklist rule, void on error
get()
Fetches a specific rule
public
get(int $id) : mixed
Parameters
- $id : int
-
The ID of the rule to remove
Return values
mixed —An object representing the rule
getList()
Returns a list of the rules
public
getList([int $page = 1 ][, array<string|int, mixed> $order_by = ['plugin_dir' => 'ASC'] ]) : mixed
Parameters
- $page : int = 1
-
The page to return results for (optional, default 1)
- $order_by : array<string|int, mixed> = ['plugin_dir' => 'ASC']
-
The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
Return values
mixed —An array of objects
getListCount()
Returns the total number of rules
public
getListCount() : int
Return values
int —The total amount of rules in the system
getTypes()
Retrieves a list of the rule types and their language
public
getTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —A key/value list of rule types and their language
remove()
Removes a rule
public
remove(int $id) : mixed
Parameters
- $id : int
-
The ID of the rule to remove
removeByPlugin()
Deletes all the rules created by a specific plugin
public
removeByPlugin(string $plugin_dir) : mixed
Parameters
- $plugin_dir : string
-
The directory name of the plugin that created the rules
validateEmail()
Validates a rule of "email" type
public
validateEmail(string $email) : bool
Parameters
- $email : string
-
The email rule to validate
Return values
bool —True if the email rule is valid, false otherwise
validateIp()
Validates a rule of "ip" type
public
validateIp(string $ip) : bool
Parameters
- $ip : string
-
The IP rule to validate
Return values
bool —True if the IP rule is valid, false otherwise
verify()
Verify an incoming request against the blacklist
public
verify(string $input, string $type[, string $direction = 'incoming' ]) : bool
Parameters
- $input : string
-
The input data to verify against the blacklist
- $type : string
-
The type of rule to use for verification
- $direction : string = 'incoming'
-
The direction where to validate the rule
Return values
bool —True if the current request is approved by the blacklist, false otherwise
validateCidr()
Validates a rule of "ip" type, in CIDR format
private
validateCidr(string $cidr) : bool
Parameters
- $cidr : string
-
The IP rule to validate
Return values
bool —True if the IP rule is valid, false otherwise