Skip to content

Commit bd1f3b4

Browse files
committed
Commenting, ability to specify middleware directives via middleware & more.
1 parent 79ea4c9 commit bd1f3b4

15 files changed

+719
-133
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "boxed-code/laravel-ip-authorization",
3-
"description": "Authorize access based on IP address, range or subnet.",
3+
"description": "Authorize access based on IPv4 & IPv6 addresses, ranges, subnets or wildcards.",
44
"type": "library",
55
"license": "MIT",
66
"authors": [
@@ -32,7 +32,7 @@
3232
"extra": {
3333
"laravel": {
3434
"providers": [
35-
"BoxedCode\\Laravel\\Auth\\Ip\\AuthServiceProvider"
35+
"BoxedCode\\Laravel\\Auth\\Ip\\IpAuthServiceProvider"
3636
]
3737
}
3838
}

config/ip_auth.php

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,100 @@
11
<?php
22

33
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Default Action
7+
|--------------------------------------------------------------------------
8+
|
9+
| By default, if the request matches none of the defined derivatives we can
10+
| either deny or allow the user. You can specify this default action here.
11+
|
12+
*/
413

5-
'repositories' => [
6-
'default' => 'config',
14+
'default_action' => 'deny',
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Directives
19+
|--------------------------------------------------------------------------
20+
|
21+
| Directives specify which groups of addresses are allowed or denied access.
22+
| A directive consists of a list name and an action to take if an address exists
23+
| within that list. Directives are processed sequentially, the result of the first
24+
| matched directive will be returned. By default, the blacklist is processed before
25+
| the whitelist, if an address was in both lists it would denied as the first
26+
| directive to be processed is the blacklist. You can reorder the directives to
27+
| suit your needs.
28+
|
29+
| You can create as many directives as you would like, by default there are two
30+
| whitelist & blacklist.
31+
|
32+
*/
33+
34+
'directives' => [
35+
'blacklist' => 'deny',
36+
'whitelist' => 'allow',
37+
],
738

8-
'configuration' => [
39+
/*
40+
|--------------------------------------------------------------------------
41+
| List Repositories
42+
|--------------------------------------------------------------------------
43+
|
44+
| Out of the box the package supports loading address lists from configuration
45+
| or the database. The default is configuration, you may configure whitelisted
46+
| or blacklisted addresses at the bottom of this file.
47+
|
48+
*/
49+
50+
'default_repository' => 'config',
51+
52+
'repositories' => [
953

10-
'eloquent' => [
11-
'model' => null,
12-
]
54+
'config' => [
55+
'key' => 'ip_auth',
56+
],
1357

58+
'database' => [
59+
'connection' => null,
60+
'table' => 'ip_auth_access_list',
1461
]
15-
],
1662

17-
'default' => 'deny',
18-
19-
'directives' => [
20-
'address_whitelisted' => 'allow',
21-
'address_blacklisted' => 'deny',
2263
],
2364

24-
'whitelist' => [
25-
//'127.0.0.1',
26-
//192.168.1.*
27-
//192.168.1/24
28-
//192.168.1.1/255.255.255.0
29-
//192.168.1.1-192.168.1.10
30-
//2001:cdba:0000:0000:0000:0000:3257:*
31-
],
65+
/*
66+
|--------------------------------------------------------------------------
67+
| Configuration Based Address Lists
68+
|--------------------------------------------------------------------------
69+
|
70+
| If you decide to use the default configuration list repository, you can
71+
| simply add the addresses you wish to control below.
72+
|
73+
*/
74+
75+
'addresses' => [
3276

33-
'blacklist' => [
34-
//'127.0.0.1',
35-
//'192.168.99.1',
36-
//192.168.1.*
37-
//192.168.1/24
38-
//192.168.1.1/255.255.255.0
39-
//192.168.1.1-192.168.1.10
40-
//2001:cdba:0000:0000:0000:0000:3257:*
77+
'whitelist' => [
78+
//'127.0.0.1',
79+
//'192.168.1.*',
80+
//192.168.1.0/24
81+
//192.168.1.1 255.255.255.0
82+
//192.168.1.1-192.168.1.10
83+
//2001:cdba:0000:0000:0000:0000:3257:*
84+
],
85+
86+
'blacklist' => [
87+
//'127.0.0.1',
88+
//'192.168.99.1',
89+
//192.168.1.*
90+
//192.168.1.0/24
91+
//192.168.1.1 255.255.255.0
92+
//192.168.1.1-192.168.1.10
93+
//2001:cdba:0000:0000:0000:0000:3257:*
94+
],
95+
96+
'custom_list' => [
97+
// place custom address definitions here.
98+
]
4199
]
42100
];
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class IpAuthAccessList extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('ip_auth_access_list', function($table) {
17+
$table->increments('id');
18+
$table->string('label');
19+
$table->string('list');
20+
$table->string('type');
21+
$table->bigInteger('range_start')->unsigned();
22+
$table->bigInteger('range_end')->unsigned();
23+
$table->timestamp('created_at')->useCurrent();
24+
25+
$table->index(['list', 'type', 'range_start', 'range_end'], 'range_index');
26+
});
27+
}
28+
29+
/**
30+
* Reverse the migrations.
31+
*
32+
* @return void
33+
*/
34+
public function down()
35+
{
36+
Schema::dropIfExists('ip_auth_access_list');
37+
}
38+
}

0 commit comments

Comments
 (0)