You are here

function spambot_account_ip_addresses in Spambot 7

Same name and namespace in other branches
  1. 8 spambot.module \spambot_account_ip_addresses()
  2. 6.3 spambot.module \spambot_account_ip_addresses()

Retrieves a list of IP addresses for an account.

Parameters

object $account: Account to retrieve IP addresses for.

Return value

array An array of IP addresses, or an empty array if none found

2 calls to spambot_account_ip_addresses()
spambot_account_is_spammer in ./spambot.module
Checks an account to see if it's a spammer.
_spambot_user_spam_admin_form_submit_check in ./spambot.pages.inc
Do complex checking at this user account.

File

./spambot.module, line 521
Main module file.

Code

function spambot_account_ip_addresses($account) {
  $hostnames = array();

  // Retrieve IPs from node_spambot table.
  $items = db_select('node_spambot')
    ->distinct()
    ->fields('node_spambot', array(
    'hostname',
  ))
    ->condition('uid', $account->uid, '=')
    ->execute()
    ->fetchCol();
  $hostnames = array_merge($hostnames, $items);

  // Retrieve IPs from any sessions which may still exist.
  $items = db_select('sessions')
    ->distinct()
    ->fields('sessions', array(
    'hostname',
  ))
    ->condition('uid', $account->uid, '=')
    ->execute()
    ->fetchCol();
  $hostnames = array_merge($hostnames, $items);

  // Retrieve IPs from comments.
  if (module_exists('comment')) {
    $items = db_select('comment')
      ->distinct()
      ->fields('comment', array(
      'hostname',
    ))
      ->condition('uid', $account->uid, '=')
      ->execute()
      ->fetchCol();
    $hostnames = array_merge($hostnames, $items);
  }

  // Retrieve IPs from statistics.
  if (module_exists('statistics')) {
    $items = db_select('accesslog')
      ->distinct()
      ->fields('accesslog', array(
      'hostname',
    ))
      ->condition('uid', $account->uid, '=')
      ->execute()
      ->fetchCol();
    $hostnames = array_merge($hostnames, $items);
  }

  // Retrieve IPs from user stats.
  if (module_exists('user_stats')) {
    $items = db_select('user_stats_ips')
      ->distinct()
      ->fields('user_stats_ips', array(
      'ip_address',
    ))
      ->condition('uid', $account->uid, '=')
      ->execute()
      ->fetchCol();
    $hostnames = array_merge($hostnames, $items);
  }

  // Retrieve IPs from IP address manager.
  if (module_exists('ip')) {
    $items = db_select('ip_tracker')
      ->distinct()
      ->fields('ip_tracker', [
      'ip',
    ])
      ->condition('uid', $account->uid, '=')
      ->execute()
      ->fetchCol();
    $rows = array();
    foreach ($items as $row) {
      if (isset($row->ip)) {
        $row->ip = long2ip($row->ip);
        $rows[] = $row;
      }
    }
    $hostnames = array_merge($hostnames, $rows);
  }
  $hostnames = array_unique($hostnames);
  return $hostnames;
}