You are here

function spam_blocked_ips_overview in Spam 5

Display a list of all IPs that have been blocked by the spam module.

1 string reference to 'spam_blocked_ips_overview'
spam_menu in ./spam.module
Implementation of hook_menu().

File

./spam.module, line 2680

Code

function spam_blocked_ips_overview() {
  drupal_set_title(t('Spam Module Blocked IPs'));
  $header = array(
    array(
      'data' => t('IP Address'),
      'field' => 'hostname',
    ),
    array(
      'data' => t('Last Seen'),
      'field' => 'timestamp',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Counter'),
      'field' => 'count',
    ),
  );

  // This SQL is *nasty*, so if you think you can do better, please be my guest!
  // This unfortunately has to be SQL because the pager module can't be told
  // how many rows we've got (so we can't do our own processing in PHP and
  // still get paging to work properly).
  $sql = "SELECT * FROM (SELECT DISTINCT x.hostname, x.timestamp, COUNT(x.hostname) AS count FROM (SELECT timestamp,hostname FROM {spam_tracker} WHERE probability>%d ORDER BY timestamp DESC) AS x GROUP BY x.hostname) AS y WHERE y.count>=%d";
  $arguments = array(
    variable_get('spam_threshold', 80),
    variable_get('spam_blacklist_ip', 2),
  );
  $count_sql = preg_replace('/^SELECT \\* /', 'SELECT count(hostname) ', $sql);
  $result = pager_query($sql . tablesort_sql($header), 50, 0, $count_sql, $arguments);
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      'data' => array(
        $log->hostname,
        format_date($log->timestamp, 'small'),
        $log->count,
      ),
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No log messages available.'),
        'colspan' => 6,
      ),
    );
  }
  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
}