/** * {@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); } }
/** * Tests an unbanned IP. */ public function testUnbannedIp() { $unbanned_ip = '18.0.0.2'; $this->banManager->expects($this->once())->method('isBanned')->with($unbanned_ip)->willReturn(FALSE); $request = Request::create('/test-path'); $request->server->set('REMOTE_ADDR', $unbanned_ip); $expected_response = new Response(200); $this->kernel->expects($this->once())->method('handle')->with($request, HttpKernelInterface::MASTER_REQUEST, TRUE)->willReturn($expected_response); $response = $this->banMiddleware->handle($request); $this->assertSame($expected_response, $response); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $ip = trim($form_state->getValue('ip')); $this->ipManager->banIp($ip); drupal_set_message($this->t('The IP address %ip has been banned.', array('%ip' => $ip))); $form_state->setRedirect('ban.admin_page'); }
/** * Executes the action with the given context. * * @param string $ip * (optional) The IP address that should be banned. */ protected function doExecute($ip = NULL) { if (!isset($ip)) { $ip = $this->request->getClientIp(); } $this->banManager->banIp($ip); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $ip = trim($form_state['values']['ip']); $this->ipManager->banIp($ip); drupal_set_message($this->t('The IP address %ip has been banned.', array('%ip' => $ip))); $form_state['redirect_route']['route_name'] = 'ban.admin_page'; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->ipManager->unbanIp($this->banIp); $this->logger('user')->notice('Deleted %ip', array('%ip' => $this->banIp)); drupal_set_message($this->t('The IP address %ip was deleted.', array('%ip' => $this->banIp))); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * Tests the action execution without Context IP set. * * Should fallback to the current IP of the request. * * @covers ::execute */ public function testActionExecutionWithoutContextIP() { // TEST-NET-1 IPv4. $ip = '192.0.2.0'; $this->request->getClientIp()->willReturn($ip)->shouldBeCalledTimes(1); $this->banManager->banIp($ip)->shouldBeCalledTimes(1); $this->action->execute(); }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $this->banManager->banIp($row->getDestinationProperty('ip')); }