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 Psr\Http\Message\ResponseInterface as Response; |
17
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
18
|
|
|
use Psr\Http\Server\MiddlewareInterface as Middleware; |
19
|
|
|
use Psr\Http\Server\RequestHandlerInterface as RequestHandler; |
20
|
|
|
use Shieldon\Firewall\Firewall; |
21
|
|
|
use Shieldon\Firewall\HttpResolver; |
22
|
|
|
use function dirname; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* PSR-15 Middleware for Zend Framework. |
26
|
|
|
*/ |
27
|
|
|
class ZendPsr15 implements Middleware |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The absolute path of the storage where stores Shieldon generated data. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $storage; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The entry point of Shieldon Firewall's control panel. |
38
|
|
|
* |
39
|
|
|
* For example: https://yoursite.com/firewall/panel/ |
40
|
|
|
* Just use the path component of a URI. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $panelUri; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor. |
48
|
|
|
* |
49
|
|
|
* @param string $storage See property `storage` explanation. |
50
|
|
|
* @param string $panelUri See property `panelUri` explanation. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function __construct(string $storage = '', string $panelUri = '') |
55
|
|
|
{ |
56
|
|
|
$dir = dirname($_SERVER['SCRIPT_FILENAME']); |
57
|
|
|
|
58
|
|
|
$this->storage = $dir . '/../data/shieldon_firewall'; |
59
|
|
|
$this->panelUri = '/firewall/panel/'; |
60
|
|
|
|
61
|
|
|
if ('' !== $storage) { |
62
|
|
|
$this->storage = $storage; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ('' !== $panelUri) { |
66
|
|
|
$this->panelUri = $panelUri; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Shieldon middleware invokable class. |
72
|
|
|
* |
73
|
|
|
* @param ServerRequest $request PSR-7 request |
|
|
|
|
74
|
|
|
* @param RequestHandler $delegat PSR-15 request handler |
75
|
|
|
* |
76
|
|
|
* @return Response |
77
|
|
|
*/ |
78
|
|
|
public function process(Request $request, RequestHandler $handler): Response |
79
|
|
|
{ |
80
|
|
|
$firewall = new Firewall($request); |
81
|
|
|
|
82
|
|
|
// Pass \Zend\Validator\Csrf CSRF Token to Captcha form. |
83
|
|
|
$firewall->getKernel()->setCaptcha( |
84
|
|
|
new \Shieldon\Captcha\Csrf([ |
|
|
|
|
85
|
|
|
'name' => '_shieldon_csrf', |
86
|
|
|
'value' => $request->getAttribute('_shieldon_csrf'), |
87
|
|
|
]) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$response = $firewall->run(); |
91
|
|
|
|
92
|
|
|
if ($response->getStatusCode() !== 200) { |
93
|
|
|
$httpResolver = new HttpResolver(); |
94
|
|
|
$httpResolver($response); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $handler->handle($request); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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