jpkleemans/htaccess-firewall

Simple access control using Htaccess

dev-master 2017-03-22 17:22 UTC

This package is auto-updated.

Last update: 2019-12-16 16:31:18 UTC


README

Build Status Code Quality License

SensioLabsInsight

Simple access control using Htaccess.

This library is currently under development. Things will change!

Install

Via Composer

$ composer require jpkleemans/htaccess-firewall:dev-master

Usage

First, create an instance of the HtaccessFirewall\HtaccessFirewall class:

$firewall = new HtaccessFirewall('path/to/.htaccess');

Block IP

$host = IP::fromString('123.0.0.1');

$firewall->deny($host);

Unblock IP

$host = IP::fromString('123.0.0.1');

$firewall->undeny($host);

Get all denied hosts

$hosts = $firewall->getDenied();

Deactivate firewall (comment .htaccess lines)

$firewall->deactivate();

// And to reactivate:
$firewall->reactivate();

Set 403 message

$hosts = $firewall->set403Message('You are blocked!');

// And to remove:
$hosts = $firewall->remove403Message();

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.

$filesystem = new YourCustomFilesystem();
$firewall = new HtaccessFirewall('path/to/.htaccess', $filesystem);

Testing

$ phpspec run