|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Someshwer\Firewall\src\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Someshwer<[email protected]> |
|
9
|
|
|
* Date: 11-08-2018 |
|
10
|
|
|
* Time: 20:42 IST |
|
11
|
|
|
* |
|
12
|
|
|
* This command returns all accept listed and reject listed |
|
13
|
|
|
* ip addresses based on the option provided. |
|
14
|
|
|
*/ |
|
15
|
|
|
class AcceptAndRejectListCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The name and signature of the console command. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $signature = 'ip:list {--option=none}'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The console command description. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $description = 'This command returns all ip addresses that are added to accept list array |
|
30
|
|
|
and reject list array in "firewall" config file.'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Create a new command instance. |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Execute the console command. |
|
44
|
|
|
* This command returns and displays all accept listed and |
|
45
|
|
|
* reject listed ip addresses based on the option value. |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public function handle() |
|
50
|
|
|
{ |
|
51
|
|
|
$option = $this->option('option'); |
|
52
|
|
|
$headers = []; |
|
53
|
|
|
$list = []; |
|
54
|
|
|
if ($option == 'none' || $option == null) { |
|
55
|
|
|
$this->warn('No option is provided!'); |
|
56
|
|
|
$this->warn('Try to use following available options:'); |
|
57
|
|
|
$this->warn('php artisan ip:list --option=accept (or)'); |
|
58
|
|
|
$this->warn('php artisan ip:list --option=reject'); |
|
59
|
|
|
} |
|
60
|
|
|
if ($option == 'accept') { |
|
61
|
|
|
$list = config('firewall.accept'); |
|
|
|
|
|
|
62
|
|
|
$headers = ['SNO', 'IP Address', 'Accept Listed']; |
|
63
|
|
|
} |
|
64
|
|
|
if ($option == 'reject') { |
|
65
|
|
|
$list = config('firewall.reject'); |
|
66
|
|
|
$headers = ['SNO', 'IP Address', 'Reject Listed']; |
|
67
|
|
|
} |
|
68
|
|
|
$ip_list = $this->formTableHeaders($list, $option); |
|
69
|
|
|
$this->table($headers, $ip_list); |
|
70
|
|
|
(($option == 'accept') || ($option == 'reject')) ? $this->info('Done!!') : null; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the data in a table view. |
|
75
|
|
|
* |
|
76
|
|
|
* @param array $list |
|
77
|
|
|
* @param $option |
|
78
|
|
|
* |
|
79
|
|
|
* @return array $ip_list |
|
80
|
|
|
*/ |
|
81
|
|
|
private function formTableHeaders($list, $option) |
|
82
|
|
|
{ |
|
83
|
|
|
$option_key = ($option == 'accept') ? 'accepted' : (($option == 'reject') ? 'rejected' : null); |
|
84
|
|
|
$ip_list = []; |
|
85
|
|
|
$i = 1; |
|
86
|
|
|
foreach ($list as $item) { |
|
87
|
|
|
$ip_list[] = [ |
|
88
|
|
|
'sno' => $i, |
|
89
|
|
|
'ip_address' => $item, |
|
90
|
|
|
$option_key => 'true', |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $ip_list; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths