You are here

public function FloodUnblockManager::get_blocked_ip_entries in Flood Unblock 8

Same name and namespace in other branches
  1. 8.2 src/FloodUnblockManager.php \Drupal\flood_unblock\FloodUnblockManager::get_blocked_ip_entries()

Generate rows from the entries in the flood table.

Return value

array Ip blocked entries in the flood table.

File

src/FloodUnblockManager.php, line 65

Class

FloodUnblockManager

Namespace

Drupal\flood_unblock

Code

public function get_blocked_ip_entries() {
  $entries = [];
  if ($this->database
    ->schema()
    ->tableExists('flood')) {
    $query = $this->database
      ->select('flood', 'f');
    $query
      ->addField('f', 'identifier');
    $query
      ->addField('f', 'identifier', 'ip');
    $query
      ->addExpression('count(*)', 'count');
    $query
      ->condition('f.event', '%failed_login_ip', 'LIKE');
    $query
      ->groupBy('identifier');
    $results = $query
      ->execute();
    foreach ($results as $result) {
      if (function_exists('smart_ip_get_location')) {
        $location = smart_ip_get_location($result->ip);
        $location_string = sprintf(" (%s %s %s)", $location['city'], $location['region'], $location['country_code']);
      }
      else {
        $location_string = '';
      }
      $blocked = !$this->flood
        ->isAllowed('user.failed_login_ip', $this->config
        ->get('ip_limit'), $this->config
        ->get('ip_window'), $result->ip);
      $entries[$result->identifier] = [
        'type' => 'ip',
        'ip' => $result->ip,
        'count' => $result->count,
        'location' => $location_string,
        'blocked' => $blocked,
      ];
    }
  }
  return $entries;
}