Skip to content

Commit

Permalink
Merge pull request #1 from LTC-fperrin/master
Browse files Browse the repository at this point in the history
Check IP with Symfony HttpFoundation IpUtils to allow the use of a netmask in the allowed IPs
  • Loading branch information
kmadejski authored Jan 12, 2020
2 parents 8841e32 + 8392ca9 commit 3d3efa1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ezpublish:
default:
maintenance_mode:
enabled: true
allowed_ips: ['::1', '10.0.0.1']
allowed_ips: ['::1', '10.0.0.1', '192.168.0.0/16']
response_code: 404
template: '@Acme/custom_maintenance.html.twig'
```
3 changes: 2 additions & 1 deletion src/bundle/Event/Subscriber/MaintenanceModeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function onKernelRequest(GetResponseEvent $event): void

$allowedIps = $this->configResolver->getParameter('maintenance_mode.allowed_ips');

if (\in_array($request->getClientIp(), $allowedIps, true)) {
if (IpUtils::checkIp($request->getClientIp(), $allowedIps)) {
return;
}

Expand Down

0 comments on commit 3d3efa1

Please sign in to comment.