Skip to content
Snippets Groups Projects

Resolve #3507242 "Display information from CrowdSec"

Compare and
6 files
+ 362
5
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -3,7 +3,8 @@
namespace Drupal\ip_info\Controller;
use Drupal\ban\BanIpManagerInterface;
use Drupal\dblog\Controller\DbLogController;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\PagerSelectExtender;
use Drupal\Core\Database\Query\TableSortExtender;
@@ -13,8 +14,9 @@ use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Link;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\dblog\Controller\DbLogController;
use Drupal\ip_info\Services\CrowdSecInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller for IP address.
@@ -28,6 +30,13 @@ class IpController extends DbLogController {
*/
protected $ipManager;
/**
* The CrowdSec service.
*
* @var \Drupal\ip_info\Services\CrowdSecInterface
*/
protected $crowdsec;
/**
* Constructs a new IpController object.
*
@@ -41,10 +50,27 @@ class IpController extends DbLogController {
* The form builder.
* @param \Drupal\ban\BanIpManagerInterface $ip_manager
* The ban IP manager.
* @param \Drupal\ip_info\Services\CrowdSecInterface $crowdsec
* The CrowdSec service.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, DateFormatterInterface $date_formatter, FormBuilderInterface $form_builder, BanIpManagerInterface $ip_manager) {
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, DateFormatterInterface $date_formatter, FormBuilderInterface $form_builder, BanIpManagerInterface $ip_manager, CrowdSecInterface $crowdsec) {
parent::__construct($database, $module_handler, $date_formatter, $form_builder);
$this->ipManager = $ip_manager;
$this->crowdsec = $crowdsec;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database'),
$container->get('module_handler'),
$container->get('date.formatter'),
$container->get('form_builder'),
$container->get('ban.ip_manager'),
$container->get('ip_info.crowdsec')
);
}
/**
@@ -95,6 +121,19 @@ class IpController extends DbLogController {
$lookup_services_links = rtrim($lookup_services_links, ', ');
$build['dblog_filter_form']['#prefix'] .= '<p>' . $this->t('Lookup the IP:') . ' ' . $lookup_services_links . '</p>';
// Get IP data from the CrowdSec CTI API.
if (!empty($crowdsec_data = $this->crowdsec->getAllData($ip_address))) {
$build['cti_label'] = [
'#type' => 'markup',
'#markup' => '<h3>' . $this->t('CrowdSec CTI data') . '</h3>',
];
$build['cti_table'] = [
'#type' => 'table',
'#rows' => $crowdsec_data,
'#attributes' => ['id' => 'admin-cti', 'class' => ['admin-list']],
];
}
// Get IP data from IPinfo.io API.
if (
($ip_info_settings = Settings::get('ip_info')) &&
Loading