/** * {@inheritdoc} */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { $ip = $request->getClientIp(); if ($this->banIpManager->isBanned($ip)) { return new Response(SafeMarkup::format('@ip has been banned', ['@ip' => $ip]), 403); } return $this->httpKernel->handle($request, $type, $catch); }
/** * Response with 403 if the visitor's IP address is banned. * * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The Event to process. */ public function onKernelRequestBannedIpCheck(GetResponseEvent $event) { $ip = $event->getRequest()->getClientIp(); if ($this->manager->isBanned($ip)) { $response = new Response('Sorry, ' . String::checkPlain($ip) . ' has been banned.', 403); $event->setResponse($response); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $ip = trim($form_state->getValue('ip')); if ($this->ipManager->isBanned($ip)) { $form_state->setErrorByName('ip', $this->t('This IP address is already banned.')); } elseif ($ip == $this->getRequest()->getClientIP()) { $form_state->setErrorByName('ip', $this->t('You may not ban your own IP address.')); } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) { $form_state->setErrorByName('ip', $this->t('Enter a valid IP address.')); } }