Total Complexity | 12 |
Total Lines | 92 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class IPFilter |
||
11 | { |
||
12 | /** |
||
13 | * Determines whether to block current request or not. |
||
14 | * |
||
15 | * @var bool |
||
16 | */ |
||
17 | private $block; |
||
18 | |||
19 | /** |
||
20 | * Sets the constant to 'BLACKLIST'. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $black_list; |
||
25 | |||
26 | /** |
||
27 | * Sets the constant to 'WHITELIST'. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $white_list; |
||
32 | |||
33 | /** |
||
34 | * Sets the constant to 'NONE'. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $none; |
||
39 | |||
40 | /** |
||
41 | * Constructor function. |
||
42 | */ |
||
43 | public function __construct() |
||
44 | { |
||
45 | $this->block = true; |
||
46 | $this->black_list = 'BLACKLIST'; |
||
47 | $this->white_list = 'WHITELIST'; |
||
48 | $this->none = 'NONE'; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Returns one of the filter type i.e; 'BLACKLIST', 'WHITELIST', or 'NONE'. |
||
53 | * |
||
54 | * @return string $list |
||
55 | */ |
||
56 | public function getFilterType() |
||
57 | { |
||
58 | $filter_type = $this->none; |
||
59 | if (config('firewall.enable_whitelist') && config('firewall.enable_blacklist')) { |
||
|
|||
60 | $filter_type = $this->black_list; |
||
61 | } |
||
62 | if (config('firewall.enable_whitelist') && (!config('firewall.enable_blacklist'))) { |
||
63 | $filter_type = $this->white_list; |
||
64 | } |
||
65 | if (config('firewall.enable_blacklist') && (!config('firewall.enable_whitelist'))) { |
||
66 | $filter_type = $this->black_list; |
||
67 | } |
||
68 | |||
69 | return $filter_type; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Filters whitelist and returns 'true' if current request ip is not in whitelist. |
||
74 | * |
||
75 | * @param object $request |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function filterWhiteList($request) |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Filters blacklist and returns 'true' if current request ip is available in blacklist. |
||
90 | * |
||
91 | * @param [type] $request |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function filterBlackList($request) |
||
102 | } |
||
103 | } |
||
104 |