1 | <?php |
||||||
2 | |||||||
3 | namespace Someshwer\Firewall\Lib; |
||||||
4 | |||||||
5 | use Someshwer\Firewall\src\Repo\FirewallRepository; |
||||||
6 | |||||||
7 | /** |
||||||
8 | * Class Firewall. |
||||||
9 | * |
||||||
10 | * @author Someshwer |
||||||
11 | * Date: 15-08-2018 |
||||||
12 | */ |
||||||
13 | class Firewall |
||||||
14 | { |
||||||
15 | /** |
||||||
16 | * @var \Illuminate\Config\Repository|mixed |
||||||
0 ignored issues
–
show
|
|||||||
17 | */ |
||||||
18 | private $whitelist; |
||||||
19 | |||||||
20 | /** |
||||||
21 | * @var \Illuminate\Config\Repository|mixed |
||||||
22 | */ |
||||||
23 | private $blacklist; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * @var \Illuminate\Config\Repository|mixed |
||||||
27 | */ |
||||||
28 | private $accept_list; |
||||||
29 | |||||||
30 | /** |
||||||
31 | * @var \Illuminate\Config\Repository|mixed |
||||||
32 | */ |
||||||
33 | private $reject_list; |
||||||
34 | |||||||
35 | /** |
||||||
36 | * @var FirewallRepository |
||||||
37 | */ |
||||||
38 | private $repo; |
||||||
39 | |||||||
40 | /** |
||||||
41 | * Firewall constructor. |
||||||
42 | * |
||||||
43 | * @param FirewallRepository $firewallRepository |
||||||
44 | */ |
||||||
45 | public function __construct(FirewallRepository $firewallRepository) |
||||||
46 | { |
||||||
47 | $this->repo = $firewallRepository; |
||||||
48 | $this->whitelist = config('firewall.whitelist'); |
||||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
49 | $this->blacklist = config('firewall.blacklist'); |
||||||
50 | $this->accept_list = config('firewall.accept'); |
||||||
51 | $this->reject_list = config('firewall.reject'); |
||||||
52 | } |
||||||
53 | |||||||
54 | /** |
||||||
55 | * This package provides some useful information about the package. |
||||||
56 | * |
||||||
57 | * @return array |
||||||
58 | */ |
||||||
59 | public function info() |
||||||
60 | { |
||||||
61 | return [ |
||||||
62 | 'package_name' => 'Laravel - Firewall', |
||||||
63 | 'description' => 'Laravel Firewall package detects unknown ip addresses based on |
||||||
64 | blacklist and whitelist ip addresses. Whitelist and Blacklist are two configuration options |
||||||
65 | any one of them you can set to TRUE based on your requirement. For example if you set blacklist |
||||||
66 | to TRUE and have added some ip addresses to blacklist then in that case any request to the |
||||||
67 | application will be blocked by the firewall from those ip addresses that listed in blacklist. |
||||||
68 | If you have added them to whitelist only the request from the whitelisted ips can be accepted |
||||||
69 | and remaining all requests will be blocked by the firewall. If you set both black and whitelist |
||||||
70 | to TRUE then in that case the preference will be given to blacklist', |
||||||
71 | 'latest_release' => '2.2.1', |
||||||
72 | 'stable_version' => '2.2.1', |
||||||
73 | 'author' => 'Someshwer Bandapally<[email protected]>', |
||||||
74 | ]; |
||||||
75 | } |
||||||
76 | |||||||
77 | /** |
||||||
78 | * Returns all whitelisted ip addresses. |
||||||
79 | * |
||||||
80 | * @return array |
||||||
81 | */ |
||||||
82 | public function whitelist() |
||||||
83 | { |
||||||
84 | return ['whitelisted_ips' => $this->whitelist]; |
||||||
85 | } |
||||||
86 | |||||||
87 | /** |
||||||
88 | * Returns all black listed ip addresses. |
||||||
89 | * |
||||||
90 | * @return array |
||||||
91 | */ |
||||||
92 | public function blacklist() |
||||||
93 | { |
||||||
94 | return ['blacklisted_ips' => $this->blacklist]; |
||||||
95 | } |
||||||
96 | |||||||
97 | /** |
||||||
98 | * Returns both combination of white and black listed ip addresses. |
||||||
99 | * |
||||||
100 | * @return array |
||||||
101 | */ |
||||||
102 | public function whiteAndBlackList() |
||||||
103 | { |
||||||
104 | $common_list = array_intersect($this->whitelist, $this->blacklist); |
||||||
0 ignored issues
–
show
It seems like
$this->whitelist can also be of type Illuminate\Config\Repository ; however, parameter $array1 of array_intersect() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$this->blacklist can also be of type Illuminate\Config\Repository ; however, parameter $array2 of array_intersect() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
105 | $whitelist = array_diff($this->whitelist, $common_list); |
||||||
0 ignored issues
–
show
It seems like
$this->whitelist can also be of type Illuminate\Config\Repository ; however, parameter $array1 of array_diff() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
106 | $blacklist = array_diff($this->blacklist, $common_list); |
||||||
107 | $list_groups = [ |
||||||
108 | 'white' => $whitelist, |
||||||
109 | 'black' => $blacklist, |
||||||
110 | 'common' => $common_list, |
||||||
111 | ]; |
||||||
112 | $result_list = []; |
||||||
113 | foreach ($list_groups as $list_type => $list_group) { |
||||||
114 | $result_list[] = $this->repo->getList($list_group, 2, $list_type); |
||||||
115 | } |
||||||
116 | |||||||
117 | return array_collapse($result_list); |
||||||
0 ignored issues
–
show
The function
array_collapse was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
118 | } |
||||||
119 | |||||||
120 | /** |
||||||
121 | * Returns accept listed ip addresses. |
||||||
122 | * |
||||||
123 | * @return array |
||||||
124 | */ |
||||||
125 | public function acceptList() |
||||||
126 | { |
||||||
127 | return ['accept_listed_ips' => $this->accept_list]; |
||||||
128 | } |
||||||
129 | |||||||
130 | /** |
||||||
131 | * Returns reject listed ip addresses. |
||||||
132 | * |
||||||
133 | * @return array |
||||||
134 | */ |
||||||
135 | public function rejectList() |
||||||
136 | { |
||||||
137 | return ['reject_listed_ips' => $this->reject_list]; |
||||||
138 | } |
||||||
139 | |||||||
140 | /** |
||||||
141 | * Returns both combination of accept and reject listed ip addresses. |
||||||
142 | * |
||||||
143 | * @return array |
||||||
144 | */ |
||||||
145 | public function acceptAndRejectList() |
||||||
146 | { |
||||||
147 | $common_list = array_intersect($this->accept_list, $this->reject_list); |
||||||
0 ignored issues
–
show
It seems like
$this->reject_list can also be of type Illuminate\Config\Repository ; however, parameter $array2 of array_intersect() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$this->accept_list can also be of type Illuminate\Config\Repository ; however, parameter $array1 of array_intersect() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
148 | $accept_list = array_diff($this->accept_list, $common_list); |
||||||
0 ignored issues
–
show
It seems like
$this->accept_list can also be of type Illuminate\Config\Repository ; however, parameter $array1 of array_diff() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
149 | $reject_list = array_diff($this->reject_list, $common_list); |
||||||
150 | $list_groups = [ |
||||||
151 | 'accept' => $accept_list, |
||||||
152 | 'reject' => $reject_list, |
||||||
153 | 'common' => $common_list, |
||||||
154 | ]; |
||||||
155 | $result_list = []; |
||||||
156 | foreach ($list_groups as $list_type => $list_group) { |
||||||
157 | $result_list[] = $this->repo->getList($list_group, 2, $list_type); |
||||||
158 | } |
||||||
159 | |||||||
160 | return array_collapse($result_list); |
||||||
0 ignored issues
–
show
The function
array_collapse was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
161 | } |
||||||
162 | |||||||
163 | /** |
||||||
164 | * Returns all ip addresses with their statuses. |
||||||
165 | * |
||||||
166 | * @return array |
||||||
167 | */ |
||||||
168 | public function getAllIpAddresses() |
||||||
169 | { |
||||||
170 | $ip_addresses = $this->repo->getUniqueIpAddresses(); |
||||||
171 | $ip_list_with_statuses = []; |
||||||
172 | $index = 0; |
||||||
173 | foreach ($ip_addresses as $ip_address) { |
||||||
174 | $ip_list_with_statuses[] = $this->repo->getIpStatus($ip_address); |
||||||
175 | $index++; |
||||||
176 | } |
||||||
177 | |||||||
178 | return $ip_list_with_statuses; |
||||||
179 | } |
||||||
180 | |||||||
181 | /** |
||||||
182 | * Returns firewall log data along with pagination if pagination is enabled in configuration. |
||||||
183 | * |
||||||
184 | * @param null $from_date |
||||||
0 ignored issues
–
show
|
|||||||
185 | * @param null $to_date |
||||||
0 ignored issues
–
show
|
|||||||
186 | * |
||||||
187 | * @return mixed|\Someshwer\Firewall\src\Entities\FirewallLog|\Someshwer\Firewall\src\Entities\FirewallRequestsLogModel |
||||||
188 | */ |
||||||
189 | public function log($from_date = null, $to_date = null) |
||||||
190 | { |
||||||
191 | $log = $this->repo->getLogInstance(); |
||||||
192 | if ((($from_date != null) || ($to_date != null))) { |
||||||
0 ignored issues
–
show
|
|||||||
193 | if (!$this->repo->validateDates($from_date, $to_date)) { |
||||||
194 | $log = $this->repo->addWhereBetweenClause($log, $from_date, $to_date); |
||||||
195 | } |
||||||
196 | } |
||||||
197 | $log = $this->repo->addPagination($log); |
||||||
198 | |||||||
199 | return $log; |
||||||
200 | } |
||||||
201 | |||||||
202 | /** |
||||||
203 | * Returns firewall requests log data along with pagination if pagination is enabled in configuration. |
||||||
204 | * |
||||||
205 | * @param null $from_date |
||||||
0 ignored issues
–
show
|
|||||||
206 | * @param null $to_date |
||||||
0 ignored issues
–
show
|
|||||||
207 | * |
||||||
208 | * @return mixed|\Someshwer\Firewall\src\Entities\FirewallLog|\Someshwer\Firewall\src\Entities\FirewallRequestsLogModel |
||||||
209 | */ |
||||||
210 | public function requestLog($from_date = null, $to_date = null) |
||||||
211 | { |
||||||
212 | $log = $this->repo->getLogInstance('request_log'); |
||||||
213 | if ((($from_date != null) || ($to_date != null))) { |
||||||
0 ignored issues
–
show
|
|||||||
214 | if (!$this->repo->validateDates($from_date, $to_date)) { |
||||||
215 | $log = $this->repo->addWhereBetweenClause($log, $from_date, $to_date); |
||||||
216 | } |
||||||
217 | } |
||||||
218 | $log = $this->repo->addPagination($log, 'request_log'); |
||||||
219 | |||||||
220 | return $log; |
||||||
221 | } |
||||||
222 | |||||||
223 | /** |
||||||
224 | * Returns exceptions log data along with pagination if pagination is enabled in configuration. |
||||||
225 | * |
||||||
226 | * @param null $from_date |
||||||
0 ignored issues
–
show
|
|||||||
227 | * @param null $to_date |
||||||
0 ignored issues
–
show
|
|||||||
228 | * |
||||||
229 | * @return mixed|\Someshwer\Firewall\src\Entities\ExceptionLog|\Someshwer\Firewall\src\Entities\FirewallLog|\Someshwer\Firewall\src\Entities\FirewallRequestsLogModel |
||||||
230 | */ |
||||||
231 | public function exceptionLog($from_date = null, $to_date = null) |
||||||
232 | { |
||||||
233 | $log = $this->repo->getLogInstance('exception_log'); |
||||||
234 | if ((($from_date != null) || ($to_date != null))) { |
||||||
0 ignored issues
–
show
|
|||||||
235 | if (!$this->repo->validateDates($from_date, $to_date)) { |
||||||
236 | $log = $this->repo->addWhereBetweenClause($log, $from_date, $to_date); |
||||||
237 | } |
||||||
238 | } |
||||||
239 | $log = $this->repo->addPagination($log, 'exception_log'); |
||||||
240 | |||||||
241 | return $log; |
||||||
242 | } |
||||||
243 | } |
||||||
244 |
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