You are here

function _flood_unblock_get_entries in Flood Unblock 7

Generate rows from the entries in the flood table.

Return value

array Entries in the flood table.

1 call to _flood_unblock_get_entries()
flood_unblock_settings in ./flood_unblock.admin.inc
The settings form function.

File

./flood_unblock.admin.inc, line 142
Admin page callbacks for the flood_unblock module.

Code

function _flood_unblock_get_entries() {
  $entries = array();
  $query = db_select('flood', 'f');
  $query
    ->addField('f', 'identifier');
  $query
    ->addField('f', 'identifier', 'ip');
  $query
    ->addExpression('count(*)', 'count');
  $query
    ->condition('f.event', 'failed_login_attempt_ip');
  $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 = '';
    }
    $entries[$result->identifier] = array(
      'type' => 'ip',
      'ip' => $result->ip,
      'count' => $result->count,
      'location' => $location_string,
    );
  }

  // TODO: Rebuild this query to a dynamic query.
  $sql = "SELECT identifier, count(*) count FROM {flood} WHERE event='failed_login_attempt_user' group by identifier";
  $results = db_query($sql);
  foreach ($results as $result) {
    $parts = explode('-', $result->identifier);
    $result->uid = $parts[0];
    $result->ip = $parts[1];
    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 = '';
    }
    $user = user_load($result->uid);
    $entries[$result->identifier] = array(
      'type' => 'user',
      'uid' => $result->uid,
      'ip' => $result->ip,
      'username' => l($user->name, 'user/' . $user->uid),
      'count' => $result->count,
      'location' => $location_string,
    );
  }
  return $entries;
}