You are here

function _httpbl_cache_update in http:BL 7

Same name and namespace in other branches
  1. 5 httpbl.module \_httpbl_cache_update()
  2. 6.2 httpbl.module \_httpbl_cache_update()
  3. 6 httpbl.module \_httpbl_cache_update()
1 call to _httpbl_cache_update()
httpbl_request_whitelist_validate in ./httpbl.module
Validate session whitelist request. Ban the user if the 'forbidden' field was filled in.

File

./httpbl.module, line 656
Implementation of http:BL for Drupal. It provides IP-based blacklisting through http:BL and allows linking to a honeypot.

Code

function _httpbl_cache_update($ip, $status, $offset = 0) {
  $txn = db_transaction();
  db_update('httpbl')
    ->fields(array(
    'status' => $status,
    'expire' => REQUEST_TIME + $offset,
  ))
    ->condition('hostname', $ip, '=')
    ->execute();
  if ($status == HTTPBL_LIST_BLACK && variable_get('httpbl_cache', HTTPBL_CACHE_DBDRUPAL) == HTTPBL_CACHE_DBDRUPAL) {
    if (_httpbl_banned_check($ip)) {
      if ($logs = variable_get('httpbl_log', HTTPBL_LOG_MIN)) {
        watchdog('httpbl', 'This IP (%ip) was already banned', array(
          '%ip' => $ip,
        ), WATCHDOG_WARNING, NULL);
      }
      drupal_set_message(t('IP address ( %ip ) currently banned from this site.', array(
        '%ip' => $ip,
      )), 'error', FALSE);
    }
    else {
      db_insert('blocked_ips')
        ->fields(array(
        'ip' => $ip,
      ))
        ->execute();
      if ($logs = variable_get('httpbl_log', HTTPBL_LOG_MIN)) {
        watchdog('httpbl', 'Banned IP (%ip).', array(
          '%ip' => $ip,
        ), WATCHDOG_WARNING, NULL);
      }
      drupal_set_message(t('Your IP address ( %ip ) has been banned from this site.', array(
        '%ip' => $ip,
      )), 'error', FALSE);
    }
  }
}