All Projects → DavidePastore → Slim-Restrict-Route

DavidePastore / Slim-Restrict-Route

Licence: other
A Slim middleware to restrict ip addresses that will access to your routes

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Slim-Restrict-Route

localization-middleware
PSR-15 middleware to assist primarily with language-based content negotiation and various other localization tasks
Stars: ✭ 24 (+14.29%)
Mutual labels:  slim-framework
slim-play
Slim Play app
Stars: ✭ 76 (+261.9%)
Mutual labels:  slim-framework
sihae
A PHP 7.4+ blog engine built with Slim Framework and Doctrine ORM
Stars: ✭ 18 (-14.29%)
Mutual labels:  slim-framework
slim-mobile-detect
Implements Mobile-Detect lib for Response's write on Slim Framework App
Stars: ✭ 18 (-14.29%)
Mutual labels:  slim-framework
lassi
PHP boilerplate for quick start projects using Slim Framework and Eloquent.
Stars: ✭ 58 (+176.19%)
Mutual labels:  slim-framework
phpindonesia.or.id-membership2
PHP Indonesia - Membership Application - Reloaded
Stars: ✭ 31 (+47.62%)
Mutual labels:  slim-framework
api rest slim framework
RESTFUL API o API REST con slim framework (PHP, MySql, PDO)
Stars: ✭ 14 (-33.33%)
Mutual labels:  slim-framework
koa-ip-filter
koa middleware to filter request IPs or custom ID with glob patterns, array, string, regexp or matcher function. Support custom 403 Forbidden message and custom ID.
Stars: ✭ 23 (+9.52%)
Mutual labels:  ip
slim-routing
Slim framework powered-up routing
Stars: ✭ 14 (-33.33%)
Mutual labels:  slim-framework
slim3-mvc
Slim 3 PHP micro framework MVC application boilerplate
Stars: ✭ 24 (+14.29%)
Mutual labels:  slim-framework
Slim-Console
Slim Framework Console
Stars: ✭ 26 (+23.81%)
Mutual labels:  slim-framework
Slim-Config
A file configuration loader that supports PHP, INI, XML, JSON, and YML files for the Slim Framework. It internally uses https://github.com/hassankhan/config.
Stars: ✭ 28 (+33.33%)
Mutual labels:  slim-framework
Slim
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Stars: ✭ 11,171 (+53095.24%)
Mutual labels:  slim-framework
Slim4-Skeleton
Web application skeleton that uses the Slim4 Framework, PHP-DI, Nyholm PSR7 and Twig.
Stars: ✭ 40 (+90.48%)
Mutual labels:  slim-framework
GeoLite2-City
GeoLite2-City.mmdb.gz CDN files based on Free Open Source CDN jsDelivr!
Stars: ✭ 170 (+709.52%)
Mutual labels:  ip
phpPgAdmin6
PHP7+ Based administration tool for PostgreSQL 9.3+
Stars: ✭ 45 (+114.29%)
Mutual labels:  slim-framework
slim-skeleton
A Slim 3 skeleton project to easily bootstrap MVC applications using Slim Framework 3
Stars: ✭ 14 (-33.33%)
Mutual labels:  slim-framework
wordpress-eloquent
A library that converts converts wordpress tables into Laravel Eloquent Models.
Stars: ✭ 129 (+514.29%)
Mutual labels:  slim-framework
private-ip
Check if IP address is private.
Stars: ✭ 26 (+23.81%)
Mutual labels:  ip
IPpy
🚀 Ping IP addresses and domains in parallel to find the accessible and inaccessible ones.
Stars: ✭ 54 (+157.14%)
Mutual labels:  ip

Slim Framework Restrict Route

Latest version Build Status Coverage Status Quality Score Total Downloads PSR2 Conformance

A slim middleware to restrict ip addresses that will access to your routes. It internally uses Ip Validator of Respect/Validation and rka-ip-address-middleware.

Install

Via Composer

$ composer require davidepastore/slim-restrict-route

Requires Slim 3.0.0 or newer.

Usage

You have to register also the RKA\Middleware\IpAddress middleware to correctly read the ip address. In most cases you want to register DavidePastore\Slim\RestrictRoute for a single route, however, as it is middleware, you can also register it for all routes.

Register per route

$app = new \Slim\App();

$app->add(new RKA\Middleware\IpAddress());

$options = array(
  'ip' => '192.*.*.*'
);

$app->get('/api/myEndPoint',function ($req, $res, $args) {
  //Your amazing route code
})->add(new \DavidePastore\Slim\RestrictRoute\RestrictRoute($options));

$app->run();

Register for all routes

$app = new \Slim\App();

$app->add(new RKA\Middleware\IpAddress());

$options = array(
  'ip' => '192.*.*.*'
);

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add(new \DavidePastore\Slim\RestrictRoute\RestrictRoute($options));

$app->get('/foo', function ($req, $res, $args) {
  //Your amazing route code
});

$app->post('/bar', function ($req, $res, $args) {
  //Your amazing route code
});

$app->run();

Ip address

You can restrict route using a different value of ip in the options given to \RestrictRoute:

  • any of the filters provided by PHP regarding FILTER_VALIDATE_IP (e.g.: FILTER_FLAG_NO_PRIV_RANGE);
  • asterisk (*) to filter ip that are in the given subnet (e.g.: 192.*);
  • ranges (-) to filter ip that are in the given range (e.g.: 192.168.0.0-192.168.255.255);
  • single ip (e.g.: 192.168.0.1-192.168.0.1);
  • array of ranges to filter ip (e.g.: array('192.0.0.0-192.255.255.255', '178.0.0.*')).

You can find more syntax information on the Ip validator documentation and in its Unit Test class.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].