├── LICENSE
├── README.md
├── composer.json
├── config
└── ipchecker.php
├── database
└── migrations
│ └── 2019_11_27_085806_create_ip_lists_table.php
├── doc
├── iplist.PNG
├── json.PNG
└── view.PNG
├── resources
└── views
│ ├── error.blade.php
│ └── index.blade.php
├── routes
└── web.php
└── src
├── Contracts
└── IpCheckerInterface.php
├── DBDriver.php
├── FileDriver.php
├── Http
├── Controllers
│ └── IpCheckerController.php
└── Middleware
│ └── IpChecker.php
├── IpCheckerServiceProvider.php
├── IpList.php
└── lang
├── en
└── messages.php
└── tr
└── messages.php
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Hayri Can BARÇIN
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel IP Checker
2 | [](https://packagist.org/packages/hayrican/ipchecker)
3 | [](https://packagist.org/packages/hayrican/ipchecker)
4 | [](//packagist.org/packages/hayrican/ipchecker)
5 | [](https://scrutinizer-ci.com/g/HayriCan/laravel-ip-checker/?branch=master)
6 | [](https://www.codacy.com/manual/HayriCan/laravel-ip-checker?utm_source=github.com&utm_medium=referral&utm_content=HayriCan/laravel-ip-checker&utm_campaign=Badge_Grade)
7 | [](https://scrutinizer-ci.com/g/HayriCan/laravel-ip-checker/build-status/master)
8 | [](https://scrutinizer-ci.com/code-intelligence)
9 | [](https://packagist.org/packages/hayrican/ipchecker)
10 |
11 | This package provides restricted access via IP Address to your application.
12 |
13 | ## Installation
14 | To get started, you should add the `hayrican/ipchecker` Composer dependency to your project:
15 | ```
16 | composer require hayrican/ipchecker
17 | ```
18 |
19 | #### Service Provider (Laravel Older 5.5)
20 |
21 | ##### If you are using later version of Laravel 5.5, you can skip this step.
22 |
23 | Register provider on your `config/app.php` file.
24 | ```php
25 | 'providers' => [
26 | ...,
27 | HayriCan\IpChecker\IpCheckerServiceProvider::class,
28 | ]
29 | ```
30 |
31 | ## Configuration
32 | You should publish vendor for configuration file.
33 | ```bash
34 | $ php artisan vendor:publish --tag="ipchecker"
35 | ```
36 |
37 | ##### Driver
38 | The config file is called *ipchecker.php*. Currently supported drivers are `db` and `file`
39 |
40 | Default driver is `file` and ipchecker will use file to record ip addresses. But if you want to use Database for records, migrate table by using
41 |
42 | ```bash
43 | php artisan migrate
44 | ```
45 | You have to change driver to `db` before migrate. Otherwise it will not migrate the table.
46 |
47 | ##### Route Group Middleware
48 | ```php
49 | 'api_middleware'=>'api',
50 | 'web_middleware'=>'web',
51 | ```
52 | If your routes has different middleware then these default values you can change them in here.
53 | These route middleware need for filtering response of denial access.
54 |
55 | ## Localization
56 | When you call ``php artisan vendor:publish --tag="ipchecker"`` command, it will also publish `lang` file to your `resources/lang` directory. You can change all fields as you desire.
57 |
58 |
59 | # Package Usage
60 | ## 1.Add Middleware
61 | Add middleware named `ipchecker` to the route or controller you want to log data
62 |
63 | ```php
64 | // in app.php or web.php
65 |
66 | Route::group(['middleware' => ['ipchecker']], function () {
67 | Route::get('test',function (){
68 | dd('Test API');
69 | });
70 | });
71 | ```
72 | When try to access this route it will check your IP Address. If you ip address is not on the list you will get response
73 | ```php
74 | {
75 | "success": false,
76 | "code": 250,
77 | "message": "Your IP Address not in the list."
78 | }
79 | ```
80 | Otherwise you will access to the route.
81 |
82 | ## 2.Add IP Address
83 |
84 | Up to default config dashboard can be accessible via ***yourdomain.com/iplists*** but it is configurable from config file `ipchecker.php`
85 |
86 | ```php
87 | {
88 | "settings"=>[
89 | "auth" => false,
90 | "admin_id"=>[],
91 | "route_prefix"=> "",
92 | ],
93 | }
94 | ```
95 |
96 | If you want to guard this page just change `"auth"` to `true` and it require `"auth"` middleware.
97 |
98 | When you enabled auth you could add admin users id to ``"admin_id"`` array.
99 | If leave ``"admin_id"`` array empty, all users can has access to IP Checker dashboard
100 | ```php
101 | {
102 | "settings"=>[
103 | "auth"=> true,
104 | "admin_id"=>[2,5],
105 | "route_prefix"=> "",
106 | ],
107 | }
108 | ```
109 |
110 | Also you can change the route prefix of this dashboard. If you change `"route_prefix"` to `"foo"` your dashboard will be accessible via ***yourdomain.com/foo/iplists***.
111 |
112 |
113 |
114 | 
115 |
116 | You can add IP Address in here.
117 |
118 | ## Author
119 |
120 | [Hayri Can BARÇIN]
121 | Email: [Contact Me]
122 |
123 | ## License
124 |
125 | This project is licensed under the MIT License - see the [License File](LICENSE) for details
126 |
127 |
128 |
129 | [//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)
130 | [Hayri Can BARÇIN]:
131 | [Contact Me]:
132 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hayrican/ipchecker",
3 | "description": "Laravel package for providing restricted access by IP Address to your application",
4 | "homepage": "https://github.com/HayriCan/laravel-ip-checker",
5 | "keywords": [
6 | "laravel",
7 | "ip address",
8 | "restricted",
9 | "access",
10 | "helper",
11 | "php7"
12 | ],
13 | "type": "library",
14 | "license": "MIT",
15 | "authors": [
16 | {
17 | "name": "hayrican",
18 | "email": "hayricanbarcin@gmail.com"
19 | }
20 | ],
21 | "minimum-stability": "dev",
22 | "require": {
23 | "ext-json": "*",
24 | "ext-simplexml": "*"
25 | },
26 | "autoload": {
27 | "psr-4": {
28 | "HayriCan\\IpChecker\\": "src/"
29 | }
30 | },
31 | "extra": {
32 | "laravel": {
33 | "providers": [
34 | "HayriCan\\IpChecker\\IpCheckerServiceProvider"
35 | ]
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/config/ipchecker.php:
--------------------------------------------------------------------------------
1 |
7 | * @license http://www.opensource.org/licenses/mit-license.php MIT
8 | * @link https://github.com/HayriCan/laravel-ip-checker
9 | */
10 |
11 | return [
12 |
13 | /*
14 | |--------------------------------------------------------------------------
15 | | Driver
16 | |--------------------------------------------------------------------------
17 | | Driver option currently supports "db" and "file"
18 | |
19 | */
20 |
21 | "driver" => "file",
22 |
23 | /*
24 | |--------------------------------------------------------------------------
25 | | File Path and File Name
26 | |--------------------------------------------------------------------------
27 | | If you switch driver to "file" it will write Allowed Ip Addresses on this path
28 | |
29 | */
30 |
31 | "filepath"=>"ipchecker",
32 | "filename" => "iplist.php",
33 |
34 |
35 | /*
36 | |--------------------------------------------------------------------------
37 | | Dashboard Settings
38 | |--------------------------------------------------------------------------
39 | | If you change "auth" to true your IpChecker dashboard will require "auth" middleware
40 | | When you enabled auth you could add admin users id to "admin_id" array.
41 | | If leave "admin_id" array empty, all users can has access to IP Checker dashboard
42 | | You can change IpChecker dashboard route prefix from "route_prefix"
43 | |
44 | */
45 |
46 | "settings"=>[
47 | "auth"=> false,
48 | "admin_id"=>[],
49 | "route_prefix"=> "",
50 | ],
51 |
52 | /*
53 | |--------------------------------------------------------------------------
54 | | Route Group Middleware
55 | |--------------------------------------------------------------------------
56 | | You can specify your "api.php" and "web.php" route group middleware for filtering response type.
57 | |
58 | |
59 | */
60 |
61 | "api_middleware"=>"api",
62 | "web_middleware"=>"web",
63 |
64 | ];
--------------------------------------------------------------------------------
/database/migrations/2019_11_27_085806_create_ip_lists_table.php:
--------------------------------------------------------------------------------
1 |
7 | * @license http://www.opensource.org/licenses/mit-license.php MIT
8 | * @link https://github.com/HayriCan/laravel-ip-checker
9 | */
10 |
11 | use Illuminate\Support\Facades\Schema;
12 | use Illuminate\Database\Schema\Blueprint;
13 | use Illuminate\Database\Migrations\Migration;
14 |
15 | class CreateIpListsTable extends Migration
16 | {
17 | /**
18 | * Run the migrations.
19 | *
20 | * @return void
21 | */
22 | public function up()
23 | {
24 | Schema::create('ip_lists', function (Blueprint $table) {
25 | $table->bigIncrements('id');
26 | $table->string('group');
27 | $table->string('definition');
28 | $table->string('ip');
29 | $table->timestamps();
30 | });
31 | }
32 |
33 | /**
34 | * Reverse the migrations.
35 | *
36 | * @return void
37 | */
38 | public function down()
39 | {
40 | Schema::dropIfExists('ip_lists');
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/doc/iplist.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HayriCan/laravel-ip-checker/cc58cc772db34bb4901602f63ac94606beb63916/doc/iplist.PNG
--------------------------------------------------------------------------------
/doc/json.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HayriCan/laravel-ip-checker/cc58cc772db34bb4901602f63ac94606beb63916/doc/json.PNG
--------------------------------------------------------------------------------
/doc/view.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HayriCan/laravel-ip-checker/cc58cc772db34bb4901602f63ac94606beb63916/doc/view.PNG
--------------------------------------------------------------------------------
/resources/views/error.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | @yield('title')
8 |
9 |
10 |
11 |
12 |
13 |
49 |
50 |
51 |