1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Shieldon package. |
4
|
|
|
* |
5
|
|
|
* (c) Terry L. <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Shieldon\Firewall\Integration; |
15
|
|
|
|
16
|
|
|
use Shieldon\Firewall\Firewall; |
17
|
|
|
use Shieldon\Firewall\HttpResolver; |
18
|
|
|
use CodeIgniter\HTTP\RequestInterface as Request; |
|
|
|
|
19
|
|
|
use CodeIgniter\HTTP\ResponseInterface as Response; |
|
|
|
|
20
|
|
|
use CodeIgniter\Filters\FilterInterface; |
|
|
|
|
21
|
|
|
use function dirname; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CodeIgniter 4 Middleware of Shieldon Firewall. |
25
|
|
|
*/ |
26
|
|
|
class CodeIgniter4 implements FilterInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The absolute path of the storage where stores Shieldon generated data. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $storage; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The entry point of Shieldon Firewall's control panel. |
37
|
|
|
* |
38
|
|
|
* For example: https://yoursite.com/firewall/panel/ |
39
|
|
|
* Just use the path component of a URI. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $panelUri; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor. |
47
|
|
|
* |
48
|
|
|
* @param string $storage See property `storage` explanation. |
49
|
|
|
* @param string $panelUri See property `panelUri` explanation. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function __construct(string $storage = '', string $panelUri = '') |
54
|
|
|
{ |
55
|
|
|
$dir = dirname($_SERVER['SCRIPT_FILENAME']); |
56
|
|
|
|
57
|
|
|
$this->storage = $dir . '/../writable/shieldon_firewall'; |
58
|
|
|
$this->panelUri = '/firewall/panel/'; |
59
|
|
|
|
60
|
|
|
if ('' !== $storage) { |
61
|
|
|
$this->storage = $storage; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ('' !== $panelUri) { |
65
|
|
|
$this->panelUri = $panelUri; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Shieldon middleware invokable class. |
71
|
|
|
* |
72
|
|
|
* @param Request $request |
73
|
|
|
* |
74
|
|
|
* @return mixed |
75
|
|
|
*/ |
76
|
|
|
public function before(Request $request) |
77
|
|
|
{ |
78
|
|
|
if ($request->isCLI()) { |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// CodeIgniter 4 is not a PSR-7 compatible framework, therefore we don't |
83
|
|
|
// pass the Reqest and Reposne to Firewall instance. |
84
|
|
|
// Shieldon will create them by its HTTP factory. |
85
|
|
|
$firewall = new Firewall(); |
86
|
|
|
$firewall->configure($this->storage); |
87
|
|
|
$firewall->controlPanel($this->panelUri); |
88
|
|
|
|
89
|
|
|
// Pass CodeIgniter CSRF Token to Captcha form. |
90
|
|
|
$firewall->getKernel()->setCaptcha( |
91
|
|
|
new \Shieldon\Captcha\Csrf([ |
|
|
|
|
92
|
|
|
'name' => csrf_token(), |
|
|
|
|
93
|
|
|
'value' => csrf_hash(), |
|
|
|
|
94
|
|
|
]) |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$response = $firewall->run(); |
98
|
|
|
|
99
|
|
|
if ($response->getStatusCode() !== 200) { |
100
|
|
|
$httpResolver = new HttpResolver(); |
101
|
|
|
$httpResolver($response); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* We don't have anything to do here. |
107
|
|
|
* |
108
|
|
|
* @param Response $request |
109
|
|
|
* @param Response $response |
110
|
|
|
* |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
|
|
public function after(Request $request, Response $response) |
114
|
|
|
{ |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
} |
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