Htaccess Firewall
, (*1)
, (*2)
Simple access control using Htaccess., (*3)
This library is currently under development. Things will change!, (*4)
Install
Via Composer, (*5)
``` bash
$ composer require jpkleemans/htaccess-firewall:dev-master, (*6)
## Usage
First, create an instance of the `HtaccessFirewall\HtaccessFirewall` class:
``` php
$firewall = new HtaccessFirewall('path/to/.htaccess');
Block IP
``` php
$host = IP::fromString('123.0.0.1');, (*7)
$firewall->deny($host);, (*8)
### Unblock IP
``` php
$host = IP::fromString('123.0.0.1');
$firewall->undeny($host);
Get all denied hosts
``` php
$hosts = $firewall->getDenied();, (*9)
### Deactivate firewall (comment .htaccess lines)
``` php
$firewall->deactivate();
// And to reactivate:
$firewall->reactivate();
Set 403 message
``` php
$hosts = $firewall->set403Message('You are blocked!');, (*10)
// And to remove:
$hosts = $firewall->remove403Message();, (*11)
## Use other filesystem
You can use another filesystem by passing it as the second argument of the `HtaccessFirewall` constructor.
The filesystem must implement the `HtaccessFirewall\Filesystem\Filesystem` interface.
``` php
$filesystem = new YourCustomFilesystem();
$firewall = new HtaccessFirewall('path/to/.htaccess', $filesystem);
Testing
bash
$ phpspec run
, (*12)