コード例 #1
0
ファイル: BanMiddleware.php プロジェクト: ddrozdik/dmaps
 /**
  * {@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);
 }
コード例 #2
0
 /**
  * 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);
     }
 }
コード例 #3
0
ファイル: BanMiddlewareTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * 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);
 }
コード例 #4
0
ファイル: BanAdmin.php プロジェクト: ddrozdik/dmaps
 /**
  * {@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');
 }
コード例 #5
0
ファイル: BanIP.php プロジェクト: Progressable/openway8
 /**
  * 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);
 }
コード例 #6
0
ファイル: BanAdmin.php プロジェクト: alnutile/drunatra
 /**
  * {@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';
 }
コード例 #7
0
ファイル: BanDelete.php プロジェクト: eigentor/tommiblog
 /**
  * {@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());
 }
コード例 #8
0
ファイル: BanIPTest.php プロジェクト: shahinam/drupal8devel
 /**
  * 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();
 }
コード例 #9
0
ファイル: BlockedIp.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $this->banManager->banIp($row->getDestinationProperty('ip'));
 }