webparking/laravel-limited-access

Limited access for Laravel

2.0.0 2022-01-28 10:01 UTC

This package is auto-updated.

Last update: 2024-03-28 14:50:56 UTC


README

Tests

This package provides an easy access-restricting layer for your Laravel application.

With limited access you can block or allow certain ip addresses on application level. You could also define a list of access codes to distribute between trusted users.

A few use-cases are:

  • Set access codes for an application that is not ready to go live yet. For example an acceptance environment.
  • Block malicious users from using your application. Simply add their ip addresses to the blocked list.
  • Making a private application only a few users can access. Just block all ip addresses except your own.

Here's an example of what your login could look like when using access codes

screenshot

Installation

Add this package to composer.

composer require webparking/laravel-limited-access

Publish assets:

php artisan vendor:publish --provider="Webparking\LimitedAccess\ServiceProvider" --tag="public"

Optional steps

Publish config:

php artisan vendor:publish --provider="Webparking\LimitedAccess\ServiceProvider" --tag="config"

Publish translations:

php artisan vendor:publish --provider="Webparking\LimitedAccess\ServiceProvider" --tag="lang"

Or just publish all the things:

php artisan vendor:publish --provider="Webparking\LimitedAccess\ServiceProvider"

Usage

To use this package you need to enable it by either enabling the package in the config or adding the following to your .env file.

LIMITED_ACCESS_ENABLED=true

To add access codes add the following key to your .env file and specify your access codes in a comma separated list.

LIMITED_ACCESS_CODES=comma,separated,access,codes

Blocking/Ignoring IP addresses

In config/limited-access you can add single IP addresses or IP address ranges in CIDR format.

Example:

return [
    'block_ips' => [
        '192.168.1.0/24',
        '66.66.66.66', // 66.66.66.66/32 is equivalent
        '2000:ffff::1',
        '2000:ffff/64',
    ],

    'ignore_ips' => [
        '11.22.33.44',
        '10.0.0.0/8',
        '127.0.0.1',
        '::1',
    ],
];

Blocked IPs take priority over ignored IPs, so adding the same address or range to both arrays will cause the given IP to be blocked.

You can leave both of these arrays empty if you wish for everyone to be prompted for a password.

Licence and Postcardware

This software is open source and licensed under the MIT license.

If you use this software in your daily development we would appreciate to receive a postcard of your hometown.

Please send it to: Webparking BV, Cypresbaan 31a, 2908 LT Capelle aan den IJssel, The Netherlands