1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\EventListener; |
15
|
|
|
|
16
|
|
|
use Eccube\Common\EccubeConfig; |
17
|
|
|
use Eccube\Request\Context; |
18
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
19
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
20
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
21
|
|
|
|
22
|
|
|
class IpAddrListener implements EventSubscriberInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var EccubeConfig |
26
|
|
|
*/ |
27
|
|
|
protected $eccubeConfig; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Context |
31
|
|
|
*/ |
32
|
|
|
protected $requestContext; |
33
|
|
|
|
34
|
|
|
public function __construct(EccubeConfig $eccubeConfig, Context $requestContext) |
35
|
|
|
{ |
36
|
|
|
$this->eccubeConfig = $eccubeConfig; |
37
|
|
|
$this->requestContext = $requestContext; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function onKernelRequest(GetResponseEvent $event) |
41
|
|
|
{ |
42
|
|
|
if (!$event->isMasterRequest()) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (!$this->requestContext->isAdmin()) { |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// IPアドレス許可リストを確認 |
51
|
|
|
$allowHosts = $this->eccubeConfig['eccube_admin_allow_hosts']; |
52
|
|
|
|
53
|
|
|
if (!empty($allowHosts) && array_search($event->getRequest()->getClientIp(), $allowHosts) === false) { |
54
|
|
|
throw new AccessDeniedHttpException(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// IPアドレス拒否リストを確認 |
58
|
|
|
$denyHosts = $this->eccubeConfig['eccube_admin_deny_hosts']; |
59
|
|
|
|
60
|
|
|
if (array_search($event->getRequest()->getClientIp(), $denyHosts) !== false) { |
61
|
|
|
throw new AccessDeniedHttpException(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function getSubscribedEvents() |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'kernel.request' => ['onKernelRequest', 512], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|